From 02043a2f9a10213cafb8723aaf1b893f78b929e6 Mon Sep 17 00:00:00 2001 From: ganesh-k13 Date: Sun, 24 Jul 2022 12:40:31 +0530 Subject: [PATCH] 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/__init__.py | 1 + numpy/distutils/misc_util.py | 78 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/numpy/__init__.py b/numpy/__init__.py index 66b8e3eca2c7..3000f3eaa6cb 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -122,6 +122,7 @@ else: try: from numpy.__config__ import show as show_config + from numpy.__config__ import runtime as show_runtime except ImportError as e: msg = """Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py index b3916a2c8c7a..dd5ec256937c 100644 --- a/numpy/distutils/misc_util.py +++ b/numpy/distutils/misc_util.py @@ -2452,6 +2452,84 @@ def show(): print(" found = %s" % (','.join(features_found))) print(" not found = %s" % (','.join(features_not_found))) + def 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. 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__` + + 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_config` again" + " for more detailed build information") + pprint(config_found) ''')) return target