Skip to content

Intersect cpu_target specs when freezing features for image builds - #28

Open
ChrisRackauckas-Claude wants to merge 1 commit into
JuliaSIMD:mainfrom
ChrisRackauckas-Claude:target-feature-intersection
Open

ChrisRackauckas-Claude wants to merge 1 commit into
JuliaSIMD:mainfrom
ChrisRackauckas-Claude:target-feature-intersection

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown

Summary

make_generic currently derives the frozen feature set from only the first ;-separated spec of cpu_target, using whole-string occursin tier checks. When a target lists a more capable spec first — e.g. skylake-avx512;generic — has_feature reports features that the generic clone cannot instruction-select. Downstream packages that emit target-specific LLVM IR gated on has_feature (e.g. VectorizationBase's inv_approx, which emits llvm.x86.avx512.rcp14) then abort image builds with LLVM ERROR: Cannot select: X86ISD::RCP14 — the root cause of JuliaSIMD/VectorizationBase.jl#131.

This PR:

  • Parses each ;-separated spec (cpu,+feat,-feat,clone_all,base(n)) into a conservative per-CPU set of LLVM feature names, and reports only features present on the host and in every spec, so generated IR can be selected for every clone of a multiversioned image and still run in the current session.
  • Handles native (resolves to the host feature set), clone_all/base(n) marker specs (no CPU name → do not constrain features), and ±feature modifiers. Unknown CPU names fall back to conservative tiers rather than whole-string matching.
  • Refreshes the CPU table: x86-64-v3/v4, znver4/znver5, cooperlake, Sapphire/Emerald/Granite/Diamond Rapids, recent client parts.
  • Fixes load-time feature application being blocked by allow_runtime_invalidation (default false): initial build-time setup now uses set_feature directly, while runtime retargeting in __init__ keeps the runtime=true path through setfeaturetrue/setfeaturefalse. Previously a non-native cpu_target could not enable features at all — it printed a "Runtime invalidation was disabled" warning per feature and silently froze everything to False().
  • On non-x86 architectures the previous behavior is preserved (all features False for non-native targets; aarch64 et al. have no feature table here).

Test plan

  • julia --project=. -e 'using Pkg; Pkg.test()' — 68/68 pass (Julia 1.12, linux x86_64 znver2 host), including new unit tests for spec_features/target_features and a subprocess --output-o image-build regression test.
  • Discrimination: the new image-build test runs a child julia --output-o -C "skylake-avx512;generic" that emits llvm.x86.avx512.rcp14 iff has_feature(Val(:x86_64_avx512f)) === True(). On main (bf62321, with allow_runtime_invalidation = true) the child aborts with LLVM ERROR: Do not know how to split the result of this operator! — the intrinsic leaked through and hit a target that cannot select it (on an AVX-512 host the same leak produces the reported Cannot select: X86ISD::RCP14 at the generic clone). On this branch the child succeeds and the object file is emitted.
  • End-to-end check from the original investigation: using VectorizationBase under PackageCompiler-style --output-o with -C "skylake-avx512;generic" builds cleanly on this branch (avx512f reported False()), and reproduces LLVM ERROR: Cannot select: X86ISD::RCP14 in julia_inv_approx_* on main.
  • Not run locally: macOS/Windows/i686 and Julia 1.10 — covered by CI. The new testset is Sys.ARCH === :x86_64-gated; on other arches only the unit tests are skipped.

Fixes the remaining gap for JuliaSIMD/VectorizationBase.jl#131 on the HostCPUFeatures side (the first-spec-only case was already handled by 0.1.18; this makes multi-spec targets order-independent).

🤖 Generated with Devin CLI 3000.10.31 (model: SWE-2 Max)
Session transcript (local): /home/crackauc/.local/share/devin/cli/transcripts/sumptuous-fontina.json
Investigation thread: JuliaSIMD/VectorizationBase.jl#131

HostCPUFeatures froze reported CPU features using only the first
`;`-separated cpu_target spec, with whole-string `occursin` tier checks.
For a target like "skylake-avx512;generic" — or any target whose first
spec is more capable than a later clone — has_feature reports features
that a clone cannot instruction-select, so downstream packages emitting
target-specific LLVM IR (e.g. VectorizationBase's inv_approx, which
emits llvm.x86.avx512.rcp14) abort image builds with
`LLVM ERROR: Cannot select` (JuliaSIMD/VectorizationBase.jl#131).

Parse each `;`-separated spec ("cpu,+feat,-feat,clone_all,base(n)")
into a conservative per-CPU set of LLVM feature names, then report only
features present on the host AND in every spec: `native` resolves to the
host set, `clone_all`/`base(n)` marker specs carry no CPU name and do not
constrain features, and unknown CPU names fall back to conservative
tiers. The CPU table now also covers x86-64-v3/v4, znver4/5, cooperlake,
and recent Intel parts.

Separately, load-time target application no longer goes through the
`allow_runtime_invalidation` gate: initial build-time feature setup uses
set_feature directly, while runtime retargeting in __init__ keeps the
runtime=true path. Previously a non-native build could not enable
features at all (allow_eval defaults to false), emitting warnings and
silently freezing every feature to false.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.31
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/transcripts/sumptuous-fontina.json (local transcript)
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.71186% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.54%. Comparing base (0deaff6) to head (3615a09).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/cpu_info_x86.jl 56.52% 20 Missing ⚠️
src/HostCPUFeatures.jl 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #28       +/-   ##
===========================================
+ Coverage   31.45%   46.54%   +15.08%     
===========================================
  Files           6        6               
  Lines         213      217        +4     
===========================================
+ Hits           67      101       +34     
+ Misses        146      116       -30     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants