You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expose whether a library's limiting API is a shared thread pool #307
In order for joblib to be able to set limits correctly, it wants to do something like this, except without hardcoding OpenBLAS-pthreads specifically since other libraries might be relevant in the future:
def_get_threadpoolctl_limits(tp_controller, limit, is_worker_thread):
"""Return limits for OpenMP/BLAS. The limits can then be passed to ``ThreadpoolController.limit()`` and related APIs. Allows setting different limits for worker threads and top-level managing thread. """limits= []
forlib_controllerintp_controller.lib_controllers:
ifis_worker_threadand (
isinstance(lib_controller, OpenBLASController)
andlib_controller.threading_layer!="openmp"
):
# Worker threads shouldn't try to set OpenBLAS-pthreads global# state in their initializer, because it might never get restored.continue# "filepath" is for threadpoolctl 3.8+, "prefix" for backwards compat# with older versions.limits.append(
{
"filepath": lib_controller.filepath,
"prefix": lib_controller.prefix,
"num_threads": limit,
}
)
returnlimits
Options:
Add API to LibController that return whether it's a shared process-wide pool (default result would probably be "unknown" rather than false). Then, document how to use it with code as above.
Add the high-level logic to threadpoolctl itself, instead of having it in joblib. This simplifies the docs! There is the question of whether to do the per-LibController API or not. Design options:
Function similar to the above example.
Add is_worker_thread to limit() API variants. This makes backwards compatible usage annoying...
ThreadpoolController.limit_for_worker_thread(). Slightly nicer to add backwards compat support in joblib, and potentially there might be other custom policies other than worker threads.
Activity