@@ -174,10 +174,10 @@ using sycl::ext::oneapi;
174
174
accessor acc(buf, cgh, property_list{no_alias_v, foo_v<32>});
175
175
```
176
176
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
181
181
names of the properties and the subsequent parameters are the property values.
182
182
183
183
```
@@ -205,13 +205,18 @@ class __attribute__((sycl_special_class)) accessor<dataT,
205
205
accessTarget,
206
206
isPlaceholder,
207
207
property_list<Props...>> {
208
- dataT *ptr
208
+ dataT *ptr;
209
+
209
210
#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
+ }
213
218
#endif
214
- ;
219
+
215
220
};
216
221
217
222
} // namespace sycl
@@ -224,37 +229,37 @@ namespace sycl {
224
229
225
230
template </* ... */>
226
231
class __attribute__((sycl_special_class)) accessor</* ... */> {
227
- dataT *ptr
232
+ dataT *ptr;
233
+
228
234
#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
+ }
235
245
#endif
236
- ;
237
246
};
238
247
239
248
} // namespace sycl
240
249
```
241
250
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.
251
256
252
257
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
255
260
` [[__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
258
263
[ ` Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &) ` ] [ 7 ] . As
259
264
before, the IR attributes are added as strings, so the front-end must convert
260
265
the property value to a string if it is not already a string.
@@ -337,12 +342,12 @@ class KernelSingleTaskWrapper<KernelType, property_list<Props...>> {
337
342
KernelSingleTaskWrapper(KernelType k) : k(k) {}
338
343
339
344
#ifdef __SYCL_DEVICE_ONLY__
340
- __attribute__(( sycl_kernel))
345
+ [[clang:: sycl_kernel]]
341
346
[[__sycl_detail__::add_ir_attributes_function(
342
347
Props::meta_name..., Props::meta_value...
343
348
)]]
344
349
#endif
345
- void operator()() {k();}
350
+ void operator()() const {k();}
346
351
};
347
352
```
348
353
@@ -361,7 +366,7 @@ string if it is not already a string.
361
366
` handler::kernel_single_task() ` with wrapper classes like
362
367
` KernelSingleTaskWrapper ` . We believe this will not cause problems for the
363
368
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
365
370
` handler::kernel_single_task() ` .
366
371
367
372
@@ -658,13 +663,6 @@ class __attribute__((sycl_special_class)) accessor<dataT,
658
663
property_list<Props...>> {
659
664
T *ptr
660
665
#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
- )]]
668
666
[[__sycl_detail__::add_ir_annotations_member(
669
667
670
668
// The properties in this list are "member annotations".
@@ -674,6 +672,20 @@ class __attribute__((sycl_special_class)) accessor<dataT,
674
672
)]]
675
673
#endif
676
674
;
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
677
689
}
678
690
```
679
691
0 commit comments