GPUArrays.jl icon indicating copy to clipboard operation
GPUArrays.jl copied to clipboard

mean fails with views

Open cossio opened this issue 2 years ago • 1 comments

A = gpu(rand(3, 5, 2))
mean(@views A[1, :, :]; dims=2)
# ERROR: Scalar indexing is disallowed.

However, the following all work:

sum(@views A[1, :, :]; dims=2)
mean(A[1, :, :]; dims=2)
sum(A[1, :, :]; dims=2)

cossio avatar Jun 13 '23 15:06 cossio

As I commented on Slack:

that view is not contiguous, so it results in a SubArray object instead of a CuArray object. and not all array abstractions have type signatures that cover SubArray

we could extend GPUArrays’ mean implementation to use AnyGPUArray (which includes SubArray) instead of AbstractGPUArray (only CuArray), but I’m hesitant to do that, because the horrible Union that is AnyGPUArray is bad for load time and creates lots of ambiguities. This needs a fix in Base, really

maleadt avatar Jun 13 '23 15:06 maleadt