Skip to content

fix(codegen): eliminate dead optimizer L3 arena allocation#25

Merged
runwangdl merged 1 commit into
develfrom
fix/optimizer-l3-arena-elimination
May 12, 2026
Merged

fix(codegen): eliminate dead optimizer L3 arena allocation#25
runwangdl merged 1 commit into
develfrom
fix/optimizer-l3-arena-elimination

Conversation

@runwangdl
Copy link
Copy Markdown
Owner

Summary

  • The arena-elimination regex in _patch_shared_buffers only matched pi_*_malloc (L2) but missed cl_ram_malloc (L3)
  • When all optimizer I/O buffers are shared with the training network, the L3 arena has zero pointer-arithmetic references and should be removed — but the regex silently failed to match, leaving a dead cl_ram_malloc that wastes external RAM
  • Fix: extend the regex to (?:pi_\w+_malloc|cl_ram_malloc) so dead-code elimination works for all memory levels

Impact

For SimpleMLP: saves 4,736 bytes of L3 (external RAM). For larger models the savings scale with the optimizer arena size.

Test plan

  • Regenerate SimpleMLP optimizer: verify cl_ram_malloc for MEMORYARENA_L3 is absent from OptimizerNetwork.c
  • Run deeployTrainingRunner_siracusa.py -t Tests/Models/Training/SimpleMLP/simplemlp_train — loss values match reference
  • Regenerate ResNet8/CCT/DSCNN optimizers — verify no L3 arena leak

The arena-elimination regex in _patch_shared_buffers only matched
pi_*_malloc (L2) but not cl_ram_malloc (L3).  When all optimizer I/O
buffers are shared with the training network, the L3 arena has no
remaining pointer-arithmetic references and should be removed — but
the regex silently failed to match the cl_ram_malloc call, leaving a
dead allocation that wastes external RAM.

Extend the pattern to match both pi_*_malloc and cl_ram_malloc so the
dead-code check works uniformly across all memory levels.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@runwangdl runwangdl force-pushed the fix/optimizer-l3-arena-elimination branch from 5554fe6 to 56000b2 Compare May 12, 2026 16:01
@runwangdl runwangdl merged commit d88b620 into devel May 12, 2026
14 checks passed
@runwangdl runwangdl deleted the fix/optimizer-l3-arena-elimination branch May 12, 2026 16:28
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