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

sum of zero-array fails #362

Open
mcabbott opened this issue Jun 22, 2021 · 0 comments · May be fixed by #363
Open

sum of zero-array fails #362

mcabbott opened this issue Jun 22, 2021 · 0 comments · May be fixed by #363

Comments

@mcabbott
Copy link
Contributor

julia> using CUDA, GPUArrays

julia> v = cu(rand(3));

julia> view(v,2)
0-dimensional CuArray{Float32, 0}:
0.8010128

julia> sum(view(v,2))
ERROR: MethodError: no method matching ndims(::Base.Broadcast.Broadcasted{CUDA.CuArrayStyle{0}, Nothing, typeof(identity), Tuple{CuArray{Float32, 0}}})

julia> reshape(v[2:2])
0-dimensional CuArray{Float32, 0}:
0.8010128

julia> sum(reshape(v[2:2]))
ERROR: MethodError: no method matching ndims(::Base.Broadcast.Broadcasted{CUDA.CuArrayStyle{0}, Nothing, typeof(identity), Tuple{CuArray{Float32, 0}}})

julia> reshape(v[2:2]) .+ v  # other broadcasting works
3-element CuArray{Float32, 1}:
 1.3723278
 1.6020256
 0.95104384

julia> Base.sum(x::GPUArrays.AbstractGPUArray{<:Any,0}) = GPUArrays.@allowscalar x[]

julia> sum(reshape(v[2:2]))
0.8010128f0

This is a trivial operation, but I wondered whether it might be useful as a package-independent way to write @allowscalar v[2]. I wrote the simplest possible fix above, but perhaps it ought to hook into mapreduce somewhere to be more general?

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 a pull request may close this issue.

1 participant