BLD: Add NPY_DISABLE_SVML env var to opt out of SVML#20695
Conversation
|
I think we try to dispatch to the proper loops at runtime. @seiko2plus Thoughts? |
|
I didn't try too hard to fix the undefined symbol issue on the AMD so I don't know if this was some oversight on my end. The bigger motivator here is the cross-compilation issue. Since SVML supports a very limited slice of numpy targets and is disabled (for native builds) on all others, it seems that the cleanest way around this is and any potential incompatibilities is to just add a switch that short-circuits the compatibility check and disables the library. |
|
I am building this with Thus, it seems the only real utility here is easy support for cross-compilation. |
|
@ahesford, you can disable avx512 features through CPU build options, it will not exclude SVML objects from the final linking but it gonna fix this undefined symbol error. |
|
The undefined symbol error is no longer an issue. It seems to have been a one-off error as a result of repeated build trials. |
|
@ahesford, May I know what is the current issue this pr trying to solve? |
|
At this point, convenient disabling of SVML when cross-compiling numpy. (The build will fail when an x86_64 host is used to compile for any other architecture because the runtime checks on the host will enable the build but the cross assembler will be unable to understand the instructions.) |
|
LGTM +1. |
numpy/core/setup.py
Outdated
| NPY_RELAXED_STRIDES_DEBUG = NPY_RELAXED_STRIDES_DEBUG and NPY_RELAXED_STRIDES_CHECKING | ||
|
|
||
| # Set NPY_DISABLE_SVML=1 in the environment to disable the vendored SVML | ||
| # library. This option only has significance on Linux x86_64. |
There was a problem hiding this comment.
| # library. This option only has significance on Linux x86_64. | |
| # library. This option only has significance on Linux x86_64 when | |
| # cross-compiling for a non-x86 platform. |
There was a problem hiding this comment.
I clarified the text along these lines and rebased on the latest main branch.
There was a problem hiding this comment.
Looks good. Is "cross-build" more commonly used? In any case, this documentation should be copied to a new section (cross-compiling or cross-building) in doc/source/user/building.rst. If you wish it could be done in a follow on PR (maybe even by someone else), in that case please open a DOC issue and I will merge this as-is. If there is any other information that would be helpful to people trying to cross-build, please add it to the issue/section.
There was a problem hiding this comment.
Not sure if it's more common, but I changed the wording to "cross compiling" to maximize understanding.
Let's add documentation in a separate issue. I'll take a look at some of the accommodations we make in Void and will add some generalized tips as appropriate.
|
Thanks @ahesford |
|
Thanks! |
|
Hi-five on merging your first pull request to NumPy, @ahesford! We hope you stick around! Your choices aren’t limited to programming – you can review pull requests, help us stay on top of new and old issues, develop educational material, work on our website, add or improve graphic design, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://numpy.org/contribute/. |
|
I want to revert these changes, there are two ways to fix this issue rather than adding an optional environment variable:
|
|
The second is the only viable option, since dispatch options do not overcome the fact that non-x86_64 cross compilers will fail when trying to assemble the SVML sources. I do agree that a build-time check that the sources successfully compile should gate the SVML requirement rather than the current platform check. However, why prohibit exclusion even for native builds given that SVML currently supports only a tiny subset of the target platforms? I recommend the current SVML disable flag remain until SVML supports a wide range of supported hardware and becomes more critical to NumPy operation. The flag is off by default and doesn't hurt anybody. |
it isn't true since we have an internal mechanism for testing each specified CPU feature against compiler and assembler before enabling it, that's why you didn't face the same issue with AVX512/C intrinsics. you can check the build log or try to take a look at the SIMD doc for more details.
SVML functions aren't executed unless the target CPU support it, otherwise we fall back to C standard math lib. It's hard for maintainers to miss the chance for Linux users to get SVML/AVX512 for free so I think it was the right decision to accept the Intel gift. currently, we are trying to convert Intel ASM code into universal intrinsics see #20363. |
|
I understand that SVML functions aren't executed unless the target CPU supports it and it's nice to have accelerated routines on those (few) systems that support them. My point is that, because the build process must always support not compiling SVML because it is only compilable on native x86_64 Linux builds, I fail to see the downside of keeping a switch that short-circuits the check (which is currently "Am I a Linux x86_64 host?" and is inaccurate for cross builds, but will hopefully one day become "Will the library successfully compile?") and always returns False in answer to these questions. At a minimum, having the switch is good for debugging and testing by allowing quick removal of the AVX512 routines. Even better, it solves a real problem---cross compilation when packaging NumPy for Void Linux---even before a more complicated build process gets smarter about checking for SVML support on the target. |
|
@charris you marked this for |
SVML uses AVX-512 extensions that are only supported on sufficiently new Intel CPUs. Hard-requiring this vendored library for all x86_64 Linux platforms is not appropriate. When I build on an AMD Zen 2 CPU, I get errors to the effect of
when trying to import numpy. Furthermore, the simple platform check thwarts cross-compilation because it is the host, rather than the target, that is checked.
This patch adds recogniton for
NPY_DISABLE_SVML=1in the environment, which will Numpy to build without the vendored SVML library. It might also be desirable to make the default-on behavior a little more nuanced than simply looking for Linux x86_64. However, I dont' have any specific ideas about the circumstances under which it should be enabled by default.