Skip to content

Commit ceb7b3f

Browse files
Removed use of Lock
Since DftiCache is allocated in thread local storage, use of Lock() is not longer needed.
1 parent d3b0c2c commit ceb7b3f

File tree

1 file changed

+81
-91
lines changed

1 file changed

+81
-91
lines changed

mkl_fft/_pydfti.pyx

Lines changed: 81 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ cimport cpython.pycapsule
3838
from cpython.exc cimport (PyErr_Occurred, PyErr_Clear)
3939
from cpython.mem cimport (PyMem_Malloc, PyMem_Free)
4040

41-
from threading import Lock
4241
from threading import local as threading_local
43-
_lock = Lock()
4442

4543
# thread-local storage
4644
_tls = threading_local()
@@ -334,21 +332,20 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
334332
in_place = 1
335333

336334
if in_place:
337-
with _lock:
338-
_cache_capsule = _tls_dfti_cache_capsule()
339-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
340-
if x_type is cnp.NPY_CDOUBLE:
341-
if dir_ < 0:
342-
status = cdouble_mkl_ifft1d_in(x_arr, n_, <int> axis_, _cache)
343-
else:
344-
status = cdouble_mkl_fft1d_in(x_arr, n_, <int> axis_, _cache)
345-
elif x_type is cnp.NPY_CFLOAT:
346-
if dir_ < 0:
347-
status = cfloat_mkl_ifft1d_in(x_arr, n_, <int> axis_, _cache)
348-
else:
349-
status = cfloat_mkl_fft1d_in(x_arr, n_, <int> axis_, _cache)
335+
_cache_capsule = _tls_dfti_cache_capsule()
336+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
337+
if x_type is cnp.NPY_CDOUBLE:
338+
if dir_ < 0:
339+
status = cdouble_mkl_ifft1d_in(x_arr, n_, <int> axis_, _cache)
350340
else:
351-
status = 1
341+
status = cdouble_mkl_fft1d_in(x_arr, n_, <int> axis_, _cache)
342+
elif x_type is cnp.NPY_CFLOAT:
343+
if dir_ < 0:
344+
status = cfloat_mkl_ifft1d_in(x_arr, n_, <int> axis_, _cache)
345+
else:
346+
status = cfloat_mkl_fft1d_in(x_arr, n_, <int> axis_, _cache)
347+
else:
348+
status = 1
352349

353350
if status:
354351
c_error_msg = mkl_dfti_error(status)
@@ -368,39 +365,38 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
368365
f_arr = __allocate_result(x_arr, n_, axis_, f_type);
369366

370367
# call out-of-place FFT
371-
with _lock:
372-
_cache_capsule = _tls_dfti_cache_capsule()
373-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
374-
if f_type is cnp.NPY_CDOUBLE:
375-
if x_type is cnp.NPY_DOUBLE:
376-
if dir_ < 0:
377-
status = double_cdouble_mkl_ifft1d_out(
378-
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
379-
else:
380-
status = double_cdouble_mkl_fft1d_out(
381-
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
382-
elif x_type is cnp.NPY_CDOUBLE:
383-
if dir_ < 0:
384-
status = cdouble_cdouble_mkl_ifft1d_out(
385-
x_arr, n_, <int> axis_, f_arr, _cache)
386-
else:
387-
status = cdouble_cdouble_mkl_fft1d_out(
388-
x_arr, n_, <int> axis_, f_arr, _cache)
389-
else:
390-
if x_type is cnp.NPY_FLOAT:
391-
if dir_ < 0:
392-
status = float_cfloat_mkl_ifft1d_out(
393-
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
394-
else:
395-
status = float_cfloat_mkl_fft1d_out(
396-
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
397-
elif x_type is cnp.NPY_CFLOAT:
398-
if dir_ < 0:
399-
status = cfloat_cfloat_mkl_ifft1d_out(
400-
x_arr, n_, <int> axis_, f_arr, _cache)
401-
else:
402-
status = cfloat_cfloat_mkl_fft1d_out(
403-
x_arr, n_, <int> axis_, f_arr, _cache)
368+
_cache_capsule = _tls_dfti_cache_capsule()
369+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
370+
if f_type is cnp.NPY_CDOUBLE:
371+
if x_type is cnp.NPY_DOUBLE:
372+
if dir_ < 0:
373+
status = double_cdouble_mkl_ifft1d_out(
374+
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
375+
else:
376+
status = double_cdouble_mkl_fft1d_out(
377+
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
378+
elif x_type is cnp.NPY_CDOUBLE:
379+
if dir_ < 0:
380+
status = cdouble_cdouble_mkl_ifft1d_out(
381+
x_arr, n_, <int> axis_, f_arr, _cache)
382+
else:
383+
status = cdouble_cdouble_mkl_fft1d_out(
384+
x_arr, n_, <int> axis_, f_arr, _cache)
385+
else:
386+
if x_type is cnp.NPY_FLOAT:
387+
if dir_ < 0:
388+
status = float_cfloat_mkl_ifft1d_out(
389+
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
390+
else:
391+
status = float_cfloat_mkl_fft1d_out(
392+
x_arr, n_, <int> axis_, f_arr, ALL_HARMONICS, _cache)
393+
elif x_type is cnp.NPY_CFLOAT:
394+
if dir_ < 0:
395+
status = cfloat_cfloat_mkl_ifft1d_out(
396+
x_arr, n_, <int> axis_, f_arr, _cache)
397+
else:
398+
status = cfloat_cfloat_mkl_fft1d_out(
399+
x_arr, n_, <int> axis_, f_arr, _cache)
404400

405401
if (status):
406402
c_error_msg = mkl_dfti_error(status)
@@ -457,21 +453,20 @@ def _rrfft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
457453
in_place = 1
458454

459455
if in_place:
460-
with _lock:
461-
_cache_capsule = _tls_dfti_cache_capsule()
462-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
463-
if x_type is cnp.NPY_DOUBLE:
464-
if dir_ < 0:
465-
status = double_mkl_irfft_in(x_arr, n_, <int> axis_, _cache)
466-
else:
467-
status = double_mkl_rfft_in(x_arr, n_, <int> axis_, _cache)
468-
elif x_type is cnp.NPY_FLOAT:
469-
if dir_ < 0:
470-
status = float_mkl_irfft_in(x_arr, n_, <int> axis_, _cache)
471-
else:
472-
status = float_mkl_rfft_in(x_arr, n_, <int> axis_, _cache)
456+
_cache_capsule = _tls_dfti_cache_capsule()
457+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
458+
if x_type is cnp.NPY_DOUBLE:
459+
if dir_ < 0:
460+
status = double_mkl_irfft_in(x_arr, n_, <int> axis_, _cache)
461+
else:
462+
status = double_mkl_rfft_in(x_arr, n_, <int> axis_, _cache)
463+
elif x_type is cnp.NPY_FLOAT:
464+
if dir_ < 0:
465+
status = float_mkl_irfft_in(x_arr, n_, <int> axis_, _cache)
473466
else:
474-
status = 1
467+
status = float_mkl_rfft_in(x_arr, n_, <int> axis_, _cache)
468+
else:
469+
status = 1
475470

476471
if status:
477472
c_error_msg = mkl_dfti_error(status)
@@ -489,19 +484,18 @@ def _rrfft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
489484
f_arr = __allocate_result(x_arr, n_, axis_, x_type);
490485

491486
# call out-of-place FFT
492-
with _lock:
493-
_cache_capsule = _tls_dfti_cache_capsule()
494-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
495-
if x_type is cnp.NPY_DOUBLE:
496-
if dir_ < 0:
497-
status = double_double_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
498-
else:
499-
status = double_double_mkl_rfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
487+
_cache_capsule = _tls_dfti_cache_capsule()
488+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
489+
if x_type is cnp.NPY_DOUBLE:
490+
if dir_ < 0:
491+
status = double_double_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
500492
else:
501-
if dir_ < 0:
502-
status = float_float_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
503-
else:
504-
status = float_float_mkl_rfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
493+
status = double_double_mkl_rfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
494+
else:
495+
if dir_ < 0:
496+
status = float_float_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
497+
else:
498+
status = float_float_mkl_rfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
505499

506500
if (status):
507501
c_error_msg = mkl_dfti_error(status)
@@ -558,15 +552,13 @@ def _rc_fft1d_impl(x, n=None, axis=-1, overwrite_arg=False):
558552

559553
# call out-of-place FFT
560554
if x_type is cnp.NPY_FLOAT:
561-
with _lock:
562-
_cache_capsule = _tls_dfti_cache_capsule()
563-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
564-
status = float_cfloat_mkl_fft1d_out(x_arr, n_, <int> axis_, f_arr, HALF_HARMONICS, _cache)
555+
_cache_capsule = _tls_dfti_cache_capsule()
556+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
557+
status = float_cfloat_mkl_fft1d_out(x_arr, n_, <int> axis_, f_arr, HALF_HARMONICS, _cache)
565558
else:
566-
with _lock:
567-
_cache_capsule = _tls_dfti_cache_capsule()
568-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
569-
status = double_cdouble_mkl_fft1d_out(x_arr, n_, <int> axis_, f_arr, HALF_HARMONICS, _cache)
559+
_cache_capsule = _tls_dfti_cache_capsule()
560+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
561+
status = double_cdouble_mkl_fft1d_out(x_arr, n_, <int> axis_, f_arr, HALF_HARMONICS, _cache)
570562

571563
if (status):
572564
c_error_msg = mkl_dfti_error(status)
@@ -645,15 +637,13 @@ def _rc_ifft1d_impl(x, n=None, axis=-1, overwrite_arg=False):
645637

646638
# call out-of-place FFT
647639
if x_type is cnp.NPY_CFLOAT:
648-
with _lock:
649-
_cache_capsule = _tls_dfti_cache_capsule()
650-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
651-
status = cfloat_float_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
640+
_cache_capsule = _tls_dfti_cache_capsule()
641+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
642+
status = cfloat_float_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
652643
else:
653-
with _lock:
654-
_cache_capsule = _tls_dfti_cache_capsule()
655-
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
656-
status = cdouble_double_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
644+
_cache_capsule = _tls_dfti_cache_capsule()
645+
_cache = <DftiCache *>cpython.pycapsule.PyCapsule_GetPointer(_cache_capsule, capsule_name)
646+
status = cdouble_double_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr, _cache)
657647

658648
if (status):
659649
c_error_msg = mkl_dfti_error(status)

0 commit comments

Comments
 (0)