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

Gather throw error on cpu and gpu array inputs #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuehhua
Copy link
Member

@yuehhua yuehhua commented Jun 3, 2022

@yuehhua yuehhua force-pushed the fix branch 2 times, most recently from 3b4e280 to 72356fd Compare June 4, 2022 05:37
@yuehhua
Copy link
Member Author

yuehhua commented Jun 5, 2022

@DhairyaLGandhi would you please review this?

dstsize = (size(src)[1:Nsrc-M]..., size(idx)...)
dst = similar(src, Tsrc, dstsize)
return NNlib.gather!(dst, src, idx)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this method? The one in Nlib is not enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it from NNlib. The dispatching rule needs to distinguish (::AnyCuArray, ::AnyCuArray) from (::AnyCuArray, ::AbstractArray).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see why we need this since we have (::AbstractArray, ::AbstractArray) in NNlib

@CarloLucibello
Copy link
Member

I'm not sure we should do this. It is a technically breaking change. Also CUDA.jl allows for cpu index, so maybe gather should do the same

@YichengDWu
Copy link

Good point. This might be over-engineered. If users care about the speed it's the standard practice to set CUDA.allowscalar(false), which would prevent users from using CPU index. This should be sufficient.

using CUDA, NNlib
CUDA.allowscalar(false)

a = CUDA.rand(200,3000,64)
idx = cu(rand(1:64,5))

NNlib.gather(a, idx)


ERROR: 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.

@yuehhua
Copy link
Member Author

yuehhua commented Jun 6, 2022

I am also not sure we need it but maybe users expect some guidance to prevent from abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

always put the index on GPU if the soure array is there when using gather
3 participants