Skip to content

Commit 2359e81

Browse files
[SYCL][Doc] Kernel parameter attribute change in compile-time properties design doc (#5341)
This commit changes the use of `__sycl_detail__::add_ir_attributes_kernel_parameter` to be on `__init` parameters rather than member variables. This simplifies the propagation of the attribute as it is closer to how the frontend generates kernel function parameters. Additionally this commit makes some minor corrections. Signed-off-by: Steffen Larsen <[email protected]>
1 parent 1f8874f commit 2359e81

File tree

1 file changed

+52
-40
lines changed

1 file changed

+52
-40
lines changed

sycl/doc/CompileTimeProperties.md

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ using sycl::ext::oneapi;
174174
accessor acc(buf, cgh, property_list{no_alias_v, foo_v<32>});
175175
```
176176

177-
The implementation in the header file is similar to the previous case. The
178-
C++ attribute `[[__sycl_detail__::add_ir_attributes_kernel_parameter()]]`
179-
decorates one of the member variables of the class, and the parameters to this
180-
attribute represent the properties. As before, the initial parameters are the
177+
In the headers the C++ attribute
178+
`[[__sycl_detail__::add_ir_attributes_kernel_parameter()]]` is used to decorate
179+
parameters of the `__init` member function in the corresponding
180+
`sycl_special_class` decorated class. As before, the initial parameters are the
181181
names of the properties and the subsequent parameters are the property values.
182182

183183
```
@@ -205,13 +205,18 @@ class __attribute__((sycl_special_class)) accessor<dataT,
205205
accessTarget,
206206
isPlaceholder,
207207
property_list<Props...>> {
208-
dataT *ptr
208+
dataT *ptr;
209+
209210
#ifdef __SYCL_DEVICE_ONLY__
210-
[[__sycl_detail__::add_ir_attributes_kernel_parameter(
211-
Props::meta_name..., Props::meta_value...
212-
)]]
211+
void __init(
212+
[[__sycl_detail__::add_ir_attributes_kernel_parameter(
213+
Props::meta_name..., Props::meta_value...
214+
)]]
215+
dataT *_ptr) {
216+
ptr = _ptr;
217+
}
213218
#endif
214-
;
219+
215220
};
216221
217222
} // namespace sycl
@@ -224,37 +229,37 @@ namespace sycl {
224229
225230
template </* ... */>
226231
class __attribute__((sycl_special_class)) accessor</* ... */> {
227-
dataT *ptr
232+
dataT *ptr;
233+
228234
#ifdef __SYCL_DEVICE_ONLY__
229-
[[__sycl_detail__::add_ir_attributes_kernel_parameter(
230-
"sycl-no-alias", // Name of first property
231-
"sycl-foo", // Name of second property
232-
nullptr, // First property has no parameter
233-
32 // Value of second property
234-
)]]
235+
void __init(
236+
[[__sycl_detail__::add_ir_attributes_kernel_parameter(
237+
"sycl-no-alias", // Name of first property
238+
"sycl-foo", // Name of second property
239+
nullptr, // First property has no parameter
240+
32 // Value of second property
241+
)]]
242+
dataT *_ptr) {
243+
ptr = _ptr;
244+
}
235245
#endif
236-
;
237246
};
238247
239248
} // namespace sycl
240249
```
241250

242-
As the name implies, this C++ attribute is only used to decorate a member
243-
variable of a class type that is as SYCL "special class" (i.e. a class that is
244-
decorated with `__attribute__((sycl_special_class))`). The device compiler
245-
front-end ignores the attribute when it is used in any other syntactic
246-
position.
247-
248-
The device compiler front-end uses this attribute only when the class type
249-
containing the decorated member variable is the type of a kernel argument,
250-
and it silently ignores the attribute when the class is used in any other way.
251+
As the name implies, this C++ attribute is only used to decorate parameters of
252+
the `__init` member function of a class type that is as SYCL "special class"
253+
(i.e. a class that is decorated with `__attribute__((sycl_special_class))`).
254+
The device compiler front-end ignores the attribute when it is used in any
255+
other syntactic position.
251256

252257
When the front-end creates a kernel argument from a SYCL "special class", it
253-
passes each member variable of the class as a separate kernel argument. If the
254-
member variable is decorated with
258+
copies all parameters of the `__init` member function to the corresponding
259+
kernel function. If a copied parameter is decorated with
255260
`[[__sycl_detail__::add_ir_attributes_kernel_parameter()]]`, the front-end adds
256-
one LLVM IR attribute to the kernel function's parameter for each property in
257-
the list. For example, this can be done by calling
261+
one LLVM IR attribute to the resulting kernel function parameter for each
262+
property in the list. For example, this can be done by calling
258263
[`Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &)`][7]. As
259264
before, the IR attributes are added as strings, so the front-end must convert
260265
the property value to a string if it is not already a string.
@@ -337,12 +342,12 @@ class KernelSingleTaskWrapper<KernelType, property_list<Props...>> {
337342
KernelSingleTaskWrapper(KernelType k) : k(k) {}
338343
339344
#ifdef __SYCL_DEVICE_ONLY__
340-
__attribute__((sycl_kernel))
345+
[[clang::sycl_kernel]]
341346
[[__sycl_detail__::add_ir_attributes_function(
342347
Props::meta_name..., Props::meta_value...
343348
)]]
344349
#endif
345-
void operator()() {k();}
350+
void operator()() const {k();}
346351
};
347352
```
348353

@@ -361,7 +366,7 @@ string if it is not already a string.
361366
`handler::kernel_single_task()` with wrapper classes like
362367
`KernelSingleTaskWrapper`. We believe this will not cause problems for the
363368
device compiler front-end because it recognizes kernel functions via the
364-
`__attribute__((sycl_kernel))` attribute, not by the name
369+
`[[clang::sycl_kernel]]` attribute, not by the name
365370
`handler::kernel_single_task()`.
366371

367372

@@ -658,13 +663,6 @@ class __attribute__((sycl_special_class)) accessor<dataT,
658663
property_list<Props...>> {
659664
T *ptr
660665
#ifdef __SYCL_DEVICE_ONLY__
661-
[[__sycl_detail__::add_ir_attributes_kernel_parameter(
662-
663-
// The properties in this list are "kernel parameter attributes".
664-
{"sycl-no-alias", "sycl-foo"},
665-
666-
Props::meta_name..., Props::meta_value...
667-
)]]
668666
[[__sycl_detail__::add_ir_annotations_member(
669667
670668
// The properties in this list are "member annotations".
@@ -674,6 +672,20 @@ class __attribute__((sycl_special_class)) accessor<dataT,
674672
)]]
675673
#endif
676674
;
675+
676+
#ifdef __SYCL_DEVICE_ONLY__
677+
void __init(
678+
[[__sycl_detail__::add_ir_attributes_kernel_parameter(
679+
680+
// The properties in this list are "kernel parameter attributes".
681+
{"sycl-no-alias", "sycl-foo"},
682+
683+
Props::meta_name..., Props::meta_value...
684+
)]]
685+
dataT *_ptr) {
686+
ptr = _ptr;
687+
}
688+
#endif
677689
}
678690
```
679691

0 commit comments

Comments
 (0)