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 allow for specifying CPU features to enable via NPY_ENABLE_CPU_FEATURES
environment variable
#22137
base: main
Are you sure you want to change the base?
Conversation
NPY_ENABLE_CPU_FEATURES
environment variable
@mattip @seiko2plus Do you know where I should add the tests for this? |
maybe within [numpy/core/tests/test_cpu_dispatcher.py] (https://github.com/numpy/numpy/blob/main/numpy/core/tests/test_cpu_dispatcher.py) but it will require loading the module in a separate process. |
@seiko2plus Is there a preference in NumPy for warnings vs errors? My question here is partially because of the fact that enabling a feature that doesn't exist is not equivalent to disabling a feature that doesn't exist, and so may require different ways of handling the error--a warning for the latter seems appropriate, but in the case of the former, it may be better to throw an error and exit. Thoughts? |
For reviewers and interested parties, the current PR's behavior regarding errors/warnings: numpy/numpy/core/src/common/npy_cpu_features.h Lines 108 to 123 in a6231b6
|
As long as the error does not affect the workflow of the following procedures, then choosing to raise runtime-warning would make sense. according to Python's warning-doc import os, warnings
os.environ['NPY_DISABLE_CPU_FEATURES'] = 'XXXX'
warnings.simplefilter("error", RuntimeWarning)
import numpy as np |
@seiko2plus That's perfect. Thank you! |
Tests are missing. For an example of tests that change the environment variables and then run python in a subprocess, see |
I can't reproduce these errors locally. Even when setting up a machine with |
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@Micky774, to reproduce this error, you have to disable the dispatch-able features similar to what the smoke test does, for example: python setup.py build --cpu-baseline=native --cpu-dispatch=none install --user
python runtests.py -n or just python runtests.py --cpu-dispatch=none In general, you have to escape the dispatch tests if |
@Micky774, please let me know when it's ready for review. |
@seiko2plus Should be good now! Thanks for the help :) |
@seiko2plus could you take a look? I think the aarch64 failure is systematic and not connected to this PR. |
Related issues/PRs
Fixes #22058
What does this PR add?
This PR enables the usage of a
NPY_ENABLE_CPU_FEATURES
environment variable whose function is described in #22058.Note that the enabling function errors when asked to enable features not supported by the CPU, or that numpy was not built with. This breaks symmetry with the disabling semantics, but I think this makes sense since it would be a drastic expectation violation otherwise.
Other comments