I have a 3d array V = zeros(N,N,N) and I would like to reverse it with respect to the last component. I achieve this by using the following function. This works well using CuArray (on master, see link) for A but this is very inefficient as N~100. Hence the gpu is wasted doing such a small reverse.
I am wondering if any of you has an idea to speed this up on GPU?
Thank you very much
Best regards
function myreverse!(A)
n = size(A)
for jj = 1:n[2], ii = 1:n[1]
reverse!(A[ii,jj,:])
end
end
It remains my opinion that myreverse! does nothing, because A[...] makes a copy, without touching A.
But indexing with a range does seem to work on CuArrays, so this is a plausible way to go. I haven’t timed it to see if it’s quick:
A = collect(reshape(1:27, 3,3,3))
A0 = copy(A)
myreverse!(A)
A
A == A0
A[:,:,3:-1:1]
view(A, :,:,3:-1:1) # or view(A, :, :, reverse(axes(A,3)) )
using CuArrays
cA = cu(A)
CuArrays.allowscalar(false)
cA[:,:,3:-1:1]
view(cA, :,:,3:-1:1)
cA .= view(cA, :,:,3:-1:1)