Skip to content

Commit 71b7e79

Browse files
committed
Remove duplicate code in the PULPOpen reshape template
1 parent 3ea12db commit 71b7e79

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

Deeploy/Targets/Generic/Templates/ReshapeTemplate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation, VariableBuffer
88

99

10-
class _ReshapeTemplate(NodeTemplate):
10+
class _GenericReshapeTemplate(NodeTemplate):
1111

1212
def __init__(self, templateStr):
1313
super().__init__(templateStr)
@@ -25,8 +25,10 @@ def alignToContext(self, ctxt: NetworkContext,
2525
ctxt.globalObjects[operatorRepresentation["shape"]]._deploy = False
2626
ctxt.globalObjects[operatorRepresentation["shape"]]._live = False
2727

28+
# Get buffers
2829
bufferIn = ctxt.lookup(operatorRepresentation['data_in'])
2930
assert isinstance(bufferIn, VariableBuffer)
31+
3032
bufferOut = ctxt.lookup(operatorRepresentation['data_out'])
3133
assert isinstance(bufferOut, VariableBuffer)
3234

@@ -37,7 +39,7 @@ def alignToContext(self, ctxt: NetworkContext,
3739
return ctxt, operatorRepresentation, []
3840

3941

40-
referenceTemplate = _ReshapeTemplate("""
42+
referenceTemplate = _GenericReshapeTemplate("""
4143
// Reshape (Name: ${nodeName}, Op: ${nodeOp})
4244
SINGLE_CORE ${data_out} = ${data_in};
4345
""")

Deeploy/Targets/PULPOpen/Templates/ReshapeTemplate.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,19 @@
2525

2626
from typing import Dict, List, Tuple
2727

28-
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation, VariableBuffer
28+
from Deeploy.DeeployTypes import NetworkContext, OperatorRepresentation, VariableBuffer
29+
from Deeploy.Targets.Generic.Templates.ReshapeTemplate import _GenericReshapeTemplate
2930

3031

31-
class _ReshapeTemplate(NodeTemplate):
32+
class _ReshapeTemplate(_GenericReshapeTemplate):
3233

3334
def __init__(self, templateStr):
3435
super().__init__(templateStr)
3536

3637
def alignToContext(self, ctxt: NetworkContext,
3738
operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]:
3839

39-
# SCHEREMO: Selectively mark 'indices' dead, since we don't need them
40-
if 'indices' in operatorRepresentation.keys():
41-
ctxt.globalObjects[operatorRepresentation['indices']]._deploy = False
42-
ctxt.globalObjects[operatorRepresentation['indices']]._live = False
43-
44-
# Same for "shape"
45-
if "shape" in operatorRepresentation.keys():
46-
ctxt.globalObjects[operatorRepresentation["shape"]]._deploy = False
47-
ctxt.globalObjects[operatorRepresentation["shape"]]._live = False
40+
ctxt, operatorRepresentation, _ = super().alignToContext(ctxt, operatorRepresentation)
4841

4942
# Get buffers
5043
bufferIn = ctxt.lookup(operatorRepresentation['data_in'])
@@ -53,10 +46,6 @@ def alignToContext(self, ctxt: NetworkContext,
5346
bufferOut = ctxt.lookup(operatorRepresentation['data_out'])
5447
assert isinstance(bufferOut, VariableBuffer)
5548

56-
# Link aliases to each buffer
57-
bufferIn.aliases.add(bufferOut.name)
58-
bufferOut.aliases.add(bufferIn.name)
59-
6049
# Linking required for tiling
6150
bufferOut._alias = bufferIn.name
6251

0 commit comments

Comments
 (0)