Repository navigation
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: The new gate repeats existing contracts, and both new kernels violate R1's unsafe-scope rule.
Must fix
1. Keep tile and row-lane parity in their existing gates
crates/qdot/tests/qdot.rs:6038 repeats tile = dot_row and lanes = dot_row. Their owners are crates/qdot/tests/qdot.rs:4376 and crates/qdot/tests/qdot.rs:5923. The existing gates select the AVX-512 bodies through the changed dispatch. The lane gate already includes the same all-0xFF fixture. This violates AGENTS.md's one-test-per-contract rule (kind B).
Consolidate now, before the duplicate clauses acquire more cases.
Keep the new gate's dot_row = dot_row_avx2 = scalar assertions. Move additional tile/lane fixtures into their existing owners. Replace lines 6038–6045 with:
eprintln!(
"Q4_K {body}: {label}, {} rows x {} columns: dot_row = dot_row_avx2 = scalar, bit-identical",
bytes.len() / row_bytes,
acols.len()
);Replace its doc comment with:
/// Q4_K's selected one-column body equals its AVX2 body and scalar mirror
/// bit for bit on seeded rows and the full-code rows of [`lane_fill`].
/// The printed line names the selected body.
2. Scope unsafe to each operation (R1)
crates/qdot/src/lib.rs:4919 and crates/qdot/src/lib.rs:5520 wrap the complete kernel bodies in unsafe, including safe setup, loops and output construction. R1 explicitly forbids a whole-function unsafe block and requires an invariant for each operation. Narrowing these scopes is mechanical (kind B); the existing checks enforce comments and counts, not block scope.
Attach each operation's bounds proof now, before either kernel grows.
Remove the two outer wrappers. Give each pointer offset, memory access and unsafe helper call its own block and // SAFETY: invariant. Keep the #[target_feature] bodies and arithmetic order intact, and update the unsafe-count pin with a dated reason. For the tile's scale setup, replace lines 4926–4933 with:
// SAFETY: this function's target-feature contract includes F16C.
let d = unsafe { f16c_to_f32(u16::from_le_bytes([wb[0], wb[1]])) };
// SAFETY: this function's target-feature contract includes F16C.
let dmin = unsafe { f16c_to_f32(u16::from_le_bytes([wb[2], wb[3]])) };
let utmp = make_q4_scales(&wb[4..16]);
// SAFETY: offset 2 stays inside this four-u32 array.
let mins_ptr = unsafe { utmp.as_ptr().add(2) };
// SAFETY: the last two u32 elements provide eight readable bytes.
let mins_i = unsafe { _mm_loadl_epi64(mins_ptr.cast()) };
let mins_v = _mm256_cvtepi32_ps(_mm256_cvtepu8_epi32(mins_i));Apply the same operation-local scoping throughout both kernels.
Checked
Duplicates: repeated tile/lane contracts confirmed; dryer reported no qualifying pairs.
Complexity: dot_row 18 → 19 from one dispatch arm; no kernel split requested.
Silent failure: flag parsing rejects invalid x86 values; chunk limits, column pairing and lane dispatch have bounds/type guards.
Tests: direct AVX2/scalar and tile/lane bit comparisons read; runtime gates were not run during validation.
Gates: unsafe counts 141/77 → 145/79 have a dated PIN and new-kernel reason; no numeric bands moved.
Escape catalog: C1–C4 do not match the changed code; the release script retains pipefail.
Notes
The PR text provides no owning-gate output on an AVX-512-capable CPU or FAIL-first evidence.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #143
There was a problem hiding this comment.
Since the last review:
- Lane duplication fixed by the dated transfer. Tile duplication remains at crates/qdot/tests/qdot.rs:6043.
- Whole-function unsafe wrappers removed. Separate operations still share blocks at crates/qdot/src/lib.rs:5576.
Verdict: MUST_FIX: The duplicate tile contract and R1 scope violations remain.
Must fix
1. Finish consolidating tile parity
crates/qdot/tests/qdot.rs:6043 repeats tile = dot_row, already owned by crates/qdot/tests/qdot.rs:4376. Both call assert_tile_matches and select the new kernel through the same dispatch. This violates AGENTS.md's one-test-per-contract rule (kind B).
Consolidate before fixtures and assertions grow in both owners.
Keep the synthetic tile coverage. Insert this after let ty = GgmlType::Q4_K; in hw_q4k_tile_matches_dot_row:
// PIN(2026-10-14): synthetic tile fixtures consolidated here; coverage retained.
let (block, _) = lane_block(ty);
for (k, rows, seed) in [
(256usize, 16usize, 0x5a12_0001u64),
(512, 16, 0x5a12_0005),
(768, 16, 0x5a12_0006),
(2048, 16, 0x5a12_0002),
(2304, 16, 0x5a12_0003),
(4096, 24, 0x5a12_0004),
] {
let bytes = lane_rows(ty, k, rows, seed);
assert_tile_matches(
ty, "seeded rows", k, k / 256 * block, &bytes, &lane_columns(ty, k),
);
}
assert_tile_matches(
ty, "0xFF rows", 4096, 16 * block,
&lane_fill(ty, 4096, 0xFF), &lane_columns(ty, 4096),
);Replace lines 6043–6050 in the new gate with:
// PIN(2026-10-14): tile fixtures moved to hw_q4k_tile_matches_dot_row.
let lanes = assert_lanes_match(ty, label, k, row_bytes, bytes, &acols);
eprintln!(
"Q4_K {body}: {label}, {} rows x {} columns: dot_row = dot_row_avx2 = scalar, \
{lanes} lane calls = dot_row, bit-identical",
bytes.len() / row_bytes,
acols.len()
);Replace its doc comment with:
/// Q4_K's selected one-column body equals its AVX2 body and scalar mirror
/// bit for bit on seeded and full-code rows. Its row lanes equal dot_row.
/// The printed line names the selected body.
2. Finish scoping each unsafe operation (R1)
crates/qdot/src/lib.rs:5576 still groups two stores. The paired loads at 4976, 4986, 5555, 5566 and 5624 also group separate accesses. These access different arrays or groups; R1's contiguous-load exception does not apply (kind B).
Attach each bounds proof now, before these blocks gain more operations.
Replace the store block and its comment with:
// SAFETY: dy[c][ii] holds eight writable f32 values.
unsafe { _mm256_storeu_ps(dy[c][ii].as_mut_ptr(), dyv) };
// SAFETY: my[c][ii] holds eight writable f32 values.
unsafe { _mm256_storeu_ps(my[c][ii].as_mut_ptr(), myv) };For each paired head load, replace the tuple block with:
// SAFETY: g0 points to a group with eight readable head bytes.
let h1 = unsafe { _mm_loadl_epi64(g0 as *const __m128i) };
// SAFETY: g1 points to a group with eight readable head bytes.
let h2 = unsafe { _mm_loadl_epi64(g1 as *const __m128i) };Apply operation-local blocks to the remaining paired loads and the half/act closures too. Separate each pointer add from its load, including line 4929. Keep the kernel bodies and arithmetic order intact; update the unsafe-count PIN to the resulting count.
Checked
Duplicates: 0 new named functions/types/constants in this update; existing owners grepped; tile duplication remains. Dryer reported 0 pairs.
Complexity: crapper's dot_row 18 → 19 is one dispatch arm; no further growth here and no kernel split requested.
Silent failure: invalid lever values panic by name; chunk limits and odd-column repetition have defined bounds.
Tests: forcing dispatch false at lib.rs:283 makes the new assertion red on ISA+enabled; dropping the my store at lib.rs:5578 makes lane parity red. Static mutation analysis; no runtime gates run.
Bounds: short buffers rejected; empty blocks skip reads; final packed slices and odd-column pairs stay in bounds.
Gates: Q4_K lane transfer and unsafe count 145 → 164 have dated reasons; no numeric bands moved.
Escape catalog: C1–C4 do not match the incremental diff.
Notes
The PR body provides no AVX-512-capable CPU gate output or FAIL-first run.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
…odies, picked at run time (qdot::q4k_avx512, BLOOMERY_QDOT_AVX512) and bit-identical to the AVX2 ones, and the release check lists the two bodies as runtime-dispatched; hw_q4k_avx512_matches_avx2_synthetic and the f16 scale sweep hold them to dot_row_avx2 and the scalar mirror (FAIL-first: the tile's sub-block fmas swapped, a sub-block paired with the wrong activations, or a lane half reading the other half's activations turns it red)
… block per operation with its SAFETY line (R1), d and dmin through f16c_pair_to_f32, Q4_K's synthetic lane clause owned by hw_q4k_avx512_matches_avx2_synthetic, and that gate asserts the selector picks AVX-512 exactly where the ISA is present and the lever allows
…lock per pointer offset, load and store (R1), and the synthetic tile fixtures owned by hw_q4k_tile_matches_dot_row
39c5f63 to
9cc1a20
Compare
There was a problem hiding this comment.
Verdict: MUST_FIX: duplicated test fixtures and an unpinned release-gate expansion violate the project contract.
Must fix
1. Give the Q4_K fixture matrix one owner
crates/qdot/tests/qdot.rs:4381 and crates/qdot/tests/qdot.rs:6023 independently define the same six size/row/seed cases and the same full-code case. This is a proven duplicate (kind B, R14). The next boundary case otherwise needs two edits.
Add this fixture owner in the test file:
fn q4k_synthetic_rows() -> Vec<(String, usize, Vec<u8>)> {
let ty = GgmlType::Q4_K;
let mut sets: Vec<_> = [
(256usize, 16usize, 0x5a12_0001u64),
(512, 16, 0x5a12_0005),
(768, 16, 0x5a12_0006),
(2048, 16, 0x5a12_0002),
(2304, 16, 0x5a12_0003),
(4096, 24, 0x5a12_0004),
]
.into_iter()
.map(|(k, rows, seed)| {
(format!("seeded rows (k = {k})"), k, lane_rows(ty, k, rows, seed))
})
.collect();
sets.push(("0xFF rows (k = 4096)".into(), 4096, lane_fill(ty, 4096, 0xFF)));
sets
}In hw_q4k_tile_matches_dot_row, replace the synthetic loop and full-code assertion, keeping block:
for (label, k, bytes) in q4k_synthetic_rows() {
assert_tile_matches(
ty, &label, k, k / 256 * block, &bytes, &lane_columns(ty, k),
);
}In hw_q4k_avx512_matches_avx2_synthetic, replace the array, collection and push:
let sets = q4k_synthetic_rows();2. Pin the widened release ISA gate
tools/release/build.sh:35 now permits both Q4_K AVX-512 kernel families without a dated PIN (kind B). The old regex rejects these names; their callers check the full ISA through q4k_avx512. Recording that justification now keeps later release exceptions auditable.
Replace the assignment with:
# PIN(2026-10-13): permit the new Q4_K VNNI entries; q4k_avx512 checks their full ISA at every caller.
DISPATCHED='^(sha2::sha256::x86::digest_blocks|sha1::compress::x86::digest_blocks|crc32fast::specialized::pclmulqdq::calculate_avx(512|2)|qdot::dot_(q4k_q82x4_tile|lanes)_avx512::<[0-9]+>)$'Non-blocking
⚠ Supply kernel and dispatch evidence: crates/qdot/src/lib.rs:5005 replaces eight maddubs plus two madd with four VNNI dots per 256 weights and column [derived], retaining three FMAs. The integer-path-reorder class needs the owning gate; default ISA dispatch also needs a same-lease A/B. Attach FAIL-first, just gate-qdot output for both lever arms, and A/B output with the CONTRIBUTING card/model/hash evidence before landing.
Checked
Duplicates: both Q4_K fixture matrices and the full-code case match. R14 requires one owner.
Dispatch: all three AVX-512 call sites use q4k_avx512, which checks the kernels' required CPU features and refuses invalid lever values.
Tests: the synthetic gate compares dot_row with AVX2 and scalar results, then checks row lanes. These assertions do not measure speed.
Gates: unsafe ratchet and moved Q4_K clauses carry PIN reasons; release allowlist expansion lacks one. The inline suggestion targets added line 35 and passes Bash syntax validation.
Escape catalog: C1–C4 do not match the changed shell lines; pipefail remains set. No ledger lessons are in force.
Notes
Hardware gates and timed A/B were not run here. The PR body supplies no gate output, FAIL-first witness or A/B evidence.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
| GLIBC_FLOOR=2.34 | ||
| BINS=(bloomery-serve) | ||
| DISPATCHED='^(sha2::sha256::x86::digest_blocks|sha1::compress::x86::digest_blocks|crc32fast::specialized::pclmulqdq::calculate_avx(512|2))$' | ||
| DISPATCHED='^(sha2::sha256::x86::digest_blocks|sha1::compress::x86::digest_blocks|crc32fast::specialized::pclmulqdq::calculate_avx(512|2)|qdot::dot_(q4k_q82x4_tile|lanes)_avx512::<[0-9]+>)$' |
There was a problem hiding this comment.
The widened release ISA allowlist requires a dated PIN and its CPU-check justification.
| DISPATCHED='^(sha2::sha256::x86::digest_blocks|sha1::compress::x86::digest_blocks|crc32fast::specialized::pclmulqdq::calculate_avx(512|2)|qdot::dot_(q4k_q82x4_tile|lanes)_avx512::<[0-9]+>)$' | |
| # PIN(2026-10-13): permit the new Q4_K VNNI entries; q4k_avx512 checks their full ISA at every caller. | |
| DISPATCHED='^(sha2::sha256::x86::digest_blocks|sha1::compress::x86::digest_blocks|crc32fast::specialized::pclmulqdq::calculate_avx(512|2)|qdot::dot_(q4k_q82x4_tile|lanes)_avx512::<[0-9]+>)$' |
Temporary internal branch with the same tip as #86 (rebased onto main) so the review workflow runs. #86 itself is what merges; this closes after.