vincefn / pyvkfft

Python interface to VkFFT
MIT License
52 stars 6 forks source link

Cannot pass 'omitDimension' to VkFFTApp #36

Open yves-surrel opened 3 months ago

yves-surrel commented 3 months ago

I have a real np.array z of size (h, w, 2), and I want to batch two FFTs on z[...,0] and z[...,1] (innermost batch in VkFFT vocabulary ???), getting the results in a complex array of size (h, (w/2)+1, 2). It seems to be feasible with VkFFT, playing with the omitDimension parameter. It does not seems possible to pass this parameter to VkFFTApp.

In the current state of pyVkFFT, is my operation possible in some way?

vincefn commented 3 months ago

I don't think this is possible with VkFFT - for an R2C transform, the fastest axis (last dimension in a python array with C-ordering) must be transformed.

As stated in the documentation (page 31):

pfUINT omitDimension[VKFFT_MAX_FFT_DIMENSIONS];: Disable FFT for this dimension (0 - FFT enabled, 1 - FFT disabled). Default 0. Doesn't work for R2C first axis for now. Doesn't work with convolutions.

So the only way to do this would be to change the axis order, but maybe you don't have that choice if the order in memory matters. It may also be possible to change the array strides while keeping the shape..

yves-surrel commented 3 months ago

Thx. I guess playing with the strides would possibly enable one FFT on z[..., 0] that would be a good start. For a 1024 x 2048 x 2 float32 numpy array, what would be the right parameters to pass to VkFFTApp (shape, dim, strides, maybe axes...)?

If I replace r2c by c2c (having the result in a complex array of shape (h, w, 2), would it be feasible then? Same question for the VkFFTApp parameters?

vincefn commented 3 months ago

It seems pyopencl does not like non-contiguous arrays, so using strides may not be possible in this case - only C or F arrays, not what you would need.. Maybe there's a way by manipulating the contents of the array, but not sure how.

As for the complex array approach, that's easy, just do a first transform with axes=-2 and then axes=-1 - no need for strides.