linalg/wasm: make the relaxed-dot int8 path bit-exact on all engines - #2594
Open
czoli1976 wants to merge 1 commit into
Open
linalg/wasm: make the relaxed-dot int8 path bit-exact on all engines#2594czoli1976 wants to merge 1 commit into
czoli1976 wants to merge 1 commit into
Conversation
The i8 kernel fed full-signed B into i32x4_relaxed_dot_i8x16_i7x16_add's second operand, which is only defined for lanes in [0, 127]: x86 lowerings (pmaddubsw/vpdpbusd) read out-of-range lanes as unsigned, so every negative B byte skewed the result by 256*a. Sign-split B into two i7-safe planes (b & 0x7f and b >> 7), give each its own relaxed dot, and fold acc -= acc_hi << 7 after the K-loop; in-range operands also keep pmaddubsw's i16 pair-sums below saturation, so the kernel is bit-exact on every engine. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under +relaxed-simd, wasm_i32_4x4 feeds full-signed i8 B into i32x4.relaxed_dot_i8x16_i7x16_add's i7-range operand, which x86 lowerings (pmaddubsw/vpdpbusd) read as unsigned: the wasm::mmm_i32 i8i8 tests fail under wasmtime on x86-64, and would block #2565's relaxed-simd CI lane once it merges. This sign-splits B into two i7-safe planes with one relaxed dot each, folded back after the K-loop as
acc -= acc_hi << 7— bit-exact on every engine, still dot-product speed, no packing change.🍍
🤖 Generated with Claude Code