-
Notifications
You must be signed in to change notification settings - Fork 8
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
Broadcasting and scalar indexing in the case of CuArrays #42
Comments
Hi, indeed it seems to be a problem with broadcasting. I've made some progress trying to fix this but it's quite tricky, especially when combined with dimension permutations! I'll try to push a fix soon. |
Thanks a lot! |
I don't know if you are aware, but this commit changed the order for broadcasting: # size nx ny nz
plan = PencilFFTPlan(pen_array, Transforms.FFT())
x = LinRange(0,2*pi,nx)
y = LinRange(0,2*pi,ny)
z = LinRange(0,2*pi,nz)
# temporary arrays
pen_hat = allocate_output(plan)
# axes
pen_hat_glob = global_view(pen_hat)
# ranges
rx_hat, ry_hat, rz_hat = axes(pen_hat_glob)
nxl_hat, nyl_hat, nzl_hat = size_local(pen_hat)
# range compatible to all types of Array
rrx_hat = rx_hat[begin]:rx_hat[end]
rry_hat = ry_hat[begin]:ry_hat[end]
rrz_hat = rz_hat[begin]:rz_hat[end]
# reshape hat versions of positions
# what used to work
x_hat = reshape(x[rrx_hat],nxl_hat,1,1)
y_hat = reshape(y[rry_hat],1,nyl_hat,1)
z_hat = reshape(z[rrz_hat],1,1,nzl_hat)
@. pen_hat = x_hat * pen_hat
# what works now
x_hat = reshape(x[rrx_hat],1,1,nxl_hat)
y_hat = reshape(y[rry_hat],1,nyl_hat,1)
z_hat = reshape(z[rrz_hat],nzl_hat,1,1)
@. pen_hat = x_hat * pen_hat The workaround works, but maybe you have some suggestions on how to do it better? |
I guess on the last line of your example you meant something like @. pen_hat = x_hat * y_hat * z_hat * pen_hat which uses the three I'm not that surprised by this change of behaviour, but I agree it's not ideal, and the original version of your example should be the good one. Sorry about that, I'm not that familiar with numpy-style broadcasting using singleton dimensions, but I see that it can be very convenient and especially useful on GPUs. I'm reopening this issue and I'll try to have this fixed. Note that the order changes only when working with the output of transforms in PencilFFTs. This is done to make sure that 1D FFTs are always done contiguously in memory. This can be disabled by passing Another workaround (which will stop working if this issue is fixed) is to do something like: x_hat = reshape(x[rrx_hat], permutation(pen_hat) * (nxl_hat,1,1))
y_hat = reshape(y[rry_hat], permutation(pen_hat) * (1,nyl_hat,1))
z_hat = reshape(z[rrz_hat], permutation(pen_hat) * (1,1,nzl_hat)) which will automatically permute the array dimensions according to the order of indices in As a side note, instead of using |
Hi Corentin, I've been playing around with an alternative way of working with grids which may "solve" this issue. The idea is to add a The details are in #45. Basically, in your example, this would allow you to do: grid = localgrid(pen_hat, (x, y, z))
@. pen_hat = (grid.x + grid.y + grid.z) * pen_hat Note that one doesn't need to care about possible index permutations and things like that. Everything is taken care of in the |
This would be really (really!) convenient! |
Just to be sure, will |
Yes. The difference is that during broadcasting it would be reshaped similarly to what you did in your example.
No, in that case it would still be
Not sure if I understand the question, but |
My concern is that it stays a CuArray. I guess I'll just try to see what it gives me! |
Right. It should stay a CuArray, since no new arrays are created. But let me know if that's not the case! |
I just merged #45, which will be included in v0.15 (being registered right now). So I'm closing this for now, but let me know if there are still issues! |
Everything seems to work, for broadcasting, I'll open an another issue with |
Hi,
Good progress was made in term of GPU support.
Some problem still arise when using
PencilArrays
. For example the following code fails:The error mention
materialize!
:I am not sure why it fails. The same kind of line with CuArray instead of PencilArray work.
Thanks a lot!
Corentin
The text was updated successfully, but these errors were encountered: