Skip to content

lab: add contributor-owned native HIP operator checks - #248

Merged
midagedev merged 4 commits into
midagedev:mainfrom
Burntgogi:contribution/hip-lab-pr-20261015
Oct 15, 2026
Merged

midagedev merged 4 commits into
midagedev:mainfrom
Burntgogi:contribution/hip-lab-pr-20261015

Conversation

@Burntgogi

@Burntgogi Burntgogi commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Adds the contributor-owned labs/hip-native/ requested in #87. Its excluded workspace compiles Rust AMDGPU kernels, loads their ELF through HIP, and checks Q4_K × F32 and a synthetic dense FFN against the existing GGUF dequantizer with FP64 accumulation. The root manifest gains only the lab exclusion; CUDA members, dependencies, pins and release paths are unchanged.

This initial operator lab does not yet port the original selected GEMV/Q8 activation path or execute a model. That follow-up remains a separate change. No libllama or alternate serving/model loop is introduced.

Validation

Base e98d6c43f95bc75475cadaf1043c1735962dcc5d; exact source head a0d81f0667f197625f6a7ff0736e50b8a1d2fe88; full tree f5c390b1d61b07fc8d6089cc0ae94962f3c7d2ae.

  • verify.sh: fmt, host test, host/device clippy with warnings denied, both release builds, and all six GPU cases passed.
  • RX7900GRE/gfx1100, i5-12600K, 64GiB, pinned nightly 2026-08-28/LLVM23.1. HIP runtime and driver API version 70253210.
  • Fixed finite/NMSE <=1e-6 contract; largest NMSE 2.331305569619408e-12. Includes real packed Q4_K K6144 rows64 at one and 32 activation columns; three steady launches, zero explicit host buffer allocations in the steady loop. FFN intermediates stay on GPU.
  • Root format/comments pass; parsed Cargo.toml equals main except lab exclusion. Dirty-source refusal was exercised in the earlier unchanged verifier evidence. No CUDA executable was built and no NVIDIA gate is claimed.
  • The existing Strata service remained running. These are functional checks with no timing claim.

Exact-head result JSON, all verification logs.

export HIP_LIB_DIR=/path/to/rocm/lib
export LD_LIBRARY_PATH="$HIP_LIB_DIR:$LD_LIBRARY_PATH"
labs/hip-native/verify.sh /path/outside/checkout/evidence \
  --q4-rows /path/to/Q4_K.bin --k 6144 --rows 64

The four default synthetic cases need no model. Optional fixture: unchanged rows0..64 of blk.1.ssm_out.weight, K6144, from Qwen3.8-27B-GSQ-RCO-IQ3_S-mtp.gguf, source SHA256 58fd826723939933dc86f45b7fe04545cbc2de1c70f6fe2cdd3858c87a98c12f. Fixture SHA256 9251b422a700bf27bf47512068c93f88d029dc6eba32ed516dbc067842b570ce, 221184bytes. No weights are included.

Code shape

  • Existing host dequantizer reused; no alternate model/session/server.
  • Invalid shape, nonfinite outputs, failed commands and dirty source return named failures.
  • No relaxed gate, lint or numerical band.
  • Comments describe current contracts; generated evidence lives outside the source tree.
  • Source, binary, runtime and per-case identities are in verify JSON.

Owner: @Burntgogi. Release note: contributor AMD operator lab; no change to released engine support or performance claims.

Review corrections: CARGO_BUILD_TARGET is rejected before builds; host tests/lint/build and output paths use the explicit rustc host triple. The redundant PhantomData/Rc marker is removed. K257 independently pins divisibility. Negative controls show target override refusal, divisibility mutation failure, and an intentionally doubled-output GPU mutant failing at NMSE0.999999753388892. The correct PR head passes all six cases.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 15, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: The verifier can report success using a stale host binary, and the context has a redundant marker field.

Must fix

1. Reject target overrides before selecting the host artifact

labs/hip-native/verify.py:125 An inherited CARGO_BUILD_TARGET set to the native triple sends the new host build to target/<triple>/release/. This code still executes target/release/bloomery-hip-spike. A previous binary at that path can pass all cases and be recorded against the current HEAD; the final hash check only proves that old binary stayed unchanged.
Cost: Fix this before verifier results are used as merge evidence.
Insert this guard beside the existing encoded-flags guard, before any build:

        if os.environ.get("CARGO_BUILD_TARGET"):
            raise RuntimeError("unset CARGO_BUILD_TARGET; verification assumes native host artifact paths")

2. Remove the redundant thread marker

labs/hip-native/host/src/main.rs:57 The existing *mut c_void fields already make Context neither Send nor Sync. The PhantomData<Rc<()>> field, its initializer, and both imports add no constraint. This violates the fewest-elements requirement.
Cost: Removing them now is a five-line deletion with no API change.
Remove the PhantomData and Rc imports. Use this struct and initializer:

struct Context {
    module: *mut c_void,
    stream: *mut c_void,
    buffers: Vec<*mut c_void>,
}
        let mut s = Self {
            module: std::ptr::null_mut(),
            stream: std::ptr::null_mut(),
            buffers: Vec::new(),
        };

Non-blocking

⚠ Pin the divisibility check independently: labs/hip-native/host/src/main.rs:470. Deleting !k.is_multiple_of(256) at line 168 leaves every assertion green: K=255 fails the weight-length check instead. Replace the tuple with (257, 1, 1, 144), so that mutant turns red before kernel work.

Checked

Duplicates: the marker repeats constraints already supplied by the raw-pointer fields. No dryer pairs were available.
Complexity: diagnostics report new dense_ffn (41) and case (25), both combining setup, launches, and reference checks.
Silent failure: two NMSE denominator floors and four ignored HIP cleanup statuses read. Work-path HIP errors and nonfinite results return named failures.
Tests: static branch analysis confirms the divisibility mutant survives every current shape assertion; the suggested tuple detects it.
Gates: fixed NMSE <= 1e-6 is new; no existing pin or gate was relaxed in this diff.
Escape catalog: C1–C4 do not match.

Notes

dryer did not run because no changed Rust file is under crates/.
Builds and GPU tests were not run. The linked HIP result JSON is outside the supplied trees. The PR body includes no FAIL-first output for the new numerical gate.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Comment thread labs/hip-native/host/src/main.rs Outdated
fn refuses_invalid_shapes_and_truncated_weights() {
for (k, r, c, w) in [
(0, 1, 1, 0),
(255, 1, 1, 144),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K=255 still fails the byte-count check when the divisibility guard is removed; K=257 with 144 bytes isolates that guard.

Suggested change
(255, 1, 1, 144),
(257, 1, 1, 144),

@Burntgogi

Copy link
Copy Markdown
Contributor Author

Addressed both must-fix items in a0d81f0. The verifier rejects CARGO_BUILD_TARGET before any build, explicitly selects rustc's host triple for every host command, and executes that triple's artifact path. PhantomData/Rc and the redundant marker are removed.

Also changed the divisibility fixture to K257: deleting that guard now fails. Negative controls show target-override refusal with zero builds, and a separate local doubled-output kernel mutant fails the actual GPU comparison at NMSE0.999999753388892. The mutant is not in this PR. The corrected clean head passes all seven checks and six GPU cases, with new JSON/binary hashes.

Exact-head result and negative controls. The dependent operator draft #252 was rebased and again passes18 cases. CI/review have been triggered on the corrected heads.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review:

Verdict: CLEAN: The earlier findings are resolved, and the incremental changes introduce no proven defect.

Checked

Duplicates: 0 new function, type or constant definitions; the redundant field and imports are removed. No dryer pairs were available.
Complexity: crapper flags dense_ffn (41) and case (25), both unchanged in this increment; no new growth to assess.
Silent failure: 0 new fallback sites. Target rejection reaches the failed-result handler and nonzero exit; missing artifacts also fail through the existing handler.
Tests: Python syntax and isolated verifier statements passed for synthetic x86_64 and aarch64 Linux triples, checking all three host commands, artifact paths and rejection before builds. Static mutation check: dropping the divisibility clause at host line 163 makes K=257 return Ok((1028, 4)), so line 470 fails.
Gates: no numerical band or pin moved; the changed shape case independently pins divisibility. No kernel or engine hot path changed.
Escape catalog: C1–C4 do not match.

Notes

dryer did not run because no changed Rust file is under crates/.
Builds and GPU tests were not run. The PR reports a doubled-output negative control; linked HIP results and logs are outside the supplied trees and were not read.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@midagedev
midagedev merged commit ade317e into midagedev:main Oct 15, 2026
6 checks passed
Burntgogi added a commit to Burntgogi/bloomery that referenced this pull request Oct 16, 2026
Rebase only the selected follow-up after merged midagedev#248. All nine extracted bodies, the selected entry, and the two scalar oracle entry bodies are unchanged from the arithmetic baseline; only unrelated core helpers changed. Build, lint, tests and GPU verification intentionally unrun for coordinated final verification.
juliankang4 pushed a commit that referenced this pull request Oct 16, 2026
Rebase only the selected follow-up after merged #248. All nine extracted bodies, the selected entry, and the two scalar oracle entry bodies are unchanged from the arithmetic baseline; only unrelated core helpers changed. Build, lint, tests and GPU verification intentionally unrun for coordinated final verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants