8000 gh-125022: add support for simple SIMD features detection by picnixz · Pull Request #125011 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9a6ccb5
support simple SIMD detection
picnixz Oct 5, 2024
f4e4f99
add _Py prefix
picnixz Oct 5, 2024
5006686
Use `_py` prefix
8000 picnixz Oct 5, 2024
3c0b4f1
make the interface friendlier for future adjustments
picnixz Oct 6, 2024
01ed21a
Allow `cpu_simd_flags` to be merged.
picnixz Oct 6, 2024
969a619
update comments
picnixz Oct 6, 2024
5a5acc2
fix typo
picnixz Oct 6, 2024
ac1b165
fix configure script
picnixz Oct 6, 2024
6f304f2
fix bit detection
picnixz Oct 6, 2024
f3bd027
Harden detection of AVX instructions.
picnixz Oct 7, 2024
16b2aed
do not guard the parsing of `os_xsave`
picnixz Oct 7, 2024
5018fa9
Remove old comment.
picnixz Oct 7, 2024
e758065
Update cpuinfo.c comments
picnixz Oct 7, 2024
731be81
Update pycore_cpuinfo.h comments
picnixz Oct 7, 2024
7947715
fix lint
picnixz Oct 7, 2024
7a17cbb
I really shouldn't use a Web UI
picnixz Oct 7, 2024
76f67b1
Fix _xgetbv() on Windows builds.
picnixz Oct 7, 2024
0b49a50
fix comment
picnixz Oct 8, 2024
9fd6152
harden detection of CPU features
picnixz Oct 8, 2024
97a0fc5
update configure
picnixz Oct 11, 2024
f7da530
Merge remote-tracking branch 'upstream/main' into core/simd-helpers-1…
picnixz Oct 11, 2024
5f2884d
update comments
picnixz Oct 13, 2024
7c3b74e
update Makefile
picnixz Oct 13, 2024
130d099
address Erlend's review
picnixz Oct 14, 2024
cd575f0
lint & comment fixups
picnixz Oct 14, 2024
2b597a4
Update docs
picnixz Oct 27, 2024
78be530
Fix typo
picnixz Oct 27, 2024
fd47f0e
Merge branch 'main' into core/simd-helpers
picnixz Dec 17, 2024
cbb7b53
re-export functions for extension modules
picnixz Dec 17, 2024
21d8ca8
rename os_xsave to osxsave for future automatism
picnixz Dec 17, 2024
1f9dbb4
remember `maxleaf` and make detection more readable
picnixz Dec 18, 2024
553aa7c
use enumeration for flags
picnixz Dec 18, 2024
39d2ba4
fix warnings
picnixz Dec 21, 2024
602bb9c
Merge branch 'main' into core/simd-helpers
picnixz Dec 21, 2024
d6a3523
remove un-necessary comment and newline continuation
picnixz Dec 22, 2024
ff4212e
Merge branch 'main' into core/simd-helpers
picnixz Feb 16, 2025
3cb79f6
regen configure
picnixz Feb 17, 2025
e0a578c
clinic now supports empty comment lines in Python blocks
picnixz Feb 17, 2025
6fdbbdf
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Mar 11, 2025
c265851
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Mar 29, 2025
c12f9c7
move cpuinfo enumerations to real invokable Python scripts
picnixz Mar 29, 2025
a6c443f
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 5, 2025
bd3589f
add comments
picnixz Apr 5, 2025
d213b67
update C comments
picnixz Apr 8, 2025
4109d90
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 8, 2025
19b7d86
TMP: usage proof-of-concept
picnixz Apr 8, 2025
1732b6b
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 22, 2025
d59d06d
improve configure.ac
picnixz Apr 22, 2025
bc2c1e5
Merge remote-tracking branch 'upstream/main' into feat/core/simd-125022
picnixz Apr 25, 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
Prev Previous commit
Next Next commit
add comments
  • Loading branch information
picnixz committed Apr 5, 2025
commit bd3589feb1adb6f0e8bd0387c784e8e3bcc99cf7
6 changes: 3 additions & 3 deletions Include/internal/pycore_cpuinfo_cpuid_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ import os
import sys

ROOT = os.getcwd()
TOOL = os.path.join(ROOT, 'Tools/cpuinfo/cpuid_features_gen.py')
TOOL = os.path.join(ROOT, "Tools/cpuinfo/cpuid_features_gen.py")
TOOL = os.path.realpath(TOOL)

if not os.path.exists(TOOL):
raise FileNotFoundError(TOOL)

sys.path.insert(0, os.path.dirname(os.path.dirname(TOOL)))
module = importlib.import_module('cpuinfo.cpuid_features_gen')
module = importlib.import_module("cpuinfo.cpuid_features_gen")
print(module.generate_cpuid_features_enum("py_cpuid_feature_mask"))
[python start generated code]*/
typedef enum py_cpuid_feature_mask {
Expand Down Expand Up @@ -96,7 +96,7 @@ typedef enum py_cpuid_feature_mask {
Py_CPUID_MASK_EDX_L7S1_AVX_NE_CONVERT = 0x00000020, // bit = 5
Py_CPUID_MASK_EDX_L7S1_AVX_VNNI_INT16 = 0x00000400, // bit = 10
} py_cpuid_feature_mask;
/*[python end generated code: output=c4460242e465fa91 input=a07f431329efd11e]*/
/*[python end generated code: output=c4460242e465fa91 input=61d2b5f1bc368b94]*/
// fmt: on

#endif // !Py_INTERNAL_CPUINFO_CPUID_FEATURES_H
10 changes: 6 additions & 4 deletions Include/internal/pycore_cpuinfo_xsave_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* @author Bénédikt Tran
* @seealso Tools/cpuinfo/xsave_features_gen.py
*
* XSAVE state components (XCR0 control register)
* XSAVE state components (XCR0 control register).
*
* See https://en.wikipedia.org/wiki/Control_register#XCR0_and_XSS.
*/
#ifndef Py_INTERNAL_CPUINFO_XSAVE_FEATURES_H
#define Py_INTERNAL_CPUINFO_XSAVE_FEATURES_H
Expand All @@ -24,14 +26,14 @@ import os
import sys

ROOT = os.getcwd()
TOOL = os.path.join(ROOT, 'Tools/cpuinfo/xsave_features_gen.py')
TOOL = os.path.join(ROOT, "Tools/cpuinfo/xsave_features_gen.py")
TOOL = os.path.realpath(TOOL)

if not os.path.exists(TOOL):
raise FileNotFoundError(TOOL)

sys.path.insert(0, os.path.dirname(os.path.dirname(TOOL)))
module = importlib.import_module('cpuinfo.xsave_features_gen')
module = importlib.import_module("cpuinfo.xsave_features_gen")
print(module.generate_xsave_features_enum("py_xsave_feature_mask"))
[python start generated code]*/
typedef enum py_xsave_feature_mask {
Expand All @@ -41,7 +43,7 @@ typedef enum py_xsave_feature_mask {
Py_XSAVE_MASK_XCR0_AVX512_ZMM_HI256 = 0x00000040, // bit = 6
Py_XSAVE_MASK_XCR0_AVX512_HI16_ZMM = 0x00000080, // bit = 7
} py_xsave_feature_mask;
/*[python end generated code: output=9a476ed0abbc617b input=78e3d4ff6b796edb]*/
/*[python end generated code: output=9a476ed0abbc617b input=41f35058299c0118]*/
// fmt: on

#endif // !Py_INTERNAL_CPUINFO_XSAVE_FEATURES_H
12 changes: 11 additions & 1 deletion Tools/cpuinfo/cpuid_features_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

The LEAF value should only 1 or 7 as other values may have different
meanings depending on the underlying architecture.

.. seealso:: Include/internal/pycore_cpuinfo_cpuid_features.h
"""

from __future__ import annotations
Expand All @@ -39,7 +41,8 @@
type Feature = str
type Bit = int

CPUID_FEATURES: Final[dict[CPUIDFeatureFamily, dict[Feature, Bit]]] = {
CPUID_FEATURES: Final[dict[FeatureFamily, dict[Feature, Bit]]] = {
# See https://en.wikipedia.org/wiki/CPUID#EAX=1:_Processor_Info_and_Feature_Bits.
(1, 0, "ECX"): {
"SSE3": 0,
"PCLMULQDQ": 1,
Expand All @@ -57,6 +60,7 @@
"SSE": 25,
"SSE2": 26,
},
# See https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features.
(7, 0, "EBX"): {
"AVX2": 5,
"AVX512_F": 16,
Expand All @@ -80,6 +84,7 @@
"AVX512_4FMAPS": 3,
"AVX512_VP2INTERSECT": 8,
},
# See https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=1:_Extended_Features.
(7, 1, "EAX"): {
"AVX_VNNI": 4,
"AVX_IFMA": 23,
Expand Down Expand Up @@ -109,6 +114,11 @@ def get_member_name(


def generate_cpuid_features_enum(enum_name: str) -> str:
"""Used by Include/internal/pycore_cpuinfo_cpuid_features.h.

The C enumeration is generated by this function and Argument Clinic.
"""

# The enumeration is rendered as follows:
#
# <INDENT><MEMBER_NAME> <TAB>= 0x<MASK>, <TAB>// bit = BIT
Expand Down
9 changes: 9 additions & 0 deletions Tools/cpuinfo/xsave_features_gen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Generate enumeration for XSAVE state components (XCR0 control register).

See https://en.wikipedia.org/wiki/Control_register#XCR0_and_XSS.

.. seealso:: Include/internal/pycore_cpuinfo_xsave_features.h
"""

from __future__ import annotations
Expand Down Expand Up @@ -36,6 +40,11 @@ def get_member_name(feature: Feature) -> str:


def generate_xsave_features_enum(enum_name: str) -> str:
"""Used by Include/internal/pycore_cpuinfo_xsave_features.h.

The C enumeration is generated by this function and Argument Clinic.
"""

# The enumeration is rendered as follows:
#
# <INDENT><MEMBER_NAME> <TAB>= 0x<MASK>, <TAB>// bit = BIT
Expand Down
Loading
0