perf(codegen): O(n²)→O(n) ISA emit (fixes mlen=16 vision DNF), faster sim_env re-parse, roll RoPE+norm, rename ATEN_UNROLL→ATEN_OPS_UNROLL#56
Merged
Conversation
…fixes mlen=16 vision codegen runaway (>30m DNF -> 52s)
…s/opcode sets out of per-line/per-instr loops, single-pass line preprocessing); byte-identical output, ~17% faster on large programs
…nv ATEN_UNROLL -> ATEN_OPS_UNROLL RoPE collapses to one C_LOOP (addr is a single k*vlen progression); RMS/LayerNorm roll their inner hidden-dim loops. Rolled by default (ATEN_OPS_UNROLL=1 forces the prior unrolled output, verified byte-identical). Cuts emitted lines (decoder 256 1L -54%, vision -5%, decoder 16/16/4 -2%); allclose 100%. Note: rolling is not sim_lat-neutral - the C_LOOP + S_ADDI_INT pointer advances replace baked address loads, shifting modeled cycles slightly (+0.08% on decoder 16/16/4).
This was referenced Jun 2, 2026
Merged
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.
Three host-time codegen/assembler perf fixes, each verified byte-identical or allclose-100%. None changes the modeled hardware latency except the small, documented loop-overhead noted in (3).
1. ISA emit O(n²)→O(n) (
aten/plena/isa_emit.py).IsaEmitMixinaccumulated the generated ISA viaself.generated_code += renderedonce per instruction — an O(n²) string copy that runs away at high instruction counts. mlen=16 vision emits 2.43M lines for a single layer, so n² blew past the 30-minute timeout (the long-standing mlen=16 vision DNF). Backing the buffer with a list of rendered chunks (append + join, exposed through agenerated_codeproperty) makes emission amortised O(1); the public type staysstrand the output is byte-identical (verified: vision 32/32/4 regenerated to the byte at 599,202 lines). Result: mlen=16 vision compiles in ~52s and PASSES (allclose 100%), and the finishing mlen=32 vision isa_gen dropped 59.2s → 2.3s.2. Faster sim_env ASM re-parse (
assembler/parser.py,assembler/assembly_to_binary.py). The sim_env phase re-parses the emitted ASM text back into binary; the hot loop redefinedparse_reg_or_intplus the masked-op sets on every line, and_convert_to_binaryrebuilt ~8 opcode lists per instruction. Hoisting those to module scope (frozensets) and a single-pass line preprocessing make it ~17% faster on large programs, with byte-identical.memoutput (verified on a 1.99M-instruction vision program and a decoder 256 5L program across the full opcode mix).3. Roll RoPE + normalization; rename
ATEN_UNROLL→ATEN_OPS_UNROLL(asm_templates/rope_asm.py,asm_templates/normalization_asm.py,aten/plena/isa_compiler.py,aten/plena/compiler.py). RoPE collapses to oneC_LOOP(its per-iteration address is a single k·vlen progression); RMS/LayerNorm roll their inner hidden-dim loops. Both are gated on the existing unroll flag and rolled by default —ATEN_OPS_UNROLL=1reproduces the prior unrolled output byte-identically (verified via a fully-unrolled old-vs-new anchor and a unit-level template diff). This cuts emitted lines (decoder 256 1L −54%, vision −5%, decoder 16/16/4 −2%) with allclose 100% across vision/decoder/vlm-e2e. NB: rolling is not exactly sim_lat-neutral — theC_LOOP+S_ADDI_INTpointer advances replace baked address loads, so modeled cycles shift slightly (measured +0.08% on decoder 16/16/4). The env var is renamed to the clearerATEN_OPS_UNROLL; the codegen-compare harnesses in PLENA_Simulator are renamed in the paired PR.Pairs with the PLENA_Simulator docs + harness-rename PR. The compiler tests pass (68/70; the 2 failures are pre-existing and unrelated — confirmed by stashing these changes) and ruff is clean.