From fe6369961f4ff136161b0dac2ae2ec620dbce5fb Mon Sep 17 00:00:00 2001 From: ganesh-k13 Date: Thu, 18 Aug 2022 19:17:09 +0530 Subject: [PATCH 1/5] ENH: Added `show_runtime` 1. Information is derived with the help of `threadpoolctl` library. 2. In case `threadpoolctl` is not installed, a message is displayed with help on how to install it. 3. SIMD related information is derived from `__cpu_features__`, `__cpu_baseline__` and `__cpu_dispatch__` --- numpy/lib/utils.py | 79 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index e8f4952d30eb..479535dcc11d 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -13,9 +13,86 @@ __all__ = [ 'issubclass_', 'issubsctype', 'issubdtype', 'deprecate', 'deprecate_with_doc', 'get_include', 'info', 'source', 'who', - 'lookfor', 'byte_bounds', 'safe_eval' + 'lookfor', 'byte_bounds', 'safe_eval', 'show_runtime' ] + +def show_runtime(): + """ + Print information about various resources in the system + including available intrinsic support and BLAS/LAPACK library + in use + + See Also + -------- + show_config : Show libraries in the system on which NumPy was built. + + Notes + ----- + 1. Information is derived with the help of `threadpoolctl` + library. + 2. SIMD related information is derived from `__cpu_features__`, + `__cpu_baseline__` and `__cpu_dispatch__` + + Examples + -------- + >>> import numpy as np + >>> np.show_runtime() + [{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'], + 'found': ['SSSE3', + 'SSE41', + 'POPCNT', + 'SSE42', + 'AVX', + 'F16C', + 'FMA3', + 'AVX2'], + 'not_found': ['AVX512F', + 'AVX512CD', + 'AVX512_KNL', + 'AVX512_KNM', + 'AVX512_SKX', + 'AVX512_CLX', + 'AVX512_CNL', + 'AVX512_ICL']}}, + {'architecture': 'Zen', + 'filepath': '/usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so', + 'internal_api': 'openblas', + 'num_threads': 12, + 'prefix': 'libopenblas', + 'threading_layer': 'pthreads', + 'user_api': 'blas', + 'version': '0.3.20'}] + """ + from numpy.core._multiarray_umath import ( + __cpu_features__, __cpu_baseline__, __cpu_dispatch__ + ) + from pprint import pprint + config_found = [] + features_found, features_not_found = [], [] + for feature in __cpu_dispatch__: + if __cpu_features__[feature]: + features_found.append(feature) + else: + features_not_found.append(feature) + config_found.append({ + "simd_extensions": { + "baseline": __cpu_baseline__, + "found": features_found, + "not_found": features_not_found + } + }) + try: + from threadpoolctl import threadpool_info + config_found.extend(threadpool_info()) + except ImportError: + print("WARNING: `threadpoolctl` not found in system!" + " Install it by `pip install threadpoolctl`." + " Once installed, try `np.show_runtime` again" + " for more detailed build information") + pprint(config_found) + + def get_include(): """ Return the directory that contains the NumPy \\*.h header files. From 5a2a84a19a125bcc1bc72598ac81938dff790dcb Mon Sep 17 00:00:00 2001 From: ganesh-k13 Date: Thu, 18 Aug 2022 19:18:24 +0530 Subject: [PATCH 2/5] TST: Added show_runtime to test_public_api --- numpy/tests/test_public_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index e028488d39d4..882a48d2ff4e 100644 --- a/numpy/tests/test_public_api.py +++ b/numpy/tests/test_public_api.py @@ -51,6 +51,7 @@ def test_numpy_namespace(): 'safe_eval': 'numpy.lib.utils.safe_eval', 'set_string_function': 'numpy.core.arrayprint.set_string_function', 'show_config': 'numpy.__config__.show', + 'show_runtime': 'numpy.lib.utils.show_runtime', 'who': 'numpy.lib.utils.who', } # We override dir to not show these members From 706c922ff278a6197f47ba678e8cc6128028d5ab Mon Sep 17 00:00:00 2001 From: ganesh-k13 Date: Thu, 18 Aug 2022 19:18:57 +0530 Subject: [PATCH 3/5] DOC: Added `np.show_runtime` (#21468) --- doc/release/upcoming_changes/21468.new_feature.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/release/upcoming_changes/21468.new_feature.rst diff --git a/doc/release/upcoming_changes/21468.new_feature.rst b/doc/release/upcoming_changes/21468.new_feature.rst new file mode 100644 index 000000000000..64678b1c3b92 --- /dev/null +++ b/doc/release/upcoming_changes/21468.new_feature.rst @@ -0,0 +1,6 @@ +New function `np.show_runtime` +------------------------------ + +A new function `np.show_runtime` has been added to display the runtime +information of the machine in addition to `np.show_config` which displays +the build-related information. From c806a0ad789908d80bdd12ffdc4f63472bb19a88 Mon Sep 17 00:00:00 2001 From: ganesh-k13 Date: Fri, 19 Aug 2022 18:19:21 +0530 Subject: [PATCH 4/5] DOC: Added `show_runtime` to Utility --- doc/source/reference/routines.other.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/reference/routines.other.rst b/doc/source/reference/routines.other.rst index bb0be71375e0..e980406eb419 100644 --- a/doc/source/reference/routines.other.rst +++ b/doc/source/reference/routines.other.rst @@ -45,6 +45,7 @@ Utility get_include show_config + show_runtime deprecate deprecate_with_doc broadcast_shapes From 3d2fe4ec796be6ae63c482e4c4f74e3c7867ff1d Mon Sep 17 00:00:00 2001 From: Ganesh Kathiresan Date: Sun, 21 Aug 2022 11:05:30 +0530 Subject: [PATCH 5/5] DOC: Fixed links for np.show_runtime (#21468) --- doc/release/upcoming_changes/21468.new_feature.rst | 8 ++++---- numpy/lib/utils.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/release/upcoming_changes/21468.new_feature.rst b/doc/release/upcoming_changes/21468.new_feature.rst index 64678b1c3b92..c37f057358fa 100644 --- a/doc/release/upcoming_changes/21468.new_feature.rst +++ b/doc/release/upcoming_changes/21468.new_feature.rst @@ -1,6 +1,6 @@ -New function `np.show_runtime` ------------------------------- +New function ``np.show_runtime`` +-------------------------------- -A new function `np.show_runtime` has been added to display the runtime -information of the machine in addition to `np.show_config` which displays +A new function `numpy.show_runtime` has been added to display the runtime +information of the machine in addition to `numpy.show_config` which displays the build-related information. diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 479535dcc11d..2fcf270c4b3b 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -29,10 +29,10 @@ def show_runtime(): Notes ----- - 1. Information is derived with the help of `threadpoolctl` + 1. Information is derived with the help of `threadpoolctl `_ library. - 2. SIMD related information is derived from `__cpu_features__`, - `__cpu_baseline__` and `__cpu_dispatch__` + 2. SIMD related information is derived from ``__cpu_features__``, + ``__cpu_baseline__`` and ``__cpu_dispatch__`` Examples --------