Skip to content

Commit 0bed77b

Browse files
CochWojciechigcbot
authored andcommitted
Add SPIR-V test suite for OpReadClockKHR instruction
This PR introduces test suite for the OpReadClockKHR SPIR-V instruction, ensuring proper compilation and intrinsic generation across different scenarios.
1 parent 97790b7 commit 0bed77b

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
;=========================== begin_copyright_notice ============================
3+
;
4+
; Copyright (C) 2025 Intel Corporation
5+
;
6+
; SPDX-License-Identifier: MIT
7+
;
8+
;============================ end_copyright_notice =============================
9+
10+
; REQUIRES: spirv-as, regkeys, pvc-supported
11+
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
12+
; RUN: ocloc compile -spirv_input -file %t.spv -device pvc -options " -igc_opts 'PrintToConsole=1 PrintAfter=BuiltinsConverterFunction'" 2>&1 | FileCheck %s
13+
; CHECK: @llvm.genx.GenISA.cycleCounter()
14+
15+
; Test: OpReadClockKHR with device scope generates GenISA.cycleCounter intrinsic
16+
OpCapability Addresses
17+
OpCapability Linkage
18+
OpCapability Kernel
19+
OpCapability Int64
20+
OpCapability ShaderClockKHR
21+
OpExtension "SPV_KHR_shader_clock"
22+
OpMemoryModel Physical64 OpenCL
23+
OpEntryPoint Kernel %clock_sub_group "clock_read_sub_group"
24+
OpDecorate %buf Alignment 4
25+
%ulong = OpTypeInt 64 0
26+
%uint = OpTypeInt 32 0
27+
%uint_0 = OpConstant %uint 0
28+
%uint_1 = OpConstant %uint 1
29+
%ulong_1 = OpConstant %ulong 1
30+
%ulong_2 = OpConstant %ulong 2
31+
%ulong_3 = OpConstant %ulong 3
32+
%scope_device = OpConstant %uint 1
33+
%void = OpTypeVoid
34+
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
35+
%functype = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
36+
%bool = OpTypeBool
37+
%clock_sub_group = OpFunction %void None %functype
38+
%buf = OpFunctionParameter %_ptr_CrossWorkgroup_uint
39+
%funcstart = OpLabel
40+
%buf_1 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_1
41+
%buf_2 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_2
42+
%buf_3 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_3
43+
%start = OpReadClockKHR %ulong %scope_device
44+
OpBranch %looptop
45+
%looptop = OpLabel
46+
%i = OpPhi %uint %uint_0 %funcstart %next_i %looptop
47+
%data0 = OpLoad %uint %buf Volatile|Aligned 4
48+
%data1 = OpLoad %uint %buf_1 Volatile|Aligned 4
49+
%sum = OpIAdd %uint %data0 %data1
50+
OpStore %buf %sum Volatile|Aligned 4
51+
%next_i = OpIAdd %uint %i %uint_1
52+
%data2 = OpLoad %uint %buf_2 Volatile|Aligned 4
53+
%looptest = OpULessThan %bool %next_i %data2
54+
OpBranchConditional %looptest %looptop %loopend
55+
%loopend = OpLabel
56+
%end = OpReadClockKHR %ulong %scope_device
57+
%test = OpULessThan %bool %end %start
58+
OpBranchConditional %test %funcend %writepass
59+
%writepass = OpLabel
60+
OpStore %buf_3 %uint_1 Volatile|Aligned 4
61+
OpBranch %funcend
62+
%funcend = OpLabel
63+
OpReturn
64+
OpFunctionEnd
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
;=========================== begin_copyright_notice ============================
3+
;
4+
; Copyright (C) 2025 Intel Corporation
5+
;
6+
; SPDX-License-Identifier: MIT
7+
;
8+
;============================ end_copyright_notice =============================
9+
10+
; REQUIRES: spirv-as, regkeys
11+
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
12+
; RUN: ocloc compile -spirv_input -file %t.spv -device dg2 -options " -igc_opts 'PrintToConsole=1 PrintAfter=BuiltinsConverterFunction'" 2>&1 | FileCheck %s
13+
; CHECK: @llvm.genx.GenISA.cycleCounter()
14+
15+
; Test case for ReadClockKHR on DG2 device (different from PVC)
16+
OpCapability Addresses
17+
OpCapability Linkage
18+
OpCapability Kernel
19+
OpCapability Int64
20+
OpCapability ShaderClockKHR
21+
OpExtension "SPV_KHR_shader_clock"
22+
OpMemoryModel Physical64 OpenCL
23+
OpEntryPoint Kernel %clock_dg2_test "clock_read_dg2_test"
24+
OpDecorate %buf Alignment 4
25+
%ulong = OpTypeInt 64 0
26+
%uint = OpTypeInt 32 0
27+
%uint2 = OpTypeVector %uint 2
28+
%uint_0 = OpConstant %uint 0
29+
%uint_1 = OpConstant %uint 1
30+
%ulong_1 = OpConstant %ulong 1
31+
%ulong_2 = OpConstant %ulong 2
32+
%ulong_3 = OpConstant %ulong 3
33+
%scope_device = OpConstant %uint 1
34+
%void = OpTypeVoid
35+
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
36+
%functype = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
37+
%clock_dg2_test = OpFunction %void None %functype
38+
%buf = OpFunctionParameter %_ptr_CrossWorkgroup_uint
39+
%funcstart = OpLabel
40+
%buf_1 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_1
41+
%buf_2 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_2
42+
%buf_3 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_3
43+
; Test both variants on DG2
44+
%clock_ulong = OpReadClockKHR %ulong %scope_device
45+
%clock_uint2 = OpReadClockKHR %uint2 %scope_device
46+
%ulong_part = OpUConvert %uint %clock_ulong
47+
%uint2_x = OpCompositeExtract %uint %clock_uint2 0
48+
%uint2_y = OpCompositeExtract %uint %clock_uint2 1
49+
OpStore %buf %ulong_part Volatile|Aligned 4
50+
OpStore %buf_1 %uint2_x Volatile|Aligned 4
51+
OpStore %buf_2 %uint2_y Volatile|Aligned 4
52+
OpStore %buf_3 %uint_1 Volatile|Aligned 4
53+
OpReturn
54+
OpFunctionEnd
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
;=========================== begin_copyright_notice ============================
3+
;
4+
; Copyright (C) 2025 Intel Corporation
5+
;
6+
; SPDX-License-Identifier: MIT
7+
;
8+
;============================ end_copyright_notice =============================
9+
10+
; REQUIRES: spirv-as, regkeys, pvc-supported
11+
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
12+
; RUN: ocloc compile -spirv_input -file %t.spv -device pvc -options " -igc_opts 'PrintToConsole=1 PrintAfter=BuiltinsConverterFunction'" 2>&1 | FileCheck %s
13+
; CHECK: @llvm.genx.GenISA.cycleCounter()
14+
15+
; Test case for ReadClockKHR with different scopes (subgroup, device, workgroup)
16+
OpCapability Addresses
17+
OpCapability Linkage
18+
OpCapability Kernel
19+
OpCapability Int64
20+
OpCapability ShaderClockKHR
21+
OpExtension "SPV_KHR_shader_clock"
22+
OpMemoryModel Physical64 OpenCL
23+
OpEntryPoint Kernel %clock_scopes_test "clock_read_scopes_test"
24+
OpDecorate %buf Alignment 4
25+
%ulong = OpTypeInt 64 0
26+
%uint = OpTypeInt 32 0
27+
%uint_0 = OpConstant %uint 0
28+
%uint_1 = OpConstant %uint 1
29+
%uint_2 = OpConstant %uint 2
30+
%uint_3 = OpConstant %uint 3
31+
%ulong_1 = OpConstant %ulong 1
32+
%ulong_2 = OpConstant %ulong 2
33+
%ulong_3 = OpConstant %ulong 3
34+
%scope_subgroup = OpConstant %uint 3
35+
%scope_workgroup = OpConstant %uint 2
36+
%scope_device = OpConstant %uint 1
37+
%void = OpTypeVoid
38+
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
39+
%functype = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
40+
%clock_scopes_test = OpFunction %void None %functype
41+
%buf = OpFunctionParameter %_ptr_CrossWorkgroup_uint
42+
%funcstart = OpLabel
43+
%buf_1 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_1
44+
%buf_2 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_2
45+
%buf_3 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_3
46+
; Test device scope
47+
%clock_device = OpReadClockKHR %ulong %scope_device
48+
%device_low = OpUConvert %uint %clock_device
49+
OpStore %buf %device_low Volatile|Aligned 4
50+
; Test workgroup scope
51+
%clock_workgroup = OpReadClockKHR %ulong %scope_workgroup
52+
%workgroup_low = OpUConvert %uint %clock_workgroup
53+
OpStore %buf_1 %workgroup_low Volatile|Aligned 4
54+
; Test subgroup scope
55+
%clock_subgroup = OpReadClockKHR %ulong %scope_subgroup
56+
%subgroup_low = OpUConvert %uint %clock_subgroup
57+
OpStore %buf_2 %subgroup_low Volatile|Aligned 4
58+
OpStore %buf_3 %uint_1 Volatile|Aligned 4
59+
OpReturn
60+
OpFunctionEnd
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
;=========================== begin_copyright_notice ============================
3+
;
4+
; Copyright (C) 2025 Intel Corporation
5+
;
6+
; SPDX-License-Identifier: MIT
7+
;
8+
;============================ end_copyright_notice =============================
9+
10+
; REQUIRES: spirv-as, regkeys, pvc-supported
11+
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
12+
; RUN: ocloc compile -spirv_input -file %t.spv -device pvc -options " -igc_opts 'PrintToConsole=1 PrintAfter=BuiltinsConverterFunction'" 2>&1 | FileCheck %s
13+
; CHECK: @llvm.genx.GenISA.cycleCounter()
14+
15+
; Test case for ReadClockKHR returning uint2
16+
OpCapability Addresses
17+
OpCapability Linkage
18+
OpCapability Kernel
19+
OpCapability Int64
20+
OpCapability ShaderClockKHR
21+
OpExtension "SPV_KHR_shader_clock"
22+
OpMemoryModel Physical64 OpenCL
23+
OpEntryPoint Kernel %clock_uint2_test "clock_read_uint2_test"
24+
OpDecorate %buf Alignment 4
25+
%ulong = OpTypeInt 64 0
26+
%uint = OpTypeInt 32 0
27+
%uint2 = OpTypeVector %uint 2
28+
%uint_0 = OpConstant %uint 0
29+
%uint_1 = OpConstant %uint 1
30+
%uint_2 = OpConstant %uint 2
31+
%ulong_1 = OpConstant %ulong 1
32+
%ulong_2 = OpConstant %ulong 2
33+
%scope_device = OpConstant %uint 1
34+
%void = OpTypeVoid
35+
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
36+
%functype = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
37+
%clock_uint2_test = OpFunction %void None %functype
38+
%buf = OpFunctionParameter %_ptr_CrossWorkgroup_uint
39+
%funcstart = OpLabel
40+
%buf_1 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_1
41+
%buf_2 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %buf %ulong_2
42+
%clock = OpReadClockKHR %uint2 %scope_device
43+
%clock_x = OpCompositeExtract %uint %clock 0
44+
%clock_y = OpCompositeExtract %uint %clock 1
45+
OpStore %buf %clock_x Volatile|Aligned 4
46+
OpStore %buf_1 %clock_y Volatile|Aligned 4
47+
OpStore %buf_2 %uint_1 Volatile|Aligned 4
48+
OpReturn
49+
OpFunctionEnd

0 commit comments

Comments
 (0)