Skip to content

Commit f198f5c

Browse files
authored
Allow for ndims query (#551)
1 parent 8eb2653 commit f198f5c

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

src/compiler.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ end
3030

3131
@inline groupsize(ctx) = __groupsize(ctx)
3232
@inline ndrange(ctx) = __ndrange(ctx)
33+
@inline Base.ndims(ctx) = ndims(__iterspace(ctx))

src/nditeration.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ end
6363
@inline workitems(range::NDRange{N, B, W}) where {N, B, W <: StaticSize} = CartesianIndices(get(W))::CartesianIndices{N}
6464
@inline blocks(range::NDRange{N, B}) where {N, B <: DynamicSize} = range.blocks::CartesianIndices{N}
6565
@inline blocks(range::NDRange{N, B}) where {N, B <: StaticSize} = CartesianIndices(get(B))::CartesianIndices{N}
66+
@inline Base.ndims(::NDRange{N}) where {N} = N
6667

6768
import Base.iterate
6869
@inline iterate(range::NDRange) = iterate(blocks(range))

test/compiler.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function compiler_testsuite(backend, ArrayT)
4141
kernel = index(CPU(), DynamicSize(), DynamicSize())
4242
iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}();
4343
ctx = KernelAbstractions.mkcontext(kernel, 1, nothing, iterspace, Val(KernelAbstractions.NoDynamicCheck()))
44+
@test ndims(ctx) == 1
4445
@test KernelAbstractions.__index_Global_NTuple(ctx, CartesianIndex(1)) == (1,)
4546

4647
A = ArrayT{Int}(undef, 1)

test/nditeration.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ function nditeration_testsuite()
77
let ndrange = NDRange{2, DynamicSize, DynamicSize}(CartesianIndices((256, 256)), CartesianIndices((32, 32)))
88
@test length(ndrange) == 256 * 256
99
@test all(p -> p[1] == p[2], zip(ndrange, CartesianIndices((256, 256))))
10+
@test ndims(ndrange) == 2
1011
end
1112
let ndrange = NDRange{2, StaticSize{(256, 256)}, DynamicSize}(nothing, CartesianIndices((32, 32)))
1213
@test length(ndrange) == 256 * 256
1314
@test all(p -> p[1] == p[2], zip(ndrange, CartesianIndices((256, 256))))
15+
@test ndims(ndrange) == 2
1416
end
1517
end
1618

@@ -40,13 +42,15 @@ function nditeration_testsuite()
4042
I = Tuple(I)
4143
@test check(idx, i - 1, ntuple(i -> I[i] - 1, length(I))..., Dim_x, Dim_y)
4244
end
45+
@test ndims(ndrange) == 2
4346
end
4447
let ndrange = NDRange{2, DynamicSize, DynamicSize}(CartesianIndices((4, 4)), CartesianIndices((Dim_x, Dim_y)))
4548
idx = linear_iteration(ndrange)
4649
for (i, I) in zip(1:length(blocks(ndrange)), blocks(ndrange))
4750
I = Tuple(I)
4851
@test check(idx, i - 1, ntuple(i -> I[i] - 1, length(I))..., Dim_x, Dim_y)
4952
end
53+
@test ndims(ndrange) == 2
5054
end
5155

5256
Dim_x = 32
@@ -58,13 +62,15 @@ function nditeration_testsuite()
5862
I = Tuple(I)
5963
@test check(idx, i - 1, ntuple(i -> I[i] - 1, length(I))..., Dim_x, Dim_y)
6064
end
65+
@test ndims(ndrange) == 2
6166
end
6267
let ndrange = NDRange{2, DynamicSize, DynamicSize}(CartesianIndices((4, 4 * 32)), CartesianIndices((Dim_x, Dim_y)))
6368
idx = linear_iteration(ndrange)
6469
for (i, I) in zip(1:length(blocks(ndrange)), blocks(ndrange))
6570
I = Tuple(I)
6671
@test check(idx, i - 1, ntuple(i -> I[i] - 1, length(I))..., Dim_x, Dim_y)
6772
end
73+
@test ndims(ndrange) == 2
6874
end
6975

7076
Dim_x = 1
@@ -76,13 +82,15 @@ function nditeration_testsuite()
7682
I = Tuple(I)
7783
@test check(idx, i - 1, ntuple(i -> I[i] - 1, length(I))..., Dim_x, Dim_y)
7884
end
85+
@test ndims(ndrange) == 2
7986
end
8087
let ndrange = NDRange{2, DynamicSize, DynamicSize}(CartesianIndices((4 * 32, 4)), CartesianIndices((Dim_x, Dim_y)))
8188
idx = linear_iteration(ndrange)
8289
for (i, I) in zip(1:length(blocks(ndrange)), blocks(ndrange))
8390
I = Tuple(I)
8491
@test check(idx, i - 1, ntuple(i -> I[i] - 1, length(I))..., Dim_x, Dim_y)
8592
end
93+
@test ndims(ndrange) == 2
8694
end
8795
end
8896
end

0 commit comments

Comments
 (0)