Skip to content

_scipy_fft_backend has global side-effects #53

Closed
@peterbell10

Description

@peterbell10

Here is a fairly minimal reproducer:

In [1]: import mkl, numpy as np
   ...: import mkl_fft
   ...: from mkl_fft._scipy_fft_backend import fft as scipy_fft
   ...:
   ...: x = np.random.rand(100, 100, 100).astype(np.cdouble)
   ...: mkl.set_num_threads(1)
   ...: %timeit scipy_fft(x, workers=8)
   ...: 
   ...: mkl.set_num_threads(8)
   ...: %timeit mkl_fft.fft(x)
320 µs ± 420 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
3.36 ms ± 1.38 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

I would expect the mkl_fft.fft call to use 8 threads and so be as fast as scipy_fft with workers=8. What actually happens is that scipy_fft set the fft domain thread count to 1 and the domain has higher precedence than the global thread setting.

n_threads = _hardware_counts.get_max_threads_count()
mkl.domain_set_num_threads(n_threads, domain='fft')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions