Any idea why this would be causing a scalar indexing problem?
begin
for n in 4:6
x4 = CuArray(rand([0, 1], n, n))
sz = size(x4)
dt = CUDA.zeros(Float32, sz),
v = CUDA.ones(Int64, sz),
z = CUDA.zeros(Float32, sz .+ 1)
end
end
Scalar indexing is disallowed.
Invocation of getindex resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore are only permitted from the REPL for prototyping purposes.
If you did intend to index this array, annotate the caller with @allowscalar.
error(::String)@error.jl:33
assertscalar(::String)@indexing.jl:53
getindex(::CUDA.CuArray{Float32, 2}, ::Int64)@indexing.jl:86
iterate@abstractarray.jl:1096[inlined]
iterate@abstractarray.jl:1094[inlined]
indexed_iterate(::CUDA.CuArray{Float32, 2}, ::Int64)@tuple.jl:89
top-level scope@Local: 5
Not sure why, but removing the [0, 1]
from rand
fixes the problem
begin
for n in 4:6
x4 = CuArray(rand(n, n))
sz = size(x4)
dt = CUDA.zeros(Float32, sz),
v = CUDA.ones(Int64, sz),
z = CUDA.zeros(Float32, sz .+ 1)
end
end
Maybe has to do with CUDA support for replacing Base intrinsics automatically. Stuff like sin
or rand
used to require calling CUDA.sin
/CUDA.rand
. Now CUDA will automatically replace those calls with CUDA equivalents when you are using CuArray
s. So here you actually ended up calling CUDA.rand
and sampling from [0, 1]
will scalar index that vector.
Maybe cu(Base.rand([0, 1], n, n))
will work?
https://juliagpu.org/post/2021-04-09-cuda_3.0/ for more info
I think your problem is the stray commas. dt = zeros(sz), v = ones(sz), z = zeros(sz)
is parsed as... some kind of unpacking like this:
julia> a, b = CUDA.ones(3)
ERROR: Scalar indexing is disallowed.
julia> sz = (4,4)
(4, 4)
julia> dt = CUDA.zeros(Float32, sz), v = CUDA.ones(Int64, sz), z = CUDA.zeros(Float32, sz .+ 1)
ERROR: Scalar indexing is disallowed.
Oh, I didn't even notice the commas before. That could've been the problem too, hmm
Last updated: Nov 06 2024 at 04:40 UTC