-
Notifications
You must be signed in to change notification settings - Fork 46
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
add reikna-backed fftn, ifftn, and fftshift #113
Conversation
Codecov Report
@@ Coverage Diff @@
## master #113 +/- ##
==========================================
+ Coverage 91.40% 91.49% +0.08%
==========================================
Files 487 492 +5
Lines 8719 8936 +217
==========================================
+ Hits 7970 8176 +206
- Misses 749 760 +11
Continue to review full report at Codecov.
|
Hey Talley @tlambert03 , that's an awesome PR! Just a minor concern as we are introducing new functions to the API: What do you think about the names of the functions. In clij2-fft there are similar functions with similar names. I would be happy to have things as similar as possible. For example on Java side we have Cheers, |
We can name them whatever you want. I was just going with the python conventions... but just tell me what you want them to be |
hey @haesleinhuepf, what's the canonical way to pad an array with zeros in cle? the equivalent of: new_array = np.zeros(new_shape)
new_array[: old_array.shape[0], : old_array.shape[1]] = old_array |
added aliases # clij2 aliases
convolve_fft = fftconvolve
inverse = ifftn
forward_fft = fftn
fft = fftn |
this is all set for review. the one thing that isn't supported yet is convolve_fft from an existing OCLArray, (waiting to hear how to pad with zeros) |
If you want to paste the |
Thanks @haesleinhuepf! am I correct in assuming that this won't currently work with complex dtypes? I'm running into some limitations here in terms of accepting existing GPU buffers... even if they come in as complex type already, will it be possible to resize them before #115? I think maybe we can just leave the |
Yes, I think so. But haven't tested. Also on clij-side support for complex types is poor.
I also could imagine that the napari-clesperanto-assistant would break if it receives Let me know what you think! |
not sure I'm following what you mean here. |
not following here either... what part of them need to be decorated by plugin_function? |
Ok, I obviously need more time to look into this in detail... :-) |
Hey @tlambert03 , I just dived into it a bit. I was thinking of making these changes, but the tests don't run and I must admit I don't know enough about pyopencl. Obviously, #115 needs to be fixed first before we can go ahead here. Things that are kind of neccessary before merging:
Things I'm not sure about yet:
In very general, I think the Not sure how to go ahead. Do you have bigger plans for this PR? Building deconvolution on top? Best, |
yeah, I suspected this might be an issue. I'm not really sure how to proceed either. my personal motivation is to have a python FFT interface that mimics the standard python ecosystem (i.e. numpy and scipy.fftpack). I've had great success easily swapping out CPU code for cupy code, and would like to be able to do similar stuff for cl. I had been starting to make such an interface for myself, but then figured I'd contribute it to In general, I'd love to see I definitely understand your hesitation, given the divergence of these functions from the rest of |
I also started doing this recently more often. I actually became a big fan of cucim. And I'm also thinking about how to make Btw. the fact that cupy (and cucim) don't take numpy-arrays as parameters is enoying. I'm happy that
That sounds like a good idea! There is one more option we might at least think about: We start a new repository which has |
Hi both! Some thoughts on this discussion:
|
Absolutely yes! I would love to build it myself. However, as I'm not using scipy.ndimage on a daily basis (not even weekly), I might not be the right lead for that project. I don't know the API well.
Yes, and I worked hard to make those things better. I also would love to multiply |
Btw, I already made a new package here: https://github.com/tlambert03/anyfft It's not published yet. But it lets you easily change between FFT backends (using the best method available for your platform) while using the scipy api. The flexibility of not being tied to the clij api there was nice, so if anything, I'd say clesperanto can depend on it if desired... but it now feels out of scope here |
? |
After partial fixing #115 I wanted to give this another shot (Just had some days of meetings and paperwork, and needed something useful to code ;-) ), I just merged it (into a new branch), fixed some minor things and cut down the API to a minimum. Cool: There is some intermediate speedup compared to convolution in real space when processing large images and kernels. See: It feels like there is a bottleneck I'm not fully aware of... But I'm still digging in it... |
Hey @tlambert03 @haesleinhuepf, I think this is the thread I was looking for. FFT in clesperanto. Wuhu! Was there any progress being made? Is it "officially" being supported now? Trying out the notebook now. |
Hi @beniroquai , |
you can also use try https://github.com/tlambert03/anyfft, if you'd like, which is where I put this pr |
Not sure what you need, but if you want easy, performant OpenCL FFT, try I think there should be no issues with using this along with |
Hey, thanks @psobolewskiPhD for your reply. I may have seen that in the forum.imagesc.com ;-) Thanks @tlambert03, I'll also investigate your repo! :) |
I've not actually used both together 🤣
So this seems to work for me: img_GPU = cle.push(img)
THB = cle.top_hat_box(img_GPU, radius_x = 10, radius_y = 10, radius_z = 10)
img_fft = rfftn(THB) # note this is R2C, so complex output, which is not supported by clesperanto This works, it looks like pyvkFFT can consume the arrays manipulated by pyclesperanto ( But the other direction doesn't work for me. If we reverse transform back (C2R): out = irfftn(img_fft)
gaus = cle.gaussian_blur(out, sigma_x= 10, sigma_y= 10, sigma_z= 10) The cle command returns a
Can test this more directly with: import pyopencl.array as cla
pushed = cla.to_device(device.queue, img)
gaus = cle.gaussian_blur(pushed, sigma_x= 10, sigma_y= 10, sigma_z= 10) That yields an error. |
Hey @psobolewskiPhD ,
Can you please try again with pyclesperanto-prototype 0.17.2 ? I just added support for that array type. If an error remains, please open an issue. @beniroquai : In it feels uncomfortable to discuss your use-case on a closed pull request, feel free to open an issue and explain what you're trying to achieve. There, we can concentrate on discussing your project. Thanks to you two! Best, |
Everything works perfectly now, based on the few tests I did above. |
Thanks @psobolewskiPhD and @haesleinhuepf for your code snippets. I think that's already enough to continue working on the prototype (Holographic Reconstruction - the Ho in HoLiSheet 😉). Once I face the next issue, I may open a new issue. I actually didn't expect it to be that straightforward to reuse memory across python libraries. Cool!! :) |
adds fftn, ifftn, fftshit, and fftconvolve using reikna (added as a dependency)
tested to match the output of
scipy.fftpack