Skip to content

Commit 7b51265

Browse files
committed
Add kernel_handler proposal to support the specialization constant
The best way to have specialization constant implementable as a library is to rely on a kernel side handler. This handler can also be extended to handle barrier or other functionalities. Signed-off-by: Victor Lomuller <[email protected]>
1 parent 6af24fd commit 7b51265

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

spec-constant/sycl_kernel_handler.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# SYCL kernel_handle
2+
3+
| | |
4+
| ---------------- | ---------------------------------------|
5+
| Name | kernel_handle |
6+
| Date of creation | 17th Feb 2020 |
7+
| Last updated | 17th Feb 2020 |
8+
| Status | WIP |
9+
| Current revision | 1 |
10+
| Available | N/A |
11+
| Reply-to | Victor Lomuller <[email protected]> |
12+
| Original author | Victor Lomuller <[email protected]> |
13+
| Contributors | TBD |
14+
15+
## Overview
16+
17+
The library implementation of certain device features require the use of a device side handler.
18+
This proposal introduces a `kernel_handler` to provide access to extra device capabilities implementable as a library.
19+
20+
## Motivation
21+
22+
The initial proposal of specialization constant forced the user to explicitly get individual `specialization_constant` objects that needed to be propagated in the final program.
23+
24+
Using a handler, the user has only 1 object to carry to access `specialization_constant` objects thus simplifying the interface.
25+
26+
For now, the proposal is limited to support specialization constant but can be extended to handle barriers or other functionalities.
27+
28+
## Revisions
29+
30+
v1:
31+
32+
* Initial proposal
33+
34+
## `sycl::kernel_handler`
35+
36+
The `sycl::kernel_handler` is a non-user constructible class only passed to user as an argument of the functor passed to `handler::parallel_for` and `handler::parallel_for_work_group`.
37+
38+
```cpp
39+
namespace sycl {
40+
class kernel_handler {
41+
private:
42+
kernel_handler();
43+
44+
public:
45+
46+
// Return the value associate with the specialization constant id `s`.
47+
// The value returned is either the
48+
template<class T, specialization_id<T>& s>
49+
T get_specialization_constant();
50+
51+
template<auto& s>
52+
typename std::remove_reference_t<decltype(s)>::type
53+
get_specialization_constant(const specialization_constant<typename std::remove_reference_t<decltype(s)>::type, s>&);
54+
55+
};
56+
}
57+
```
58+
59+
## Update `sycl::handler` class definition
60+
61+
Functor passed to `sycl::handler::single_task`, `sycl::handler::parallel_for` and `sycl::handler::parallel_for_work_group` can take an extra `sycl::kernel_handler` as extra by-value argument.
62+
63+
Below is an example of invoking a SYCL kernel function with `single_task`:
64+
65+
```cpp
66+
myQueue.submit([&](handler & cgh) {
67+
cgh.single_task<class myKernel>([=] () {});
68+
});
69+
```
70+
71+
or
72+
73+
```cpp
74+
myQueue.submit([&](handler & cgh) {
75+
cgh.single_task<class myKernel>([=] (sycl::kernel_handler h) {});
76+
});
77+
```
78+
79+
Below is an example of invoking a SYCL kernel function with `parallel_for`:
80+
81+
```cpp
82+
myQueue.submit([&](handler & cgh) {
83+
cgh.parallel_for<class myKernel>(range<1>(numWorkItems),
84+
[=] (id<1> index) {});
85+
});
86+
```
87+
88+
or
89+
90+
```cpp
91+
myQueue.submit([&](handler & cgh) {
92+
cgh.parallel_for<class myKernel>(range<1>(numWorkItems),
93+
[=] (id<1> index, sycl::kernel_handler h) {});
94+
});
95+
```

0 commit comments

Comments
 (0)