flatironinstitute / cufinufft

Nonuniform fast Fourier transforms of types 1 and 2, in 1D, 2D, and 3D, on the GPU
Other
83 stars 18 forks source link

Compatibility with Pytorch #154

Closed pierre-weiss closed 1 year ago

pierre-weiss commented 1 year ago

This is a great implementation. One regret I have is its lack of "direct" compatibility with Pytorch. To make it compatible, I followed the tweak indicated by Alban Gossard here : https://github.com/albangossard/Bindings-NUFFT-pytorch

And replaced if not c.dtype == fk.dtype == self.complex_dtype: raise TypeError("cufinufft execute expects {} dtype arguments " "for this plan. Check plan and arguments.".format( self.complex_dtype)) ier = self._exec_plan(c.ptr, fk.ptr, self.plan) by ier = self._exec_plan(c, fk, self.plan) in cufinufft.py

Unfortunately, this results in memory leaks. Any advice on how to use this excellent implementation with Pytorch arrays ?

blackwer commented 1 year ago

We've sense moved cufinufft into the main finufft codebase. There is currently a PR with a working pytorch interface here: https://github.com/flatironinstitute/finufft/pull/326 That implementation should avoid memory leaks properly when using the plan object. Hopefully this will be put into the next major release. If you'd like to try it in the meantime, you'll need to build it yourself or make the relevant hacks to the python code. The underlying cufinufft C API has changed, so the python code requires a bit of work to backport to the release version though.

pierre-weiss commented 1 year ago

Dear Robert,

Thanks a lot for your fast answer. Together with Alban Gossard, we just modified the nufft_bindings https://github.com/albangossard/Bindings-NUFFT-pytorch with a strategy similar to what is proposed in your link... We think there should be no problem anymore for us temporarily. It will be nice to see finufft handling pytorch near natively.

Best ! Pierre

Le lun. 14 août 2023 à 19:40, Robert Blackwell @.***> a écrit :

We've sense moved cufinufft into the main finufft codebase. There is currently a PR with a working pytorch interface here: flatironinstitute/finufft#326 https://github.com/flatironinstitute/finufft/pull/326 That implementation should avoid memory leaks properly when using the plan object. Hopefully this will be put into the next major release. If you'd like to try it in the meantime, you'll need to build it yourself or make the relevant hacks to the python code. The underlying cufinufft C API has changed, so the python code requires a bit of work to backport to the release version though.

— Reply to this email directly, view it on GitHub https://github.com/flatironinstitute/cufinufft/issues/154#issuecomment-1677794545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEUG7BGARYNLXJOT2N67OBLXVJPHPANCNFSM6AAAAAA3MRXUFU . You are receiving this because you authored the thread.Message ID: @.***>