Skip to content

Commit ebc4efb

Browse files
Merge pull request #455 from vchuravy/vc/ka
Add KernelAbstractions.get_backend for VectorOfArray
2 parents d40c74d + 499c280 commit ebc4efb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module RecursiveArrayToolsKernelAbstractions
2+
3+
import RecursiveArrayTools: VectorOfArray
4+
import KernelAbstractions
5+
6+
7+
function KernelAbstractions.get_backend(x::VectorOfArray)
8+
u = parent(x)
9+
if length(u) == 0
10+
error("VectorOfArray is empty, cannot determine backend.")
11+
end
12+
# Use the backend of the first element in the parent array
13+
return KernelAbstractions.get_backend(u[1])
14+
end
15+
16+
end

test/gpu/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
34

45
[compat]
56
CUDA = "3.12, 4, 5"

test/gpu/vectorofarray_gpu.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
using RecursiveArrayTools, CUDA, Test, Zygote, Adapt
1+
using RecursiveArrayTools, CUDA, Test, Zygote, Adapt, KernelAbstractions
22
CUDA.allowscalar(false)
33

44
# Test indexing with colon
55
x = zeros(5)
66
y = VectorOfArray([x, x, x])
77
y[:, :]
88

9+
KernelAbstractions.get_backend(y) isa KernelAbstractions.CPU
10+
911
x = CUDA.zeros(5)
1012
y = VectorOfArray([x, x, x])
1113
y[:, :]
1214

15+
KernelAbstractions.get_backend(y) isa CUDA.CUDABackend
16+
1317
# Test indexing with boolean masks and colon
1418
nx, ny, nt = 3, 4, 5
1519
x = CUDA.rand(nx, ny, nt)

0 commit comments

Comments
 (0)