Commit 7151ac0
[programming_examples] AWQ int4 matvec examples (GEMV + GEMV+R) (#1632)
* [programming_examples] AWQ int4 matvec examples (GEMV + GEMV+R)
Add matrix_vector_multiplication/int4_awq/ with two NPU2 designs that
match the bf16 matvec_2tile_add reference structurally:
- matvec_int4_packed : D = dequant(A_q, A_s, A_z) @ B
- matvec_int4_packed_add : D = dequant(A_q, A_s, A_z) @ B + R
(2-tile cascade matching matvec_2tile_add)
Q+S+Z are prepacked into a single L3 BO so the per-tile shim DMA fits
one BD per shim channel, keeping the compute tile within its 2-S2MM
budget when paired with the broadcast B input. R stays a separate L3
BO so it can be produced/consumed by other NPU operators in a decode
pipeline without host repacking.
At M=K=2048 (Llama Wo decode shape) on NPU2 vs bf16 matvec_2tile_add:
matvec_int4_packed : ~170 us min
matvec_int4_packed_add : ~206 us min (vs bf16 ~286 us min)
Lit coverage: NPU2 correctness at M=K=2048 for both designs, plus a
M=2048 K=8192 (wdown decode shape) variant that exercises the K
inner-loop trip > 1 path.
Adds the int4_awq row to programming_examples/generate_readme.py.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [int4_awq] Address PR #1632 review comments
- matvec_int4_packed_add.py: include launch_off in the R broadcast so
addr_h's launch-relative offset arithmetic reads the correct slab on
every launch (was wrong for any --m-per-launch < M). Verified with
M=2048 K=2048 M_PER_LAUNCH=512 -> 4 launches PASS corr 0.999993.
- test_packed{,_add}.cpp: add <algorithm> and <cstring> headers for
std::min/std::max and memset rather than depending on transitive
XRT/test-utility includes.
- test_packed{,_add}.cpp: fill each per-tile packed slab with valid
AWQ subregions (Q random uint8 pairs, S bf16 in [0.005,0.02], Z in
[7,9)) instead of raw random bytes, so the profile loop doesn't run
on bf16 NaN/Inf scales.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 79d2ac8 commit 7151ac0
10 files changed
Lines changed: 1373 additions & 0 deletions
File tree
- programming_examples
- matrix_vector_multiplication/int4_awq
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
| |||
Lines changed: 106 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
0 commit comments