Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:main
base:main
Choose a base branch
Loading
frompicnixz:core/simd-helpers
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
90 commits
Select commitHold shift + click to select a range
9a6ccb5
support simple SIMD detection
picnixzOct 5, 2024
f4e4f99
add _Py prefix
picnixzOct 5, 2024
5006686
Use `_py` prefix
picnixzOct 5, 2024
3c0b4f1
make the interface friendlier for future adjustments
picnixzOct 6, 2024
01ed21a
Allow `cpu_simd_flags` to be merged.
picnixzOct 6, 2024
969a619
update comments
picnixzOct 6, 2024
5a5acc2
fix typo
picnixzOct 6, 2024
ac1b165
fix configure script
picnixzOct 6, 2024
6f304f2
fix bit detection
picnixzOct 6, 2024
f3bd027
Harden detection of AVX instructions.
picnixzOct 7, 2024
16b2aed
do not guard the parsing of `os_xsave`
picnixzOct 7, 2024
5018fa9
Remove old comment.
picnixzOct 7, 2024
e758065
Update cpuinfo.c comments
picnixzOct 7, 2024
731be81
Update pycore_cpuinfo.h comments
picnixzOct 7, 2024
7947715
fix lint
picnixzOct 7, 2024
7a17cbb
I really shouldn't use a Web UI
picnixzOct 7, 2024
76f67b1
Fix _xgetbv() on Windows builds.
picnixzOct 7, 2024
0b49a50
fix comment
picnixzOct 8, 2024
9fd6152
harden detection of CPU features
picnixzOct 8, 2024
97a0fc5
update configure
picnixzOct 11, 2024
f7da530
Merge remote-tracking branch 'upstream/main' into core/simd-helpers-1…
picnixzOct 11, 2024
5f2884d
update comments
picnixzOct 13, 2024
7c3b74e
update Makefile
picnixzOct 13, 2024
130d099
address Erlend's review
picnixzOct 14, 2024
cd575f0
lint & comment fixups
picnixzOct 14, 2024
2b597a4
Update docs
picnixzOct 27, 2024
78be530
Fix typo
picnixzOct 27, 2024
fd47f0e
Merge branch 'main' into core/simd-helpers
picnixzDec 17, 2024
cbb7b53
re-export functions for extension modules
picnixzDec 17, 2024
21d8ca8
rename os_xsave to osxsave for future automatism
picnixzDec 17, 2024
1f9dbb4
remember `maxleaf` and make detection more readable
picnixzDec 18, 2024
553aa7c
use enumeration for flags
picnixzDec 18, 2024
39d2ba4
fix warnings
picnixzDec 21, 2024
602bb9c
Merge branch 'main' into core/simd-helpers
picnixzDec 21, 2024
d6a3523
remove un-necessary comment and newline continuation
picnixzDec 22, 2024
ff4212e
Merge branch 'main' into core/simd-helpers
picnixzFeb 16, 2025
3cb79f6
regen configure
picnixzFeb 17, 2025
e0a578c
clinic now supports empty comment lines in Python blocks
picnixzFeb 17, 2025
6fdbbdf
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzMar 11, 2025
c265851
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzMar 29, 2025
c12f9c7
move cpuinfo enumerations to real invokable Python scripts
picnixzMar 29, 2025
a6c443f
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzApr 5, 2025
bd3589f
add comments
picnixzApr 5, 2025
d213b67
update C comments
picnixzApr 8, 2025
4109d90
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzApr 8, 2025
19b7d86
TMP: usage proof-of-concept
picnixzApr 8, 2025
1732b6b
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzApr 22, 2025
d59d06d
improve configure.ac
picnixzApr 22, 2025
bc2c1e5
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzApr 25, 2025
4a92103
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixzJun 2, 2025
26ed6fd
Merge branch 'main' into feat/core/simd-125022
picnixzJun 30, 2025
d00da3e
post-merge
picnixzJun 30, 2025
8b7ecfb
use `_Py` prefix to prevent public namespace pollution
picnixzJun 30, 2025
3c31ba3
let the compiler decide on the inlineness
picnixzJun 30, 2025
143d57e
drop CPUID_REG alias
picnixzJun 30, 2025
ee2a83c
simplify `_Py_cpuid_check_features`
picnixzJun 30, 2025
e6d4583
amend docs for `_Py_cpuid_disable_features`
picnixzJun 30, 2025
838f928
use macros to support larger flag ranges
picnixzJun 30, 2025
62c9a40
handle -Wpedantic
picnixzJun 30, 2025
a22aa95
reorganize files
picnixzJul 8, 2025
87039dc
suppress compilation warnings
picnixzJul 8, 2025
8a4b120
add linting
picnixzJul 8, 2025
8603e14
typo
picnixzJul 8, 2025
d6213a5
typo
picnixzJul 8, 2025
79d5b34
log more!
picnixzJul 13, 2025
f69d74a
skip CI
picnixzJul 13, 2025
cb9065d
more printf
picnixzJul 13, 2025
88df3b7
faster ci
picnixzJul 13, 2025
db64ba5
!!
picnixzJul 13, 2025
04012b4
!!
picnixzJul 13, 2025
144d9ef
does it work now..?
picnixzJul 14, 2025
b364ad2
does it work now..?
picnixzJul 14, 2025
0791e89
remove xgetbv support?
picnixzJul 14, 2025
48b2cb2
remove xgetbv support?
picnixzJul 14, 2025
34f1337
huh?
picnixzJul 14, 2025
91effb4
only parse maxleaf
picnixzJul 14, 2025
6dc532d
use different variables!
picnixzJul 14, 2025
6d5dd0b
disable everything!
picnixzJul 14, 2025
8e5b2f0
revert CI
picnixzJul 14, 2025
3b495f6
only check maxleaf
picnixzJul 14, 2025
8019f09
parse L1
picnixzJul 14, 2025
820d140
parse L7
picnixzJul 14, 2025
df85ce5
it *should* work now
picnixzJul 14, 2025
915383e
:@
picnixzJul 14, 2025
c6cf903
:@
picnixzJul 14, 2025
498518f
waaaaa!
picnixzJul 14, 2025
3d56d93
remove support for XCR0 registers
picnixzJul 14, 2025
08daa8a
fix SIMD-256 detection
picnixzJul 14, 2025
afd1137
simplify `get_cpuid_info`
picnixzJul 14, 2025
79eb72d
add CODEOWNERS
picnixzJul 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions.github/CODEOWNERS
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,10 @@ Lib/test/test_capi/test_misc.py @markshannon
Lib/test/test_pyrepl/* @pablogsal @lysnikolaou @ambv
Tools/c-analyzer/ @ericsnowcurrently

# cpuinfo
Python/cpuinfo.c @picnixz
Python/pycore_cpuinfo*.h @picnixz

# dbm
**/*dbm* @corona10 @erlend-aasland @serhiy-storchaka

Expand Down
86 changes: 82 additions & 4 deletions.github/workflows/build.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -260,7 +260,7 @@ jobs:
free-threading:${{ matrix.free-threading }}
os:${{ matrix.os }}

build-ubuntu-ssltests:
build-ubuntu-ssltests-openssl:
name:'Ubuntu SSL tests with OpenSSL'
runs-on:${{ matrix.os }}
timeout-minutes:60
Expand DownExpand Up@@ -322,6 +322,81 @@ jobs:
-name:SSL tests
run:./python Lib/test/ssltests.py

build-ubuntu-ssltests-awslc:
name:'Ubuntu SSL tests with AWS-LC'
runs-on:${{ matrix.os }}
timeout-minutes:60
needs:build-context
if:needs.build-context.outputs.run-tests == 'true'
strategy:
fail-fast:false
matrix:
os:[ubuntu-24.04]
awslc_ver:[1.55.0]
env:
AWSLC_VER:${{ matrix.awslc_ver}}
MULTISSL_DIR:${{ github.workspace }}/multissl
OPENSSL_DIR:${{ github.workspace }}/multissl/aws-lc/${{ matrix.awslc_ver }}
LD_LIBRARY_PATH:${{ github.workspace }}/multissl/aws-lc/${{ matrix.awslc_ver }}/lib
steps:
-uses:actions/checkout@v4
with:
persist-credentials:false
-name:Runner image version
run:echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
-name:Restore config.cache
uses:actions/cache@v4
with:
path:config.cache
key:${{ github.job }}-${{ env.IMAGE_OS_VERSION }}-${{ needs.build-context.outputs.config-hash }}
-name:Register gcc problem matcher
run:echo "::add-matcher::.github/problem-matchers/gcc.json"
-name:Install dependencies
run:sudo ./.github/workflows/posix-deps-apt.sh
-name:Configure SSL lib env vars
run:|
echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> "$GITHUB_ENV"
echo "OPENSSL_DIR=${GITHUB_WORKSPACE}/multissl/aws-lc/${AWSLC_VER}" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/multissl/aws-lc/${AWSLC_VER}/lib" >> "$GITHUB_ENV"
-name:'Restore AWS-LC build'
id:cache-aws-lc
uses:actions/cache@v4
with:
path:./multissl/aws-lc/${{ matrix.awslc_ver }}
key:${{ matrix.os }}-multissl-aws-lc-${{ matrix.awslc_ver }}
-name:Install AWS-LC
if:steps.cache-aws-lc.outputs.cache-hit != 'true'
run:|
python3 Tools/ssl/multissltests.py \
--steps=library \
--base-directory "$MULTISSL_DIR" \
--awslc ${{ matrix.awslc_ver }} \
--system Linux
-name:Add ccache to PATH
run:|
echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV"
-name:Configure ccache action
uses:hendrikmuhs/ccache-action@v1.2
with:
save:false
-name:Configure CPython
run:|
./configure CFLAGS="-fdiagnostics-format=json" \
--config-cache \
--enable-slower-safety \
--with-pydebug \
--with-openssl="$OPENSSL_DIR" \
--with-builtin-hashlib-hashes=blake2 \
--with-ssl-default-suites=openssl
-name:Build CPython
run:make -j
-name:Display build info
run:make pythoninfo
-name:Verify python is linked to AWS-LC
run:./python -c 'import ssl; print(ssl.OPENSSL_VERSION)' | grep AWS-LC
-name:SSL tests
run:./python Lib/test/ssltests.py

build-wasi:
name:'WASI'
needs:build-context
Expand DownExpand Up@@ -628,7 +703,8 @@ jobs:
-build-windows-msi
-build-macos
-build-ubuntu
-build-ubuntu-ssltests
-build-ubuntu-ssltests-awslc
-build-ubuntu-ssltests-openssl
-build-wasi
-test-hypothesis
-build-asan
Expand All@@ -643,7 +719,8 @@ jobs:
with:
allowed-failures:>-
build-windows-msi,
build-ubuntu-ssltests,
build-ubuntu-ssltests-awslc,
build-ubuntu-ssltests-openssl,
test-hypothesis,
cifuzz,
allowed-skips:>-
Expand All@@ -661,7 +738,8 @@ jobs:
check-generated-files,
build-macos,
build-ubuntu,
build-ubuntu-ssltests,
build-ubuntu-ssltests-awslc,
build-ubuntu-ssltests-openssl,
build-wasi,
test-hypothesis,
build-asan,
Expand Down
168 changes: 168 additions & 0 deletionsInclude/internal/pycore_cpuinfo.h
View file
Open in desktop
Original file line numberDiff line numberDiff 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 */
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp