File tree Expand file tree Collapse file tree 5 files changed +92
-0
lines changed
libclc/amdgcn-amdhsa/libspirv Expand file tree Collapse file tree 5 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,7 @@ math/sin.cl
77math/sqrt.cl
88math/atan.cl
99math/cbrt.cl
10+ workitem/get_max_sub_group_size.cl
11+ workitem/get_num_sub_groups.cl
12+ workitem/get_sub_group_id.cl
13+ workitem/get_sub_group_size.cl
Original file line number Diff line number Diff line change 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 <spirv/spirv.h>
10+
11+ // FIXME: Remove the following workaround once the clang change is released.
12+ // This is for backward compatibility with older clang which does not define
13+ // __AMDGCN_WAVEFRONT_SIZE. It does not consider -mwavefrontsize64.
14+ // See:
15+ // https://github.com/intel/llvm/blob/sycl/clang/lib/Basic/Targets/AMDGPU.h#L414
16+ // and:
17+ // https://github.com/intel/llvm/blob/sycl/clang/lib/Basic/Targets/AMDGPU.cpp#L421
18+ #ifndef __AMDGCN_WAVEFRONT_SIZE
19+ #if __gfx1010__ || __gfx1011__ || __gfx1012__ || __gfx1030__ || __gfx1031__
20+ #define __AMDGCN_WAVEFRONT_SIZE 32
21+ #else
22+ #define __AMDGCN_WAVEFRONT_SIZE 64
23+ #endif
24+ #endif
25+
26+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize () {
27+ return __AMDGCN_WAVEFRONT_SIZE ;
28+ }
Original file line number Diff line number Diff line change 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 <spirv/spirv.h>
10+
11+ _CLC_DEF _CLC_OVERLOAD uint __spirv_NumSubgroups () {
12+ size_t size_x = __spirv_WorkgroupSize_x ();
13+ size_t size_y = __spirv_WorkgroupSize_y ();
14+ size_t size_z = __spirv_WorkgroupSize_z ();
15+ uint sg_size = __spirv_SubgroupMaxSize ();
16+ size_t linear_size = size_z * size_y * size_x ;
17+ return (uint )((linear_size + sg_size - 1 ) / sg_size );
18+ }
Original file line number Diff line number Diff line change 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 <spirv/spirv.h>
10+
11+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupId () {
12+ size_t id_x = __spirv_LocalInvocationId_x ();
13+ size_t id_y = __spirv_LocalInvocationId_y ();
14+ size_t id_z = __spirv_LocalInvocationId_z ();
15+ size_t size_x = __spirv_WorkgroupSize_x ();
16+ size_t size_y = __spirv_WorkgroupSize_y ();
17+ size_t size_z = __spirv_WorkgroupSize_z ();
18+ uint sg_size = __spirv_SubgroupMaxSize ();
19+ return (id_z * size_y * size_x + id_y * size_x + id_x ) / sg_size ;
20+ }
Original file line number Diff line number Diff line change 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 <spirv/spirv.h>
10+
11+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupSize () {
12+ if (__spirv_SubgroupId () != __spirv_NumSubgroups () - 1 ) {
13+ return __spirv_SubgroupMaxSize ();
14+ }
15+ size_t size_x = __spirv_WorkgroupSize_x ();
16+ size_t size_y = __spirv_WorkgroupSize_y ();
17+ size_t size_z = __spirv_WorkgroupSize_z ();
18+ size_t linear_size = size_z * size_y * size_x ;
19+ size_t uniform_groups = __spirv_NumSubgroups () - 1 ;
20+ size_t uniform_size = __spirv_SubgroupMaxSize () * uniform_groups ;
21+ return linear_size - uniform_size ;
22+ }
You can’t perform that action at this time.
0 commit comments