Skip to content

hpc::int8_tile_gemm: prepacked INT8 B (PackedI8B) and strided-A entries - #418

Merged
AdaWorldAPI merged 6 commits into
masterfrom
ccr-8062bcc7-l7lkz9-packed-i8b
Nov 10, 2026
Merged

AdaWorldAPI merged 6 commits into
masterfrom
ccr-8062bcc7-l7lkz9-packed-i8b

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

These are the INT8 (u8 × i8 → i32, AMX TDPBUSD) counterparts of PackedBf16B and bf16_tile_gemm_16x16_packed[_strided] (#414), plus a multi-tile entry. All of them are reachable through ndarray::simd.

Why

backend::gemm_i8 gathers 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

Item What it does
PackedI8B One K × 16 band of B in TDPBUSD's VNNI quad layout. Provides pack / pack_from, which reuses the buffer, vnni_index / data_mut for direct staging, and LE bytes. K must be a multiple of 64.
int8_tile_gemm_16x16_packed[_strided] One 16×16 tile over a prepacked band, with A read at the caller's row pitch. Accumulates into C.
int8_gemm_packed_strided An M × N GEMM over N/16 prepacked bands and a strided A, with one tile configuration per call. Overwrites C. On AMX it reuses int8_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_tier Names the tier that runs, for run reports.

A 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.

256 fields × 256 columns, K = 256 Time
backend::gemm_i8 (gathers and packs B on every call) 78.3–78.8 µs
… of which band gather + VNNI pack 28.6–29.4 µs
int8_gemm_packed_strided, B prepacked once 45.5–48.1 µs (348–368 GMAC/s)
int8_tile_gemm_16x16_packed_strided called once per tile 99–108 µs

At 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:

Test What it checks
vnni_index_matches_vnni_pack_i8 Every (row, col) index matches the layout vnni_pack_i8 produces
packed_equals_the_row_major_entry The packed entry equals int8_tile_gemm_16x16 and the scalar reference at K = 64, 128, 192
strided_reads_a_in_place_at_its_pitch Pitches K, K+1, K+64 and 3K+7 all match the reference
scalar_tier_matches_reference_at_a_pitch The scalar tier is called directly, so an AMX host covers it too
multi_tile_packed_strided_matches_reference_on_every_strip Full 32×32 blocks, a 16-row bottom strip, an odd band count and M = 16, on both tiers
packed_keeps_the_unsigned_a_signed_b_contract, packed_accumulates_into_c, pack_from_reuses_the_buffer_and_bytes_round_trip Sign contract, accumulation, buffer reuse and the LE byte round trip
Five should_panic guards Pitch shorter than K, A too short (both entries), K not a multiple of 64, bands of different K

Disable runs, each restored afterwards; each made the named test fail:

Change Failing test
AMX path loads A at stride K instead of the pitch strided_reads_a_in_place_at_its_pitch
vnni_index drops the row & 3 term vnni_index_matches_vnni_pack_i8
Multi-tile kernel loads A at stride K multi_tile_packed_strided_matches_reference_on_every_strip

cargo fmt --check and cargo clippy --release --lib --tests -D warnings are clean. facet-stride-guard --diff origin/master reports 0 hits.

The existing int8_tile_gemm_16x16 now passes K as the stride to its AMX path, so its behaviour is unchanged.


Generated by Claude Code

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
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d91b9ed3-4b01-45dc-96e9-8ce2a74cb353
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T19:06:18.365882Z d07deeb Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/hpc/int8_tile_gemm.rs Resolved
Comment thread src/hpc/int8_tile_gemm.rs Resolved
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

Copy link
Copy Markdown
Owner Author

Memory-safety review gate: resolved (head 4b87d85).

Both Codex P1 findings were real and are fixed. Both review threads are resolved.

Fixes

  • PackedI8B::zeroed and from_le_bytes now compute 16·K with a checked multiply (packed_len) and panic on overflow. The A-length checks in int8_tile_gemm_16x16 and int8_tile_gemm_16x16_packed use the same helper. A PackedI8B therefore always holds exactly K·16 bytes.
  • int8_gemm_packed_strided now computes N = 16·bands and M·N with checked multiplies. The stride extents were already checked: (M-1)·stride + K here, and 15·stride + K in the single-tile strided entry.

Regression tests, run in release mode on an AMX host (int8_tile_gemm_tier() reports AMX TDPBUSD). All 31 module tests pass.

Test Input
packed_refuses_a_k_whose_size_overflows, from_le_bytes_refuses_a_k_whose_size_overflows K = 2⁶⁰
multi_tile_refuses_an_output_size_that_overflows Codex's case: one zeroed(0) band, stride 0, empty A and C, M = 2⁶⁰
multi_tile_refuses_a_stride_whose_extent_overflows, strided_refuses_a_stride_whose_extent_overflows stride ≈ usize::MAX/4 and usize::MAX/8
k0_multi_tile_overwrites_with_zeros_on_both_tiers K = 0 with 32-row blocks, a 16-row strip and 3 bands, through the dispatched AMX kernel and the scalar tier called directly
k0_single_tile_accumulates_nothing_on_both_tiers K = 0 through both single-tile entries and the scalar tier
m0_multi_tile_is_a_no_op M = 0 with an empty C

Disable runs (release mode, each restored afterwards):

Check reverted to wrapping Result
16·K both K = 2⁶⁰ tests fail
M·N the test process is killed by SIGSEGV, the out-of-bounds tile store Codex described
(M-1)·stride + K multi_tile_refuses_a_stride_whose_extent_overflows fails

cargo fmt --check and cargo clippy --release --lib --tests -D warnings are clean. facet-stride-guard --diff origin/master reports 0 hits.


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

Copy link
Copy Markdown
Owner Author

CI: realization/avx2 × x86_64 failure is not this PR's. Fix pushed (ci(simd-matrix)).

rustc itself took SIGILL in the step cargo test --lib -- hpc::amx_ops simd_amx, while loading target/debug/deps/libpaste-….so. The rust-cache had restored target/ with a full key match, and that proc macro had been built with -Ctarget-cpu=native on a different runner CPU. This runner has AVX2 but no AVX-512 (avx512f=false, AMX report TILE=false INT8=false BF16=false). The same row is red on master at 09ca908, the merge of #417.

The host-native row already guards against this by keying its cache on a hash of the target features rustc resolves for native (#344, same paste .so). The avx2 row now uses the same key.

The INT8 code itself does not depend on the runner's CPU. Every tile entry dispatches on amx_available() at runtime and falls back to the scalar tier. tests/stable ran all 31 module tests on a non-AMX runner and passed.


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Add Carrot credits or activate Agent usage billing to use Autofix

Copy link
Copy Markdown
Owner Author

@codex review

Please review head d07deeb. It contains the checked-arithmetic fixes for both earlier P1 findings, the degenerate/oversized-dimension tests, and the simd-matrix avx2 cache-key fix. All CI is green on this head.


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: d07deebb80

ℹ️ 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".

@AdaWorldAPI
AdaWorldAPI merged commit 79ed32c into master Nov 10, 2026
31 checks passed
AdaWorldAPI added a commit to AdaWorldAPI/lance-graph that referenced this pull request Nov 10, 2026
* 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>
AdaWorldAPI added a commit to AdaWorldAPI/lance-graph that referenced this pull request Nov 10, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants