Replace hand-maintained CPU tables with cpufeatures library#61292
Replace hand-maintained CPU tables with cpufeatures library#61292
Conversation
c8feee0 to
305e39a
Compare
Replace processor_x86.cpp, processor_arm.cpp, and processor_fallback.cpp with a unified processor_cpufeatures.cpp that uses the cpufeatures library (github.com/gbaraldi/cpufeatures) for CPU detection and feature management. The cpufeatures library extracts CPU/feature tables from LLVM's TableGen data at build time and provides them as standalone C headers with no LLVM runtime dependency. This eliminates ~5000 lines of hand-maintained processor tables and feature definitions. Key changes: - New dep: cpufeatures library (downloaded and built as part of deps/) - processor_cpufeatures.cpp: unified replacement for all arch-specific files - processor.h: feature enum replaced with uint32_t typedef (indices from cpufeatures) - cpuid.jl: ISA feature sets queried from C library instead of hardcoded - base/Makefile: features_h.jl generated from cpufeatures headers - JULIA_DEBUG=cpufeatures enables debug output for target selection - Tuning features filtered from sysimage serialization (hw_feature_mask) Supported architectures: x86_64, aarch64, riscv64 (same as before). This was written with the assistance of generative AI (Claude). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The cpufeatures library switched from extern "C" tp_* functions to a namespace tp with C++ return types. Update the four call sites: get_host_cpu_name, get_host_features, build_feature_string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use Julia's standard C++ flags (which include -std=c++17) instead of bare $(CXXFLAGS). The cpufeatures public API uses std::string_view which requires C++17. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The non-template base case is only called by template overloads used in the old processor backends. The cpufeatures backend doesn't use these templates, so clang -Werror,-Wunused-function flags it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
99ee2ec to
70a6976
Compare
The analyzer needs cpufeatures headers installed to compile processor.cpp, same as the other runtime dependencies. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
src/processor_cpufeatures.cpp
Outdated
|
|
||
| #if defined(_CPU_X86_64_) || defined(_CPU_X86_) | ||
| // KNL/KNM special case | ||
| if (!(t.dis.flags & JL_TARGET_CLONE_ALL)) { |
There was a problem hiding this comment.
I don't think we care about knl
Compile-time check that TARGET_TABLES_LLVM_VERSION_MAJOR (from the cpufeatures generated headers) matches LLVM_VERSION_MAJOR (from Julia's LLVM). Catches version mismatches early instead of at runtime. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use the cpufeatures cross_lookup_cpu API so ISAs_by_family has real feature data for all architectures regardless of host. Previously non-host arch entries were empty or used synthetic fallbacks. New Julia-side APIs: - CPUID._cross_lookup_cpu(arch, name) — look up any CPU on any arch - CPUID.feature_names(arch, isa) — map ISA feature bits to names New C exports (jl_cpufeatures_cross_*): - cross_lookup, cross_nbytes, cross_num_features/cpus - cross_feature_name, cross_feature_bit, cross_cpu_name Also: - Install cross_arch.h in cpufeatures.mk - static_assert that cpufeatures tables match Julia's LLVM version - Add cross-arch and feature name tests to binaryplatforms.jl Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Haven't reviewed in detail, but directionally, this is exactly what I wanted. |
|
This makes the aarch64-linux-gnu tests error (more than usual, that is), because now this literally spamming everywhere. Edit: same for aarch64-darwin, which at least errors more loudly. |
|
Also, on an aarch64-linux system with big.LITTLE architecture Cortex-X925 + A725, this PR detects the CPU as the little variant: $ julia +nightly -E 'Sys.CPU_NAME'
"cortex-x925"
$ julia +pr61292 -E 'Sys.CPU_NAME'
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
'-contextidrel2' is not a recognized feature for this target (ignoring feature)
"cortex-a725" |
|
Is there a way to handle aliases? M1, M2, and M3 are aliases of their mobile a1x counterparts. julia> Base.BinaryPlatforms.CPUID._lookup_cpu("apple-a15")
Base.BinaryPlatforms.CPUID.ISA(Set(UInt32[0x00000002, 0x00000067, 0x00000073, 0x00000077, 0x0000005b, 0x0000002a, 0x000000a1, 0x0000003f, 0x00000057, 0x000000d1 … 0x0000009e, 0x0000000f, 0x000000e7, 0x000000e1, 0x00000047, 0x00000081, 0x000000e8, 0x000000da, 0x00000033, 0x00000009]))
julia> Base.BinaryPlatforms.CPUID._lookup_cpu("apple-m2")
Base.BinaryPlatforms.CPUID.ISA(Set{UInt32}()) |
Knights Landing/Mill are discontinued and not worth special-casing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…iases) Bump version to 0.2.0 and pin to specific commit to bust CI cache. Previous builds cached the old tarball from refs/heads/main. Fixes: - CONTEXTIDREL2 warnings on aarch64 - big.LITTLE detecting the little core instead of big - apple-m1/m2/m3 alias resolution Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes hw_feature_mask also excluding CONTEXTIDREL2 (the previous pin only fixed is_hw but not the mask itself). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Includes: hw_feature_mask fix for CONTEXTIDREL2, big.LITTLE detection, Apple M-series aliases, aarch64 CPU table baseline for host features, and cross-arch architecture version tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New method feature_names(arch, cpu) for direct CPU name queries:
feature_names("x86_64", "haswell")
feature_names("aarch64", "cortex-x925")
Tests cover all CPUID APIs:
- _cross_lookup_cpu: cross-arch, aliases, normalization, negatives
- feature_names: by CPU name, by ISA, host defaults, cross-arch
- _build_bit_to_name: mapping completeness
- Architecture version features (v8.1a, v9a) on ARM cores
- x86 psABI level features (avx2, avx512f)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pin to commit with find_cpu alias resolution (fixes macOS M-series detection). Copy all include/*.h instead of listing individual files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
My m2 is now properly detected and displayed on macOS and Linux! |
|
Should the Also, when I opened gbaraldi/cpufeatures#1, I had forgotten that the Also also, should |
Summary
processor_x86.cpp,processor_arm.cpp,processor_fallback.cpp(~5000 lines of hand-maintained CPU/feature tables) with a unifiedprocessor_cpufeatures.cppthat uses the cpufeatures librarycpuid.jlnow queries feature sets from the C library instead of hardcoding themJULIA_DEBUG=cpufeaturesWhat is cpufeatures?
A standalone library that extracts CPU names, feature sets, and feature dependencies from LLVM's
MCSubtargetInfoat build time into generated C headers. The generated headers are committed to the repo, so a normal build only needs a C++17 compiler — no LLVM required. Supports x86_64, aarch64, and riscv64.Changes
New files:
deps/cpufeatures.mk,deps/cpufeatures.version— build system integrationsrc/processor_cpufeatures.cpp— unified processor implementationModified files:
src/processor.cpp— includes new file instead of arch-specific onessrc/processor.h— feature enum →uint32_ttypedef (indices from cpufeatures)src/Makefile— updated dependencies, link-ltarget_parsingsrc/crc32c.c— hardcode HWCAP bit instead of using removed enumbase/cpuid.jl— ISA sets from C queries, not hardcodedbase/Makefile—features_h.jlfrom cpufeatures headersdeps/Makefile— add cpufeatures toDEP_LIBSFiles to delete (follow-up):
src/processor_x86.cpp,src/processor_arm.cpp,src/processor_fallback.cppsrc/features_x86.h,src/features_aarch32.h,src/features_aarch64.hTest plan
make clean && make -jsucceeds (downloads, builds, links cpufeatures)generic;haswell;skylake-avx512): correct target selection-C haswellselects haswell target,-C genericselects genericBinaryPlatformsISA matching worksJULIA_DEBUG=cpufeaturesshows target selection detailsRelated
🤖 Generated with Claude Code