Skip to content

Commit 6e79f42

Browse files
[ESIMD] Mark ESIMD globals with sycl_explicit_simd attribute (#3348)
[ESIMD] Mark ESIMD globals with sycl_explicit_simd attribute This patch is a part of the efforts for allowing ESIMD and regular SYCL kernels to coexist in the same translation unit and in the same program. There are differences in semantic analysis of global variables used in ESIMD and regular SYCL kernels. One such difference is that ESIMD does not permit private global variable to have an initializer. Before this patch we used -fsycl-explicit-simd compiler flag to differentiate globals used in ESIMD and regular kernels. With this change we mark ESIMD globals with sycl_explicit_simd attribute. So, the goal of this change is to remove dependency on compiler option, while preserving the same behavior in semantic analysis. Co-authored-by: Aaron Ballman <[email protected]>
1 parent e0455ee commit 6e79f42

File tree

8 files changed

+29
-16
lines changed

8 files changed

+29
-16
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def SYCLKernel : InheritableAttr {
11911191
def SYCLSimd : InheritableAttr {
11921192
let Spellings = [GNU<"sycl_explicit_simd">,
11931193
CXX11<"intel", "sycl_explicit_simd">];
1194-
let Subjects = SubjectList<[Function]>;
1194+
let Subjects = SubjectList<[Function, GlobalVar]>;
11951195
let LangOpts = [SYCLExplicitSIMD];
11961196
let Documentation = [SYCLSimdDocs];
11971197
let SupportsNonconformingLambdaSyntax = 1;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ def SYCLSimdDocs : Documentation {
360360
let Category = DocCatFunction;
361361
let Content = [{
362362
The ``__attribute__((sycl_explicit_simd))`` attribute is used by the device
363-
compiler front end to mark kernels and functions to be compiled and executed
364-
in the explicit SIMD mode. In this mode subgroup size is always 1 and
365-
explicit SIMD extensions - such as manual vectorization using wide vector
366-
data types and operations can be used. Compiler may decide to compile such
367-
functions using different optimization and code generation
368-
pipeline.
363+
compiler front end to mark ESIMD kernels and functions. In this mode,
364+
subgroup size is always equal to 1 and explicit SIMD extensions, such as
365+
manual vectorization using wide vector data types and operations can be used.
366+
The compiler may decide to compile such functions using different optimization
367+
and code generation pipeline. Also, this attribute is used to distinguish
368+
ESIMD private globals from regular SYCL global variables.
369369
}];
370370
}
371371

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13082,7 +13082,7 @@ class Sema final {
1308213082
/// Tells whether given variable is a SYCL explicit SIMD extension's "private
1308313083
/// global" variable - global variable in the private address space.
1308413084
bool isSYCLEsimdPrivateGlobal(VarDecl *VDecl) {
13085-
return getLangOpts().SYCLIsDevice && getLangOpts().SYCLExplicitSIMD &&
13085+
return getLangOpts().SYCLIsDevice && VDecl->hasAttr<SYCLSimdAttr>() &&
1308613086
VDecl->hasGlobalStorage() &&
1308713087
(VDecl->getType().getAddressSpace() == LangAS::opencl_private);
1308813088
}

clang/test/CodeGenSYCL/esimd-private-global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// This test checks that FE allows globals with register_num attribute in ESIMD mode.
1212

13-
__attribute__((opencl_private)) __attribute__((register_num(17))) int vc;
13+
__attribute__((opencl_private)) __attribute__((sycl_explicit_simd)) __attribute__((register_num(17))) int vc;
1414
// CHECK: @vc = {{.+}} i32 0, align 4 #0
1515

1616
template <typename name, typename Func>

clang/test/Misc/pragma-attribute-supported-attributes-list.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
// CHECK-NEXT: SYCLIntelSchedulerTargetFmaxMhz (SubjectMatchRule_function)
163163
// CHECK-NEXT: SYCLIntelUseStallEnableClusters (SubjectMatchRule_function)
164164
// CHECK-NEXT: SYCLRegisterNum (SubjectMatchRule_variable_is_global)
165-
// CHECK-NEXT: SYCLSimd (SubjectMatchRule_function)
165+
// CHECK-NEXT: SYCLSimd (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
166166
// CHECK-NEXT: ScopedLockable (SubjectMatchRule_record)
167167
// CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
168168
// CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)

clang/test/SemaSYCL/esimd-private-global.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
// RUN: %clang_cc1 -fsycl-is-device -fsycl-explicit-simd -fsyntax-only -verify -pedantic %s
22

3+
// This test checks specifics of semantic analysis of ESIMD private globals
4+
5+
// No error expected. SYCL private globals are allowed to have initializers
6+
__attribute__((opencl_private)) int syclPrivGlob;
7+
__attribute__((opencl_private)) int syclPrivGlobInit = 10;
8+
9+
// expected-error@+1{{SYCL explicit SIMD does not permit private global variable to have an initializer}}
10+
__attribute__((opencl_private)) __attribute__((sycl_explicit_simd)) int esimdPrivGlobInit = 10;
11+
12+
// No error expected. ESIMD private globals without initializers are OK
13+
__attribute__((opencl_private)) __attribute__((sycl_explicit_simd)) int esimdPrivGlob;
14+
315
// no error expected
416
__attribute__((opencl_private)) __attribute__((register_num(17))) int privGlob;
517

@@ -9,9 +21,6 @@ __attribute__((opencl_private)) __attribute__((register_num())) int privGlob1;
921
// expected-error@+1{{'register_num' attribute takes one argument}}
1022
__attribute__((opencl_private)) __attribute__((register_num(10, 11))) int privGlob2;
1123

12-
// expected-error@+1{{SYCL explicit SIMD does not permit private global variable to have an initializer}}
13-
__attribute__((opencl_private)) int privGlob3 = 10;
14-
1524
void foo() {
1625
// expected-warning@+1{{'register_num' attribute only applies to global variables}}
1726
__attribute__((register_num(17))) int privLoc;

clang/test/SemaSYCL/sycl-esimd.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// RUN: %clang_cc1 -fsycl-is-device -fsycl-explicit-simd -fsyntax-only -Wno-sycl-2017-compat -verify %s
22

3+
// This test checks specifics of semantic analysis of ESIMD kernels.
4+
35
// ----------- Negative tests
46

5-
__attribute__((sycl_explicit_simd)) // expected-warning {{'sycl_explicit_simd' attribute only applies to functions}}
6-
int N;
7+
void foo(
8+
__attribute__((sycl_explicit_simd)) // expected-warning {{'sycl_explicit_simd' attribute only applies to functions and global variables}}
9+
int N);
710

811
__attribute__((sycl_explicit_simd(3))) // expected-error {{'sycl_explicit_simd' attribute takes no arguments}}
912
void

sycl/include/CL/sycl/INTEL/esimd/esimd_enum.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ using uint = unsigned int;
2828
// Mark a "ESIMD global": accessible from all functions in current translation
2929
// unit, separate copy per subgroup (work-item), mapped to SPIR-V private
3030
// storage class.
31-
#define ESIMD_PRIVATE __attribute__((opencl_private))
31+
#define ESIMD_PRIVATE \
32+
__attribute__((opencl_private)) __attribute__((sycl_explicit_simd))
3233
// Bind a ESIMD global variable to a specific register.
3334
#define ESIMD_REGISTER(n) __attribute__((register_num(n)))
3435
#else

0 commit comments

Comments
 (0)