Skip to content

Commit 75236d0

Browse files
committed
Applied fixes suggested in the PR review
1 parent e79a454 commit 75236d0

File tree

7 files changed

+42
-16
lines changed

7 files changed

+42
-16
lines changed

Deeploy/CommonExtensions/CodeTransformationPasses/Closure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def apply(self,
156156
name: str,
157157
verbose: CodeGenVerbosity = _NoVerbosity) -> Tuple[NetworkContext, ExecutionBlock]:
158158
# Add underscore to avoid name issues when beginning with problematic characters (like numbers)
159-
self.closureName = "_" + name + self.closureSuffix
159+
self.closureName = "op_" + name + self.closureSuffix
160160
self.functionCall = executionBlock.generate(ctxt)
161161
self._generateClosureStruct(ctxt, executionBlock)
162162
ctxt = self._generateClosureCtxt(ctxt, name)

Deeploy/CommonExtensions/OptimizationPasses/TopologyOptimizationPasses/LoweringOptimizationPasses.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,26 @@ def __init__(self, default_channels_first: bool = True):
283283
super().__init__(graph, partial(_NCHWtoNHWC_fun, default_channels_first = default_channels_first), name)
284284

285285

286+
@contextagnostic
287+
class NCHWtoNHWCPass(SequentialPass):
288+
289+
def __init__(self, default_channels_first: bool = True):
290+
passes = [
291+
NCHWtoNHWCPadPass(default_channels_first),
292+
NCHWtoNHWCMaxPoolPass(default_channels_first),
293+
NCHWtoNHWCConvPass(default_channels_first),
294+
NCHWtoNHWCRequantizedConvPass(default_channels_first),
295+
]
296+
super().__init__(*passes)
297+
298+
299+
def _PULPDWNCHWtoNHWC_fun(graph: gs.Graph, match: Match, name: str, default_channels_first: bool = True):
300+
301+
matched_nodes = [m for k, m in match.nodes_map.items()]
302+
opNode = matched_nodes[0]
303+
node_op = opNode.op
304+
305+
if 'group' in opNode.attrs and opNode.attrs['group'] == 1:
286306
def _NCWHtoNHWC_dw_fun(graph: gs.Graph, match: Match, name: str, default_channels_first: bool) -> gs.Graph:
287307
node = next(iter((match.nodes_map.values())))
288308

Deeploy/DeeployTypes.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def get_aliases_of(self):
359359
"""
360360

361361
if hasattr(self, "alias_of"):
362-
return self.alias_of
362+
return list(self.alias_of)
363363
else:
364364
return list()
365365

@@ -407,6 +407,11 @@ class TransientBuffer(VariableBuffer):
407407

408408
def __init__(self, name: str = '', size = 0):
409409
super().__init__(name, shape = (size,))
410+
self.name = name
411+
self.size = size # int or str: Total BYTE size, or regular size if _type manually set for this TransientBuffer
412+
413+
# Do not override - Should be written in the parsing passes
414+
self._users = []
410415

411416
# Do not override - Should be written in the parsing passes
412417
self._type: Type[Pointer] = PointerClass(VoidType)
@@ -417,7 +422,7 @@ def __eq__(self, other):
417422
return ret
418423

419424
def _bufferRepresentation(self) -> Dict:
420-
return {"type": self._type, "name": self.name, "size": int(self.size)}
425+
return {"type": self._type, "name": self.name, "size": self.size}
421426

422427
def __str__(self) -> str:
423428
return f'TransientBuffer: name: {self.name}, size: {self.size}'
@@ -434,8 +439,10 @@ class ConstantBuffer(VariableBuffer):
434439
435440
"""
436441

437-
def __init__(self, name: str = '', shape = [1], values = [0], alias_of: Optional[List[str]] = []):
438-
super().__init__(name, shape, alias_of)
442+
def __init__(self, name: str = '', shape = [1], values = [0], alias_of: Optional[List[str]] = None):
443+
# Pass a copy of alias_of to avoid shared references
444+
super().__init__(name, shape, list(alias_of) if alias_of is not None else None)
445+
439446
values = np.asarray(values)
440447
# intArray = values.astype(int)
441448
# assert (np.abs(values - intArray)).max() < 0.001, "Constant value {name} is NOT an integer!"
@@ -868,7 +875,7 @@ def is_buffer(self, value: Any) -> bool:
868875
obj = self.lookup(value)
869876
return isinstance(obj, VariableBuffer)
870877

871-
def hoistTransientBuffer(self, name: str, size: int) -> str:
878+
def hoistTransientBuffer(self, name: str, size: Union[int, str]) -> str:
872879
"""Registers a new TransientBuffer in the local context
873880
874881
Parameters

Deeploy/Targets/Generic/Parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def parseNodeCtxt(self,
10891089
# Add new aliases to output node
10901090
output_node.add_aliases(aliases_to_add = new_output_node_aliases)
10911091

1092-
# Add output node as alias to its aliases (alias relationship is reflexive)
1092+
# Add output node as alias to its aliases (alias relationship is symmetric)
10931093
for alias in new_output_node_aliases:
10941094
alias_node = ctxt.lookup(alias)
10951095
alias_node.add_aliases(aliases_to_add = [

Deeploy/Targets/PULPOpen/Parsers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def parseNodeCtxt(self,
116116

117117
return newCtxt, True
118118

119-
return newCtxt, False
119+
return ctxt, False
120120

121121

122122
class PULPFPDWConv2DParser(Conv2DParser):
@@ -185,7 +185,7 @@ def parseNodeCtxt(self,
185185
if self.operatorRepresentation['group'] == self.operatorRepresentation['ch_im_in']:
186186
return newCtxt, True
187187

188-
return newCtxt, False
188+
return ctxt, False
189189

190190

191191
class PULPDWConv1DParser(RQSConv1DParser):

Deeploy/Targets/PULPOpen/Templates/FloatAddTemplate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
referenceTemplate = NodeTemplate("""
88
// Add Parallel with 1x6 unrolling (Name: ${nodeName}, Op: ${nodeOp})
9-
int8_t ${nodeName}_core_id = (int8_t) pi_core_id();
10-
int8_t ${nodeName}_log2Core = (int8_t) log2(NUM_CORES);
11-
int16_t ${nodeName}_chunk = (${size} >> ${nodeName}_log2Core) + ((${size} & (NUM_CORES-1))!=0);
12-
int16_t ${nodeName}_chunk_start = (int16_t) MIN(${nodeName}_chunk*${nodeName}_core_id, ${size});
13-
int16_t ${nodeName}_chunk_stop = (int16_t) MIN(${nodeName}_chunk_start + ${nodeName}_chunk, ${size});
9+
uint8_t ${nodeName}_core_id = (uint8_t) pi_core_id();
10+
uint8_t ${nodeName}_log2Core = (uint8_t) log2(NUM_CORES);
11+
uint32_t ${nodeName}_chunk = (${size} >> ${nodeName}_log2Core) + ((${size} & (NUM_CORES-1))!=0);
12+
uint32_t ${nodeName}_chunk_start = (uint32_t) MIN(${nodeName}_chunk*${nodeName}_core_id, (uint32_t) ${size});
13+
uint32_t ${nodeName}_chunk_stop = (uint32_t) MIN(${nodeName}_chunk_start + ${nodeName}_chunk, (uint32_t) ${size});
1414
15-
int32_t i = ${nodeName}_chunk_start;
15+
uint32_t i = ${nodeName}_chunk_start;
1616
for (; i + 5 < ${nodeName}_chunk_stop; i += 6) {
1717
${data_out}[i] = ${data_in_1}[i] + ${data_in_2}[i];
1818
${data_out}[i+1] = ${data_in_1}[i+1] + ${data_in_2}[i+1];

TargetLibraries/PULPOpen/inc/DeeployPULPMath.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "kernel/RequantShift.h"
3333
#include "kernel/Softmax.h"
3434
#include "kernel/UniformRequantShift.h"
35-
#include "kernel/gemm.h"
3635
#include "kernel/gemv.h"
3736
#include "kernel/iRMSnorm.h"
3837

0 commit comments

Comments
 (0)