Skip to content

Commit b74e031

Browse files
authored
Bug fixes, API Cleanup and Reduce Compiler Warning on PULP (#112)
- Reshape operator support for PULP (`ReshapeTemplate` in bindings) - Missing class attributes in `Closure.py` - Removed unnecessary includes from the PULP platform header list, such as `DeeployBasicMath.h`, for cleaner code generation - Changed types and added correct casts to fix many compiler warnings in the PULP target library - Fixed multiple typos in variable and method names, such as changing `includeGobalReferences` to `includeGlobalReferences` and `dicardedMappers` to `discardedMappers` - Corrected method usage in `importDeeployState` to call `NetworkContext.importNetworkContext` instead of the incorrect method name - Correctly return `signProp` from `setupDeployer` instead of hardcoding the value to `False` in `testMVP.py`
1 parent 59ac79e commit b74e031

File tree

34 files changed

+355
-210
lines changed

34 files changed

+355
-210
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This file contains the changelog for the Deeploy project. The changelog is divid
44
## Unreleased (Planned Release Target: v0.2.1)
55

66
### List of Pull Requests
7+
- Bug fixes, API Cleanup and Reduce Compiler Warning on PULP [#112](https://github.com/pulp-platform/Deeploy/pull/112)
78
- Fix PULP GEMM `batch` serialization [#109](https://github.com/pulp-platform/Deeploy/pull/109)
89
- Split CI Workflows by Platform and Task, Improve Formatting and Linting Reliability [#108](https://github.com/pulp-platform/Deeploy/pull/108)
910
- Refactor tiling code generation [#105](https://github.com/pulp-platform/Deeploy/pull/105)
@@ -34,6 +35,8 @@ This file contains the changelog for the Deeploy project. The changelog is divid
3435
- Added YAML linting to CI
3536
- Added missing license headers and C header include guards
3637
- Extended the pre-commit hooks to remove trailing whitespace, check licenses, format and lint files
38+
- Reshape operator support for PULP (`ReshapeTemplate` in bindings)
39+
- Missing class attributes in `Closure.py`
3740

3841
### Changed
3942
- Replaced platform-specific tags (`*-amd64`, `*-arm64`) with direct digest references in `Noelware/docker-manifest-action`.
@@ -57,12 +60,17 @@ This file contains the changelog for the Deeploy project. The changelog is divid
5760
- Split CI into multiple workflow files: one per platform, one for lint & license, one for general Deeploy tests, one for infrastructure, and two for Docker flows, improving maintainability and status reporting
5861
- Extended CI to check license in cMake and YAML files
5962
- Removed all trailing whitespace
63+
- Removed unnecessary includes from the PULP platform header list, such as `DeeployBasicMath.h`, for cleaner code generation
64+
- Changed types and added correct casts to fix many compiler warnings in the PULP target library
6065

6166
### Fixed
6267
- Prevent node duplication for graphs generated via GraphSurgeon
6368
- Resolved issue with missing `id` in the `Build Cache for Docker` step, used in the `Inject build-cache` step.
6469
- Fix license CI check and prevent potential issues with `jq` installation
6570
- PULP Gemm `batch` variable serialization
71+
- Fixed multiple typos in variable and method names, such as changing `includeGobalReferences` to `includeGlobalReferences` and `dicardedMappers` to `discardedMappers`
72+
- Corrected method usage in `importDeeployState` to call `NetworkContext.importNetworkContext` instead of the incorrect method name
73+
- Correctly return `signProp` from `setupDeployer` instead of hardcoding the value to `False` in `testMVP.py`
6674

6775
### Removed
6876
- Delete outdated and unused `.gitlab-ci.yml` file

Deeploy/CommonExtensions/CodeTransformationPasses/Closure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def baseBlock(self):
8585

8686
class ClosureGeneration(CodeTransformationPass, IntrospectiveCodeTransformationMixIn):
8787

88-
closureStructArgs: Struct
88+
closureStructArgType: Dict[str, Type[Union[Pointer, Immediate, Struct]]]
89+
closureStructArgs: Dict[str, Union[Pointer, Immediate, Struct]]
8990

9091
def __init__(self,
9192
closureCallTemplate: NodeTemplate = _closureCallTemplate,

Deeploy/CommonExtensions/CodeTransformationPasses/IntrospectiveCodeTransformation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ def extractDynamicReferences(self,
117117
ctxt: NetworkContext,
118118
executionBlock: ExecutionBlock = None,
119119
unrollStructs = False,
120-
includeGobalReferences = False):
120+
includeGlobalReferences = False):
121121

122122
makoDynamicReferences = []
123123
for codeSnippet in executionBlock.codeSnippets:
124124
template, operatorRepresentation = codeSnippet.template, codeSnippet.operatorRepresentation
125125

126126
newRefs = self._extractDynamicExpressions(ctxt, operatorRepresentation, template.template, unrollStructs,
127-
includeGobalReferences)
127+
includeGlobalReferences)
128128

129129
makoDynamicReferences += newRefs
130130

@@ -145,7 +145,7 @@ def _extractDynamicExpressions(self,
145145
operatorRepresentation: OperatorRepresentation,
146146
template: Template,
147147
unrollStructs = False,
148-
includeGobalReferences = False):
148+
includeGlobalReferences = False):
149149
codeHash = hash(template._source)
150150

151151
if codeHash in self.parseTreeDict.keys():
@@ -194,7 +194,7 @@ def _unrollStructReferences(val: Struct) -> List[str]:
194194
dynamicLocalReferences = [ref for ref in localReferences if ctxt.lookup(ref)._deploy]
195195
dynamicGlobalReferences = [ref for ref in globalReferences if isinstance(ctxt.lookup(ref), VariableBuffer)]
196196

197-
if includeGobalReferences:
197+
if includeGlobalReferences:
198198
return dynamicLocalReferences + dynamicGlobalReferences
199199
else:
200200
return dynamicLocalReferences

Deeploy/CommonExtensions/CodeTransformationPasses/MemoryAllocation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def topologicallySortBuffers(buffers: List[VariableBuffer]) -> List[VariableBuff
117117
sortedBuffers.append(buffer)
118118
unsortedBufferNames.remove(buffer.name)
119119

120-
assert len(unsortedBufferNames) != lastLen, f"Circular reference detected."
120+
assert len(
121+
unsortedBufferNames) != lastLen, f"Circular reference detected among buffers: {unsortedBufferNames}"
121122
lastLen = len(unsortedBufferNames)
122123

123124
return sortedBuffers
@@ -130,7 +131,7 @@ def apply(self,
130131
references = self.extractDynamicReferences(ctxt,
131132
executionBlock,
132133
unrollStructs = True,
133-
includeGobalReferences = False)
134+
includeGlobalReferences = False)
134135
localBuffers = [ctxt.localObjects[ref] for ref in references]
135136
memoryLevelBuffers = [buff for buff in localBuffers if self.is_memory_level(buff)]
136137

@@ -167,7 +168,7 @@ def apply(self,
167168
references = self.extractDynamicReferences(ctxt,
168169
executionBlock,
169170
unrollStructs = True,
170-
includeGobalReferences = False)
171+
includeGlobalReferences = False)
171172
localBuffers = [ctxt.localObjects[ref] for ref in references]
172173
memoryLevelBuffers = [buff for buff in localBuffers if self.is_memory_level(buff)]
173174

Deeploy/CommonExtensions/CodeTransformationPasses/PrintInputs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def apply(self,
8383
references = self.extractDynamicReferences(ctxt,
8484
executionBlock,
8585
unrollStructs = True,
86-
includeGobalReferences = True)
86+
includeGlobalReferences = True)
8787

8888
for ref in references:
8989
refDict = self._getRepDict(ctxt, ref, name)
@@ -126,7 +126,7 @@ def apply(self,
126126
references = self.extractDynamicReferences(ctxt,
127127
executionBlock,
128128
unrollStructs = True,
129-
includeGobalReferences = True)
129+
includeGlobalReferences = True)
130130

131131
filteredReferences = [ref for ref in references if self._matchesRegex(ctxt, ref)]
132132

@@ -167,7 +167,7 @@ def apply(self,
167167
references = self.extractDynamicReferences(ctxt,
168168
executionBlock,
169169
unrollStructs = True,
170-
includeGobalReferences = True)
170+
includeGlobalReferences = True)
171171

172172
for ref in references:
173173
rep = self._getRepDict(ctxt, ref, name)
@@ -188,7 +188,7 @@ def apply(self,
188188
references = self.extractDynamicReferences(ctxt,
189189
executionBlock,
190190
unrollStructs = True,
191-
includeGobalReferences = True)
191+
includeGlobalReferences = True)
192192

193193
filteredReferences = [ref for ref in references if self._matchesRegex(ctxt, ref)]
194194

@@ -220,7 +220,7 @@ def apply(self, ctxt: NetworkContext, executionBlock: ExecutionBlock,
220220
references = self.extractDynamicReferences(ctxt,
221221
executionBlock,
222222
unrollStructs = True,
223-
includeGobalReferences = True)
223+
includeGlobalReferences = True)
224224

225225
for ref in references:
226226
rep = self._getRepDict(ctxt, ref, name)
@@ -241,7 +241,7 @@ def apply(self,
241241
references = self.extractDynamicReferences(ctxt,
242242
executionBlock,
243243
unrollStructs = True,
244-
includeGobalReferences = True)
244+
includeGlobalReferences = True)
245245

246246
filteredReferences = [ref for ref in references if self._matchesRegex(ctxt, ref)]
247247

Deeploy/DeeployTypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ def discardCurrentMapper(self):
19721972
"""Discard the current Mapper
19731973
19741974
"""
1975-
self.dicardedMappers.add(self.mapper)
1975+
self.discardedMappers.add(self.mapper)
19761976
self.mapper = None
19771977

19781978
def resetDiscardedMappers(self):
@@ -2124,7 +2124,7 @@ def bind(self, ctxt: NetworkContext) -> Tuple[NetworkContext, bool]:
21242124
self.mapper.parser.operatorRepresentation['nodeOps'] = int(self.computeOps())
21252125
return newCtxt, True
21262126

2127-
self.discardedMappers.append(self.mapper)
2127+
self.discardedMappers.add(self.mapper)
21282128
return ctxt, False
21292129

21302130
def codeTransform(self, ctxt: NetworkContext, verbose: CodeGenVerbosity = _NoVerbosity) -> NetworkContext:
@@ -3175,7 +3175,7 @@ def importDeeployState(self, folderPath: str, fileName: str):
31753175
31763176
"""
31773177
self.graph = NetworkDeployer._importONNXGraph(folderPath, f"{fileName}")
3178-
self.ctxt = NetworkContext.importNetworkCtxt(folderPath, f"{fileName}")
3178+
self.ctxt = NetworkContext.importNetworkContext(folderPath, f"{fileName}")
31793179

31803180

31813181
class NetworkDeployer(NetworkContainer):

Deeploy/Targets/PULPOpen/Bindings.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from Deeploy.AbstractDataTypes import PointerClass
3232
from Deeploy.CommonExtensions.CodeTransformationPasses.Closure import ClosureGeneration, MemoryAwareClosureGeneration
3333
from Deeploy.CommonExtensions.CodeTransformationPasses.MemoryAllocation import ArgumentStructGeneration, \
34-
MemoryManagementGeneration
34+
MemoryManagementGeneration, MemoryPassthroughGeneration
3535
from Deeploy.CommonExtensions.DataTypes import IntegerDataTypes, SignedIntegerDataTypes, float32_t, int8_t, int32_t, \
3636
uint8_t
3737
from Deeploy.DeeployTypes import CodeTransformation, NodeBinding, NodeTemplate
@@ -41,8 +41,8 @@
4141
GatherTemplate, QuantTemplate, RQSiGELUTemplate, iHardswishTemplate
4242
from Deeploy.Targets.Generic.TypeCheckers import AddChecker, ConcatChecker, ConvChecker, DequantChecker, \
4343
GatherChecker, GELUChecker, GEMMChecker, HardswishChecker, LayerNormChecker, MatMulChecker, MulChecker, \
44-
QuantChecker, ReduceMeanChecker, ReluChecker, RQAddChecker, RQHardswishChecker, SGDChecker, SliceChecker, \
45-
SoftmaxChecker, SoftmaxCrossEntropyLossChecker, TransposeChecker
44+
QuantChecker, ReduceMeanChecker, ReluChecker, ReshapeChecker, RQAddChecker, RQHardswishChecker, SGDChecker, \
45+
SliceChecker, SoftmaxChecker, SoftmaxCrossEntropyLossChecker, TransposeChecker
4646
from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterSynch import PULPSynchCoresPass
4747
from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterTiling import PULPClusterTiling
4848
from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPL3Tiling import PULPL3Tiling
@@ -53,8 +53,8 @@
5353
from Deeploy.Targets.PULPOpen.Templates import ConvTemplate, FloatAddTemplate, FloatConvTemplate, FloatGELUTemplate, \
5454
FloatGemmTemplate, FloatLayernormTemplate, FloatMatMulTemplate, FloatMaxPoolTemplate, FloatMulTemplate, \
5555
FloatReluTemplate, FloatSoftmaxTemplate, GEMMTemplate, MatrixVectorTemplate, MaxPool2DTemplate, MulTemplate, \
56-
ReduceMeanTemplate, RequantShiftTemplate, RQAddTemplate, RQSiHardswishTemplate, SGDTemplate, SliceTemplate, \
57-
SoftmaxCrossEntropyLossTemplate, TallGEMMTemplate, TransposeTemplate, UniformRequantShiftTemplate, \
56+
ReduceMeanTemplate, RequantShiftTemplate, ReshapeTemplate, RQAddTemplate, RQSiHardswishTemplate, SGDTemplate, \
57+
SliceTemplate, SoftmaxCrossEntropyLossTemplate, TallGEMMTemplate, TransposeTemplate, UniformRequantShiftTemplate, \
5858
iRMSNormTemplate, iSoftmaxTemplate
5959
from Deeploy.Targets.PULPOpen.TypeCheckers import PULPConvChecker, PULPLinearChecker, PULPMaxPoolChecker, \
6060
PULPRequantShiftChecker
@@ -76,6 +76,12 @@
7676
pi_cl_team_fork(NUM_CORES, (void*)${closureName}, &${closureStructArgName});
7777
""")
7878

79+
SkipTransformer = CodeTransformation(
80+
[ArgumentStructGeneration(),
81+
MemoryPassthroughGeneration("L.*"),
82+
MemoryPassthroughGeneration(),
83+
FutureGeneration()])
84+
7985
FunctionCallClosure = partial(ClosureGeneration, closureSuffix = "_closure")
8086
ClusterClosure = partial(ClosureGeneration,
8187
closureSuffix = "_cluster_entry",
@@ -169,6 +175,14 @@
169175
for type in IntegerDataTypes
170176
]
171177

178+
PULPReshapeBindings = [
179+
NodeBinding(ReshapeChecker([PointerClass(type), PointerClass(int32_t)], [PointerClass(type)]),
180+
ReshapeTemplate.referenceTemplate, SkipTransformer) for type in IntegerDataTypes
181+
] + [
182+
NodeBinding(ReshapeChecker([PointerClass(float32_t), PointerClass(type)], [PointerClass(float32_t)]),
183+
ReshapeTemplate.referenceTemplate, SkipTransformer) for type in IntegerDataTypes
184+
]
185+
172186
PULPRQAddBindings = [
173187
NodeBinding(RQAddChecker([PointerClass(_type), PointerClass(_type2)], [PointerClass(_type3)]),
174188
RQAddTemplate.referenceTemplate, ForkTransformer)

Deeploy/Targets/PULPOpen/Platform.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ class PULPStructBuffer(StructBuffer):
253253

254254
# SCHEREMO: stdint is included before pulp_nn_kernels.h because it is supposed to be included in there, but isn't...
255255
_includeList = [
256-
"pmsis.h", "stdint.h", "pulp_nn_kernels.h", "DeeployBasicMath.h", "DeeployPULPMath.h", "mchan_siracusa.h",
257-
"dory_mem.h", "bsp/ram.h", "pulp_core.h"
256+
"pmsis.h", "stdint.h", "pulp_nn_kernels.h", "DeeployPULPMath.h", "mchan_siracusa.h", "dory_mem.h", "bsp/ram.h"
258257
]
259258

260259

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: ReshapeTemplate.py
4+
#
5+
# Last edited: 16.12.2021
6+
#
7+
# Copyright (C) 2021, ETH Zurich and University of Bologna.
8+
#
9+
# Author: Moritz Scherer, ETH Zurich
10+
#
11+
# ----------------------------------------------------------------------
12+
# SPDX-License-Identifier: Apache-2.0
13+
#
14+
# Licensed under the Apache License, Version 2.0 (the License); you may
15+
# not use this file except in compliance with the License.
16+
# You may obtain a copy of the License at
17+
#
18+
# www.apache.org/licenses/LICENSE-2.0
19+
#
20+
# Unless required by applicable law or agreed to in writing, software
21+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
22+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
# See the License for the specific language governing permissions and
24+
# limitations under the License.
25+
26+
from typing import Dict, List, Tuple
27+
28+
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation
29+
30+
31+
class _ReshapeTemplate(NodeTemplate):
32+
33+
def __init__(self, templateStr):
34+
super().__init__(templateStr)
35+
36+
def alignToContext(self, ctxt: NetworkContext,
37+
operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]:
38+
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
48+
49+
inBuffer = ctxt.lookup(operatorRepresentation['data_in'])
50+
outBuffer = ctxt.lookup(operatorRepresentation['data_out'])
51+
outBuffer._alias = inBuffer.name
52+
53+
return ctxt, operatorRepresentation, []
54+
55+
56+
referenceTemplate = _ReshapeTemplate("""
57+
// Reshape (Name: ${nodeName}, Op: ${nodeOp})
58+
${data_out} = ${data_in};
59+
""")

Deeploy/Targets/PULPOpen/Tiler.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727
import copy
2828

29-
from Deeploy.CommonExtensions.CodeTransformationPasses.MemoryAllocation import MemoryPassthroughGeneration
30-
from Deeploy.DeeployTypes import CodeTransformation
31-
from Deeploy.Targets.Generic.Bindings import BasicReshapeBindings
3229
from Deeploy.Targets.Generic.TileConstraints.AddTileConstraint import AddTileConstraint
3330
from Deeploy.Targets.Generic.TileConstraints.ConcatTileConstraint import ConcatTileConstraint
3431
from Deeploy.Targets.Generic.TileConstraints.iHardswishTileConstraint import iHardswishTileConstraint
@@ -43,10 +40,11 @@
4340
from Deeploy.Targets.PULPOpen.Bindings import PULPAddBindings, PULPConcatBindings, PULPFloatConv2DBindings, \
4441
PULPFloatGELUBinding, PULPFloatGEMMBindings, PULPGatherBindings, PULPiHardswishBindings, PULPiRMSNormBindings, \
4542
PULPiRQSGELUBindings, PULPLayernormBinding, PULPMatMulBindings, PULPMaxPool2DBindings, PULPMulBindings, \
46-
PULPReduceSumBindings, PULPReluBinding, PULPRQAddBindings, PULPRQSBindings, PULPRQSConv2DBindings, \
47-
PULPRQSDWConv2DBindings, PULPRQSGEMMBindings, PULPRQSiHardswishBindings, PULPRQSMatrixVecBindings, \
48-
PULPRQSTallGEMMBindings, PULPSGDBindings, PULPSoftmaxBindings, PULPSoftmaxCrossEntropyLossBindings, \
49-
PULPSoftmaxCrossEntropyLossGradBindings, PULPSoftmaxGradBindings, PULPTransposeBindings, PULPUniformRQSBindings
43+
PULPReduceSumBindings, PULPReluBinding, PULPReshapeBindings, PULPRQAddBindings, PULPRQSBindings, \
44+
PULPRQSConv2DBindings, PULPRQSDWConv2DBindings, PULPRQSGEMMBindings, PULPRQSiHardswishBindings, \
45+
PULPRQSMatrixVecBindings, PULPRQSTallGEMMBindings, PULPSGDBindings, PULPSoftmaxBindings, \
46+
PULPSoftmaxCrossEntropyLossBindings, PULPSoftmaxCrossEntropyLossGradBindings, PULPSoftmaxGradBindings, \
47+
PULPTransposeBindings, PULPUniformRQSBindings
5048
from Deeploy.Targets.PULPOpen.TileConstraints.ConvTileConstraint import Conv2DTileConstraint, RQConv2DTileConstraint
5149
from Deeploy.Targets.PULPOpen.TileConstraints.DWConvTileConstraint import DWConv2DTileConstraint
5250
from Deeploy.Targets.PULPOpen.TileConstraints.GatherTileConstraint import GatherTileConstraint
@@ -94,9 +92,7 @@
9492
PULPRQSiHardswishTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = PULPRQSiHardswishBindings,
9593
tileConstraint = RQSiHardswishTileConstraint())
9694

97-
_BasicFlattenBindings = copy.deepcopy(BasicReshapeBindings)
98-
for binding in _BasicFlattenBindings:
99-
binding.codeTransformer = CodeTransformation([MemoryPassthroughGeneration("L.*"), MemoryPassthroughGeneration()])
95+
_BasicFlattenBindings = copy.deepcopy(PULPReshapeBindings)
10096

10197
PULPFlattenTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = _BasicFlattenBindings,
10298
tileConstraint = NOPTileConstraint())

0 commit comments

Comments
 (0)