pytorch_fft icon indicating copy to clipboard operation
pytorch_fft copied to clipboard

Specify output array and in-place operations?

Open eickenberg opened this issue 7 years ago • 3 comments

Either I am missing something or it is not present in this package:

Is there a way to specify target output arrays for the fft? If not, is this planned?

Cufft can do inplace fft, which one could then invoke simply by specifying the output array as the input array.

Having this would make memory-intense work which requires precise control possible. Related to this: Are the cufft plans cached somewhere in memory or on gpu and reusable? Are there plans to make these accessible?

eickenberg avatar Nov 19 '17 21:11 eickenberg

Looks like plans are destroyed always https://github.com/locuslab/pytorch_fft/blob/2ca24e3a1300bf0bfdaeeae29b082138a043a4b3/pytorch_fft/src/generic/th_fft_cuda.c#L84

Any plans to make it possible to keep them?

eickenberg avatar Nov 19 '17 22:11 eickenberg

There is not currently a way to specify the output tensor, however that is a fairly simple change to make (the internal C call allows specified output already, so this is just a matter of adjusting the python interface).

Cufft plans are, as you pointed out, currently destroyed. I hadn't thought about making then reusable and it didn't seem to be that costly, do you have a way in mind of exposing the plan through the interface?

riceric22 avatar Nov 20 '17 23:11 riceric22

It would have to be persisted in a pytorch module or something (like e.g. nn.Conv2d stores its own weights) and initialized when the object is created, with a specific shape. There could be an option to keep or not the fft plan. The thing is that for big ffts recreating the plan every time can actually make it slower than even a normal implementation on CPU. So for large amounts of data it makes quite a difference.

On Mon, Nov 20, 2017 at 3:06 PM, Eric Wong [email protected] wrote:

There is not currently a way to specify the output tensor, however that is a fairly simple change to make (the internal C call allows specified output already, so this is just a matter of adjusting the python interface).

Cufft plans are, as you pointed out, currently destroyed. I hadn't thought about making then reusable and it didn't seem to be that costly, do you have a way in mind of exposing the plan through the interface?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/locuslab/pytorch_fft/issues/16#issuecomment-345861680, or mute the thread https://github.com/notifications/unsubscribe-auth/ABPwCz04PruHBwgC6Pzi9NDagL7cyWDKks5s4gYAgaJpZM4Qjjpj .

eickenberg avatar Nov 20 '17 23:11 eickenberg