Skip to content

Commit 7187f7b

Browse files
authored
[SYCL] Add support for 'sycl_special_class' attribute. (#3892)
Special classes such as accessor, sampler, and stream need additional implementation when they are passed from host to device. Currently the compiler recognizes these classes by their name. This patch is adding a new attribute “sycl_special_class” used to mark SYCL classes that need the additional compiler handling. Usage: ```c++ class __attribute__((sycl_special_class)) class special_class { ... }; ``` Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
1 parent bc8a00a commit 7187f7b

File tree

13 files changed

+241
-396
lines changed

13 files changed

+241
-396
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,13 @@ def SYCLKernel : InheritableAttr {
12331233
let Documentation = [SYCLKernelDocs];
12341234
}
12351235

1236+
def SYCLSpecialClass: InheritableAttr {
1237+
let Spellings = [Clang<"sycl_special_class">];
1238+
let Subjects = SubjectList<[CXXRecord]>;
1239+
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
1240+
let Documentation = [SYCLSpecialClassDocs];
1241+
}
1242+
12361243
// Marks functions which must not be vectorized via horizontal SIMT widening,
12371244
// e.g. because the function is already vectorized. Used to mark SYCL
12381245
// explicit SIMD kernels and functions.

clang/include/clang/Basic/AttrDocs.td

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,26 @@ The SYCL kernel in the previous code sample meets these expectations.
405405
}];
406406
}
407407

408+
def SYCLSpecialClassDocs : Documentation {
409+
let Category = DocCatStmt;
410+
let Content = [{
411+
The ``__attribute__((sycl_special_class))`` attribute is used in SYCL
412+
headers to indicate that a class or a struct needs additional handling when
413+
it is passed from host to device. Please note that this is an attribute that is
414+
used for internal implementation and not intended to be used by external users.
415+
It is used for ``accessor``, ``sampler`` , or ``stream`` classes.
416+
The types that own this attribute are excluded from device-copyable and other
417+
type-legalization steps.
418+
419+
.. code-block:: c++
420+
class __attribute__((sycl_special_class)) accessor {
421+
422+
private:
423+
void __init() {}
424+
};
425+
}];
426+
}
427+
408428
def SYCLSimdDocs : Documentation {
409429
let Category = DocCatFunction;
410430
let Content = [{

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9796,6 +9796,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
97969796
case ParsedAttr::AT_SYCLSimd:
97979797
handleSimpleAttribute<SYCLSimdAttr>(S, D, AL);
97989798
break;
9799+
case ParsedAttr::AT_SYCLSpecialClass:
9800+
handleSimpleAttribute<SYCLSpecialClassAttr>(S, D, AL);
9801+
break;
97999802
case ParsedAttr::AT_SYCLDevice:
98009803
handleSYCLDeviceAttr(S, D, AL);
98019804
break;

0 commit comments

Comments
 (0)