Skip to content

Commit 8fe0c4d

Browse files
authored
[SYCL] Use SPIR-V built-in function call for all targets and add BuiltIn to the name (#19359)
Before this PR, SPIR-V built-in is represented as global variable for SPIR/SPIR-V targets and as function call for other targets in include/sycl/__spirv/spirv_vars.hpp. According to https://github.com/llvm/llvm-project/blob/main/llvm/docs/SPIRVUsage.rst, SPIR-V built-in variable can be mapped to either function call or global variable. So function call representation should work for SPIR-V target as well. The benefit of choosing function call over global variable is that function call works better for AOT targets that bypass SPIR-V. It is easier for these targets to implements SPIR-V built-in function via built-in modules like libclc rather than special handling for lowering global variable in a custom pass. Add `BuiltIn` to the name to align with SPIR-V friendly IR and global variable name.
1 parent 7b2ac54 commit 8fe0c4d

File tree

92 files changed

+1251
-1819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1251
-1819
lines changed

libclc/libspirv/include/libspirv/async/common.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#define CLC_ASYNC_COMMON
1111

1212
#define SET_GROUP_SIZE_AND_ID(SIZE, ID) \
13-
SIZE = __spirv_WorkgroupSize_x() * __spirv_WorkgroupSize_y() * \
14-
__spirv_WorkgroupSize_z(); \
15-
ID = (__spirv_WorkgroupSize_y() * __spirv_WorkgroupSize_x() * \
16-
__spirv_LocalInvocationId_z()) + \
17-
(__spirv_WorkgroupSize_x() * __spirv_LocalInvocationId_y()) + \
18-
__spirv_LocalInvocationId_x();
13+
SIZE = __spirv_BuiltInWorkgroupSize(0) * __spirv_BuiltInWorkgroupSize(1) * \
14+
__spirv_BuiltInWorkgroupSize(2); \
15+
ID = (__spirv_BuiltInWorkgroupSize(1) * __spirv_BuiltInWorkgroupSize(0) * \
16+
__spirv_BuiltInLocalInvocationId(2)) + \
17+
(__spirv_BuiltInWorkgroupSize(0) * \
18+
__spirv_BuiltInLocalInvocationId(1)) + \
19+
__spirv_BuiltInLocalInvocationId(0);
1920

2021
// Macro used by all data types, for generic and nvidia, for async copy when
2122
// arch < sm80

libclc/libspirv/include/libspirv/workitem/get_global_offset.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_GlobalOffset_x();
10-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_GlobalOffset_y();
11-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_GlobalOffset_z();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInGlobalOffset(int);

libclc/libspirv/include/libspirv/workitem/get_global_size.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_GlobalSize_x();
10-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_GlobalSize_y();
11-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_GlobalSize_z();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInGlobalSize(int);

libclc/libspirv/include/libspirv/workitem/get_group_id.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_WorkgroupId_x();
10-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_WorkgroupId_y();
11-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_WorkgroupId_z();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInWorkgroupId(int);

libclc/libspirv/include/libspirv/workitem/get_local_id.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_LocalInvocationId_x();
10-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_LocalInvocationId_y();
11-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_LocalInvocationId_z();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInLocalInvocationId(int);

libclc/libspirv/include/libspirv/workitem/get_local_linear_id.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_LocalInvocationIndex();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInLocalInvocationIndex();

libclc/libspirv/include/libspirv/workitem/get_local_size.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_WorkgroupSize_x();
10-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_WorkgroupSize_y();
11-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_WorkgroupSize_z();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInWorkgroupSize(int);

libclc/libspirv/include/libspirv/workitem/get_max_sub_group_size.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize();
9+
_CLC_DEF _CLC_OVERLOAD uint __spirv_BuiltInSubgroupMaxSize();

libclc/libspirv/include/libspirv/workitem/get_num_groups.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_NumWorkgroups_x();
10-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_NumWorkgroups_y();
11-
_CLC_DECL _CLC_OVERLOAD size_t __spirv_NumWorkgroups_z();
9+
_CLC_DECL _CLC_OVERLOAD size_t __spirv_BuiltInNumWorkgroups(int);

libclc/libspirv/include/libspirv/workitem/get_num_sub_groups.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_DEF _CLC_OVERLOAD uint __spirv_NumSubgroups();
9+
_CLC_DEF _CLC_OVERLOAD uint __spirv_BuiltInNumSubgroups();

0 commit comments

Comments
 (0)