Skip to content

Commit 13113de

Browse files
authored
Fix/tiling stack scoping and tiling information corruption (#177)
* [Deeploy PR] put the tiling information into layer code as well * [Deeploy PR] Fix the tiling information corruption. Add bracket before and after L3 code for each layer to reduce stack usage - Previosuly the tiling information was corrupted after each run, because the generated code put the next element in the tiling information array to current location. So after one runnetwork run, we will see that the last element in the tiling array goes to the first location, corrupting the tiling information. The fix in tilingvariablereplacement fix this by pointer the reference to the new location, instead of assigning value into the reference. - The C code generated by Deeploy has been causing big stack usage. This is because all variables defined in Runnetwork lives in stack, including all the tiling pointers and call arguements. By adding bracket before and after each layer in RunNetwork, this makes the call args only live for one layer, thus significantly reduce the stack usage. The tiling pointers still live in stack, they need to be moved as well. But this require more changes * Update CHANGELOG.md
1 parent 09993fb commit 13113de

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ This file contains the changelog for the Deeploy project. The changelog is divid
4646
- im2col buffer size in Conv1d template
4747
- Fix missing dependency in pre-commit-config
4848
- Fix test paths in Deeploy 101 tutorial
49+
- Fix tiling variable replacement corrupting static arrays by changing pointer update from value copy to address reassignment
50+
- Reduce RunNetwork stack usage by scoping per-layer variables with braces and moving tileIdxPtr allocation into per-layer execution blocks
4951

5052
### Removed
5153
- `testDMA.py` was an old test; we now have `test_dmas.py` instead.

Deeploy/DeeployTypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,8 @@ def generateInferenceCode(self) -> str:
28002800
self.ctxt, code = node.generate(self.ctxt)
28012801

28022802
sections = reduce(lambda a, b: a + b, code, [])
2803-
callStack += reduce(lambda a, b: a + b, sections, "")
2803+
layerCode = reduce(lambda a, b: a + b, sections, "")
2804+
callStack += "{\n" + layerCode + "\n}\n"
28042805

28052806
return callStack
28062807

Deeploy/TilingExtension/CodeTransformationPasses/TilingHoistingMixIn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def _hoistTileNumAndIdxPtr(self, ctxt: NetworkContext,
9292
# LMACAN: Intentionally don't annotate memory level so it gets allocated
9393
# outside of the tiling loops
9494

95-
tileIdxPtr.allocTemplate = NodeTemplate("")
96-
tileIdxPtr.deallocTemplate = NodeTemplate("")
97-
tileIdxPtr.initTemplate = NodeTemplate("""
95+
tileIdxPtr.allocTemplate = NodeTemplate("""
9896
${type.referencedType.typeName} bu_${name} = 0;
9997
${type.referencedType.typeName}* ${name} = &bu_${name};""")
98+
tileIdxPtr.deallocTemplate = NodeTemplate("")
99+
tileIdxPtr.initTemplate = NodeTemplate("")
100100

101101
return (tileNum, tileIdxPtr)
102102

Deeploy/TilingExtension/CodeTransformationPasses/TilingVariableReplacement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class TilingVariableReplacementUpdate(CodeTransformationPass, IntrospectiveCodeT
177177

178178
_updateReferenceTemplate = NodeTemplate("""
179179
// UPDATE VARIABLE ${reference}
180-
*${reference} = ${baseReference}[${tileIdxVar}];
180+
${reference} = &${baseReference}[${tileIdxVar}];
181181
""")
182182

183183
def __init__(self, targetMemLevel: str, tileIdxVar: str = "TILING_I"):

0 commit comments

Comments
 (0)