Skip to content

Commit 07d8bab

Browse files
authored
[SYCL][NativeCPU] Unify definitions of __spirv_* functions. (#18010)
Several functions were being defined both in libclc and in libdevice, but had different definitions between the two. This commit changes it so that they are only defined once, in libclc, with the definition that we had in libdevice that we were relying on taking precedence.
1 parent b38eb60 commit 07d8bab

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

libclc/libspirv/lib/native_cpu/SOURCES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ math/native_log2.cl
1111
math/native_sin.cl
1212
math/native_sqrt.cl
1313
math/round.cl
14+
workitem/get_global_id.cl
15+
workitem/get_global_size.cl
16+
workitem/get_num_sub_groups.cl
17+
workitem/get_sub_group_size.cl
1418
cl_khr_int64_extended_atomics/minmax_helpers.ll
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <libspirv/spirv.h>
10+
11+
ulong __mux_get_global_id(int);
12+
13+
_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalInvocationId_x() {
14+
return __mux_get_global_id(0);
15+
}
16+
17+
_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalInvocationId_y() {
18+
return __mux_get_global_id(1);
19+
}
20+
21+
_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalInvocationId_z() {
22+
return __mux_get_global_id(2);
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <libspirv/spirv.h>
10+
11+
ulong __mux_get_global_size(int);
12+
13+
_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalSize_x() {
14+
return __mux_get_global_size(0);
15+
}
16+
17+
_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalSize_y() {
18+
return __mux_get_global_size(1);
19+
}
20+
21+
_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalSize_z() {
22+
return __mux_get_global_size(2);
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <libspirv/spirv.h>
10+
11+
uint __mux_get_num_sub_groups();
12+
13+
_CLC_DEF _CLC_OVERLOAD uint __spirv_NumSubgroups() {
14+
return __mux_get_num_sub_groups();
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <libspirv/spirv.h>
10+
11+
uint __mux_get_sub_group_size();
12+
13+
_CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupSize() {
14+
return __mux_get_sub_group_size();
15+
}

libdevice/nativecpu_utils.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,6 @@ DefineShuffleVec2to16(int32_t, i32, int32_t);
323323
DefineShuffleVec2to16(uint32_t, i32, int32_t);
324324
DefineShuffleVec2to16(float, f32, float);
325325

326-
#define Define2ArgForward(Type, Name, Callee) \
327-
DEVICE_EXTERNAL Type Name(Type a, Type b) noexcept { return Callee(a, b); } \
328-
static_assert(true)
329-
330-
Define2ArgForward(uint64_t, __spirv_ocl_u_min, std::min);
331-
332326
#define GET_PROPS __attribute__((pure))
333327
#define GEN_u32(bname, muxname) \
334328
DEVICE_EXTERN_C GET_PROPS uint32_t muxname(); \
@@ -338,8 +332,6 @@ Define2ArgForward(uint64_t, __spirv_ocl_u_min, std::min);
338332
GEN_u32(__spirv_SubgroupLocalInvocationId, __mux_get_sub_group_local_id);
339333
GEN_u32(__spirv_SubgroupMaxSize, __mux_get_max_sub_group_size);
340334
GEN_u32(__spirv_SubgroupId, __mux_get_sub_group_id);
341-
GEN_u32(__spirv_NumSubgroups, __mux_get_num_sub_groups);
342-
GEN_u32(__spirv_SubgroupSize, __mux_get_sub_group_size);
343335

344336
// I64_I32
345337
#define GEN_p(bname, muxname, arg) \
@@ -352,8 +344,6 @@ GEN_u32(__spirv_SubgroupSize, __mux_get_sub_group_size);
352344
GEN_p(bname##_y, ncpu_name, 1); \
353345
GEN_p(bname##_z, ncpu_name, 2)
354346

355-
GEN_xyz(__spirv_GlobalInvocationId, __mux_get_global_id);
356-
GEN_xyz(__spirv_GlobalSize, __mux_get_global_size);
357347
GEN_xyz(__spirv_GlobalOffset, __mux_get_global_offset);
358348
GEN_xyz(__spirv_LocalInvocationId, __mux_get_local_id);
359349
GEN_xyz(__spirv_NumWorkgroups, __mux_get_num_groups);

0 commit comments

Comments
 (0)