Skip to content

test(xla): qualify the OpenXLA/IREE engine on ROCm/HIP - #2307

Merged
inureyes merged 4 commits into
mainfrom
feature/issue-851-iree-rocm
Oct 14, 2026
Merged

inureyes merged 4 commits into
mainfrom
feature/issue-851-iree-rocm

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Qualifies the OpenXLA/IREE engine (--features xla-backend,xla-iree) on AMD ROCm/HIP (MLXCEL_XLA_DEVICE=hip, gfx1151 / AMD Radeon 8060S Graphics, ROCm 7.2.2) across all 5 phases defined in #851.

Changes

  • Phase 0 (scripts/iree/setup-rocm.sh, Makefile, build.rs, src/lib/mlxcel-xla/build.rs, src/lib/mlxcel-core/build_support/rocm_rpath.rs): Provision IREE 3.12.0rc20260721 (dc9601f88654749456c7cee4ae87e13de2654e1e) with IREE_HAL_DRIVER_HIP=ON into ~/.cache/mlxcel/iree-rocm-3.12.0rc20260721, wire IREE_ROCM_HOME + IREE_ROCM_COMPILE into Cargo and Makefile (make iree-rocm), and emit /opt/rocm/lib into DT_RPATH when xla_iree_rocm is active so IREE's dynamic dlopen("libamdhip64.so", ...) works out of the box.
  • Phase 1 (IREE HIP HAL smoke): Verified iree-run-module --list_drivers (hip), --dump_devices=hip (AMD Radeon 8060S Graphics, gfx1151), and 5/5 bit-exact runs of add_f32.vmfb, matmul_f32.vmfb, and matmul_f16.vmfb on hip.
  • Phase 2 (src/lib/mlxcel-xla/csrc/xla_iree.c, src/lib/mlxcel-xla/src/emitter/builder.rs, src/lib/mlxcel-xla/src/iree.rs): Upgraded the C shim to capture full multi-line IREE status tracebacks via iree_status_fprint and emit stage-annotated [compile], [runtime-init], [module-load], and [weight-upload] errors; enforced strict validation on MLXCEL_XLA_ROCM_TARGET (requiring a single gfx* SKU on hip) and MLXCEL_XLA_PRECISION (defaulting hip to f16 and rejecting invalid strings); verified mlxcel generate on Llama-3.2-1B-Instruct-4bit (14.22 tok/s vs 0.42 tok/s CPU, 33.9x) and Qwen3-0.6B-4bit (21.05 tok/s vs 4.78 tok/s CPU, 4.4x).
  • Phase 3 (Numerical parity, continuous batching, server SSE, 20-run soak): Passed 64-token greedy xla_oracle_check (64/64 TOKEN-EXACT PASS across f32, f16, bf16, and packed on Llama-3.2-1B-Instruct-4bit, and 64/64 on f32 and f16 for Qwen3-0.6B-4bit), xla_batch_bench continuous batching (B_max=4 at 65.80 tok/s mean and B_max=8 at 82.06 tok/s mean, 100% REFERENCE-EXACT PASS), mlxcel-server /v1/completions (non-streaming and streaming SSE on hip), and a 20-iteration stability smoke loop (20/20 identical completions, steady 147.8 MiB post-exit VRAM).
  • Phase 4 (scripts/xla/fusion_spike.sh, scripts/xla/validate_arch.sh): Generalized fusion_spike.sh for MLXCEL_XLA_DEVICE=hip (--iree-rocm-target), measured packed int8 dequant on hip (1,209 dispatches, 2 unfused dispatches per linear layer, --iree-global-opt-data-tiling fails in iree-ROCMSelectLoweringStrategyPass), and cross-posted the ROCm findings to track(upstream-iree): fused dequant->matmul for the packed int8 bandwidth win #574.
  • Documentation (docs/benchmark_results/xla_iree_rocm_qualification.md, src/lib/mlxcel-xla/README.md, docs/installation.md, docs/environment-variables.md): Checked in the full qualification report and updated user/crate documentation.

Verification

  • cargo fmt --check
  • cargo test -p mlxcel-xla --lib
  • cargo clippy -p mlxcel-xla --lib --tests -- -D warnings
  • bash scripts/xla/validate_arch.sh --structural-only
  • Full hardware qualification on gfx1151 documented in docs/benchmark_results/xla_iree_rocm_qualification.md

Closes #851

Provision and qualify the `mlxcel-xla` runtime and compiler pipeline on AMD ROCm/HIP (`gfx1151`, Radeon 8060S Graphics) across Phase 0 through Phase 4.

- Add `scripts/iree/setup-rocm.sh` and `Makefile` targets (`iree-rocm`, `iree`, `iree-env`) to build the IREE `3.12.0rc20260721` HIP runtime (`libiree_runtime_unified.a` with `IREE_HAL_DRIVER_HIP=ON`) and install the matching `iree-compile` and `iree-run-module` binaries.
- Extend `build.rs`, `src/lib/mlxcel-xla/build.rs`, and `src/lib/mlxcel-core/build_support/rocm_rpath.rs` to consume `IREE_ROCM_HOME` (`cfg(xla_iree_rocm)`) and emit `DT_RPATH` (`/opt/rocm/lib`) when either `rocm` or `xla_iree_rocm` is active so `dlopen("libamdhip64.so", ...)` succeeds without manual `LD_LIBRARY_PATH`.
- Format full multi-line IREE status details via `iree_status_fprint` in `src/lib/mlxcel-xla/csrc/xla_iree.c` and annotate `[compile]`, `[runtime-init]`, `[module-load]`, and `[weight-upload]` errors with actionable environment-variable remedies.
- Validate `MLXCEL_XLA_ROCM_TARGET` (rejecting unset, empty, comma-separated, or non-`gfx*` targets) and `MLXCEL_XLA_PRECISION` (defaulting `hip` to `f16` and rejecting invalid values) in `src/lib/mlxcel-xla/src/emitter/builder.rs` and `src/lib/mlxcel-xla/src/iree.rs`.
- Generalize `scripts/xla/fusion_spike.sh` for `MLXCEL_XLA_DEVICE=hip` and update `scripts/xla/validate_arch.sh` with ROCm instructions and a Rust `xla_traj_dump` reference fallback when the Python HF oracle venv is unavailable.
- Document the ROCm build, environment variables, and full `gfx1151` qualification report in `docs/benchmark_results/xla_iree_rocm_qualification.md`, `src/lib/mlxcel-xla/README.md`, `docs/installation.md`, and `docs/environment-variables.md`.

Closes #851
@inureyes inureyes added status:review Under review type:test Test related changes priority:high High priority priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) and removed priority:high High priority labels Oct 14, 2026
…n reports

Enforce rustfmt formatting, refine precision environment variable parsing with unit tests, record the explicit support decision in the ROCm qualification report, and add bilingual technical reports for PR #2307.

- Fix line wrapping in `src/lib/mlxcel-xla/src/emitter/builder.rs`, `src/lib/mlxcel-xla/src/iree.rs`, and `src/lib/mlxcel-xla/src/phi4_audio.rs` so `cargo fmt --check` passes cleanly.

- Trim whitespace in `precision_env_override`, extract pure `resolve_precision_checked_with_override`, and add `resolve_precision_validates_and_defaults` unit test.

- Append Section 6 ("Support Decision & Support Boundaries") in `docs/benchmark_results/xla_iree_rocm_qualification.md` declaring the Conditionally Supported verdict and boundaries.

- Add bilingual technical reports `TECHNICAL_REPORTS/2307-xla-iree-rocm-qualification-20261014.en.md` and `TECHNICAL_REPORTS/2307-xla-iree-rocm-qualification-20261014.ko.md`.
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Qualify the OpenXLA/IREE execution engine on AMD ROCm/HIP across all five phases defined in #851.

Findings Addressed

  • Fix line-wrapping format diffs in builder.rs, iree.rs, and phi4_audio.rs so cargo fmt --check passes cleanly (LOW)
  • Trim whitespace in precision_env_override, extract pure resolve_precision_checked_with_override, and add resolve_precision_validates_and_defaults unit test (LOW)
  • Append Section 6 ("Support Decision & Support Boundaries") in docs/benchmark_results/xla_iree_rocm_qualification.md declaring the Conditionally Supported verdict and boundaries (MEDIUM)
  • Generate bilingual technical reports TECHNICAL_REPORTS/2307-xla-iree-rocm-qualification-20261014.{en,ko}.md and commit with .keep-reports opt-in (LOW)

Remaining Items

  • None

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass (cargo fmt --check, cargo test -p mlxcel-xla --lib, cargo clippy -p mlxcel-xla --lib --tests -- -D warnings, bash scripts/xla/validate_arch.sh --structural-only)

Harden ROCm build support, compile binary discovery, target architecture validation, and shell verification tooling for PR #2307 (issue #851).

- Restrict ROCm rpath emission in `rocm_rpath.rs` to Linux target OS so macOS builds avoid unsupported linker flags when `IREE_ROCM_HOME` is set.
- Require non-empty trimmed binary path when resolving `MLXCEL_XLA_IREE_COMPILE` from environment variables in `iree.rs`.
- Lowercase AMD GPU target architecture in `validate_rocm_target` to handle identifiers like `GFX1151` and add corresponding test coverage.
- Add `-f` flag to curl in `scripts/iree/setup-rocm.sh` to fail fast on HTTP download errors.
- Ensure temporary oracle file created by `mktemp` in `scripts/xla/validate_arch.sh` is cleaned up on exit when `--oracle` is not supplied.
…al reports

Update bilingual technical reports for PR #2307 to document the security, performance, and portability hardening findings:
- ROCm rpath target OS gate in `rocm_rpath.rs` protecting non-Linux builds from unsupported linker flags.
- Non-empty validation on trimmed `MLXCEL_XLA_IREE_COMPILE` paths in `iree.rs`.
- AMD GPU target architecture identifier lowercase normalization in `validate_rocm_target` (`builder.rs`).
- Fast-fail curl downloads (`-f`) in `setup-rocm.sh` and temporary oracle cleanup trap in `validate_arch.sh`.
@inureyes

Copy link
Copy Markdown
Member Author

Security and Performance Review Summary

Review Scope

PR #2307 qualifies the OpenXLA/IREE execution backend (xla-iree) on AMD ROCm/HIP (MLXCEL_XLA_DEVICE=hip, gfx1151, ROCm 7.2.2). Review focused on C runtime FFI safety and status lifecycle, ELF dynamic linker RPATH configuration, environment variable validation and shell command injection guards, and resource reclamation.

Findings Addressed

  • Restrict ROCm rpath emission in src/lib/mlxcel-core/build_support/rocm_rpath.rs to Linux target OS (if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("linux") { return; }) so macOS builds avoid unsupported -Wl,--disable-new-dtags linker flags when IREE_ROCM_HOME is set (MEDIUM)
  • Require non-empty trimmed binary path when resolving MLXCEL_XLA_IREE_COMPILE from runtime environment variables and compile-time options in src/lib/mlxcel-xla/src/iree.rs to prevent opaque empty-path errors (LOW)
  • Normalize AMD GPU target architecture identifier to lowercase in validate_rocm_target (src/lib/mlxcel-xla/src/emitter/builder.rs) to cleanly accept uppercase inputs like GFX1151 and add unit test coverage (LOW)
  • Add -f flag to curl in scripts/iree/setup-rocm.sh (curl -fsSL -o) to fail fast on HTTP errors rather than saving error HTML to the wheel path (LOW)
  • Register an exit trap in scripts/xla/validate_arch.sh to remove temporary oracle JSON files created via mktemp when --oracle is not explicitly supplied (LOW)
  • Record all security, performance, and portability review findings in bilingual technical reports TECHNICAL_REPORTS/2307-xla-iree-rocm-qualification-20261014.{en,ko}.md (LOW)

Verification

  • cargo fmt --check: Passed with 0 differences
  • cargo test -p mlxcel-xla --lib: Passed (282 passed, 0 failed, 11 ignored)
  • cargo clippy -p mlxcel-xla --lib --tests -- -D warnings: Passed with 0 warnings
  • bash scripts/xla/validate_arch.sh --structural-only: Passed
  • Hardware qualification verified on gfx1151: 64/64 token-exact single-sequence parity, continuous batching 82.06 tok/s at B8, HTTP SSE streaming verified, 20-run soak with zero leaked VRAM

@inureyes

Copy link
Copy Markdown
Member Author

PR Finalization Complete

Summary

  • Tests: Verified CPU test suite with cargo test -p mlxcel-xla --lib (282 passed, 0 failed, 11 ignored) and bash scripts/xla/validate_arch.sh --structural-only (passed). Full GPU qualification executed and recorded on gfx1151 in docs/benchmark_results/xla_iree_rocm_qualification.md (64/64 token-exact parity, continuous batching at 82.06 tok/s mean on B8, HTTP SSE streaming, 20-run soak with zero VRAM leaks).
  • Documentation: Updated src/lib/mlxcel-xla/README.md, docs/installation.md, and docs/environment-variables.md with ROCm setup guides, toolchain instructions, and runtime variables; published qualification results in docs/benchmark_results/xla_iree_rocm_qualification.md with Conditionally Supported verdict and boundaries; authored bilingual technical reports in TECHNICAL_REPORTS/2307-xla-iree-rocm-qualification-20261014.{en,ko}.md.
  • Lint/Format: cargo fmt --check and cargo clippy -p mlxcel-xla --lib --tests -- -D warnings passed cleanly with 0 warnings. C runtime error handling, RPATH target OS gating, whitespace-tolerant precision parsing, and lowercase target validation verified.

All checks passing. Ready for merge.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Oct 14, 2026
@inureyes
inureyes merged commit df909a7 into main Oct 14, 2026
27 checks passed
@inureyes
inureyes deleted the feature/issue-851-iree-rocm branch October 14, 2026 02:47
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:benchmark Benchmark harness and performance measurement (bench_*.sh, /update-benchmarks) area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority status:done Completed type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(xla): qualify the OpenXLA/IREE engine on ROCm/HIP

1 participant