File tree Expand file tree Collapse file tree 15 files changed +185
-20
lines changed Expand file tree Collapse file tree 15 files changed +185
-20
lines changed Original file line number Diff line number Diff line change 37
37
#include <macros.h>
38
38
39
39
/* 6.11.1 Work-Item Functions */
40
- #include <spirv/workitem/get_global_size.h>
41
40
#include <spirv/workitem/get_global_id.h>
42
- #include <spirv/workitem/get_local_size.h>
41
+ #include <spirv/workitem/get_global_offset.h>
42
+ #include <spirv/workitem/get_global_size.h>
43
+ #include <spirv/workitem/get_group_id.h>
43
44
#include <spirv/workitem/get_local_id.h>
45
+ #include <spirv/workitem/get_local_size.h>
46
+ #include <spirv/workitem/get_max_sub_group_size.h>
44
47
#include <spirv/workitem/get_num_groups.h>
45
- #include <spirv/workitem/get_group_id.h>
46
- #include <spirv/workitem/get_global_offset.h>
48
+ #include <spirv/workitem/get_num_sub_groups.h>
49
+ #include <spirv/workitem/get_sub_group_id.h>
50
+ #include <spirv/workitem/get_sub_group_local_id.h>
51
+ #include <spirv/workitem/get_sub_group_size.h>
47
52
#include <spirv/workitem/get_work_dim.h>
48
53
49
54
/* 6.11.2.1 Floating-point macros */
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
+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize ();
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
+ _CLC_DEF _CLC_OVERLOAD uint __spirv_NumSubgroups ();
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
+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupId ();
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
+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupLocalInvocationId ();
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
+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupSize ();
Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ workitem/get_global_size.cl
75
75
workitem/get_group_id.cl
76
76
workitem/get_local_id.cl
77
77
workitem/get_local_size.cl
78
+ workitem/get_max_sub_group_size.cl
78
79
workitem/get_num_groups.cl
80
+ workitem/get_num_sub_groups.cl
81
+ workitem/get_sub_group_id.cl
82
+ workitem/get_sub_group_local_id.cl
83
+ workitem/get_sub_group_size.cl
79
84
images/image_helpers.ll
80
85
images/image.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
+ _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize () {
12
+ return 32 ;
13
+ // FIXME: warpsize is defined by NVVM IR but doesn't compile if used here
14
+ // return __nvvm_read_ptx_sreg_warpsize();
15
+ }
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
+ // sreg.nwarpid returns number of warp identifiers, not number of warps
13
+ // see https://docs.nvidia.com/cuda/parallel-thread-execution/index.html
14
+ size_t size_x = __spirv_WorkgroupSize_x ();
15
+ size_t size_y = __spirv_WorkgroupSize_y ();
16
+ size_t size_z = __spirv_WorkgroupSize_z ();
17
+ uint sg_size = __spirv_SubgroupMaxSize ();
18
+ uint linear_size = size_z * size_y * size_x ;
19
+ return (linear_size + sg_size - 1 ) / 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_SubgroupId () {
12
+ // sreg.warpid is volatile and doesn't represent virtual warp index
13
+ // see https://docs.nvidia.com/cuda/parallel-thread-execution/index.html
14
+ size_t id_x = __spirv_LocalInvocationId_x ();
15
+ size_t id_y = __spirv_LocalInvocationId_y ();
16
+ size_t id_z = __spirv_LocalInvocationId_z ();
17
+ size_t size_x = __spirv_WorkgroupSize_x ();
18
+ size_t size_y = __spirv_WorkgroupSize_y ();
19
+ size_t size_z = __spirv_WorkgroupSize_z ();
20
+ uint sg_size = __spirv_SubgroupMaxSize ();
21
+ return (id_z * size_y * size_x + id_y * size_x + id_x ) / sg_size ;
22
+ }
You can’t perform that action at this time.
0 commit comments