Repository navigation
hpc::int8_tile_gemm: prepacked INT8 B (PackedI8B) and strided-A entries - #418
Conversation
The INT8 twins of PackedBf16B and bf16_tile_gemm_16x16_packed[_strided] (#414), plus a multi-tile entry: - PackedI8B: one K x 16 band of B in TDPBUSD's VNNI quad layout, with pack / pack_from / vnni_index / data_mut and LE bytes. - int8_tile_gemm_16x16_packed[_strided]: one 16x16 tile over a prepacked band, A read in place at the caller's row pitch. Accumulates. - int8_gemm_packed_strided: M x N over N/16 prepacked bands and a strided A. On AMX it is int8_gemm_amx_tiled's 2x2 register-blocked kernel without the per-call band gather and VNNI pack; otherwise the scalar reference per tile. Overwrites. - int8_tile_gemm_tier names the tier that runs. A stays unsigned and B signed; nothing reinterprets either. Measured in lance-graph's dr-isa-stream-lab on one AMX VM (median of 41 warm runs, three runs): a 256 x 256 output over K = 256, A read in place from u8 lanes, takes 45.5-48.1 us against 78.3-78.8 us through backend::gemm_i8, whose per-call band gather and pack is 28.6-29.4 us. Calling the 16x16 entry once per tile instead is slower (99-108 us): each call pays its own tile configuration and loses the 2x2 blocking, so the multi-tile entry is the one for whole matrices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32260db34a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ndarray::simd now re-exports PackedI8B, int8_tile_gemm_16x16_packed[_strided], int8_gemm_packed_strided and int8_tile_gemm_tier from simd_amx, the AMX backend, which faces the kernels in hpc::int8_tile_gemm. Consumers import them from ndarray::simd only; nothing outside ndarray names hpc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
Codex P1 x2 on #418. On 64-bit, PackedI8B::zeroed(1 << 60) wrapped 16*K to 0 and built an empty buffer claiming a huge K; int8_gemm_packed_strided's M*N wrapped past the C length check. Either let the AMX kernel touch memory outside its slices through a safe API. Every such product is now checked and panics; three falsifiers pin it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
K = 0 through the multi-tile and single-tile entries on the dispatched tier (AMX here) and the scalar tier; M = 0; and stride extents that overflow in both strided entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
|
Memory-safety review gate: resolved (head Both Codex P1 findings were real and are fixed. Both review threads are resolved. Fixes
Regression tests, run in release mode on an AMX host (
Disable runs (release mode, each restored afterwards):
Generated by Claude Code |
The avx2 row's last two steps build with target-cpu=native. Its cache was keyed only by job, so on a heterogeneous runner pool it restored a paste proc-macro .so compiled for another CPU and rustc died with SIGILL loading it (#418; also master 09ca908). host-native already keys its cache by the target features rustc resolves for native (#344); the avx2 row now does the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
|
CI: rustc itself took SIGILL in the step The The INT8 code itself does not depend on the runner's CPU. Every tile entry dispatches on Generated by Claude Code |
|
Add Carrot credits or activate Agent usage billing to use Autofix |
|
@codex review Please review head Generated by Claude Code |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
* dr-isa-stream-lab: INT8 direct arm on ndarray's prepacked INT8 entries Adds int8::direct and int8::PreparedI8B. A is read in place at the u8 lanes' pitch and B is prepared once as PackedI8B bands, through ndarray::simd::int8_gemm_packed_strided (AdaWorldAPI/ndarray#418). The prepared-B reuse rule moves into shape::ReuseKey, shared by the BF16 and INT8 prepared operands so the two cannot drift. Measured on one AMX VM (median of 41 warm runs, three runs), 256 fields x 256 columns: the direct GEMM takes 45.5-48.1 us against 78.3-78.8 us for backend::gemm_i8, end to end 47.5-57.9 us against 88.9-92.2 us; at 64 fields 0.98-1.01 us against 3.4-3.6 us. No A copied, no allocation. Needs ndarray#418. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: record the INT8 direct arm results Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: time the B pack through ndarray::simd, not hpc The benchmark's pack-timing row called ndarray::hpc::amx_matmul::vnni_pack_i8 directly. hpc is reached only through the ndarray::simd polyfill, so the row now times PackedI8B::pack_from, which packs into the same VNNI layout. The measured share is unchanged (23.1 us, 39% of the gemm_i8 row at 256 fields). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk --------- Co-authored-by: Claude <noreply@anthropic.com>
…cross GEMMs (D-DT64-G2L-1) (#1994) * dr-isa-stream-lab: INT8 direct arm on ndarray's prepacked INT8 entries Adds int8::direct and int8::PreparedI8B. A is read in place at the u8 lanes' pitch and B is prepared once as PackedI8B bands, through ndarray::simd::int8_gemm_packed_strided (AdaWorldAPI/ndarray#418). The prepared-B reuse rule moves into shape::ReuseKey, shared by the BF16 and INT8 prepared operands so the two cannot drift. Measured on one AMX VM (median of 41 warm runs, three runs), 256 fields x 256 columns: the direct GEMM takes 45.5-48.1 us against 78.3-78.8 us for backend::gemm_i8, end to end 47.5-57.9 us against 88.9-92.2 us; at 64 fields 0.98-1.01 us against 3.4-3.6 us. No A copied, no allocation. Needs ndarray#418. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: record the INT8 direct arm results Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * wip: G2L lab, one witnessed translation reused across GEMMs (untested) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: time the B pack through ndarray::simd, not hpc The benchmark's pack-timing row called ndarray::hpc::amx_matmul::vnni_pack_i8 directly. hpc is reached only through the ndarray::simd polyfill, so the row now times PackedI8B::pack_from, which packs into the same VNNI layout. The measured share is unchanged (23.1 us, 39% of the gemm_i8 row at 256 fields). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * feat(dr-isa-stream-lab): G2L lab falsifier — one witnessed translation reused across GEMMs D-DT64-G2L-1. A selection named in global ids is translated once under one frame of the source's DR MapTable into the source's own row order (counted lookups). The object is bound in the source's space, B is prepared once through the translation (one map read per row), and every run reads the source's lanes in place with zero lookups. Cross-space reads without a translation stay refused (ADMISSION B, #1640). One AMX VM, three runs: translate once 68-85 us (3200 lookups), prepare B 37-47 us, warm run 16-22 us with 0 lookups; re-translating per operation 128-166 us (about 8x). Six falsifiers in tests/integration/g2l.rs, four disable runs red. Contract doc G2L row moves from OPEN to measured (lab). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: refuse a translated identity past the inner B table TranslatedB::extent() reported the source's position range, so an identity past the inner table passed admit_operand and packing indexed past the table. extent() now reports the inner operand's own extent, and BValues gains highest_row(selection), which TranslatedB overrides to resolve each selected position to the identity it reads. admit_operand then refuses with ShapeRefusal::OperandShape before any packing (#1990's contract). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: report G2L costs one by one The G2L bench now reports separately: G2L lookups and translation time; admission and packing map reads during B preparation; B bytes packed and preparation time; A staging bytes and time per warm run; GEMM-only time; and the complete warm run. GEMM alone is 0.71-0.86 us; staging the sparse selection into a padded A is 11-14 us of a 20-24 us warm run, so zero lookups is not zero data movement. BENCH-SHAPE, the board entry and the contract doc record that K order changes under translation and is validated only for exact integer GEMM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * board: regenerate entries index after merging main Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk * dr-isa-stream-lab: refuse a translation made on another source Two sources built in the same order have equal coordinate digests, so Translation::check admitted a translation from the other one and packing then panicked reading a table with a frame it never issued (Codex, #1994). check now asks the source's own map table whether it issued the translation's frame, and refuses with G2lRefusal::Foreign before packing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk --------- Co-authored-by: Claude <noreply@anthropic.com>
These are the INT8 (
u8 × i8 → i32, AMXTDPBUSD) counterparts ofPackedBf16Bandbf16_tile_gemm_16x16_packed[_strided](#414), plus a multi-tile entry. All of them are reachable throughndarray::simd.Why
backend::gemm_i8gathers and VNNI-packs every 16-column band of B on every call, and it needs A dense with row stride K. lance-graph's dr-isa-stream-lab (lance-graph#1990) measured that band gather and pack at 36–38% of the INT8 GEMM at 256 × 256. It also showed that A has to be copied out of the source's lanes first.What is added
PackedI8Bpack/pack_from, which reuses the buffer,vnni_index/data_mutfor direct staging, and LE bytes. K must be a multiple of 64.int8_tile_gemm_16x16_packed[_strided]int8_gemm_packed_stridedint8_gemm_amx_tiled's 2×2 register-blocked kernel, minus the per-call band gather and pack; without AMX it falls back to the scalar reference per tile.int8_tile_gemm_tierA stays unsigned and B stays signed. Nothing reinterprets either one (test
packed_keeps_the_unsigned_a_signed_b_contract: 200 × −1 = −200 per position).Measurement
Measured in lance-graph's dr-isa-stream-lab on one AMX VM (4 vCPU, single-threaded), as the median of 41 warm runs. Each figure is the range over three runs. A is read in place from u8 lanes; every result is checked against an i64 oracle.
backend::gemm_i8(gathers and packs B on every call)int8_gemm_packed_strided, B prepacked onceint8_tile_gemm_16x16_packed_stridedcalled once per tileAt 64 × 64 the multi-tile entry takes 0.98–1.01 µs, against 3.4–3.6 µs for
gemm_i8. Packing B into bands costs about 105 µs at 256, so it pays off after roughly three calls.The per-tile entry is slower than the per-call pack it was meant to replace. Each of the 256 calls pays its own tile configuration, and the 2×2 blocking is lost. That is why the multi-tile entry exists; the per-tile entries are kept for parity with the BF16 API and for single-tile callers.
Tests
Nine new tests and three doctests. Every test checks exact equality:
vnni_index_matches_vnni_pack_i8(row, col)index matches the layoutvnni_pack_i8producespacked_equals_the_row_major_entryint8_tile_gemm_16x16and the scalar reference at K = 64, 128, 192strided_reads_a_in_place_at_its_pitchscalar_tier_matches_reference_at_a_pitchmulti_tile_packed_strided_matches_reference_on_every_strippacked_keeps_the_unsigned_a_signed_b_contract,packed_accumulates_into_c,pack_from_reuses_the_buffer_and_bytes_round_tripshould_panicguardsDisable runs, each restored afterwards; each made the named test fail:
strided_reads_a_in_place_at_its_pitchvnni_indexdrops therow & 3termvnni_index_matches_vnni_pack_i8multi_tile_packed_strided_matches_reference_on_every_stripcargo fmt --checkandcargo clippy --release --lib --tests -D warningsare clean.facet-stride-guard --diff origin/masterreports 0 hits.The existing
int8_tile_gemm_16x16now passes K as the stride to its AMX path, so its behaviour is unchanged.Generated by Claude Code