Skip to content

openrknn: route exNorm trailing REFORMATs through scratch tensor - #88

Merged
widgetii merged 1 commit into
masterfrom
openrknn/exnorm-scratch-routing
Apr 13, 2026
Merged

widgetii merged 1 commit into
masterfrom
openrknn/exnorm-scratch-routing

Conversation

@widgetii

@widgetii widgetii commented Apr 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Route exNorm trailing REFORMAT SRC and DST through scratch tensor (input[3])
  • Detect final trailing REFORMAT via next-task op_idx lookahead — it writes to real output + applies gamma/beta
  • Remove BS/BN for intermediate REFORMATs (oracle has 0), keep for final

Results

DMA-class diffs on l0_mlp: 72 → 3 (96% reduction)

Category Before After
exNorm REFORMAT BS/BN 24 0
exNorm REFORMAT SRC 12 0
exNorm REFORMAT DST 12 0
CONV SRC/EW tile offset 2 2
Post-exNorm op SRC 1 1
Input/output routing 4 0 (fixed in #87)
pc2/pc3 PPU 20 0 (fixed in #86)
Total 72 3

Remaining 3 diffs: the post-em0d CONV reads from scratch+tile_offset where the tile offset is vendor-computed (not in template val), and the next op's SRC uses a different tensor base than openrknn resolves.

Test plan

  • CI: 9/9 pass, 5/5 CNN byte-exact
  • l0_mlp diff: 72 → 3 DMA-class diffs
  • Model runs without crashes (no submit timeout)
  • Cosine vs vendor still near-zero — the 3 remaining diffs affect the CONV computation path

🤖 Generated with Claude Code

The vendor's oracle shows that exNorm trailing REFORMAT tasks (after
the em=0x0d + CONV pass) read from and write to the scratch tensor
(input[3]), not the data tensor (input[0]) or output tensor (output[0]).

Analysis of all 48 DMA diffs confirmed a constant vendor_base of
0x480000 (scratch) for both SRC and DST, with identical raw vals.
The final trailing REFORMAT is special: it writes to the real output
tensor (dst_tensor_off) and applies BS/BN (gamma/beta).

Changes:
- SRC (0x5018): use rdma_tensor_off (scratch) for exNorm trailing
  REFORMATs when em0d_block_idx > 0
- DST (0x4020): use rdma_tensor_off (scratch) for intermediate exNorm
  REFORMATs; final one uses dst_tensor_off (real output)
- BS/BN (0x5020/0x502c): remove exNorm from intermediate REFORMATs,
  keep for final REFORMAT and BatchNormalization
- Detect final REFORMAT via next-task op_idx lookahead

Reduces l0_mlp DMA-class diffs from 48 to 3 (72 → 3 total, 96%).
Remaining 3: CONV SRC/EW tile offset + post-exNorm op SRC.

CI: 9/9 pass, 5/5 CNN byte-exact, 0 gating.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii
widgetii force-pushed the openrknn/exnorm-scratch-routing branch from c0c50cc to 48e59eb Compare April 13, 2026 05:30
@widgetii
widgetii merged commit bac972f into master Apr 13, 2026
7 checks passed
@widgetii
widgetii deleted the openrknn/exnorm-scratch-routing branch April 13, 2026 05:33
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.

1 participant