Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Use threadpoolctl in show_runtime (a new function) #21468

Merged
merged 5 commits into from Aug 21, 2022

Conversation

ganesh-k13
Copy link
Member

@ganesh-k13 ganesh-k13 commented May 6, 2022

ENH: Use threadpoolctl

  • Use threadpoolctl at np.show_config np.show_runtime
  • Refactor SIMD extensions display logic

Sample output

>>> 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'}]

or

>>> np.show_runtime()
WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information
[{'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']}}]

resolves: #21340
related: #20939

@rgommers
Copy link
Member

Thanks for working on this @ganesh-k13!

Note that gh-14492 is also very much related. I think we'd like show_config to display both build-time and runtime info, and clearly state which is which (right now it's build-time only info, but it's a bit confusing).

@rgommers rgommers changed the title ENH: Use threadpoolctl ENH: Use threadpoolctl in show_config May 15, 2022
@charris
Copy link
Member

charris commented May 15, 2022

@rgommers Out of curiosity, can the build time information be obtained from meson?

@ganesh-k13
Copy link
Member Author

display both build-time and runtime info

Ah ok, thanks for the info @rgommers! Let me see how we can pull up that info today. As @charris suggested, maybe meson can help, but only if it's built using that?

@rgommers
Copy link
Member

@rgommers Out of curiosity, can the build time information be obtained from meson?

There's always a way:) It has sane configure-time output, which may make sense to store in full:

meson setup build
The Meson build system
Version: 0.61.0
Source dir: /Users/rgommers/code/bldscipy
Build dir: /Users/rgommers/code/bldscipy/build
Build type: native build
Project name: SciPy
Project version: 1.9.0.dev0
C compiler for the host machine: arm64-apple-darwin20.0.0-clang (clang 11.1.0 "clang version 11.1.0")
C linker for the host machine: arm64-apple-darwin20.0.0-clang ld64 530
C++ compiler for the host machine: arm64-apple-darwin20.0.0-clang++ (clang 11.1.0 "clang version 11.1.0")
C++ linker for the host machine: arm64-apple-darwin20.0.0-clang++ ld64 530
Host machine cpu family: aarch64
Host machine cpu: arm64
Compiler for C supports arguments -Wno-unused-but-set-variable: NO
Library m found: YES
['/Users/rgommers/mambaforge/envs/scipy-dev/bin/arm64-apple-darwin20.0.0-gfortran', '-Wno-conversion', '-Wl,-pie', '-Wl,-headerpad_max_install_names', '-Wl,-dead_strip_dylibs', '-Wl,-rpath,/Users/rgommers/mambaforge/envs/scipy-dev/lib', '-L/Users/rgommers/mambaforge/envs/scipy-dev/lib', '/Users/rgommers/code/bldscipy/build/meson-private/sanitycheckf.f90', '-o', '/Users/rgommers/code/bldscipy/build/meson-private/sanitycheckf']
AHH
['/Users/rgommers/code/bldscipy/build/meson-private/sanitycheckf']
 Fortran compilation is working.
0
Fortran compiler for the host machine: /Users/rgommers/mambaforge/envs/scipy-dev/bin/arm64-apple-darwin20.0.0-gfortran (gcc 11.0.1 "GNU Fortran (GCC) 11.0.1 20210403 (experimental)")
Fortran linker for the host machine: /Users/rgommers/mambaforge/envs/scipy-dev/bin/arm64-apple-darwin20.0.0-gfortran ld64 530
Program cython found: YES (/Users/rgommers/mambaforge/envs/scipy-dev/bin/cython)
Program pythran found: YES (/Users/rgommers/mambaforge/envs/scipy-dev/bin/pythran)
Program cp found: YES (/bin/cp)
Program python3 found: YES (/Users/rgommers/mambaforge/envs/scipy-dev/bin/python3.9)
WARNING: Python files installed by Meson might not be found by python interpreter.
 This warning can be avoided by setting "python.platlibdir" option.
WARNING: Python files installed by Meson might not be found by python interpreter.
 This warning can be avoided by setting "python.purelibdir" option.
Found pkg-config: /Users/rgommers/mambaforge/envs/scipy-dev/bin/pkg-config (0.29.2)
Library npymath found: YES
Library npyrandom found: YES
Run-time dependency openblas found: YES 0.3.18
Dependency openblas found: YES 0.3.18 (cached)
Program _build_utils/cythoner.py found: YES (/Users/rgommers/mambaforge/envs/scipy-dev/bin/python3.9 /Users/rgommers/code/bldscipy/scipy/_build_utils/cythoner.py)
Checking for function "open_memstream" : YES
Configuring messagestream_config.h using configuration
Checking for size of "void*" : 8
Run-time dependency threads found: YES
Checking for size of "void*" : 8
Dependency threads found: YES unknown (cached)
Compiler for C supports arguments -Wno-unused-but-set-variable: NO (cached)
Dependency openblas found: YES 0.3.18 (cached)
Compiler for C++ supports arguments -mmacosx-version-min=10.9: YES
Compiler for C supports arguments -Wno-unused-but-set-variable: NO (cached)
Compiler for C++ supports arguments -Wno-format-truncation: NO

It contains Run-time dependency openblas found: YES 0.3.18, so yes that covers BLAS/LAPACK at build time, but some of the other things in there are equally useful for debugging user-reported issues.

@mattip
Copy link
Member

mattip commented May 19, 2022

I would be fine with fixing show_config one step at a time if it is complicated to do all the fixes in one go. Having the threadpoolctl runtime information would already help in many situations.

@ganesh-k13
Copy link
Member Author

Hey @mattip, I see two enhancements based on various discussions,

  1. Show both runtime and build time info.
  2. Figure out a fix for Windows.

Which do you think is apt for this PR, I can work on that.

directories, include directories, etc.) in the system on which
NumPy was built.
Print information about various resources in the system
on which NumPy was built.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information presented no longer is the build-time information.

Suggested change
on which NumPy was built.
including available intrinsic support and BLAS/LAPACK library
in use

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done via 77198c9

'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.20'}]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the example of the SIMD information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to clutter the docstring, but yeah makes sense to add it as it'll always be displayed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done via 77198c9

@mattip
Copy link
Member

mattip commented May 30, 2022

I think this change would be more appropriate as a new show_runtime() function. Then we can iterate on this in the future.

@ganesh-k13
Copy link
Member Author

Oh yeah that's a good point, we can make show_runtime() and later show_buildinfo() (or something like that) and then merge with show_config if it's received well. Will do 👍

@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch 2 times, most recently from 02043a2 to 49ed995 Compare July 24, 2022 07:14
@ganesh-k13 ganesh-k13 changed the title ENH: Use threadpoolctl in show_config ENH: Use threadpoolctl in show_runtime (a new function) Jul 24, 2022
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from 49ed995 to 77198c9 Compare July 24, 2022 07:16
@mattip
Copy link
Member

mattip commented Jul 25, 2022

I see you updated the PR description to show the new function output. It looks good to me.

This is failing since it adds a new function to the namespace. It should probably hit the mailing list in parallel with fixing the test to allow the addition. When you post, please add the output.

@ganesh-k13
Copy link
Member Author

Thanks Matti, fixing the tests now.

I've posted to the mailing list today: https://mail.python.org/archives/list/numpy-discussion@python.org/thread/A3Q2WXBRFK3MKHOSEX3RUVRJRKCFGWKX/

@mattip
Copy link
Member

mattip commented Aug 10, 2022

I don't think this needs to be part of the generated __config__.py file. Maybe a better home would be in numpy/lib/utils.py. The distutils module is due to be deprecated.

ganesh-k13 added a commit to ganesh-k13/numpy that referenced this pull request Aug 18, 2022
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from 99e25bc to 4da4044 Compare August 18, 2022 13:50
@ganesh-k13
Copy link
Member Author

Thanks for the review Matti! I have moved it to lib/utils.py and also added a release note.

ganesh-k13 added a commit to ganesh-k13/numpy that referenced this pull request Aug 18, 2022
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from 4da4044 to 73e2245 Compare August 18, 2022 13:53
Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just some documentation tweaks.

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.
This function returns a list of dictionaries as follows::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think everything from here down should be removed. show_runtime should be added to the documentation here

. Then the references above could change to numpy.show_runtime, and numpy.show_config (with single back-ticks), and they would be turned into links.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow yeah, that's nice! Added via 706c922 and c806a0a

Comment on lines 24 to 26
in use
See Also
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line needed

Suggested change
in use
See Also
in use
See Also

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in fe63699

Comment on lines 27 to 30
show_config : Show libraries in the system on which
NumPy was built.
Notes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line, reformat

Suggested change
show_config : Show libraries in the system on which
NumPy was built.
Notes
show_config : Show libraries in the system on which NumPy was built.
Notes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in fe63699

Comment on lines 36 to 37
`__cpu_baseline__` and `__cpu_dispatch__`
Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line needed

Suggested change
`__cpu_baseline__` and `__cpu_dispatch__`
Examples
`__cpu_baseline__` and `__cpu_dispatch__`
Examples

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in fe63699

Comment on lines 33 to 34
2. In case `threadpoolctl` is not installed, a message is
displayed with help on how to install it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is really needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in fe63699

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__`
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from 73e2245 to c806a0a Compare August 19, 2022 12:50
Comment on lines 1 to 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double back-ticks for np.* to format as code. If you want a link, you need to use numpy.* with single back-ticks. We tried telling sphinx that np is an alias for numpy, but couldn't get the links to work.

Suggested change
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.
New function ``np.show_runtime``
--------------------------------
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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info! Learning Sphinx on the way :). Fixed via 3d2fe4e

Comment on lines 34 to 35
2. SIMD related information is derived from `__cpu_features__`,
`__cpu_baseline__` and `__cpu_dispatch__`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double back-ticks to format as code. Single back-ticks for links. I don't think we have links for those attributes.

Suggested change
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__``

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via 3d2fe4e


Notes
-----
1. Information is derived with the help of `threadpoolctl`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want this to be a link, you have to provide the url. Otherwise use double back-ticks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks yeah it renders now: https://output.circle-artifacts.com/output/job/79c7902f-6c77-4b35-8f43-d55ceaee6ff5/artifacts/0/doc/build/html/reference/generated/numpy.show_runtime.html, all though it will give flake8 errors, I'm not sure why adding new line like this did not work:

numpy/numpy/lib/npyio.py

Lines 1846 to 1847 in 17d730a

.. [1] NumPy User Guide, section `I/O with NumPy
<https://docs.scipy.org/doc/numpy/user/basics.io.genfromtxt.html>`_.

ganesh-k13 added a commit to ganesh-k13/numpy that referenced this pull request Aug 21, 2022
ganesh-k13 added a commit to ganesh-k13/numpy that referenced this pull request Aug 21, 2022
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from b5d1e93 to ab63e3f Compare August 21, 2022 10:54
ganesh-k13 added a commit to ganesh-k13/numpy that referenced this pull request Aug 21, 2022
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from ab63e3f to c8ed74e Compare August 21, 2022 11:05
numpy/lib/utils.py Outdated Show resolved Hide resolved
@ganesh-k13 ganesh-k13 force-pushed the enh_21340_show_config_threadpoolctl branch from c8ed74e to 3d2fe4e Compare August 21, 2022 12:45
@mattip mattip merged commit 185c4f2 into numpy:main Aug 21, 2022
@mattip
Copy link
Member

mattip commented Aug 21, 2022

Thanks @ganesh-k13 this will be helpful going forward

BvB93 added a commit to BvB93/numpy that referenced this pull request Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: use threadpoolctl to show runtime acceleration framework in show_config()
4 participants