-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
gather
is not friendly with matrix of size 0 on GPU
#411
Comments
Looks like https://github.com/FluxML/NNlib.jl/blob/master/src/gather.jl#L76 so this can probably be fixed by adding a short-circuit like https://github.com/FluxML/NNlibCUDA.jl/blob/master/src/gather.jl#L52 Should be an easy PR you're interested. Would want tests in this file: https://github.com/FluxML/NNlibCUDA.jl/blob/master/test/gather.jl |
We need to check if size(srt,1)==0
NNlib.gather(srt,idx_gpu) = NNlib.gather(srt,cpu(idx_gpu))
end This works fine but is not ideal |
Maybe it's a good idea to remove the After doing this, we have the desired error info
|
It's not good to remove |
So the problem is we need to add a bounds checking function here, and make it compatible with empty arrays |
In the beginning, |
It is a coincidence we should avoid. Using using NNlib, CUDA
src = CUDA.rand(2,3)
NNlib.gather(src,cu[1,4])
ERROR: BoundsError: attempt to access 2×3 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer} at index [1:2, 4]
Stacktrace:
[1] throw_boundserror(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, I::Tuple{Base.Slice{Base.OneTo{Int64}}, Int64})
@ Base .\abstractarray.jl:691
[2] checkbounds
@ .\abstractarray.jl:656 [inlined]
[3] view
@ C:\Users\Luffy\.julia\packages\CUDA\qAl31\src\array.jl:617 [inlined]
[4] _view(X::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, colons::Tuple{Colon}, k::Int64)
@ NNlib C:\Users\Luffy\.julia\packages\NNlib\hydo3\src\scatter.jl:38
[5] gather!(dst::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, src::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, idx::CuArray{Int64, 1, CUDA.Mem.DeviceBuffer})
@ NNlib C:\Users\Luffy\.julia\packages\NNlib\hydo3\src\gather.jl:27
[6] gather(src::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, idx::CuArray{Int64, 1, CUDA.Mem.DeviceBuffer})
@ NNlib C:\Users\Luffy\.julia\packages\NNlib\hydo3\src\gather.jl:77
[7] top-level scope
@ c:\Users\Luffy\gather_test.jl:5 unless we write using NNlib, CUDA
using NNlibCUDA
src = CUDA.rand(2,3)
NNlib.gather(src,cu[1,4])
2×2 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}:
0.430532 0.0
0.474528 0.0 Now we have the bounds checking thing. This causes problems downstream as in CarloLucibello/GraphNeuralNetworks.jl#181. Now it's more like a bug.
As you can see above, bounds checking is a separate issue, empty array is another, and you need to deal with both. |
Oh! Now I get your point. |
The so-called coincidence may be the third issue. For instance, if I'm using
It won't throw an error since under the hood we are calling |
For these points, you can fire corresponding issues. |
The text was updated successfully, but these errors were encountered: