Wire TOSA admission and the compiler helper for IDENTITY (#89) - #136
Open
aravishankar-mp wants to merge 2 commits into
Open
Wire TOSA admission and the compiler helper for IDENTITY (#89)#136aravishankar-mp wants to merge 2 commits into
aravishankar-mp wants to merge 2 commits into
Conversation
aravishankar-mp
force-pushed
the
task/xdna-tosa-identity
branch
from
August 24, 2026 23:53
06fde59 to
18cff66
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Wires end-to-end TOSA BF16 IDENTITY support for the AMD XDNA backend by adding a portable TOSA admission layer, a bounded compiler-helper subprocess that produces precompiled artifacts, and native load_program support to admit+compile TOSA artifacts at load time (with new on-hardware tests).
Changes:
- Add portable TOSA admission (
lower::admit) that validates a strict BF16 IDENTITY subset and emits aCompilerSpec. - Add a bounded compiler-helper subprocess driver (
src/compiler.rs) plus embedded helper script (compiler/xdna_compile.py) and a content-addressed artifact cache. - Extend native
load_programto accept either precompiled artifacts directly or TOSA artifacts via admit-then-compile; add hardware and compiler tests.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/release-policy.md | Updates release policy entry to reflect the new tosa-build dev dependency usage. |
| docs/portability.md | Updates portability docs to describe compilation and on-device testing behavior. |
| crates/virtio-accel-xdna/tests/hardware.rs | Adds hardware-free compile test and on-NPU BF16 IDENTITY compile+run test. |
| crates/virtio-accel-xdna/src/native.rs | Extends load_program to accept TOSA artifacts by admitting+compiling them; factors out executable construction. |
| crates/virtio-accel-xdna/src/lower.rs | Implements portable TOSA admission into CompilerSpec for BF16 IDENTITY subset + unit tests. |
| crates/virtio-accel-xdna/src/lib.rs | Re-exports admission API/types and adds public compile_artifact entry point (va_xdna). |
| crates/virtio-accel-xdna/src/compiler.rs | Adds bounded subprocess compiler driver with cache and helper embedding. |
| crates/virtio-accel-xdna/SAFETY.md | Updates safety scope notes to include the safe compiler driver and compiled path. |
| crates/virtio-accel-xdna/README.md | Updates crate README to describe new TOSA compilation support and offline compilation path. |
| crates/virtio-accel-xdna/compiler/xdna_compile.py | Adds the embedded compiler helper script (compile + identity modes). |
| crates/virtio-accel-xdna/Cargo.toml | Adds virtio-accel-tosa-build as a dev-dependency for test graph construction. |
| Cargo.lock | Records the new dev-dependency resolution. |
Suppressed comments (2)
crates/virtio-accel-xdna/src/compiler.rs:172
- The helper is placed in its own process group (
process_group(0)), but on timeout only the immediate child is killed. Any subprocesses spawned by the toolchain may survive, breaking the “bounded subprocess” guarantee. Consider killing the whole process group on timeout (e.g.,killpg/SIGKILL) in addition tochild.kill().
if Instant::now() >= deadline {
let _ = child.kill();
let _ = child.wait();
return Err(external(code::TIMEOUT));
crates/virtio-accel-xdna/src/compiler.rs:125
cache_keyhashes only the toolchain path, not a measured toolchain identity. If the toolchain is updated in-place (same prefix), the cache can serve stale artifacts. Since the helper already has anidentitymode, consider incorporating its output (and/or hashes/mtimes of key tool binaries) into the cache key so updates invalidate correctly.
1u32.hash(&mut hasher); // key schema version
spec.hash(&mut hasher);
self.toolchain.hash(&mut hasher);
HELPER_SOURCE.hash(&mut hasher);
format!("{:016x}", hasher.finish())
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
SnowCheetos
force-pushed
the
task/xdna-tosa-identity
branch
from
August 25, 2026 03:32
18cff66 to
4012fc2
Compare
15 tasks
aravishankar-mp
added a commit
that referenced
this pull request
Aug 25, 2026
- submit re-checks BufferDesc::allows_access as defense in depth (PermissionDenied, mirroring OpenVINO; the host-side check remains the contract's requirement). Closes the corresponding #138 item. - The artifact-cache key mixes in the measured toolchain identity (the helper's identity mode: mlir_aie / llvm-aie versions), so an in-place toolchain update under the same prefix can never serve stale artifacts. The probe runs once per driver, lazily; a failed probe keys the cache on the failure marker. - Cache staging filenames carry the pid so two processes compiling the same key cannot collide on a staging path. - check()'s doc no longer claims the rendered HRX message is surfaced (it is freed unread; no logging facility exists at this layer), and the example's docs no longer defer program loading to a later ticket. The negative-dimension admission comment on #136 was already fixed by the review commit (usize::try_from in admit_identity); the two compile- error comments on #134 are false positives (size_of is in the Rust 2024 prelude, and Option<BackendError> is Copy so unwrap_or reads through the MutexGuard) - CI compiles both. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
aravishankar-mp
force-pushed
the
task/xdna-tosa-identity
branch
from
August 25, 2026 19:09
4012fc2 to
46aff9c
Compare
SnowCheetos
previously approved these changes
Aug 25, 2026
Implements the compiler-helper contract (issue #84) and TOSA admission (issue #83) for the BF16 IDENTITY tier, end to end on hardware: - src/lower.rs: portable TOSA admission (parse + analyze_for + strict subset check) turning an artifact into a CompilerSpec, rejecting anything outside the BF16 IDENTITY subset before any subprocess runs. Unit-tested on every host (admits bf16 identity; rejects fp32, non-line-size, wrong target). - compiler/xdna_compile.py: the embedded aiecc helper (IDENTITY IRON template + spec-driven compile + toolchain identity), self-configuring the pinned toolchain under a cleared environment. - src/compiler.rs: the bounded subprocess driver — cleared env + pinned prefix + private workdir, wall-clock timeout, process group, and a content-addressed artifact cache (spec + toolchain + helper source). - src/native.rs load_program: precompiled artifacts load directly; a TOSA artifact is admitted, compiled, and built into an executable (shared build_executable path). compile_artifact exposes the admit-then-compile path without a device (offline / catalog mode). - tests: CI admission unit tests; a hardware-free golden artifact test (compile IDENTITY, assert xclbin magic + rejection of fp32); and the on-NPU test compiling a TOSA BF16 IDENTITY and matching output == input. Hosts without HRX compile the portable admission surface, artifact codec, and placeholder, with no unsafe. Local gates green: fmt, clippy, tests (placeholder admission in CI + on-hardware), doc under -D warnings, release-policy, and publish-dry-run for all 17 crates. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The admission items in lower.rs (admit, CompilerSpec, SpecOp, SpecDType, AdmitError, IDENTITY_LINE_SIZE) are consumed only by va_xdna code (compiler.rs, compile_artifact), so a non-HRX placeholder build sees them as dead code and -D dead-code fails style-and-api. They belong in the public API regardless: portable admissibility checking is a real, useful capability and compile_artifact is already public. Re-export them unconditionally from the crate root. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
SnowCheetos
force-pushed
the
task/xdna-tosa-identity
branch
from
August 25, 2026 21:45
46aff9c to
0a0f99f
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Fourth code ticket of the AMD XDNA wayfinder map (#78): TOSA graphs now compile and run on the NPU. Implements the compiler-helper contract (#84) and TOSA admission (#83) for the first tier operator — BF16 IDENTITY — end to end.
Highlights:
src/lower.rs— portable TOSA admission: parse +analyze_for+ a strict subset check that turns an artifact into a validatedCompilerSpec(integers and enums only) and rejects anything outside the BF16 IDENTITY subset before any subprocess runs. Unit-tested on every host (CI): admits BF16 identity; rejects FP32, non-line-size shapes, and the wrong target.compiler/xdna_compile.py— the embedded aiecc helper: an IDENTITY IRON template + spec-driven compile + a toolchain-identity mode, self-configuring the pinned toolchain (NPU_RUNTIME=hrxfor the unfolded ABI, Peano/xclbinutil/HRX paths) under a cleared environment.src/compiler.rs— the bounded subprocess driver: cleared env + pinned prefix + private workdir, wall-clock timeout, own process group, and a content-addressed artifact cache (spec ‖ toolchain ‖ helper source). Never a Cargo dependency, never in-process.src/native.rsload_program— precompiled artifacts load directly; a TOSA artifact is admitted, compiled, and built into an executable (sharedbuild_executable).compile_artifactexposes the admit-then-compile path without a device — the offline / catalog-population use from Decide the compiler-helper subprocess contract #84.Deferred: MATMUL (#90), MAX_POOL2D (#91), full conformance + device-loss tier-2 (#92). The compute tiers add IRON templates to the same helper and dtype/op arms to admission.
Compatibility
Checklist
compile_artifactand the portablelower::{admit, CompilerSpec, ...}; the TOSA path inload_program. No core/guest/device/transport changes.va_xdna; the compiler is a subprocess, not a linked dependency.unsafe(the compiler driver is safe code);SAFETY.mdnotescompiler.rsis safe; the FFI/native audit and release-policy entry stand.Verification
On the reference machine (Fedora 44, Krackan NPU, pinned toolchain):
🤖 Generated with Claude Code