--- numba/np/ufunc/tbbpool.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) --- a/numba/np/ufunc/tbbpool.cpp +++ b/numba/np/ufunc/tbbpool.cpp @@ -12,6 +12,7 @@ Implement parallel vectorize workqueue o #undef _XOPEN_SOURCE #endif +#include #include #include #include @@ -27,10 +28,28 @@ Implement parallel vectorize workqueue o * from here: * https://github.com/intel/tbb/blob/2019_U5/include/tbb/tbb_stddef.h#L29 */ -#if (TBB_INTERFACE_VERSION >= 12060) || (TBB_INTERFACE_VERSION < 12010) -#error "TBB version is incompatible, 2021.1 through to 2021.5 required, i.e. 12010 <= TBB_INTERFACE_VERSION < 12060" +#if TBB_INTERFACE_VERSION < 12010 +#error "TBB version is too old, 2021 update 1, i.e. TBB_INTERFACE_VERSION >= 12010 required" #endif +static tbb::task_scheduler_handle tbb_tsh_attach() +{ +#if TBB_INTERFACE_VERSION >= 12060 + return tbb::attach(); +#else + return tbb::task_scheduler_handle::get(); +#endif +} + +static void tbb_tsh_release(tbb::task_scheduler_handle& tsh) +{ +#if TBB_INTERFACE_VERSION >= 12060 + tsh.release(); +#else + tbb::task_scheduler_handle::release(tsh); +#endif +} + #define _DEBUG 0 #define _TRACE_SPLIT 0 @@ -235,7 +254,7 @@ static void prepare_fork(void) { if (!tbb::finalize(tsh, std::nothrow)) { - tbb::task_scheduler_handle::release(tsh); + tbb_tsh_release(tsh); puts("Unable to join threads to shut down before fork(). " "This can break multithreading in child processes.\n"); } @@ -260,7 +279,7 @@ static void reset_after_fork(void) if(need_reinit_after_fork) { - tsh = tbb::task_scheduler_handle::get(); + tbb_tsh_attach(); set_main_thread(); tsh_was_initialized = true; need_reinit_after_fork = false; @@ -298,7 +317,7 @@ static void launch_threads(int count) if(count < 1) count = tbb::task_arena::automatic; - tsh = tbb::task_scheduler_handle::get(); + tsh = tbb_tsh_attach(); tsh_was_initialized = true; tg = new tbb::task_group;