|
| 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 |
0 commit comments