You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++] Use existing library for CPU detection #45331
We currently use our own home-grown module for detecting CPU features, but it mainly supports x86, which implies that for now we cannot do dynamic dispatch on non-x86 CPUs (for example ARM where we might want to detect ARM or even SVE support at runtime).
We could probably reuse https://github.com/google/cpu_features instead. It doesn't seem to have any dependencies, and could be bundled as a private static library.
And by the way, xsimd has a more limited functionality for CPU feature detection: https://xsimd.readthedocs.io/en/latest/api/arch.html . It only supports x86 and ARM, does not offer detailed CPU information, does not expose things like BMI2 etc.
For completeness, you might be interested in https://github.com/archspec/archspec - it supports x64, aarch, ppc & risc, plus a lot of meta-information about the (partial) inclusion ordering of the various CPUs in terms of feature sets.
I think it doesn't have a C/C++ API though, so this is probably a long shot (slow to call python from C++), but OTOH, querying CPU features is not a common occurrence (once per session...?) and could be cached.
Numpy does it the other way around, detecting individual CPU features, rather than processor models, with a result à la:
Supported SIMD extensions in this NumPy install:
baseline = SSE,SSE2,SSE3
found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2
not found = AVX512F,AVX512CD,AVX512_KNL,AVX512_KNM,AVX512_SKX,AVX512_CLX,AVX512_CNL,AVX512_ICL
It's implemented in C, but I don't think it has a public API.
@h-vetinari Well, we don't want the core Arrow C++ library to depend on the existence of a Python interpreter and Python libraries. As for the NumPy C code, since it's internal it's probably not trivial to vendor, and I suppose its APIs have no stability guarantee either.
My 2c as not an arrow maintainer: if we want to use more of xsimd in arrow, it could be relevant to extend support for what we lack in xsimd. It would make static/dynamic dispatch of xsimd code in arrow more convenient as opposed to requiring a conversion layer and another dependency.
Use xsimd. Pros: header-only, already a dependency. Cons: might not have all desired functionality, so we'd either need to add them to xsimd (if that's ok to the xsimd maintainers) or keep maintaining code for it in Arrow.
Use Google's cpu-features. Pros: it's more featureful. Cons: it's an additional dependency, and requires a compilation step as it's not header-only; therefore it will some complication to the build system.
@AntoinePrv Do you want to do a bit more research to find out which functionality is needed in xsimd and whether it can be added there? (and feel free it to contribute it of course :))
Update on this, the current idea discussed with @pitrou is to use xsimd (already a dependency).
We've done some work on xsimd to match Arrow CPU detection needs (excluding cache size, but that is a separate topic and apparently only used for tests at the moment). There is a good basis to easily add more feature as needed.
Activity
pitrou commentedon Jan 22, 2025
Looking at https://github.com/google/cpu_features/blob/main/include/cpuinfo_aarch64.h , it's not obvious to me how we could get the supported SVE vector widths. Do you have any idea @cyb70289 ?
pitrou commentedon Jan 22, 2025
Edit: apparently there's an intrinsic to get the vector width: https://lemire.me/blog/2022/11/29/how-big-are-your-sve-registers-aws-graviton/
kou commentedon Jan 22, 2025
+1
cyb70289 commentedon Jan 23, 2025
+1
wgtmac commentedon Jan 23, 2025
The library itself looks good. My main concern is the slowdown of its release cadence: https://github.com/google/cpu_features/releases
pitrou commentedon Jan 23, 2025
Hmm, that's a good point. Maintenance also seems to have slowed down a bit: https://github.com/google/cpu_features/graphs/contributors?from=20%2F01%2F2024
pitrou commentedon Jan 23, 2025
There's also https://github.com/anrieff/libcpuid , which only supports x86 and ARM but exposes a lot of information.
pitrou commentedon Jan 23, 2025
And by the way, xsimd has a more limited functionality for CPU feature detection: https://xsimd.readthedocs.io/en/latest/api/arch.html . It only supports x86 and ARM, does not offer detailed CPU information, does not expose things like BMI2 etc.
h-vetinari commentedon Jan 23, 2025
For completeness, you might be interested in https://github.com/archspec/archspec - it supports x64, aarch, ppc & risc, plus a lot of meta-information about the (partial) inclusion ordering of the various CPUs in terms of feature sets.
I think it doesn't have a C/C++ API though, so this is probably a long shot (slow to call python from C++), but OTOH, querying CPU features is not a common occurrence (once per session...?) and could be cached.
Numpy does it the other way around, detecting individual CPU features, rather than processor models, with a result à la:
It's implemented in C, but I don't think it has a public API.
pitrou commentedon Jan 23, 2025
@h-vetinari Well, we don't want the core Arrow C++ library to depend on the existence of a Python interpreter and Python libraries. As for the NumPy C code, since it's internal it's probably not trivial to vendor, and I suppose its APIs have no stability guarantee either.
h-vetinari commentedon Jan 23, 2025
Yeah, I understand. That's why I said "for completeness". :)
pitrou commentedon May 6, 2025
For the record, a new release was just made (v0.10.0).
pitrou commentedon Jul 15, 2025
Also cc @AntoinePrv
AntoinePrv commentedon Jul 15, 2025
My 2c as not an arrow maintainer: if we want to use more of
xsimdin arrow, it could be relevant to extend support for what we lack inxsimd. It would make static/dynamic dispatch ofxsimdcode in arrow more convenient as opposed to requiring a conversion layer and another dependency.pitrou commentedon Jul 15, 2025
Perhaps, but some information such as cache sizes might be out of scope for
xsimdanyway.pitrou commentedon Jul 17, 2025
So, IMHO, we have two reasonable options:
@AntoinePrv Do you want to do a bit more research to find out which functionality is needed in xsimd and whether it can be added there? (and feel free it to contribute it of course :))
AntoinePrv commentedon Apr 10, 2026
Update on this, the current idea discussed with @pitrou is to use xsimd (already a dependency).
We've done some work on xsimd to match Arrow CPU detection needs (excluding cache size, but that is a separate topic and apparently only used for tests at the moment). There is a good basis to easily add more feature as needed.
GH-49921: [C++] Bump xsimd to 14.2.0 (#49922)
GH-45331: [C++] Use xsimd for CPU feature detection (#49940)
pitrou commentedon Jun 10, 2026
Issue resolved by pull request 49940
#49940