Skip to content

Commit d88b620

Browse files
runwangdlRun Wangclaude
authored
fix(codegen): eliminate dead optimizer L3 arena allocation (#25)
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: Run Wang <runwang@skylab.ee.ethz.ch> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 42f87d2 commit d88b620

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

DeeployTest/testUtils/codeGenerateTraining.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ def _replace(m: re.Match) -> str:
583583
for level in ('L2', 'L3'):
584584
arena_sym = f'DeeployOptNetwork_MEMORYARENA_{level}'
585585
# Pattern for the malloc assignment line itself
586-
malloc_line_pat = re.compile(rf'[^\n]*{re.escape(arena_sym)}\s*=\s*\([^)]+\)\s*pi_\w+_malloc\([^;]+\);\s*\n')
586+
malloc_line_pat = re.compile(
587+
rf'[^\n]*{re.escape(arena_sym)}\s*=\s*\([^)]+\)\s*(?:pi_\w+_malloc|cl_ram_malloc)\([^;]+\);\s*\n')
587588
# Pattern for any use of the arena in pointer arithmetic:
588589
# (char *)ARENA + OFFSET or (void *)ARENA etc.
589590
arena_use_pat = re.compile(rf'\(\s*(?:char|void|int8_t)\s*\*\s*\)\s*{re.escape(arena_sym)}')

0 commit comments

Comments
 (0)