Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-125022: add support for simple SIMD features detection#125011
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
picnixz wants to merge90 commits intopython:mainChoose a base branch frompicnixz:core/simd-helpers
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
Show all changes
90 commits Select commitHold shift + click to select a range
9a6ccb5
support simple SIMD detection
picnixzf4e4f99
add _Py prefix
picnixz5006686
Use `_py` prefix
picnixz3c0b4f1
make the interface friendlier for future adjustments
picnixz01ed21a
Allow `cpu_simd_flags` to be merged.
picnixz969a619
update comments
picnixz5a5acc2
fix typo
picnixzac1b165
fix configure script
picnixz6f304f2
fix bit detection
picnixzf3bd027
Harden detection of AVX instructions.
picnixz16b2aed
do not guard the parsing of `os_xsave`
picnixz5018fa9
Remove old comment.
picnixze758065
Update cpuinfo.c comments
picnixz731be81
Update pycore_cpuinfo.h comments
picnixz7947715
fix lint
picnixz7a17cbb
I really shouldn't use a Web UI
picnixz76f67b1
Fix _xgetbv() on Windows builds.
picnixz0b49a50
fix comment
picnixz9fd6152
harden detection of CPU features
picnixz97a0fc5
update configure
picnixzf7da530
Merge remote-tracking branch 'upstream/main' into core/simd-helpers-1…
picnixz5f2884d
update comments
picnixz7c3b74e
update Makefile
picnixz130d099
address Erlend's review
picnixzcd575f0
lint & comment fixups
picnixz2b597a4
Update docs
picnixz78be530
Fix typo
picnixzfd47f0e
Merge branch 'main' into core/simd-helpers
picnixzcbb7b53
re-export functions for extension modules
picnixz21d8ca8
rename os_xsave to osxsave for future automatism
picnixz1f9dbb4
remember `maxleaf` and make detection more readable
picnixz553aa7c
use enumeration for flags
picnixz39d2ba4
fix warnings
picnixz602bb9c
Merge branch 'main' into core/simd-helpers
picnixzd6a3523
remove un-necessary comment and newline continuation
picnixzff4212e
Merge branch 'main' into core/simd-helpers
picnixz3cb79f6
regen configure
picnixze0a578c
clinic now supports empty comment lines in Python blocks
picnixz6fdbbdf
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzc265851
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzc12f9c7
move cpuinfo enumerations to real invokable Python scripts
picnixza6c443f
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzbd3589f
add comments
picnixzd213b67
update C comments
picnixz4109d90
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz19b7d86
TMP: usage proof-of-concept
picnixz1732b6b
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzd59d06d
improve configure.ac
picnixzbc2c1e5
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz4a92103
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz26ed6fd
Merge branch 'main' into feat/core/simd-125022
picnixzd00da3e
post-merge
picnixz8b7ecfb
use `_Py` prefix to prevent public namespace pollution
picnixz3c31ba3
let the compiler decide on the inlineness
picnixz143d57e
drop CPUID_REG alias
picnixzee2a83c
simplify `_Py_cpuid_check_features`
picnixze6d4583
amend docs for `_Py_cpuid_disable_features`
picnixz838f928
use macros to support larger flag ranges
picnixz62c9a40
handle -Wpedantic
picnixza22aa95
reorganize files
picnixz87039dc
suppress compilation warnings
picnixz8a4b120
add linting
picnixz8603e14
typo
picnixzd6213a5
typo
picnixz79d5b34
log more!
picnixzf69d74a
skip CI
picnixzcb9065d
more printf
picnixz88df3b7
faster ci
picnixzdb64ba5
!!
picnixz04012b4
!!
picnixz144d9ef
does it work now..?
picnixzb364ad2
does it work now..?
picnixz0791e89
remove xgetbv support?
picnixz48b2cb2
remove xgetbv support?
picnixz34f1337
huh?
picnixz91effb4
only parse maxleaf
picnixz6dc532d
use different variables!
picnixz6d5dd0b
disable everything!
picnixz8e5b2f0
revert CI
picnixz3b495f6
only check maxleaf
picnixz8019f09
parse L1
picnixz820d140
parse L7
picnixzdf85ce5
it *should* work now
picnixz915383e
:@
picnixzc6cf903
:@
picnixz498518f
waaaaa!
picnixz3d56d93
remove support for XCR0 registers
picnixz08daa8a
fix SIMD-256 detection
picnixzafd1137
simplify `get_cpuid_info`
picnixz79eb72d
add CODEOWNERS
picnixzFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletionsInclude/internal/pycore_cpuinfo.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* @author Bénédikt Tran | ||
* | ||
* Interface for detecting the different CPUID flags in an opaque manner. | ||
* See https://en.wikipedia.org/wiki/CPUID for details on the bit values. | ||
* | ||
* If a module requires to support SIMD instructions, it should determine | ||
* the compiler flags and the instruction sets required for the intrinsics | ||
* to work. | ||
* | ||
* For the headers and expected CPUID bits needed by Intel intrinsics, see | ||
* https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html. | ||
*/ | ||
#ifndef Py_INTERNAL_CPUINFO_H | ||
#define Py_INTERNAL_CPUINFO_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
#include "Python.h" | ||
#include "pycore_cpuinfo_cpuid_features.h" | ||
typedef struct _Py_cpuid_features_s { | ||
uint32_t maxleaf; | ||
/* | ||
* Macro to declare a member flag of '_Py_cpuid_features' as a uint8_t. | ||
* Whenever this macro is used, do not forget to update the number of | ||
* fields and the bitsize of the 'ready' member (see structure end). | ||
*/ | ||
#define _Py_CPUID_DECL_FLAG(MEMBER_NAME) uint8_t MEMBER_NAME:1 | ||
// --- Streaming SIMD Extensions ------------------------------------------ | ||
_Py_CPUID_DECL_FLAG(sse); | ||
_Py_CPUID_DECL_FLAG(sse2); | ||
_Py_CPUID_DECL_FLAG(sse3); | ||
_Py_CPUID_DECL_FLAG(ssse3); // Supplemental SSE3 instructions | ||
_Py_CPUID_DECL_FLAG(sse41); // SSE4.1 | ||
_Py_CPUID_DECL_FLAG(sse42); // SSE4.2 | ||
// --- Advanced Vector Extensions ----------------------------------------- | ||
_Py_CPUID_DECL_FLAG(avx); | ||
_Py_CPUID_DECL_FLAG(avx_ifma); | ||
_Py_CPUID_DECL_FLAG(avx_ne_convert); | ||
_Py_CPUID_DECL_FLAG(avx_vnni); | ||
_Py_CPUID_DECL_FLAG(avx_vnni_int8); | ||
_Py_CPUID_DECL_FLAG(avx_vnni_int16); | ||
// --- Advanced Vector Extensions 2 --------------------------------------- | ||
_Py_CPUID_DECL_FLAG(avx2); | ||
// --- Advanced Vector Extensions (512-bit) ------------------------------- | ||
/* | ||
* AVX-512 instruction set are grouped by the processor generation | ||
* that implements them (see https://en.wikipedia.org/wiki/AVX-512). | ||
* | ||
* We do not include GFNI, VPCLMULQDQ and VAES instructions since | ||
* they are not exactly AVX-512 per se, nor do we include BF16 or | ||
* FP16 since they operate on bfloat16 and binary16 (half-float). | ||
* | ||
* See https://en.wikipedia.org/wiki/AVX-512#Instruction_set for | ||
* the suffix meanings (for instance 'f' stands for 'Foundation'). | ||
*/ | ||
_Py_CPUID_DECL_FLAG(avx512_f); | ||
_Py_CPUID_DECL_FLAG(avx512_cd); | ||
_Py_CPUID_DECL_FLAG(avx512_er); | ||
_Py_CPUID_DECL_FLAG(avx512_pf); | ||
_Py_CPUID_DECL_FLAG(avx512_4fmaps); | ||
_Py_CPUID_DECL_FLAG(avx512_4vnniw); | ||
_Py_CPUID_DECL_FLAG(avx512_vpopcntdq); | ||
_Py_CPUID_DECL_FLAG(avx512_vl); | ||
_Py_CPUID_DECL_FLAG(avx512_dq); | ||
_Py_CPUID_DECL_FLAG(avx512_bw); | ||
_Py_CPUID_DECL_FLAG(avx512_ifma); | ||
_Py_CPUID_DECL_FLAG(avx512_vbmi); | ||
_Py_CPUID_DECL_FLAG(avx512_vnni); | ||
_Py_CPUID_DECL_FLAG(avx512_vbmi2); | ||
_Py_CPUID_DECL_FLAG(avx512_bitalg); | ||
_Py_CPUID_DECL_FLAG(avx512_vp2intersect); | ||
// --- Instructions ------------------------------------------------------- | ||
_Py_CPUID_DECL_FLAG(cmov); | ||
_Py_CPUID_DECL_FLAG(fma); | ||
_Py_CPUID_DECL_FLAG(popcnt); | ||
_Py_CPUID_DECL_FLAG(pclmulqdq); | ||
_Py_CPUID_DECL_FLAG(xsave); // XSAVE/XRSTOR/XSETBV/XGETBV | ||
_Py_CPUID_DECL_FLAG(osxsave); // XSAVE is enabled by the OS | ||
#undef _Py_CPUID_DECL_FLAG | ||
// Whenever a field is added or removed above, update the | ||
// number of fields (35) and adjust the bitsize of 'ready' | ||
// so that the size of this structure is a multiple of 8. | ||
uint8_t ready: 5; // set if the structure is ready for usage | ||
} _Py_cpuid_features; | ||
/* | ||
* Explicitly set all members to zero to guarantee that | ||
* we never have a non-initialized attribute at runtime | ||
* which could lead to an illegal instruction error. | ||
* | ||
* This readiness state of 'flags' is ignored and left untouched. | ||
* | ||
* Note: This function does not set any exception and thus never fails. | ||
*/ | ||
PyAPI_FUNC(void) | ||
_Py_cpuid_disable_features(_Py_cpuid_features *flags); | ||
/* | ||
* Check whether the structure is ready and flags are inter-compatible, | ||
* returning 1 on success and 0 otherwise. | ||
* | ||
* The caller should disable all CPUID detected features if the check | ||
* fails to avoid encountering runtime illegal instruction errors. | ||
* | ||
* Note: This function does not set any exception and thus never fails. | ||
*/ | ||
PyAPI_FUNC(int) | ||
_Py_cpuid_check_features(const _Py_cpuid_features *flags); | ||
/* | ||
* Return 1 if all expected flags are set in 'actual', 0 otherwise. | ||
* | ||
* If 'actual' or 'expect' are not ready yet, this also returns 0. | ||
* | ||
* Note: This function does not set any exception and thus never fails. | ||
*/ | ||
PyAPI_FUNC(int) | ||
_Py_cpuid_has_features(const _Py_cpuid_features *actual, | ||
const _Py_cpuid_features *expect); | ||
/* | ||
* Return 1 if 'actual' and 'expect' are identical, 0 otherwise. | ||
* | ||
* If 'actual' or 'expect' are not ready yet, this also returns 0. | ||
* | ||
* Note: This function does not set any exception and thus never fails. | ||
*/ | ||
PyAPI_FUNC(int) | ||
_Py_cpuid_match_features(const _Py_cpuid_features *actual, | ||
const _Py_cpuid_features *expect); | ||
/* | ||
* Detect the available host features, storing the result in 'flags'. | ||
* | ||
* Note: This function does not set any exception and thus never fails. | ||
*/ | ||
PyAPI_FUNC(void) | ||
_Py_cpuid_detect_features(_Py_cpuid_features *flags); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_CPUINFO_H */ |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.