-
Notifications
You must be signed in to change notification settings - Fork 0
feat(simd): Phase 1 — explicit cargo configs + AVX2 dispatch hardening #172
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [build] | ||
| # Explicit AVX-512 config — `x86-64-v4`. Use with: | ||
| # cargo --config .cargo/config-avx512.toml build | ||
| # cargo --config .cargo/config-avx512.toml test | ||
| # | ||
| # Compiles `target_feature = "avx512f"` on, so `src/simd.rs` selects the | ||
| # `simd_avx512` backend with native `__m512` / `__m512d` / `__m512i` | ||
| # storage. Required for the Sapphire Rapids / Granite Rapids hot paths | ||
| # (`f32_to_bf16_batch_rne`, the AVX-512BF16 BF16 lanes, the AMX tiles). | ||
| # | ||
| # Binary produced here will SIGILL on AVX2-only silicon — only use on | ||
| # hosts that report `avx512f` in `/proc/cpuinfo`. For shipping a single | ||
| # release artifact that adapts at process start, see the LazyLock runtime | ||
| # dispatch path in § 7.1 of the architecture doc instead. | ||
| [target.'cfg(target_arch = "x86_64")'] | ||
| rustflags = ["-Ctarget-cpu=x86-64-v4"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [build] | ||
| # Native build config — `target-cpu = "native"`. Use with: | ||
| # cargo --config .cargo/config-native.toml build | ||
| # cargo --config .cargo/config-native.toml test | ||
| # | ||
| # rustc resolves the build host's CPUID at invocation and enables every | ||
| # `target_feature` the host CPU advertises. `simd.rs` then picks the | ||
| # matching backend (typically `simd_avx512` on modern dev machines). | ||
| # | ||
| # Produces a binary tuned for the developer's exact silicon. The result | ||
| # is NOT portable: do not distribute artifacts built with this config. | ||
| [target.'cfg(target_arch = "x86_64")'] | ||
| rustflags = ["-Ctarget-cpu=native"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,26 @@ | ||
| [build] | ||
| # No global target-cpu. Each kernel uses #[target_feature(enable = "avx512f")] | ||
| # per-function, with LazyLock runtime detection. One binary, all ISAs. | ||
| # Railway (AVX-512) and GitHub CI (AVX2) use the same binary. | ||
| # Default cargo config — x86-64-v3 (AVX2) baseline. Portable across all | ||
| # x86_64 silicon shipping since ~2013 (Haswell+). This is what GitHub CI | ||
| # runs against and what `cargo build` produces for general distribution. | ||
| # | ||
| # Why v3 and not "no target-cpu": | ||
| # `src/simd_avx2.rs` composes `F32x16` as two `__m256` halves (AVX | ||
| # intrinsics), and the `simd_avx2_*` op funcs use `__m256i` (AVX2). | ||
| # Without a global v3 baseline, rustc compiles to x86-64 generic (SSE2) | ||
| # and those intrinsics emit instructions the CPU never executes → | ||
| # SIGILL at run time, exactly the PR #170 CI failure mode. | ||
| # | ||
| # AVX-512 builds: use `--config .cargo/config-avx512.toml` (or | ||
| # `CARGO_BUILD_RUSTFLAGS='-Ctarget-cpu=x86-64-v4'`). The simd.rs dispatch | ||
| # arms key off `target_feature = "avx512f"`; under v4 they pick the | ||
| # `simd_avx512` backend (native `__m512` / `__m512d` / `__m512i`). | ||
| # | ||
| # Build-machine-tuned binaries: use `--config .cargo/config-native.toml` | ||
| # (`target-cpu = "native"`); rustc resolves the host CPUID at compile. | ||
| # | ||
| # Runtime LazyLock dispatch (one release binary, heterogeneous deployment | ||
| # silicon) is a fifth opt-in mode — see § 7.1 of | ||
| # .claude/knowledge/simd-dispatch-architecture.md. Reserved for the | ||
| # release-binary distribution path; never the dev / CI default. | ||
| [target.'cfg(target_arch = "x86_64")'] | ||
| rustflags = ["-Ctarget-cpu=x86-64-v3"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring
target_feature = "avx2"on the x86_64 re-export arm removes allF32x16/F64x8/integer SIMD type exports for x86_64 builds that are not compiled with AVX2 (for example downstream users building this crate with default x86_64 flags orx86-64-v2). Because this file defines unconditional APIs likesimd_exp_f32(x: F32x16), those builds now fail at compile time due to missing type definitions instead of falling back;.cargo/config.tomlin this repo does not protect dependency builds in other workspaces.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e3ad707 (already on the merged branch) — reverted the
target_feature = "avx2"predicate tightening for exactly this reason. Same root cause surfaced in our CI:RUSTFLAGS="-D warnings"env inci.yamloverrides.cargo/config.tomlrustflags entirely (cargo doesn't merge — env wins), so even our own GitHub runner landed on x86-64 baseline withouttarget_feature = "avx2"set, leaving no matching arm → consumer references tocrate::simd::F32x16failed to compile.Predicate is back to
not(avx512f). Per-function#[target_feature(enable = "avx,avx2,fma")]annotations insidesimd_avx2.rsgate the actual intrinsic execution at the symbol level; the struct-field types (__m256/__m256i) arecore::archdeclarations that don't require AVX/AVX2 at the type level. Downstream consumers building this crate with default x86_64 flags orx86-64-v2now keep their type exports.Generated by Claude Code