Add RMSNorm kernel to latency-demo roofline notebook (#165) - #197
Conversation
lasch
left a comment
There was a problem hiding this comment.
Summary
- (cleanup) Maintainability M1 hand-rolled access-tile boilerplate instead of the existing
_access_tilehelper - (not blocker) Finding F1, silent wrong output when
hidden_dimdoesn't divide evenly byblock_size(this is the same for other kernels and the notebook doesn't exercise any odd cases)
Details
-
M1 — reinvents the
_access_tilehelper the module explicitly exists to avoid. The module's own docstring states: "Private helpers (_mem_view,_access_tile,_indirect_kv_tile) factor out repeated boilerplate." Every sibling generator (gen_matmul_mlir,gen_softmax_mlir,gen_sdpa_mlir) builds its access tiles via_access_tile(name, view, offsets, tile_shape, view_shape).gen_rmsnorm_mlirinstead hand-writes four access-tile blocks inline (x_acc,x_acc2,w_acc,y_acc), each reproducing_access_tile's exactaccess_tile_set/access_tile_orderboilerplate by and.
x_accandx_acc2are, byte-for-byte, the same template (_access_tile("x_acc*", "x_view", ["%row", "%col"], [1, bs], [n_rows, hd])) duplicated verbatim between pass 1 and pass 2. This is exactly the kind of divergence the helper was written to prevent — a maintainer extending_mem_view/_access_tile(e.g. to fix an affine-bound convention, or add a dtype) would silently miss this generator's four inline copies. -
F1 — silent wrong output when
hidden_dim % block_size != 0(confirmed, not exercised by the notebook). Bothscf.for %col = %c0 to %c_hd step %BLOCK_SIZEloops (pass 1 and pass 2) iterate whilecol < hidden_dim, but each iteration unconditionally requests a fixed1×block_sizeaccess tile via a hardcoded affine bound-d1 + {block_size - 1} >= 0. Whenhidden_dimisn't a multiple ofblock_size, the final iteration's tile extends past the memory view's declaredhidden_dimbound. Unlikegen_paged_attention_mlir, which explicitly ceiling-divides (num_tiles = (context_len + block_size - 1) // block_size) to handle a non-divisible trailing block,gen_rmsnorm_mlirhas no such guard, no assertion, and no docstring note of the precondition. Not a merge blocker for this PR (every call site useshidden_dim=4096, block_size=1024, which divides evenly), but it's a latent correctness hazard in reusable generator code that the next person to changeRMS_HIDDENorblock_sizein the notebook — or reusegen_rmsnorm_mlirelsewhere — will hit silently. This PR inherits/follows an existing repo-wide gap/pattern rather than introducing a new one.
…ibility assert Signed-off-by: Hao Yu <yuh@us.ibm.com>
|
@lasch Addressed your review feedbacks. Please take a look The full messaging from the semi-auto Claude-sessionAddress PR #197 review: use _access_tile helper, add divisibility assert
|
lasch
left a comment
There was a problem hiding this comment.
thx for addressing the comments.
/lgtm
Review — RMSNorm notebook kernel (head
|
Integrate a parameterized RMSNorm generator and 3-config scaling study (4-core baseline, 32-core strong, 32-core weak) into the multi-kernel roofline sections alongside matmul/softmax/SDPA/paged-attention. Design choices: - Unfused standalone kernel — models the HBM pass-through between matmul stages as it appears in prefill. - 1D grid [N,1] row-partition — prefill has abundant row parallelism; hidden-dim sharding adds allreduce for zero benefit. - W is 1D [hidden_dim] per PyTorch convention — avoids inflated HBM traffic (8 KB stays LX-resident after one cold miss). Signed-off-by: Hao Yu <yuh@us.ibm.com>
…ibility assert Signed-off-by: Hao Yu <yuh@us.ibm.com>
…ce phase of rmsnorm kernel 1. fix(rmsnorm mlir): promote accumulation-reduction block to f32-based 2. feature(latency): charge SIMD cost for extf, truncf, and splat (reflecting Spyre Rapid Core specs) 3. LX-residency docstring claim 4. explanation for bottleneck=compute at 4 cores Signed-off-by: Hao Yu <yuh@us.ibm.com>
e8a186c to
c87cd52
Compare
|
The latest commit addresses the latest comments from @lasch and @WarningRan , with conflict resolution following the merging of sister notebook related PRs. Changes to address comments:Added f16-to-f32 and back conversions to address overflow in acc-reduce phase of rmsnorm kernel
|
F3, site 2 ( Your item (2) introduces a new issue (sorry for blasting the full text without summary). The recommendation here would be to extract that into a separate PR. On the other hand, we wanted to wrap up for now and not introduce new loose ends.
|
- F3: rmsnorm roofline docstring in the notebook - F4: keep the zero-latency premise for type-casting and splat ops Signed-off-by: Hao Yu <yuh@us.ibm.com>
|
@lasch Namely F3 and F4 are addressed. Suggested fixes:
Additional Notebook Prose Fixes
|
Goal: to close issue #165
Belonging Epic: #94
Commit message:
Integrate a parameterized RMSNorm generator and 3-config scaling study (4-core baseline, 32-core strong, 32-core weak) into the multi-kernel roofline sections alongside matmul/softmax/SDPA/paged-attention.
Design choices:
Artifacts for reviewing:
latency_demo_after.html
latency_demo_before.html