From 706b85fa96ba4ff5f64cfef92ad46c6a599bd3a4 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Thu, 24 Oct 2019 16:02:05 +0200 Subject: [PATCH 1/4] expose threading layer of mkl --- threadpoolctl.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/threadpoolctl.py b/threadpoolctl.py index 8e4e1376..23d0f4ee 100644 --- a/threadpoolctl.py +++ b/threadpoolctl.py @@ -243,6 +243,9 @@ def threadpool_info(): # we map it to 1 for consistency with other libraries. if module['num_threads'] == -1 and module['internal_api'] == 'blis': module['num_threads'] = 1 + if module['internal_api'] == 'mkl': + layer = _get_mkl_threading_layer(module['dynlib']) + module['threading_layer'] = layer # Remove the wrapper for the module and its function del module['set_num_threads'], module['get_num_threads'] del module['dynlib'] @@ -251,6 +254,17 @@ def threadpool_info(): return infos +def _get_mkl_threading_layer(mkl_dynlib): + """Return the threading layer of MKL""" + # The function mkl_set_threading_layer returns the current threading layer + # Calling it with an invalid threading layer allows us to safely get + # the threading layer + set_threading_layer = getattr(mkl_dynlib, "MKL_Set_Threading_Layer") + layer_map = {0: "intel", 1: "sequential", 2: "pgi", + 3: "gnu", 4: "tbb", -1: "not specified"} + return layer_map[set_threading_layer(-1)] + + def _get_version(dynlib, internal_api): if internal_api == "mkl": return _get_mkl_version(dynlib) From 4ebace5aba695bbbe6aaae1cc2d27a7af4c7d345 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 25 Oct 2019 11:34:52 +0200 Subject: [PATCH 2/4] add a test and explicitly set the threading layer in a ci job --- .azure_pipeline.yml | 1 + tests/test_threadpoolctl.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.azure_pipeline.yml b/.azure_pipeline.yml index af4cd24d..41bde87a 100644 --- a/.azure_pipeline.yml +++ b/.azure_pipeline.yml @@ -58,6 +58,7 @@ jobs: VERSION_PYTHON: '*' CC_OUTER_LOOP: 'clang-8' CC_INNER_LOOP: 'gcc' + MKL_THREADING_LAYER: 'INTEL' # Same but with numpy / scipy installed with pip from PyPI and switched # compilers. pylatest_pip_openblas_gcc_clang: diff --git a/tests/test_threadpoolctl.py b/tests/test_threadpoolctl.py index d7698456..5083a23d 100644 --- a/tests/test_threadpoolctl.py +++ b/tests/test_threadpoolctl.py @@ -1,3 +1,4 @@ +import os import re import ctypes import pytest @@ -301,3 +302,17 @@ def test_get_original_num_threads(limit): with pytest.warns(None, match='Multiple value possible'): expected = min([module['num_threads'] for module in original_infos]) assert original_num_threads['blas'] == expected + + +def test_mkl_threading_layer(): + mkl_info = [module for module in threadpool_info() + if module['internal_api'] == 'mkl'] + + if not mkl_info: + pytest.skip("mkl runtime missing") + + expected_layer = os.getenv("MKL_THREADING_LAYER") + actual_layer = mkl_info[0]['threading_layer'] + + if expected_layer: + assert actual_layer == expected_layer.lower() From 9d81b07695b9f6c5e8cd595c47fa3ed3feab041b Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Fri, 25 Oct 2019 11:36:46 +0200 Subject: [PATCH 3/4] cln --- tests/test_threadpoolctl.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_threadpoolctl.py b/tests/test_threadpoolctl.py index 5083a23d..c0d2c130 100644 --- a/tests/test_threadpoolctl.py +++ b/tests/test_threadpoolctl.py @@ -305,11 +305,13 @@ def test_get_original_num_threads(limit): def test_mkl_threading_layer(): + # Check that threadpool_info correctly recovers the threading layer used + # by mkl mkl_info = [module for module in threadpool_info() if module['internal_api'] == 'mkl'] if not mkl_info: - pytest.skip("mkl runtime missing") + pytest.skip("requires MKL") expected_layer = os.getenv("MKL_THREADING_LAYER") actual_layer = mkl_info[0]['threading_layer'] From 91dfa970d4bf792119755c1706842e59d0c4eb3a Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Wed, 6 Nov 2019 13:57:47 +0100 Subject: [PATCH 4/4] add change log entry --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4850acd5..35fe4605 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +1.2.0 (TBD) +=========== + +- Expose MKL threading layer in informations displayed by `threadpool_info`. + This information is referenced in the `threading_layer` field. + https://github.com/joblib/threadpoolctl/pull/48 + + 1.1.0 (2019-09-12) ==================