@@ -409,6 +409,71 @@ The SYCL kernel in the previous code sample meets these expectations.
409
409
}];
410
410
}
411
411
412
+ def SYCLSpecialClassDocs : Documentation {
413
+ let Category = DocCatStmt;
414
+ let Content = [{
415
+ SYCL defines some special classes (accessor, sampler, and stream) which require
416
+ specific handling during the generation of the SPIR entry point.
417
+ The ``__attribute__((sycl_special_class))`` attribute is used in SYCL
418
+ headers to indicate that a class or a struct needs a specific handling when
419
+ it is passed from host to device.
420
+ Special classes will have a mandatory ``__init`` method and an optional
421
+ ``__finalize`` method (the ``__finalize`` method is used only with the
422
+ ``stream`` type). Kernel parameters types are extract from the ``__init`` method
423
+ parameters. The kernel function arguments list is derived from the
424
+ arguments of the ``__init`` method. The arguments of the ``__init`` method are
425
+ copied into the kernel function argument list and the ``__init`` and
426
+ ``__finalize`` methods are called at the beginning and the end of the kernel,
427
+ respectively.
428
+ The ``__init`` and ``__finalize`` methods must be defined inside the
429
+ special class.
430
+ Please note that this is an attribute that is used as an internal
431
+ implementation detail and not intended to be used by external users.
432
+
433
+ The syntax of the attribute is as follows:
434
+
435
+ .. code-block:: c++
436
+
437
+ class __attribute__((sycl_special_class)) accessor {};
438
+ class [[clang::sycl_special_class]] accessor {};
439
+
440
+ This is a code example that illustrates the use of the attribute:
441
+
442
+ .. code-block:: c++
443
+
444
+ class __attribute__((sycl_special_class)) SpecialType {
445
+ int F1;
446
+ int F2;
447
+ void __init(int f1) {
448
+ F1 = f1;
449
+ F2 = f1;
450
+ }
451
+ void __finalize() {}
452
+ public:
453
+ SpecialType() = default;
454
+ int getF2() const { return F2; }
455
+ };
456
+
457
+ int main () {
458
+ SpecialType T;
459
+ cgh.single_task([=] {
460
+ T.getF2();
461
+ });
462
+ }
463
+
464
+ This would trigger the following kernel entry point in the AST:
465
+
466
+ .. code-block:: c++
467
+
468
+ void __sycl_kernel(int f1) {
469
+ SpecialType T;
470
+ T.__init(f1);
471
+ ...
472
+ T.__finalize()
473
+ }
474
+ }];
475
+ }
476
+
412
477
def C11NoReturnDocs : Documentation {
413
478
let Category = DocCatFunction;
414
479
let Content = [{
0 commit comments