Skip to content

Commit

Permalink
apply Victor's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tahaelbayad committed Jan 7, 2025
1 parent 1034298 commit 89f24d1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 142 deletions.
22 changes: 22 additions & 0 deletions Deeploy/Targets/Generic/TypeCheckers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ def _inferSignedness(self, inputs: List[VariableBuffer],
else:
return [False]

class RQAddChecker(SignPropTypeChecker):

def __init__(self, input_types: Sequence[Type[Pointer]], output_types: Sequence[Type[Pointer]]):
super().__init__(input_types, output_types)

def _inferNumLevels(self, inputs: List[VariableBuffer],
operatorRepresentation: OperatorRepresentation) -> List[int]:
return [operatorRepresentation['rqsOut_n_levels']]

def _inferSignedness(self, inputs: List[VariableBuffer],
operatorRepresentation: OperatorRepresentation) -> List[bool]:
return [bool(operatorRepresentation["rqsOut_signed"])]

# Override this. This should compute the signednes of each output node of the Layer
def checkOutputType(self, inputs: List[VariableBuffer], operatorRepresentation: OperatorRepresentation) -> bool:
outputTypeSigned = self.output_types[0].referencedType.typeMin < 0
if operatorRepresentation['rqsOut_signed'] and outputTypeSigned:
return True
if (not operatorRepresentation['rqsOut_signed']) and (not outputTypeSigned):
return True
return False


class FloatAddChecker(SignPropTypeChecker):

Expand Down
6 changes: 3 additions & 3 deletions Deeploy/Targets/PULPOpen/Bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from Deeploy.Targets.Generic.Templates import ConcatTemplate, RQSiGELUTemplate, iHardswishTemplate, RQAddTemplate
from Deeploy.Targets.Generic.TypeCheckers import ConcatChecker, GELUChecker, HardswishChecker, MatMulChecker, \
MulChecker, ReduceMeanChecker, RQHardswishChecker, SliceChecker, SoftmaxChecker, TransposeChecker, \
iLayerNormChecker
iLayerNormChecker, RQAddChecker
from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterSynch import PULPSynchCoresPass
from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterTiling import PULPClusterTiling
from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPL3Tiling import PULPL3Tiling
Expand All @@ -48,7 +48,7 @@
MulTemplate, ReduceMeanTemplate, RequantShiftTemplate, RQSiHardswishTemplate, SliceTemplate, \
TallGEMMTemplate, TransposeTemplate, UniformRequantShiftTemplate, iRMSNormTemplate, iSoftmaxTemplate
from Deeploy.Targets.PULPOpen.TypeCheckers import PULPConvChecker, PULPLinearChecker, PULPMaxPoolChecker, \
PULPRequantShiftChecker, PULPRQAddChecker
PULPRequantShiftChecker
from Deeploy.TilingExtension.CodeTransformationPasses.TilingVariableReplacement import TilingVariableReplacement

_clusterEntryClosureCallTemplate = NodeTemplate("""
Expand Down Expand Up @@ -156,7 +156,7 @@
]

PULPRQAddBindings = [
NodeBinding(PULPRQAddChecker([PointerClass(_type), PointerClass(_type2)], [PointerClass(_type3)]),
NodeBinding(RQAddChecker([PointerClass(_type), PointerClass(_type2)], [PointerClass(_type3)]),
RQAddTemplate.referenceTemplate, ForkTransformer)
for _type in [int8_t, uint8_t]
for _type2 in [int8_t, uint8_t]
Expand Down
58 changes: 1 addition & 57 deletions Deeploy/Targets/PULPOpen/Parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,63 +29,7 @@
import onnx_graphsurgeon as gs

from Deeploy.DeeployTypes import NetworkContext
from Deeploy.Targets.Generic.Parsers import AddParser, GEMMParser, RQSConv1DParser, RQSConv2DParser, RQSParserInterface


class PULPRQAddParser(AddParser):

def parseNode(self, node: gs.Node) -> bool:

if not super().parseNode(node):
return False

ret = all([
'rqs1_mul' in node.attrs,
'rqs1_add' in node.attrs,
'rqs1_div' in node.attrs,
'rqs1_signed' in node.attrs,
any(['rqs1_n_levels' in node.attrs, 'rqs1_n_levels_out' in node.attrs]),
'rqs2_mul' in node.attrs,
'rqs2_add' in node.attrs,
'rqs2_div' in node.attrs,
'rqs2_signed' in node.attrs,
any(['rqs2_n_levels' in node.attrs, 'rqs2_n_levels_out' in node.attrs]),
'rqsOut_mul' in node.attrs,
'rqsOut_add' in node.attrs,
'rqsOut_div' in node.attrs,
'rqsOut_signed' in node.attrs,
any(['rqsOut_n_levels' in node.attrs, 'rqsOut_n_levels_out' in node.attrs]),
])

if ret:
if 'rqs1_n_levels' in node.attrs:
self.operatorRepresentation['rqs1_n_levels'] = int(node.attrs['rqs1_n_levels'].values)
else:
self.operatorRepresentation['rqs1_n_levels'] = int(node.attrs['rqs1_n_levels_out'].values)
self.operatorRepresentation['rqs1_mul'] = int(node.attrs['rqs1_mul'])
self.operatorRepresentation['rqs1_add'] = int(node.attrs['rqs1_add'])
self.operatorRepresentation['rqs1_signed'] = int(node.attrs['rqs1_signed'].values)
self.operatorRepresentation['rqs1_log2D'] = int(math.log2(node.attrs['rqs1_div'].values))

if 'rqs2_n_levels' in node.attrs:
self.operatorRepresentation['rqs2_n_levels'] = int(node.attrs['rqs2_n_levels'].values)
else:
self.operatorRepresentation['rqs2_n_levels'] = int(node.attrs['rqs2_n_levels_out'].values)
self.operatorRepresentation['rqs2_mul'] = int(node.attrs['rqs2_mul'])
self.operatorRepresentation['rqs2_add'] = int(node.attrs['rqs2_add'])
self.operatorRepresentation['rqs2_signed'] = int(node.attrs['rqs2_signed'].values)
self.operatorRepresentation['rqs2_log2D'] = int(math.log2(node.attrs['rqs2_div'].values))

if 'rqsOut_n_levels' in node.attrs:
self.operatorRepresentation['rqsOut_n_levels'] = int(node.attrs['rqsOut_n_levels'].values)
else:
self.operatorRepresentation['rqsOut_n_levels'] = int(node.attrs['rqsOut_n_levels_out'].values)
self.operatorRepresentation['rqsOut_mul'] = int(node.attrs['rqsOut_mul'])
self.operatorRepresentation['rqsOut_add'] = int(node.attrs['rqsOut_add'])
self.operatorRepresentation['rqsOut_signed'] = int(node.attrs['rqsOut_signed'].values)
self.operatorRepresentation['rqsOut_log2D'] = int(math.log2(node.attrs['rqsOut_div'].values))

return ret
from Deeploy.Targets.Generic.Parsers import GEMMParser, RQSConv1DParser, RQSConv2DParser, RQSParserInterface


class PULPConv2DParser(RQSConv2DParser):
Expand Down
6 changes: 3 additions & 3 deletions Deeploy/Targets/PULPOpen/Platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from Deeploy.Targets.Generic.Parsers import AddParser, ConcatParser, FlattenParser, GatherParser, MatMulParser, \
MulParser, Pad1DParser, Pad2DParser, ReduceMeanParser, RequantShiftParser, ReshapeParser, RQIntegerDivParser, \
RQSiGELUParser, RQSiHardswishParser, SliceParser, TransposeParser, UniformRequantShiftParser, UnsqueezeParser, \
iHardswishParser, iRMSNormParser, iSoftmaxParser
iHardswishParser, iRMSNormParser, iSoftmaxParser, RQAddParser
from Deeploy.Targets.Generic.Templates import AllocateTemplate as BasicAllocateTemplate
from Deeploy.Targets.Generic.TopologyOptimizationPasses.Passes import IntegerDivRequantMergePass, \
MergeConstAddAndRequantPass, MergeTrueIntegerDivRequantShiftPass, RQSSplitPass, SkipEmptyConcatPass, \
Expand All @@ -50,7 +50,7 @@
PULPReduceMeanBindings
from Deeploy.Targets.PULPOpen.Layers import PULPRQSConvLayer, PULPRQSGEMMLayer
from Deeploy.Targets.PULPOpen.Parsers import PULPConv1DParser, PULPConv2DParser, PULPDWConv1DParser, \
PULPDWConv2DParser, PULPGEMMParser, PULPMatrixVecParser, PULPRQAddParser, PULPTallGEMMParser
PULPDWConv2DParser, PULPGEMMParser, PULPMatrixVecParser, PULPTallGEMMParser
from Deeploy.Targets.PULPOpen.Templates import AllocateTemplate, FreeTemplate
from Deeploy.Targets.PULPOpen.Tiler import PULPAddTilingReadyBindings, PULPConcatTilingReadyBindings, \
PULPFlattenTilingReadyBindings, PULPiHardswishTilingReadyBindings, PULPiRMSNormTilingReadyBindings, \
Expand All @@ -62,7 +62,7 @@
from Deeploy.Targets.PULPOpen.TopologyOptimizationPasses.Passes import PULPAddRequantMergePass, \
PULPConvRequantMergePass, PULPGEMMRequantMergePass, PULPMatMulRequantMergePass

RQAddMapper = NodeMapper(PULPRQAddParser(), PULPRQAddTilingReadyBindings)
RQAddMapper = NodeMapper(RQAddParser(), PULPRQAddTilingReadyBindings)
AddMapper = NodeMapper(AddParser(), PULPAddTilingReadyBindings)
FlattenMapper = NodeMapper(FlattenParser(), PULPFlattenTilingReadyBindings)
GatherMapper = NodeMapper(GatherParser(), BasicGatherBindings)
Expand Down
23 changes: 0 additions & 23 deletions Deeploy/Targets/PULPOpen/TypeCheckers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,6 @@ def _inferSignedness(self, inputs: List[VariableBuffer],
return [False]


class PULPRQAddChecker(SignPropTypeChecker):

def __init__(self, input_types: Sequence[Type[Pointer]], output_types: Sequence[Type[Pointer]]):
super().__init__(input_types, output_types)

def _inferNumLevels(self, inputs: List[VariableBuffer],
operatorRepresentation: OperatorRepresentation) -> List[int]:
return [operatorRepresentation['rqsOut_n_levels']]

def _inferSignedness(self, inputs: List[VariableBuffer],
operatorRepresentation: OperatorRepresentation) -> List[bool]:
return [bool(operatorRepresentation["rqsOut_signed"])]

# Override this. This should compute the signednes of each output node of the Layer
def checkOutputType(self, inputs: List[VariableBuffer], operatorRepresentation: OperatorRepresentation) -> bool:
outputTypeSigned = self.output_types[0].referencedType.typeMin < 0
if operatorRepresentation['rqsOut_signed'] and outputTypeSigned:
return True
if (not operatorRepresentation['rqsOut_signed']) and (not outputTypeSigned):
return True
return False


class PULPRequantShiftChecker(SignPropTypeChecker):

def __init__(self, input_types: Sequence[Type[Pointer]], output_types: Sequence[Type[Pointer]]):
Expand Down
5 changes: 2 additions & 3 deletions Deeploy/Targets/Snitch/Bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
from Deeploy.DeeployTypes import CodeTransformation, NodeBinding
from Deeploy.FutureExtension.CodeTransformationPasses.FutureCodeTransformation import FutureGeneration
from Deeploy.Targets.Generic.Templates import iNoNormTemplate, RQAddTemplate
from Deeploy.Targets.Generic.TypeCheckers import AddChecker, GEMMChecker, SoftmaxChecker, iNoNormChecker
from Deeploy.Targets.Generic.TypeCheckers import AddChecker, GEMMChecker, SoftmaxChecker, iNoNormChecker, RQAddChecker
from Deeploy.Targets.Snitch.CodeTransformationPasses import SnitchClusterTiling, SnitchCoreFilterPass, \
SnitchProfileExecutionBlockPass, SnitchSynchCoresPass
from Deeploy.Targets.Snitch.Templates import AddTemplate, iSoftmaxTemplate
from Deeploy.Targets.Snitch.Templates.GemmTemplate import SnitchGemm_Template
from Deeploy.Targets.Snitch.Templates.RqGemmTemplate import SnitchRqGemm_Template
from Deeploy.Targets.Snitch.TypeCheckers import SnitchRQAddChecker
from Deeploy.TilingExtension.CodeTransformationPasses.TilingVariableReplacement import TilingVariableReplacement

TilingCallClosure = partial(ClosureGeneration, closureSuffix = "_tiling_closure")
Expand Down Expand Up @@ -78,7 +77,7 @@
TiledTransformer) for _type in [int8_t]
]
SnitchRQAddBindings = [
NodeBinding(SnitchRQAddChecker([PointerClass(_type), PointerClass(_type)], [PointerClass(_type)]),
NodeBinding(RQAddChecker([PointerClass(_type), PointerClass(_type)], [PointerClass(_type)]),
RQAddTemplate.referenceTemplate, TiledTransformer) for _type in [int8_t]
]
SnitchAddBindings = [
Expand Down
53 changes: 0 additions & 53 deletions Deeploy/Targets/Snitch/TypeCheckers.py

This file was deleted.

0 comments on commit 89f24d1

Please sign in to comment.