Continuous view of CuArray using CartesianIndices does not return native CuArray

views of CuArrays generally return a native CuArray object if the underlying data is contiguous. However, the does not seem to be the case if views are formed using CartesianIndices.

example:

sz = (8,4,2,2)
x = CUDA.rand(ComplexF32,sz);

@show typeof(view(x,:,:,1,1))

i = CartesianIndex(1, 1)
@show typeof(view(x,:,:,i))

returns:

typeof(view(x, :, :, 1, 1)) = CuArray{ComplexF32, 2}
typeof(view(x, :, :, i)) = SubArray{ComplexF32, 2, CuArray{ComplexF32, 4}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}, Int64, Int64}, true}

Currently, the following code does not work, since fft does not play nicely with the SubArray type on GPU

for nn in CartesianIndices(sz[3:end])
    xv = view(x,:,:,nn)
    fftplan * xv
end
2 Likes

Wow - thanks!