diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-08-21 07:29:28 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-21 07:29:28 -0600 |
commit | 185c4f205c51049a2a21e406e205e4135fab5273 (patch) | |
tree | 09a5600269fb0133178cb3dbf9f8b91b377aeb10 /numpy | |
parent | 17d730ae32f5f60c9c2ca75d202b4e866debd686 (diff) | |
parent | 3d2fe4ec796be6ae63c482e4c4f74e3c7867ff1d (diff) | |
download | numpy-185c4f205c51049a2a21e406e205e4135fab5273.tar.gz |
Merge pull request #21468 from ganesh-k13/enh_21340_show_config_threadpoolctl
ENH: Use `threadpoolctl` in `show_runtime` (a new function)
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/utils.py | 79 | ||||
-rw-r--r-- | numpy/tests/test_public_api.py | 1 |
2 files changed, 79 insertions, 1 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index e8f4952d3..2fcf270c4 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -13,9 +13,86 @@ import numpy as np __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 <https://pypi.org/project/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. diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index e028488d3..882a48d2f 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 |