Skip to content
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

Executing Pyfftw in a nogil block #374

Open
gabrielfougeron opened this issue Mar 22, 2024 · 3 comments · May be fixed by #375
Open

Executing Pyfftw in a nogil block #374

gabrielfougeron opened this issue Mar 22, 2024 · 3 comments · May be fixed by #375

Comments

@gabrielfougeron
Copy link

          I think that should work fine assuming Cython is happy. I would suggest limiting yourself to the normal calls.

I think you can call execute with nogil. The innards of that are read-only properties so unless you're doing something nefarious to the class it should be ok. Is it more than just the execute part?

Have you noted that execute already runs as no-gil?

Originally posted by @hgomersall in #373 (comment)

@gabrielfougeron
Copy link
Author

Sorry for the horrendous formatting of the previous message, this is straight from the "Reference in a new issue" feature from Github.

Anyway.

Coming back to the idea of computing ffts with the gil released, turns out you still need the gil to call FTW.execute().
Here is the code to the execute method.

    cpdef execute(self):
        '''execute()

        Execute the planned operation, taking the correct kind of FFT of
        the input array (i.e. :attr:`FFTW.input_array`),
        and putting the result in the output array (i.e.
        :attr:`FFTW.output_array`).
        '''
        cdef void *input_pointer = (
                <void *>np.PyArray_DATA(self._input_array))
        cdef void *output_pointer = (
                <void *>np.PyArray_DATA(self._output_array))

        cdef void *plan = self._plan
        cdef fftw_generic_execute fftw_execute = self._fftw_execute
        with nogil:
            fftw_execute(plan, input_pointer, output_pointer)

In order to call it from a nogil block, this should really be marked nogil (and probably be cdef, I'm not sure)

HOWEVER, if self._fftw_execute and self._plan were not private, but readonly, I think I could get away with it.

My question is: how do you feel about those two properties being readonly ?

@hgomersall
Copy link
Collaborator

I think execute can happily be nogil for calling from Cython (though we should check that np.PyArray_DATA does not do anything pythony). Is this possible? This code is pretty ancient nowadays so things might have improved to make this sort of this possible/better now.

Do you have a reference to making it readonly? Does this just make it more broadly accessible from Cython?

@gabrielfougeron
Copy link
Author

gabrielfougeron commented Mar 25, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants