Skip to content

Commit 202a63e

Browse files
committed
Conform more strictly to the SPIR-V/OpenCL spec.
1 parent 922568e commit 202a63e

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

lib/intrinsics/src/work_item.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# Work-Item Functions
2+
#
3+
# https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Env.html#_built_in_variables
24

35
# NOTE: these functions now unsafely truncate to Int to avoid top bit checks.
46
# we should probably use range metadata instead.
57

68
# 1D values
7-
for (julia_name, (spirv_name, offset)) in [
9+
for (julia_name, (spirv_name, julia_type, offset)) in [
810
# indices
9-
:get_global_linear_id => (:BuiltInGlobalLinearId, 1),
10-
:get_local_linear_id => (:BuiltInLocalInvocationIndex, 1),
11-
:get_sub_group_id => (:BuiltInSubgroupId, 1),
12-
:get_sub_group_local_id => (:BuiltInSubgroupLocalInvocationId, 1),
11+
:get_global_linear_id => (:BuiltInGlobalLinearId, Csize_t, 1),
12+
:get_local_linear_id => (:BuiltInLocalInvocationIndex, Csize_t, 1),
13+
:get_sub_group_id => (:BuiltInSubgroupId, UInt32, 1),
14+
:get_sub_group_local_id => (:BuiltInSubgroupLocalInvocationId, UInt32, 1),
1315
# sizes
14-
:get_work_dim => (:BuiltInWorkDim, 0),
15-
:get_sub_group_size => (:BuiltInSubgroupSize, 0),
16-
:get_max_sub_group_size => (:BuiltInSubgroupMaxSize, 0),
17-
:get_num_sub_groups => (:BuiltInNumSubgroups, 0),
18-
:get_enqueued_num_sub_groups => (:BuiltInNumEnqueuedSubgroups, 0)]
16+
:get_work_dim => (:BuiltInWorkDim, UInt32, 0),
17+
:get_sub_group_size => (:BuiltInSubgroupSize, UInt32, 0),
18+
:get_max_sub_group_size => (:BuiltInSubgroupMaxSize, UInt32, 0),
19+
:get_num_sub_groups => (:BuiltInNumSubgroups, UInt32, 0),
20+
:get_enqueued_num_sub_groups => (:BuiltInNumEnqueuedSubgroups, UInt32, 0)]
1921
gvar_name = Symbol("@__spirv_$(spirv_name)")
20-
width = Int === Int64 ? 64 : 32
22+
width = sizeof(julia_type) * 8
2123
@eval begin
2224
export $julia_name
2325
@device_function $julia_name() =
@@ -28,7 +30,7 @@ for (julia_name, (spirv_name, offset)) in [
2830
ret i$(width) %val
2931
}
3032
attributes #0 = { alwaysinline }
31-
""", "entry"), UInt, Tuple{}) % Int + $offset
33+
""", "entry"), $julia_type, Tuple{}) % Int + $offset
3234
end
3335
end
3436

src/compiler/compilation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ end
4747
supports_fp64 = "cl_khr_fp64" in dev.extensions
4848

4949
# create GPUCompiler objects
50-
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, kwargs...)
50+
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, validate=true, kwargs...)
5151
params = OpenCLCompilerParams()
5252
CompilerConfig(target, params; kernel, name, always_inline)
5353
end

0 commit comments

Comments
 (0)