Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing with a CuArrays causes a 'scalar indexing disallowed' error from checkbounds #90

Closed
tanhevg opened this issue Apr 8, 2020 · 1 comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request

Comments

@tanhevg
Copy link

tanhevg commented Apr 8, 2020

I have stumbled upon this when playing around with FluxML/Flux.jl#1006

MWE:

using CuArrays
CuArrays.allowscalar(false)
x = cu(rand(10));
ind = cu(rand(1:10, 20));
x[ind]

This gives an error, because checkbounds in base goes through the index array one by one:

ERROR: scalar getindex is disallowed
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] assertscalar(::String) at /data/.julia/packages/GPUArrays/QDGmr/src/host/indexing.jl:41
 [3] getindex(::CuArray{Int64,1,Nothing}, ::Int64) at /data/.julia/packages/GPUArrays/QDGmr/src/host/indexing.jl:86
 [4] iterate at ./abstractarray.jl:914 [inlined]
 [5] iterate at ./abstractarray.jl:912 [inlined]
 [6] checkindex at ./abstractarray.jl:572 [inlined]
 [7] checkbounds at ./abstractarray.jl:488 [inlined]
 [8] checkbounds at ./abstractarray.jl:503 [inlined]
 [9] _getindex at ./multidimensional.jl:669 [inlined]
 [10] getindex(::CuArray{Float32,1,Nothing}, ::CuArray{Int64,1,Nothing}) at ./abstractarray.jl:981
 [11] top-level scope at REPL[5]:1

Now, disable checkindex:

import Base.checkindex

checkindex(::Type{Bool}, inds::AbstractUnitRange, I::CuArray) = true
checkindex (generic function with 12 methods)

x[ind]
# prints the expected output

I presume, checkindex needs overriding to something meaningful for GPUArrays?

@maleadt maleadt transferred this issue from JuliaGPU/CuArrays.jl May 27, 2020
@maleadt maleadt added cuda array Stuff about CuArray. enhancement New feature or request labels May 27, 2020
@maleadt
Copy link
Member

maleadt commented Aug 25, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants