Skip to content

Commit a7483a1

Browse files
committed
Add basic tests
Modified from initial Claude code
1 parent 668b3cf commit a7483a1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

test/intrinsics.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
@kernel cpu=false inbounds=true unsafe_indices=true function test_intrinsics_kernel(results)
3+
# Test all intrinsics return NamedTuples with x, y, z fields
4+
global_size = KernelIntrinsics.get_global_size()
5+
global_id = KernelIntrinsics.get_global_id()
6+
local_size = KernelIntrinsics.get_local_size()
7+
local_id = KernelIntrinsics.get_local_id()
8+
num_groups = KernelIntrinsics.get_num_groups()
9+
group_id = KernelIntrinsics.get_group_id()
10+
11+
if UInt32(global_id.x) <= UInt32(global_size.x)
12+
results[1, global_id.x] = global_id.x
13+
results[2, global_id.x] = local_id.x
14+
results[3, global_id.x] = group_id.x
15+
results[4, global_id.x] = global_size.x
16+
results[5, global_id.x] = local_size.x
17+
results[6, global_id.x] = num_groups.x
18+
end
19+
end
20+
21+
22+
function intrinsics_testsuite(backend, AT)
23+
@testset "KernelIntrinsics Tests" begin
24+
@testset "Basic intrinsics functionality" begin
25+
26+
# Test with small kernel
27+
N = 16
28+
results = AT(zeros(UInt32, 6, N))
29+
30+
kernel = test_intrinsics_kernel(backend(), 4, (N,))
31+
kernel(results, ndrange=N)
32+
KernelAbstractions.synchronize(backend())
33+
34+
host_results = Array(results)
35+
36+
# Verify results make sense
37+
for i in 1:N
38+
global_id_x, local_id_x, group_id_x, global_size_x, local_size_x, num_groups_x = host_results[:, i]
39+
40+
# Global IDs should be 1-based and sequential
41+
@test global_id_x == i
42+
43+
# Global size should match our ndrange
44+
@test global_size_x == N
45+
46+
# Local size should be 4 (our workgroupsize)
47+
@test local_size_x == 4
48+
49+
# Number of groups should be ceil(N/4) = 4
50+
@test num_groups_x == 4
51+
52+
# Group ID should be 1-based
53+
expected_group = div(i - 1, 4) + 1
54+
@test group_id_x == expected_group
55+
56+
# Local ID should be 1-based within group
57+
expected_local = ((i - 1) % 4) + 1
58+
@test local_id_x == expected_local
59+
end
60+
end
61+
end
62+
end

test/testsuite.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ end
2626

2727

2828
include("test.jl")
29+
include("intrinsics.jl")
2930
include("localmem.jl")
3031
include("private.jl")
3132
include("unroll.jl")
@@ -47,6 +48,10 @@ function testsuite(backend, backend_str, backend_mod, AT, DAT; skip_tests = Set{
4748
specialfunctions_testsuite(backend)
4849
end
4950

51+
@conditional_testset "Intrinsics" skip_tests begin
52+
intrinsics_testsuite(backend, AT)
53+
end
54+
5055
@conditional_testset "Localmem" skip_tests begin
5156
localmem_testsuite(backend, AT)
5257
end

0 commit comments

Comments
 (0)