diff --git a/.github/workflows/ci-platform-gap9-tiled.yml b/.github/workflows/ci-platform-gap9-tiled.yml index 0043f8d3e9..fd10a4b6e7 100644 --- a/.github/workflows/ci-platform-gap9-tiled.yml +++ b/.github/workflows/ci-platform-gap9-tiled.yml @@ -27,7 +27,7 @@ jobs: select-env: uses: ./.github/workflows/_select-env.yml with: - docker_image_deeploy: ${{ github.event.inputs.docker_image_deeploy || github.repository == 'pulp-platform/Deeploy' && 'ghcr.io/pulp-platform/deeploy-gap9:latest'}} + docker_image_deeploy: "ghcr.io/filippocordella/deeploy:gap9" gap9-kernels-tiled-singlebuffer-L2: needs: select-env diff --git a/.github/workflows/ci-platform-gap9.yml b/.github/workflows/ci-platform-gap9.yml index 079f13c2a5..2f3cb80fbe 100644 --- a/.github/workflows/ci-platform-gap9.yml +++ b/.github/workflows/ci-platform-gap9.yml @@ -28,7 +28,7 @@ jobs: select-env: uses: ./.github/workflows/_select-env.yml with: - docker_image_deeploy: ${{ github.event.inputs.docker_image_deeploy || (github.repository == 'pulp-platform/Deeploy' && 'ghcr.io/pulp-platform/deeploy-gap9:latest') }} + docker_image_deeploy: "ghcr.io/filippocordella/deeploy:gap9" gap9-kernels: needs: select-env diff --git a/.github/workflows/infra-generate-ccache-gap9.yml b/.github/workflows/infra-generate-ccache-gap9.yml index b189bfd708..109b28bee8 100644 --- a/.github/workflows/infra-generate-ccache-gap9.yml +++ b/.github/workflows/infra-generate-ccache-gap9.yml @@ -20,7 +20,7 @@ jobs: generate-ccache-gap9: runs-on: ubuntu-latest container: - image: ${{ github.event.inputs.docker_image_deeploy || 'ghcr.io/pulp-platform/deeploy-gap9:latest' }} + image: ${{ github.event.inputs.docker_image_deeploy || 'ghcr.io/filippocordella/deeploy:gap9' }} steps: - name: Checkout Repo uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index dc93328e4a..7f5a70a202 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ DeeployTest/Tests/**/generateTest.py DeeployTest/out.txt CHANGELOG_GEN.md +TargetLibraries/PULPOpen/third_party/pulp-nn-mixed/ +TargetLibraries/PULPOpen/third_party/pulp-nnx/ diff --git a/Deeploy/Targets/GAP9/Bindings.py b/Deeploy/Targets/GAP9/Bindings.py index 2bda98af8f..d90b56b6e6 100644 --- a/Deeploy/Targets/GAP9/Bindings.py +++ b/Deeploy/Targets/GAP9/Bindings.py @@ -22,11 +22,12 @@ from Deeploy.Targets.GAP9.DMA.MchanDma import GAP9MchanDma # Import templates from PULPOpen and Generic from Deeploy.Targets.Generic.Templates import AddTemplate, ConcatTemplate, DequantTemplate, FloatReduceMeanTemplate, \ - FloatReduceSumTemplate, GatherTemplate, QuantTemplate, RQSiGELUTemplate, SliceTemplate, iHardswishTemplate + FloatReduceSumTemplate, GatherTemplate, QuantTemplate, RQSiGELUTemplate, RQSILUTemplate, SILUTemplate, \ + SliceTemplate, iHardswishTemplate from Deeploy.Targets.Generic.TypeCheckers import AddChecker, ConcatChecker, ConvChecker, DequantChecker, \ GatherChecker, GELUChecker, GEMMChecker, HardswishChecker, LayerNormChecker, MatMulChecker, MulChecker, \ QuantChecker, ReduceMeanChecker, ReluChecker, ReshapeChecker, RQAddChecker, RQHardswishChecker, SGDChecker, \ - SliceChecker, SoftmaxChecker, SoftmaxCrossEntropyLossChecker, TransposeChecker + SILUChecker, SliceChecker, SoftmaxChecker, SoftmaxCrossEntropyLossChecker, TransposeChecker from Deeploy.Targets.PULPOpen.Bindings import ForkClosure, L3MemoryAwareFunctionCallClosure, \ MemoryAwareForkTransformer, MemoryAwareFunctionCallClosure, TilingCallClosure from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterSynch import PULPSynchCoresPass @@ -380,6 +381,16 @@ GELUChecker([PointerClass(float32_t), PointerClass(float32_t)], [PointerClass(float32_t)]), FloatGELUTemplate.referenceTemplate, GAP9Transformer) +GAP9SILUBindings = [ + NodeBinding(SILUChecker([PointerClass(int8_t)], [PointerClass(int32_t)]), SILUTemplate.referenceTemplate, + GAP9Transformer) +] + +GAP9RQSILUBindings = [ + NodeBinding(SILUChecker([PointerClass(int8_t)], [PointerClass(int8_t)]), RQSILUTemplate.referenceTemplate, + GAP9Transformer) +] + GAP9GatherBindings = [ NodeBinding(GatherChecker([PointerClass(float32_t), PointerClass(type)], [PointerClass(float32_t)]), GatherTemplate.referenceTemplate, GAP9Transformer) for type in IntegerDataTypes diff --git a/Deeploy/Targets/GAP9/Platform.py b/Deeploy/Targets/GAP9/Platform.py index bad6f8d859..64214d8655 100644 --- a/Deeploy/Targets/GAP9/Platform.py +++ b/Deeploy/Targets/GAP9/Platform.py @@ -18,22 +18,22 @@ GAP9LayernormTilingReadyBindings, GAP9MatMulTilingReadyBindings, GAP9MaxPool2DTilingReadyBindings, \ GAP9MulTilingReadyBindings, GAP9ReduceSumTilingReadyBindings, GAP9ReluTilingReadyBindings, \ GAP9RQAddTilingReadyBindings, GAP9RQSConv2DTilingReadyBindings, GAP9RQSDWConv2DTilingReadyBindings, \ - GAP9RQSGEMMTilingReadyBindings, GAP9RQSiHardswishTilingReadyBindings, GAP9RQSMatrixVecTilingReadyBindings, \ - GAP9RQSTallGEMMTilingReadyBindings, GAP9RQSTilingReadyBindings, GAP9SGDTilingReadyBindings, \ - GAP9SoftmaxCrossEntropyGradTilingReadyBindings, GAP9SoftmaxCrossEntropyTilingReadyBindings, \ - GAP9SoftmaxGradTilingReadyBindings, GAP9SoftmaxTilingReadyBindings, GAP9TransposeTilingReadyBindings, \ - GAP9UniformRQSTilingReadyBindings + GAP9RQSGEMMTilingReadyBindings, GAP9RQSiHardswishTilingReadyBindings, GAP9RQSILUTilingReadyBindings, \ + GAP9RQSMatrixVecTilingReadyBindings, GAP9RQSTallGEMMTilingReadyBindings, GAP9RQSTilingReadyBindings, \ + GAP9SGDTilingReadyBindings, GAP9SILUTilingReadyBindings, GAP9SoftmaxCrossEntropyGradTilingReadyBindings, \ + GAP9SoftmaxCrossEntropyTilingReadyBindings, GAP9SoftmaxGradTilingReadyBindings, GAP9SoftmaxTilingReadyBindings, \ + GAP9TransposeTilingReadyBindings, GAP9UniformRQSTilingReadyBindings from Deeploy.Targets.Generic.Bindings import BasicGEMMBindings, BasicPad1DBindings, BasicPad2DBindings, \ BasicRQIntegerDivBinding from Deeploy.Targets.Generic.Layers import AddLayer, ConcatLayer, ConvLayer, GatherLayer, GELULayer, GEMMLayer, \ LayerNormLayer, MatMulLayer, MaxPoolLayer, MulLayer, PadLayer, QuantLayer, ReduceMeanLayer, ReduceSumLayer, \ - ReluLayer, RequantShiftLayer, ReshapeLayer, RQIntegerDivLayer, RQSiGELULayer, RQSiHardswishLayer, SGDLayer, \ - SliceLayer, SoftmaxCrossEntropyLossGradLayer, SoftmaxCrossEntropyLossLayer, SoftmaxGradLayer, SoftmaxLayer, \ - TransposeLayer, iHardswishLayer, iRMSNormLayer + ReluLayer, RequantShiftLayer, ReshapeLayer, RQIntegerDivLayer, RQSiGELULayer, RQSiHardswishLayer, RQSILULayer, \ + SGDLayer, SILULayer, SliceLayer, SoftmaxCrossEntropyLossGradLayer, SoftmaxCrossEntropyLossLayer, SoftmaxGradLayer, \ + SoftmaxLayer, TransposeLayer, iHardswishLayer, iRMSNormLayer from Deeploy.Targets.Generic.Parsers import AddParser, ConcatParser, DequantParser, FlattenParser, GatherParser, \ GELUParser, GEMMParser, LayerNormParser, MatMulParser, MaxPool2DParser, MulParser, Pad1DParser, Pad2DParser, \ QuantParser, ReduceMeanParser, ReduceSumParser, ReluParser, RequantShiftParser, ReshapeParser, RQAddParser, \ - RQIntegerDivParser, RQSiGELUParser, RQSiHardswishParser, SGDParser, SliceParser, \ + RQIntegerDivParser, RQSiGELUParser, RQSiHardswishParser, SGDParser, SILUParser, SliceParser, \ SoftmaxCrossEntropyLossGradParser, SoftmaxCrossEntropyLossParser, SoftmaxGradParser, SoftmaxParser, \ TransposeParser, UniformRequantShiftParser, UnsqueezeParser, iHardswishParser, iRMSNormParser, iSoftmaxParser from Deeploy.Targets.Generic.Templates import AllocateTemplate as BasicAllocateTemplate @@ -49,6 +49,8 @@ GAP9_AddMapper = NodeMapper(AddParser(), GAP9AddTilingReadyBindings) GAP9_FlattenMapper = NodeMapper(FlattenParser(), GAP9FlattenTilingReadyBindings) GAP9_GELUMapper = NodeMapper(GELUParser(), GAP9FPGELUTilingReadyBindings) +GAP9_SILUMapper = NodeMapper(SILUParser(), GAP9SILUTilingReadyBindings) +GAP9_RQSILUMapper = NodeMapper(SILUParser(), GAP9RQSILUTilingReadyBindings) GAP9_GatherMapper = NodeMapper(GatherParser(), GAP9GatherTilingReadyBindings) GAP9_MulMapper = NodeMapper(MulParser(), GAP9MulTilingReadyBindings) GAP9_Pad1DMapper = NodeMapper(Pad1DParser(), BasicPad1DBindings) @@ -106,6 +108,10 @@ GEMMLayer([GAP9_FloatGEMMMapper, GAP9_GEMMDequantMapper]), 'Gelu': GELULayer([GAP9_GELUMapper]), + 'SILU': + SILULayer([GAP9_SILUMapper]), + 'RQSILU': + RQSILULayer([GAP9_RQSILUMapper]), 'LayerNormalization': LayerNormLayer([GAP9_LayerNormMapper]), 'MaxPool': diff --git a/Deeploy/Targets/GAP9/Tiler.py b/Deeploy/Targets/GAP9/Tiler.py index fefe12b6d7..6c54da8854 100644 --- a/Deeploy/Targets/GAP9/Tiler.py +++ b/Deeploy/Targets/GAP9/Tiler.py @@ -15,9 +15,9 @@ GAP9iHardswishBindings, GAP9iRMSNormBindings, GAP9iRQSGELUBindings, GAP9LayernormBinding, GAP9MatMulBindings, \ GAP9MaxPool2DBindings, GAP9MulBindings, GAP9ReduceSumBindings, GAP9ReluBinding, GAP9ReshapeBindings, \ GAP9RQAddBindings, GAP9RQSBindings, GAP9RQSConv2DBindings, GAP9RQSDWConv2DBindings, GAP9RQSGEMMBindings, \ - GAP9RQSiHardswishBindings, GAP9RQSMatrixVecBindings, GAP9RQSTallGEMMBindings, GAP9SGDBindings, \ - GAP9SoftmaxBindings, GAP9SoftmaxCrossEntropyLossBindings, GAP9SoftmaxCrossEntropyLossGradBindings, \ - GAP9SoftmaxGradBindings, GAP9TransposeBindings, GAP9UniformRQSBindings + GAP9RQSiHardswishBindings, GAP9RQSILUBindings, GAP9RQSMatrixVecBindings, GAP9RQSTallGEMMBindings, GAP9SGDBindings, \ + GAP9SILUBindings, GAP9SoftmaxBindings, GAP9SoftmaxCrossEntropyLossBindings, \ + GAP9SoftmaxCrossEntropyLossGradBindings, GAP9SoftmaxGradBindings, GAP9TransposeBindings, GAP9UniformRQSBindings from Deeploy.Targets.Generic.TileConstraints.AddTileConstraint import AddTileConstraint from Deeploy.Targets.Generic.TileConstraints.ConcatTileConstraint import ConcatTileConstraint from Deeploy.Targets.Generic.TileConstraints.iHardswishTileConstraint import iHardswishTileConstraint @@ -26,6 +26,7 @@ from Deeploy.Targets.Generic.TileConstraints.NOPTileConstraint import NOPTileConstraint from Deeploy.Targets.Generic.TileConstraints.RQSiGELUTileConstraint import RQSiGELUTileConstraint from Deeploy.Targets.Generic.TileConstraints.RQSiHardswishTileConstraint import RQSiHardswishTileConstraint +from Deeploy.Targets.Generic.TileConstraints.SILUTileConstraint import SILUTileConstraint from Deeploy.Targets.Generic.TileConstraints.TransposeTileConstraint import TransposeTileConstraint from Deeploy.Targets.Generic.TileConstraints.UnaryTileConstraint import UnaryTileConstraint from Deeploy.Targets.Generic.TileConstraints.UntiledTileConstraint import UntiledTileConstraint @@ -142,3 +143,9 @@ GAP9SGDTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = GAP9SGDBindings, tileConstraint = SGDTileConstraint()) + +GAP9SILUTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = GAP9SILUBindings, + tileConstraint = SILUTileConstraint()) + +GAP9RQSILUTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = GAP9RQSILUBindings, + tileConstraint = SILUTileConstraint()) \ No newline at end of file diff --git a/Deeploy/Targets/Generic/Bindings.py b/Deeploy/Targets/Generic/Bindings.py index 308b179aef..43de2667b8 100644 --- a/Deeploy/Targets/Generic/Bindings.py +++ b/Deeploy/Targets/Generic/Bindings.py @@ -18,13 +18,13 @@ FloatPowTemplate, FloatReduceMeanTemplate, FloatReluTemplate, FloatSoftmaxTemplate, FloatSqrtTemplate, \ GatherTemplate, GemmTemplate, IntegerDivTemplate, ITAMaxTemplate, ITAPartialMaxTemplate, MatMulTemplate, \ MaxPoolTemplate, MulTemplate, PadTemplate, QuantTemplate, ReduceMeanTemplate, ReduceSumTemplate, \ - RequantShiftTemplate, ReshapeTemplate, RQIntegerDivTemplate, RQSiGELUTemplate, SliceTemplate, TransposeTemplate, \ - iGELUTemplate, iLayernormTemplate, iRMSNormTemplate, iSoftmaxTemplate + RequantShiftTemplate, ReshapeTemplate, RQIntegerDivTemplate, RQSiGELUTemplate, RQSILUTemplate, SILUTemplate, \ + SliceTemplate, TransposeTemplate, iGELUTemplate, iLayernormTemplate, iRMSNormTemplate, iSoftmaxTemplate from Deeploy.Targets.Generic.TypeCheckers import AddChecker, BatchNormChecker, ConcatChecker, ConvChecker, \ DebugPrintChecker, DequantChecker, DivChecker, DummyChecker, GatherChecker, GELUChecker, GEMMChecker, \ LayerNormChecker, MatMulChecker, MaxPoolChecker, MulChecker, PadChecker, QuantChecker, ReduceMeanChecker, \ - ReduceSumChecker, ReluChecker, RequantShiftChecker, ReshapeChecker, RQIntegerDivChecker, SliceChecker, \ - SoftmaxChecker, TransposeChecker + ReduceSumChecker, ReluChecker, RequantShiftChecker, ReshapeChecker, RQIntegerDivChecker, SILUChecker, \ + SliceChecker, SoftmaxChecker, TransposeChecker BasicTransformer = CodeTransformation([ArgumentStructGeneration(), MemoryManagementGeneration(), FutureGeneration()]) @@ -327,3 +327,13 @@ ConvTransposeTemplate.referenceTemplate, BasicTransformer) for type in FloatDataTypes ] + +BasicSILUBindings = [ + NodeBinding(SILUChecker([PointerClass(int8_t)], [PointerClass(int32_t)]), SILUTemplate.referenceTemplate, + BasicTransformer) +] + +BasicRQSILUBindings = [ + NodeBinding(SILUChecker([PointerClass(int8_t), PointerClass(int8_t)], [PointerClass(int8_t)]), + RQSILUTemplate.referenceTemplate, BasicTransformer) +] diff --git a/Deeploy/Targets/Generic/Layers.py b/Deeploy/Targets/Generic/Layers.py index cc733937cc..65e03b59b0 100644 --- a/Deeploy/Targets/Generic/Layers.py +++ b/Deeploy/Targets/Generic/Layers.py @@ -709,3 +709,15 @@ def computeOps(self): numPx = opRep['dim_im_out_x'] return numPx * opsPerPx + + +class SILULayer(ONNXLayer): + + def __init__(self, maps: List[NodeMapper]): + super().__init__(maps) + + +class RQSILULayer(SILULayer): + + def __init__(self, maps: List[NodeMapper]): + super().__init__(maps) diff --git a/Deeploy/Targets/Generic/Parsers.py b/Deeploy/Targets/Generic/Parsers.py index ad787d9e4b..8b8d466a0c 100644 --- a/Deeploy/Targets/Generic/Parsers.py +++ b/Deeploy/Targets/Generic/Parsers.py @@ -2886,3 +2886,28 @@ def parseNodeCtxt(self, self.operatorRepresentation['size'] = int(np.prod(data_in.shape)) return ctxt, True + + +class SILUParser(NodeParser): + + def __init__(self): + super().__init__() + + def parseNode(self, node: gs.Node) -> bool: + + ret = all([len(node.inputs) >= 1, len(node.outputs) == 1]) + + return ret + + def parseNodeCtxt(self, + ctxt: NetworkContext, + node: gs.Node, + channels_first: bool = True) -> Tuple[NetworkContext, bool]: + + data_in = ctxt.lookup(node.inputs[0].name) + data_out = ctxt.lookup(node.outputs[0].name) + self.operatorRepresentation['data_in'] = data_in.name + self.operatorRepresentation['data_out'] = data_out.name + self.operatorRepresentation['size'] = np.prod(data_in.shape) + + return ctxt, True diff --git a/Deeploy/Targets/Generic/Platform.py b/Deeploy/Targets/Generic/Platform.py index e05e897270..a4ee4456aa 100644 --- a/Deeploy/Targets/Generic/Platform.py +++ b/Deeploy/Targets/Generic/Platform.py @@ -13,20 +13,20 @@ BasicLayerNormBindings, BasicMatMulBindings, BasicMaxPool1DBindings, BasicMaxPool2DBindings, BasicMulBindings, \ BasicPad1DBindings, BasicPad2DBindings, BasicPowBindings, BasicQuantBindings, BasicReduceMeanBindings, \ BasicReduceSumBindings, BasicReluBinding, BasicReshapeBindings, BasicRQIntegerDivBinding, BasicRQSBindings, \ - BasicRQSGELUBinding, BasicSliceBindings, BasicSoftmaxBindings, BasicSqrtBindings, BasicTransposeBindings, \ - DummyBinding + BasicRQSGELUBinding, BasicRQSILUBindings, BasicSILUBindings, BasicSliceBindings, BasicSoftmaxBindings, \ + BasicSqrtBindings, BasicTransposeBindings, DummyBinding from Deeploy.Targets.Generic.Layers import AddLayer, BatchNormalizationLayer, ConcatLayer, ConvLayer, \ ConvTransposeLayer, DebugPrintLayer, DequantLayer, DivLayer, GatherLayer, GELULayer, GEMMLayer, ITAMaxLayer, \ LayerNormLayer, MatMulLayer, MaxPoolLayer, MulLayer, PadLayer, PowLayer, QuantLayer, ReduceMeanLayer, \ - ReduceSumLayer, ReluLayer, RequantShiftLayer, ReshapeLayer, RQIntegerDivLayer, RQSiGELULayer, SliceLayer, \ - SoftmaxLayer, SqrtLayer, TransposeLayer + ReduceSumLayer, ReluLayer, RequantShiftLayer, ReshapeLayer, RQIntegerDivLayer, RQSiGELULayer, RQSILULayer, \ + SILULayer, SliceLayer, SoftmaxLayer, SqrtLayer, TransposeLayer from Deeploy.Targets.Generic.Parsers import AddParser, BatchNormParser, ConcatParser, ConvTranspose1DParser, \ DebugParser, DequantParser, DivParser, DummyParser, FlattenParser, GatherParser, GELUParser, GenericConv1DParser, \ GenericConv2DParser, GenericDWConv1DParser, GenericDWConv2DParser, GenericGEMMParser, GenericMaxPool2DParser, \ IntegerDivParser, ITAMaxParser, ITAPartialMaxParser, LayerNormParser, MatMulParser, MaxPool1DParser, MulParser, \ Pad1DParser, Pad2DParser, PowParser, QuantParser, ReduceMeanParser, ReduceSumParser, ReluParser, \ - RequantShiftParser, ReshapeParser, RQIntegerDivParser, RQSiGELUParser, SliceParser, SoftmaxParser, SqrtParser, \ - TransposeParser, UnsqueezeParser, iLayerNormParser, iSoftmaxParser + RequantShiftParser, ReshapeParser, RQIntegerDivParser, RQSiGELUParser, SILUParser, SliceParser, SoftmaxParser, \ + SqrtParser, TransposeParser, UnsqueezeParser, iLayerNormParser, iSoftmaxParser from Deeploy.Targets.Generic.Templates import AllocateTemplate, FreeTemplate from Deeploy.Targets.Generic.TopologyOptimizationPasses.Passes import DequantPatternPass, ExtractPaddingFromConvPass, \ ExtractPaddingFromPoolPass, MatMulAddMergePass, MergeConstAddAndRequantPass, QuantPatternPass, \ @@ -73,6 +73,8 @@ BatchNormalizationMapper = NodeMapper(BatchNormParser(), BasicBatchNormBindings) ConvTransposeMapper = NodeMapper(ConvTranspose1DParser(), BasicConvTransposeBindings) SliceMapper = NodeMapper(SliceParser(), BasicSliceBindings) +SILUMapper = NodeMapper(SILUParser(), BasicSILUBindings) +RQSILUMapper = NodeMapper(SILUParser(), BasicRQSILUBindings) # Dummy nodes are intended for development purposes only! # They should always generate compiler errors to not accidentally end up in production code @@ -118,7 +120,10 @@ 'Quant': QuantLayer([QuantMapper]), 'Dequant': DequantLayer([DequantMapper]), 'BatchNormalization': BatchNormalizationLayer([BatchNormalizationMapper]), - 'ConvTranspose': ConvTransposeLayer([ConvTransposeMapper]) + 'ConvTranspose': ConvTransposeLayer([ConvTransposeMapper]), + 'SILU': SILULayer([SILUMapper]), + 'RQSILU': RQSILULayer([RQSILUMapper]), + # # For example, you can use the DummpyMapper, in case you want to test # # deployment or optimizations with GlobalAveragePool nodes but did not yet # # implement the corresponding kernel diff --git a/Deeploy/Targets/Generic/Templates/RQSILUTemplate.py b/Deeploy/Targets/Generic/Templates/RQSILUTemplate.py new file mode 100644 index 0000000000..99f0e3beec --- /dev/null +++ b/Deeploy/Targets/Generic/Templates/RQSILUTemplate.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2024 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +from typing import Dict, List, Tuple + +from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation + + +class _SILUTemplate(NodeTemplate): + + def __init__(self, templateStr): + super().__init__(templateStr) + + def alignToContext(self, ctxt: NetworkContext, + operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: + + data_in = ctxt.lookup(operatorRepresentation['data_in']) + data_out = ctxt.lookup(operatorRepresentation['data_out']) + operatorRepresentation['input_offset'] = 0 + if hasattr(data_in, "_signed") and hasattr(data_in, "nLevels"): + operatorRepresentation['input_offset'] = (data_in._signed == 0) * int(data_in.nLevels / 2) + operatorRepresentation['output_offset'] = 0 + if hasattr(data_out, "_signed") and hasattr(data_out, "nLevels"): + operatorRepresentation['output_offset'] = -(data_out._signed == 0) * int(data_out.nLevels / 2) + + return ctxt, operatorRepresentation, [] + + +referenceTemplate = _SILUTemplate(""" +// RQSILU (Name: ${nodeName}, Op: ${nodeOp}) +SINGLE_CORE RQSILU_s${data_in_type.referencedType.typeWidth}_s${data_out_type.referencedType.typeWidth}(${data_in}, ${data_out}, ${size}, ${input_offset}); +""") diff --git a/Deeploy/Targets/Generic/Templates/SILUTemplate.py b/Deeploy/Targets/Generic/Templates/SILUTemplate.py new file mode 100644 index 0000000000..eb84a268d9 --- /dev/null +++ b/Deeploy/Targets/Generic/Templates/SILUTemplate.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2024 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +from typing import Dict, List, Tuple + +from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation + + +class _SILUTemplate(NodeTemplate): + + def __init__(self, templateStr): + super().__init__(templateStr) + + def alignToContext(self, ctxt: NetworkContext, + operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: + + data_in = ctxt.lookup(operatorRepresentation['data_in']) + data_out = ctxt.lookup(operatorRepresentation['data_out']) + operatorRepresentation['input_offset'] = 0 + if hasattr(data_in, "_signed") and hasattr(data_in, "nLevels"): + operatorRepresentation['input_offset'] = (data_in._signed == 0) * int(data_in.nLevels / 2) + operatorRepresentation['output_offset'] = 0 + if hasattr(data_out, "_signed") and hasattr(data_out, "nLevels"): + operatorRepresentation['output_offset'] = -(data_out._signed == 0) * int(data_out.nLevels / 2) + + return ctxt, operatorRepresentation, [] + + +referenceTemplate = _SILUTemplate(""" +// SILU (Name: ${nodeName}, Op: ${nodeOp}) +SINGLE_CORE SILU_s${data_in_type.referencedType.typeWidth}_s${data_out_type.referencedType.typeWidth}(${data_in}, ${data_out}, ${size}, ${input_offset}); +""") diff --git a/Deeploy/Targets/Generic/TileConstraints/SILUTileConstraint.py b/Deeploy/Targets/Generic/TileConstraints/SILUTileConstraint.py new file mode 100644 index 0000000000..7d5cb4af15 --- /dev/null +++ b/Deeploy/Targets/Generic/TileConstraints/SILUTileConstraint.py @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2024 ETH Zurich and University of Bologna +# +# SPDX-License-Identifier: Apache-2.0 + +from Deeploy.Targets.Generic.TileConstraints.UnaryTileConstraint import UnaryTileConstraint + + +class SILUTileConstraint(UnaryTileConstraint): + pass diff --git a/Deeploy/Targets/Generic/TypeCheckers.py b/Deeploy/Targets/Generic/TypeCheckers.py index c2c8d436f8..8a0d4ea19e 100644 --- a/Deeploy/Targets/Generic/TypeCheckers.py +++ b/Deeploy/Targets/Generic/TypeCheckers.py @@ -610,3 +610,20 @@ def _inferNumLevels(self, inputs: List[VariableBuffer], def _inferSignedness(self, inputs: List[VariableBuffer], operatorRepresentation: OperatorRepresentation) -> List[bool]: return [True] + + +class SILUChecker(SignPropTypeChecker): #same as GELU due to the same input-output quantization parameters + + 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 [2**(self.input_types[0].referencedType.typeWidth)] + + def _inferSignedness(self, inputs: List[VariableBuffer], + operatorRepresentation: OperatorRepresentation) -> List[bool]: + if inputs[0]._signed: + return [True] + else: + return [False] diff --git a/Deeploy/Targets/PULPOpen/Bindings.py b/Deeploy/Targets/PULPOpen/Bindings.py index 84ee2420e3..ae877af781 100644 --- a/Deeploy/Targets/PULPOpen/Bindings.py +++ b/Deeploy/Targets/PULPOpen/Bindings.py @@ -15,11 +15,11 @@ from Deeploy.FutureExtension.Bindings.AutoFutureBinding import AutoFutureBinding from Deeploy.FutureExtension.CodeTransformationPasses.FutureCodeTransformation import FutureGeneration from Deeploy.Targets.Generic.Templates import AddTemplate, ConcatTemplate, DequantTemplate, FloatReduceSumTemplate, \ - GatherTemplate, QuantTemplate, RQSiGELUTemplate, SliceTemplate, iHardswishTemplate + GatherTemplate, QuantTemplate, RQSiGELUTemplate, RQSILUTemplate, SILUTemplate, SliceTemplate, iHardswishTemplate from Deeploy.Targets.Generic.TypeCheckers import AddChecker, ConcatChecker, ConvChecker, DequantChecker, \ GatherChecker, GELUChecker, GEMMChecker, HardswishChecker, LayerNormChecker, MatMulChecker, MulChecker, \ QuantChecker, ReduceMeanChecker, ReluChecker, ReshapeChecker, RQAddChecker, RQHardswishChecker, SGDChecker, \ - SliceChecker, SoftmaxChecker, SoftmaxCrossEntropyLossChecker, TransposeChecker + SILUChecker, SliceChecker, SoftmaxChecker, SoftmaxCrossEntropyLossChecker, TransposeChecker from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterSynch import PULPSynchCoresPass from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPClusterTiling import PULPClusterTiling from Deeploy.Targets.PULPOpen.CodeTransformationPasses.PULPL3Tiling import PULPL3Tiling @@ -446,6 +446,16 @@ GatherTemplate.referenceTemplate, ForkTransformer) for type in IntegerDataTypes ] +PULPSILUBindings = [ + NodeBinding(SILUChecker([PointerClass(int8_t), PointerClass(int32_t)], [PointerClass(int32_t)]), + SILUTemplate.referenceTemplate, ForkTransformer) #See with ClusterTransformer also +] + +PULPRQSILUBindings = [ + NodeBinding(SILUChecker([PointerClass(int8_t), PointerClass(int8_t)], [PointerClass(int8_t)]), + RQSILUTemplate.referenceTemplate, ForkTransformer) +] + BasicQuantBindings = [ NodeBinding(QuantChecker([PointerClass(float32_t)], [PointerClass(int8_t)]), QuantTemplate.referenceTemplate, ForkTransformer), diff --git a/Deeploy/Targets/PULPOpen/Platform.py b/Deeploy/Targets/PULPOpen/Platform.py index 7456dd9e1b..99045d13a9 100644 --- a/Deeploy/Targets/PULPOpen/Platform.py +++ b/Deeploy/Targets/PULPOpen/Platform.py @@ -16,15 +16,15 @@ from Deeploy.Targets.Generic.Layers import AddLayer, ConcatLayer, ConvLayer, GatherLayer, GELUGradLayer, GELULayer, \ GEMMLayer, LayerNormGradLayer, LayerNormLayer, MatMulLayer, MaxPoolLayer, MulLayer, PadLayer, QuantLayer, \ ReduceMeanLayer, ReduceSumLayer, ReluLayer, RequantShiftLayer, ReshapeLayer, RQIntegerDivLayer, RQSiGELULayer, \ - RQSiHardswishLayer, SGDLayer, SliceLayer, SoftmaxCrossEntropyLossGradLayer, SoftmaxCrossEntropyLossLayer, \ - SoftmaxGradLayer, SoftmaxLayer, TransposeLayer, iHardswishLayer, iRMSNormLayer + RQSiHardswishLayer, RQSILULayer, SGDLayer, SILULayer, SliceLayer, SoftmaxCrossEntropyLossGradLayer, \ + SoftmaxCrossEntropyLossLayer, SoftmaxGradLayer, SoftmaxLayer, TransposeLayer, iHardswishLayer, iRMSNormLayer from Deeploy.Targets.Generic.Parsers import AddParser, ConcatParser, DequantParser, FlattenParser, GatherParser, \ GELUGradParser, GELUParser, GEMMParser, LayerNormGradParser, LayerNormParser, MatMulParser, MaxPool1DParser, \ MaxPool2DParser, MulParser, Pad1DParser, Pad2DParser, QuantParser, ReduceSumParser, ReluParser, \ RequantShiftParser, ReshapeParser, RQAddParser, RQIntegerDivParser, RQSiGELUParser, RQSiHardswishParser, \ - SGDParser, SliceParser, SoftmaxCrossEntropyLossGradParser, SoftmaxCrossEntropyLossParser, SoftmaxGradParser, \ - SoftmaxParser, TransposeParser, UniformRequantShiftParser, UnsqueezeParser, iHardswishParser, iRMSNormParser, \ - iSoftmaxParser + SGDParser, SILUParser, SliceParser, SoftmaxCrossEntropyLossGradParser, SoftmaxCrossEntropyLossParser, \ + SoftmaxGradParser, SoftmaxParser, TransposeParser, UniformRequantShiftParser, UnsqueezeParser, iHardswishParser, \ + iRMSNormParser, iSoftmaxParser from Deeploy.Targets.Generic.Templates import AllocateTemplate as BasicAllocateTemplate from Deeploy.Targets.Generic.TopologyOptimizationPasses.Passes import DequantPatternPass, IntegerDivRequantMergePass, \ MergeConstAddAndRequantPass, MergeTrueIntegerDivRequantShiftPass, QuantPatternPass, RQSSplitPass, \ @@ -45,11 +45,11 @@ PULPMulTilingReadyBindings, PULPReduceMeanTilingReadyBindings, PULPReduceSumTilingReadyBindings, \ PULPReluTilingReadyBindings, PULPRQAddTilingReadyBindings, PULPRQSConv1DTilingReadyBindings, \ PULPRQSConv2DTilingReadyBindings, PULPRQSDWConv2DTilingReadyBindings, PULPRQSGEMMTilingReadyBindings, \ - PULPRQSiHardswishTilingReadyBindings, PULPRQSMatrixVecTilingReadyBindings, PULPRQSTallGEMMTilingReadyBindings, \ - PULPRQSTilingReadyBindings, PULPSGDTilingReadyBindings, PULPSliceTilingReadyBindings, \ - PULPSoftmaxCrossEntropyGradTilingReadyBindings, PULPSoftmaxCrossEntropyTilingReadyBindings, \ - PULPSoftmaxGradTilingReadyBindings, PULPSoftmaxTilingReadyBindings, PULPTransposeTilingReadyBindings, \ - PULPUniformRQSTilingReadyBindings + PULPRQSiHardswishTilingReadyBindings, PULPRQSILUTilingReadyBindings, PULPRQSMatrixVecTilingReadyBindings, \ + PULPRQSTallGEMMTilingReadyBindings, PULPRQSTilingReadyBindings, PULPSGDTilingReadyBindings, \ + PULPSILUTilingReadyBindings, PULPSliceTilingReadyBindings, PULPSoftmaxCrossEntropyGradTilingReadyBindings, \ + PULPSoftmaxCrossEntropyTilingReadyBindings, PULPSoftmaxGradTilingReadyBindings, PULPSoftmaxTilingReadyBindings, \ + PULPTransposeTilingReadyBindings, PULPUniformRQSTilingReadyBindings from Deeploy.Targets.PULPOpen.TopologyOptimizationPasses.Passes import PULPAddRequantMergePass, \ PULPConvRequantMergePass, PULPGEMMRequantMergePass, PULPMatMulRequantMergePass @@ -58,6 +58,8 @@ FlattenMapper = NodeMapper(FlattenParser(), PULPFlattenTilingReadyBindings) GELUMapper = NodeMapper(GELUParser(), PULPFPGELUTilingReadyBindings) GELUGradMapper = NodeMapper(GELUGradParser(), PULPFPGELUGradTilingReadyBindings) +SILUMapper = NodeMapper(SILUParser(), PULPSILUTilingReadyBindings) +RQSILUMapper = NodeMapper(SILUParser(), PULPRQSILUTilingReadyBindings) GatherMapper = NodeMapper(GatherParser(), PULPGatherTilingReadyBindings) MulMapper = NodeMapper(MulParser(), PULPMulTilingReadyBindings) Pad1DMapper = NodeMapper(Pad1DParser(), BasicPad1DBindings) @@ -74,6 +76,8 @@ MatMulMapper = NodeMapper(MatMulParser(), PULPMatMulTilingReadyBindings) RQIntegerDivMapper = NodeMapper(RQIntegerDivParser(), [BasicRQIntegerDivBinding]) RQGELU_int8_Mapper = NodeMapper(RQSiGELUParser(), PULPiRQSGELUTilingReadyBindings) +SILUMapper = NodeMapper(SILUParser(), PULPSILUTilingReadyBindings) +RQSILUMapper = NodeMapper(SILUParser(), PULPRQSILUTilingReadyBindings) Conv1DMapper = NodeMapper(PULPConv1DParser(), PULPRQSConv1DTilingReadyBindings) DWConv1DMapper = NodeMapper(PULPDWConv1DParser(), [PULPDWConv1DBinding]) @@ -118,6 +122,8 @@ 'Gemm': GEMMLayer([FloatGEMMMapper, GEMMDequantMapper]), 'Gelu': GELULayer([GELUMapper]), 'GeluGrad': GELUGradLayer([GELUGradMapper]), + 'SILU': SILULayer([SILUMapper]), + 'RQSILU': RQSILULayer([RQSILUMapper]), 'LayerNormalization': LayerNormLayer([LayerNormMapper]), 'LayerNormalizationGrad': LayerNormGradLayer([LayerNormGradMapper]), 'MaxPool': MaxPoolLayer([MaxPool1DMapper, MaxPool2DMapper]), diff --git a/Deeploy/Targets/PULPOpen/Tiler.py b/Deeploy/Targets/PULPOpen/Tiler.py index 901106459e..4f23eef087 100644 --- a/Deeploy/Targets/PULPOpen/Tiler.py +++ b/Deeploy/Targets/PULPOpen/Tiler.py @@ -12,6 +12,7 @@ from Deeploy.Targets.Generic.TileConstraints.NOPTileConstraint import NOPTileConstraint from Deeploy.Targets.Generic.TileConstraints.RQSiGELUTileConstraint import RQSiGELUTileConstraint from Deeploy.Targets.Generic.TileConstraints.RQSiHardswishTileConstraint import RQSiHardswishTileConstraint +from Deeploy.Targets.Generic.TileConstraints.SILUTileConstraint import SILUTileConstraint from Deeploy.Targets.Generic.TileConstraints.TransposeTileConstraint import TransposeTileConstraint from Deeploy.Targets.Generic.TileConstraints.UnaryTileConstraint import UnaryTileConstraint from Deeploy.Targets.PULPOpen.Bindings import PULPAddBindings, PULPConcatBindings, PULPFloatConv2DBindings, \ @@ -20,9 +21,9 @@ PULPLayernormGradBinding, PULPMatMulBindings, PULPMaxPool1DBindings, PULPMaxPool2DBindings, PULPMulBindings, \ PULPReduceMeanBindings, PULPReduceSumBindings, PULPReluBinding, PULPReshapeBindings, PULPRQAddBindings, \ PULPRQSBindings, PULPRQSConv1DBindings, PULPRQSConv2DBindings, PULPRQSDWConv2DBindings, PULPRQSGEMMBindings, \ - PULPRQSiHardswishBindings, PULPRQSMatrixVecBindings, PULPRQSTallGEMMBindings, PULPSGDBindings, PULPSliceBindings, \ - PULPSoftmaxBindings, PULPSoftmaxCrossEntropyLossBindings, PULPSoftmaxCrossEntropyLossGradBindings, \ - PULPSoftmaxGradBindings, PULPTransposeBindings, PULPUniformRQSBindings + PULPRQSiHardswishBindings, PULPRQSILUBindings, PULPRQSMatrixVecBindings, PULPRQSTallGEMMBindings, PULPSGDBindings, \ + PULPSILUBindings, PULPSliceBindings, PULPSoftmaxBindings, PULPSoftmaxCrossEntropyLossBindings, \ + PULPSoftmaxCrossEntropyLossGradBindings, PULPSoftmaxGradBindings, PULPTransposeBindings, PULPUniformRQSBindings from Deeploy.Targets.PULPOpen.TileConstraints.ConvTileConstraint import Conv2DTileConstraint, RQConv1DTileConstraint, \ RQConv2DTileConstraint from Deeploy.Targets.PULPOpen.TileConstraints.DWConvTileConstraint import DWConv2DTileConstraint, \ @@ -137,6 +138,12 @@ PULPFPGELUGradTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = [PULPFloatGELUGradBinding], tileConstraint = GeluGradTileConstraint()) +PULPSILUTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = PULPSILUBindings, + tileConstraint = SILUTileConstraint()) + +PULPRQSILUTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = PULPRQSILUBindings, + tileConstraint = SILUTileConstraint()) + PULPGatherTilingReadyBindings = TilingReadyNodeBindings(nodeBindings = PULPGatherBindings, tileConstraint = GatherTileConstraint()) diff --git a/DeeployTest/Tests/Kernels/Integer/RQSILU/inputs.npz b/DeeployTest/Tests/Kernels/Integer/RQSILU/inputs.npz new file mode 100644 index 0000000000..cd5012a292 Binary files /dev/null and b/DeeployTest/Tests/Kernels/Integer/RQSILU/inputs.npz differ diff --git a/DeeployTest/Tests/Kernels/Integer/RQSILU/network.onnx b/DeeployTest/Tests/Kernels/Integer/RQSILU/network.onnx new file mode 100644 index 0000000000..24cadbe64f Binary files /dev/null and b/DeeployTest/Tests/Kernels/Integer/RQSILU/network.onnx differ diff --git a/DeeployTest/Tests/Kernels/Integer/RQSILU/outputs.npz b/DeeployTest/Tests/Kernels/Integer/RQSILU/outputs.npz new file mode 100644 index 0000000000..380d521dd4 Binary files /dev/null and b/DeeployTest/Tests/Kernels/Integer/RQSILU/outputs.npz differ diff --git a/DeeployTest/Tests/Kernels/Integer/SILU/inputs.npz b/DeeployTest/Tests/Kernels/Integer/SILU/inputs.npz new file mode 100644 index 0000000000..cd5012a292 Binary files /dev/null and b/DeeployTest/Tests/Kernels/Integer/SILU/inputs.npz differ diff --git a/DeeployTest/Tests/Kernels/Integer/SILU/network.onnx b/DeeployTest/Tests/Kernels/Integer/SILU/network.onnx new file mode 100644 index 0000000000..fffe8c3182 Binary files /dev/null and b/DeeployTest/Tests/Kernels/Integer/SILU/network.onnx differ diff --git a/DeeployTest/Tests/Kernels/Integer/SILU/outputs.npz b/DeeployTest/Tests/Kernels/Integer/SILU/outputs.npz new file mode 100644 index 0000000000..09a92f25d3 Binary files /dev/null and b/DeeployTest/Tests/Kernels/Integer/SILU/outputs.npz differ diff --git a/DeeployTest/test_gap9_config.py b/DeeployTest/test_gap9_config.py index 69b940f0c3..1c7ec75731 100644 --- a/DeeployTest/test_gap9_config.py +++ b/DeeployTest/test_gap9_config.py @@ -9,13 +9,13 @@ "Kernels/Integer/Add/Regular", "Kernels/Integer/Add/MultIO", "Kernels/Integer/Pad/Regular_1D", "Kernels/Integer/Pad/Regular_2D", "Kernels/Integer/MatMul/Regular", "Kernels/Integer/MatMul/Add", "Kernels/Integer/Conv/DW_2D_RQ", "Kernels/Integer/Conv/Regular_2D_RQ", "Kernels/Integer/Softmax/Regular", - "Kernels/Integer/Concat", "Kernels/Integer/Hardswish/Regular", "Others/Backtracking", "Kernels/FP32/Add/Regular", - "Kernels/FP32/GEMM/Regular", "Kernels/FP32/Conv/Regular_2D_Bias", "Kernels/FP32/Conv/Regular_2D_NoBias", - "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", "Kernels/FP32/Conv/DW_2D_Bias", "Kernels/FP32/Conv/DW_2D_NoBias", - "Kernels/FP32/Conv/DW_2D_ZeroValuedBias", "Kernels/FP32/LayerNorm", "Kernels/FP32/ReLU", - "Kernels/FP32/MaxPool/Regular_2D", "Kernels/FP32/MatMul", "Kernels/FP32/Softmax/Regular", "Kernels/FP32/Transpose", - "Kernels/FP32/Mul", "Kernels/Mixed/Dequant", "Kernels/Mixed/Quant", "Kernels/FP32/ReduceSum", - "Kernels/FP32/Reshape/SkipConnection" + "Kernels/Integer/Concat", "Kernels/Integer/Hardswish/Regular", "Kernels/Integer/SILU", "Others/Backtracking", + "Kernels/FP32/Add/Regular", "Kernels/FP32/GEMM/Regular", "Kernels/FP32/Conv/Regular_2D_Bias", + "Kernels/FP32/Conv/Regular_2D_NoBias", "Kernels/FP32/Conv/Regular_2D_ZeroValuedBias", + "Kernels/FP32/Conv/DW_2D_Bias", "Kernels/FP32/Conv/DW_2D_NoBias", "Kernels/FP32/Conv/DW_2D_ZeroValuedBias", + "Kernels/FP32/LayerNorm", "Kernels/FP32/ReLU", "Kernels/FP32/MaxPool/Regular_2D", "Kernels/FP32/MatMul", + "Kernels/FP32/Softmax/Regular", "Kernels/FP32/Transpose", "Kernels/FP32/Mul", "Kernels/Mixed/Dequant", + "Kernels/Mixed/Quant", "Kernels/FP32/ReduceSum", "Kernels/FP32/Reshape/SkipConnection" ] MODEL_TESTS = [ diff --git a/DeeployTest/test_generic_config.py b/DeeployTest/test_generic_config.py index b0d8c659ca..311b932a23 100644 --- a/DeeployTest/test_generic_config.py +++ b/DeeployTest/test_generic_config.py @@ -63,6 +63,7 @@ "Kernels/Integer/ReduceMean", "Kernels/Integer/ReduceSum", "Kernels/Integer/Slice", + "Kernels/Integer/SILU", # Special test from TinyViT model layers "Models/TinyViT/5M/Layers/FP32/ReduceMean", # Mixed Precision / Quantization diff --git a/DeeployTest/test_siracusa_config.py b/DeeployTest/test_siracusa_config.py index 8fa105d9f4..18cba35918 100644 --- a/DeeployTest/test_siracusa_config.py +++ b/DeeployTest/test_siracusa_config.py @@ -55,6 +55,7 @@ "Kernels/Integer/Pad/Regular_1D", "Kernels/Integer/Pad/Regular_2D", "Kernels/Integer/RMSNorm", + "Kernels/Integer/SILU", "Models/TinyViT/5M/Layers/FP32/ReduceMean", "Others/Backtracking", "Kernels/Mixed/Dequant", diff --git a/TargetLibraries/GAP9/inc/DeeployGAP9Math.h b/TargetLibraries/GAP9/inc/DeeployGAP9Math.h index 0efa74c72e..e4aa3ec134 100644 --- a/TargetLibraries/GAP9/inc/DeeployGAP9Math.h +++ b/TargetLibraries/GAP9/inc/DeeployGAP9Math.h @@ -24,4 +24,4 @@ #include "pmsis.h" -#endif // __DEEPLOY_MATH_HEADER_ +#endif // __DEEPLOY_MATH_HEADER_ \ No newline at end of file diff --git a/TargetLibraries/Generic/inc/DeeployBasicMath.h b/TargetLibraries/Generic/inc/DeeployBasicMath.h index 22081701a3..e57a15f3db 100644 --- a/TargetLibraries/Generic/inc/DeeployBasicMath.h +++ b/TargetLibraries/Generic/inc/DeeployBasicMath.h @@ -48,8 +48,10 @@ #include "kernel/RQDiv.h" #include "kernel/RQGELU.h" #include "kernel/RQHardswish.h" +#include "kernel/RQSILU.h" #include "kernel/Relu.h" #include "kernel/RequantShift.h" +#include "kernel/SILU.h" #include "kernel/Softmax.h" #include "kernel/Sqrt.h" diff --git a/TargetLibraries/Generic/inc/kernel/RQSILU.h b/TargetLibraries/Generic/inc/kernel/RQSILU.h new file mode 100644 index 0000000000..9e1956d9d2 --- /dev/null +++ b/TargetLibraries/Generic/inc/kernel/RQSILU.h @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __DEEPLOY_BASIC_MATH_RQSILU_KERNEL_HEADER_ +#define __DEEPLOY_BASIC_MATH_RQSILU_KERNEL_HEADER_ + +#include "DeeployBasicMath.h" + +static int8_t RQSILU_lut_s8_s8[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -3, -3, + -3, -3, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, + -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, + -3, -3, -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 4, + 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, + 127, +}; + +void RQSILU_s8_s8(int8_t *data_in, int8_t *data_out, int32_t dataSize, + int32_t input_offset); + +#endif //__DEEPLOY_BASIC_MATH_RQSILU_KERNEL_HEADER_ diff --git a/TargetLibraries/Generic/inc/kernel/SILU.h b/TargetLibraries/Generic/inc/kernel/SILU.h new file mode 100644 index 0000000000..a10af2dd74 --- /dev/null +++ b/TargetLibraries/Generic/inc/kernel/SILU.h @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __DEEPLOY_BASIC_MATH_SILU_KERNEL_HEADER_ +#define __DEEPLOY_BASIC_MATH_SILU_KERNEL_HEADER_ + +#include "DeeployBasicMath.h" + +static int32_t SILU_lut_s8_s32[256] = { + -176, -186, -196, -207, -219, -231, -244, -257, -272, + -287, -303, -320, -337, -356, -375, -396, -418, -441, + -465, -491, -517, -546, -575, -607, -639, -674, -711, + -749, -789, -832, -876, -923, -972, -1024, -1078, -1136, + -1196, -1259, -1325, -1394, -1467, -1544, -1624, -1708, -1796, + -1888, -1985, -2087, -2193, -2304, -2421, -2543, -2670, -2803, + -2943, -3088, -3240, -3399, -3564, -3737, -3917, -4105, -4300, + -4503, -4715, -4935, -5163, -5401, -5647, -5902, -6167, -6440, + -6724, -7016, -7318, -7630, -7950, -8280, -8620, -8968, -9324, + -9689, -10062, -10442, -10829, -11222, -11620, -12023, -12429, -12837, + -13245, -13654, -14060, -14462, -14858, -15246, -15624, -15989, -16339, + -16670, -16979, -17264, -17520, -17745, -17933, -18082, -18186, -18241, + -18244, -18188, -18070, -17884, -17625, -17290, -16871, -16366, -15769, + -15075, -14281, -13380, -12371, -11249, -10011, -8653, -7173, -5570, + -3840, -1984, 0, 2112, 4352, 6718, 9211, 11827, 14565, + 17423, 20397, 23484, 26679, 29981, 33383, 36882, 40473, 44150, + 47911, 51748, 55658, 59636, 63676, 67775, 71926, 76126, 80371, + 84655, 88976, 93328, 97709, 102114, 106541, 110987, 115448, 119922, + 124406, 128898, 133396, 137898, 142403, 146907, 151411, 155913, 160412, + 164906, 169395, 173878, 178354, 182823, 187284, 191736, 196180, 200616, + 205042, 209458, 213866, 218264, 222652, 227032, 231401, 235762, 240113, + 244455, 248789, 253113, 257429, 261737, 266036, 270327, 274611, 278887, + 283156, 287417, 291672, 295920, 300161, 304397, 308626, 312849, 317067, + 321280, 325487, 329689, 333887, 338080, 342268, 346452, 350632, 354808, + 358981, 363150, 367315, 371477, 375636, 379792, 383946, 388096, 392244, + 396389, 400532, 404672, 408811, 412947, 417081, 421214, 425345, 429473, + 433601, 437726, 441851, 445973, 450095, 454215, 458334, 462452, 466569, + 470684, 474799, 478912, 483025, 487137, 491248, 495359, 499468, 503577, + 507685, 511793, 515900, 520006, +}; + +void SILU_s8_s32(int8_t *data_in, int32_t *data_out, int32_t dataSize, + int32_t input_offset); + +#endif //__DEEPLOY_BASIC_MATH_SILU_KERNEL_HEADER_ diff --git a/TargetLibraries/Generic/src/RQSILU_s8.c b/TargetLibraries/Generic/src/RQSILU_s8.c new file mode 100644 index 0000000000..c26cdbd4b9 --- /dev/null +++ b/TargetLibraries/Generic/src/RQSILU_s8.c @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "DeeployBasicMath.h" + +void RQSILU_s8_s8(int8_t *data_in, int8_t *data_out, int32_t dataSize, + int32_t input_offset) { + for (int i = 0; i < dataSize; i++) { + int32_t x = data_in[i] + 128 - input_offset; + data_out[i] = RQSILU_lut_s8_s8[x]; + } +} diff --git a/TargetLibraries/Generic/src/SILU_s8.c b/TargetLibraries/Generic/src/SILU_s8.c new file mode 100644 index 0000000000..4af4d02677 --- /dev/null +++ b/TargetLibraries/Generic/src/SILU_s8.c @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "DeeployBasicMath.h" + +void SILU_s8_s32(int8_t *data_in, int32_t *data_out, int32_t dataSize, + int32_t input_offset) { + for (int i = 0; i < dataSize; i++) { + int32_t x = data_in[i] + 128 - input_offset; + data_out[i] = SILU_lut_s8_s32[x]; + } +} \ No newline at end of file diff --git a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h index f6e8308c97..edacf416c3 100644 --- a/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h +++ b/TargetLibraries/PULPOpen/inc/DeeployPULPMath.h @@ -28,8 +28,10 @@ #include "kernel/Layernorm.h" #include "kernel/Matmul.h" #include "kernel/MaxPool.h" +#include "kernel/RQSILU.h" #include "kernel/RQiHardswish.h" #include "kernel/RequantShift.h" +#include "kernel/SILU.h" #include "kernel/Softmax.h" #include "kernel/UniformRequantShift.h" #include "kernel/gemv.h" @@ -37,4 +39,4 @@ #define LOG2(x) (__builtin_pulp_fl1(x)) -#endif // __DEEPLOY_MATH_HEADER_ +#endif // __DEEPLOY_MATH_HEADER_ \ No newline at end of file diff --git a/TargetLibraries/PULPOpen/inc/kernel/RQSILU.h b/TargetLibraries/PULPOpen/inc/kernel/RQSILU.h new file mode 100644 index 0000000000..ffeb68c71a --- /dev/null +++ b/TargetLibraries/PULPOpen/inc/kernel/RQSILU.h @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __DEEPLOY_BASIC_MATH_RQSILU_KERNEL_HEADER_ +#define __DEEPLOY_BASIC_MATH_RQSILU_KERNEL_HEADER_ + +#include "DeeployBasicMath.h" + +static PI_L1 int8_t RQSILU_lut_s8_s8[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -3, -3, + -3, -3, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, + -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, + -3, -3, -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 4, + 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, + 127, +}; + +void RQSILU_s8_s8(int8_t *data_in, int8_t *data_out, int32_t dataSize, + int32_t input_offset); + +#endif //__DEEPLOY_BASIC_MATH_RQSILU_KERNEL_HEADER_ \ No newline at end of file diff --git a/TargetLibraries/PULPOpen/inc/kernel/SILU.h b/TargetLibraries/PULPOpen/inc/kernel/SILU.h new file mode 100644 index 0000000000..fbd4d48e2c --- /dev/null +++ b/TargetLibraries/PULPOpen/inc/kernel/SILU.h @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __DEEPLOY_BASIC_MATH_SILU_KERNEL_HEADER_ +#define __DEEPLOY_BASIC_MATH_SILU_KERNEL_HEADER_ + +#include "DeeployBasicMath.h" + +static PI_L1 int32_t SILU_lut_s8_s32[256] = { + -176, -186, -196, -207, -219, -231, -244, -257, -272, + -287, -303, -320, -337, -356, -375, -396, -418, -441, + -465, -491, -517, -546, -575, -607, -639, -674, -711, + -749, -789, -832, -876, -923, -972, -1024, -1078, -1136, + -1196, -1259, -1325, -1394, -1467, -1544, -1624, -1708, -1796, + -1888, -1985, -2087, -2193, -2304, -2421, -2543, -2670, -2803, + -2943, -3088, -3240, -3399, -3564, -3737, -3917, -4105, -4300, + -4503, -4715, -4935, -5163, -5401, -5647, -5902, -6167, -6440, + -6724, -7016, -7318, -7630, -7950, -8280, -8620, -8968, -9324, + -9689, -10062, -10442, -10829, -11222, -11620, -12023, -12429, -12837, + -13245, -13654, -14060, -14462, -14858, -15246, -15624, -15989, -16339, + -16670, -16979, -17264, -17520, -17745, -17933, -18082, -18186, -18241, + -18244, -18188, -18070, -17884, -17625, -17290, -16871, -16366, -15769, + -15075, -14281, -13380, -12371, -11249, -10011, -8653, -7173, -5570, + -3840, -1984, 0, 2112, 4352, 6718, 9211, 11827, 14565, + 17423, 20397, 23484, 26679, 29981, 33383, 36882, 40473, 44150, + 47911, 51748, 55658, 59636, 63676, 67775, 71926, 76126, 80371, + 84655, 88976, 93328, 97709, 102114, 106541, 110987, 115448, 119922, + 124406, 128898, 133396, 137898, 142403, 146907, 151411, 155913, 160412, + 164906, 169395, 173878, 178354, 182823, 187284, 191736, 196180, 200616, + 205042, 209458, 213866, 218264, 222652, 227032, 231401, 235762, 240113, + 244455, 248789, 253113, 257429, 261737, 266036, 270327, 274611, 278887, + 283156, 287417, 291672, 295920, 300161, 304397, 308626, 312849, 317067, + 321280, 325487, 329689, 333887, 338080, 342268, 346452, 350632, 354808, + 358981, 363150, 367315, 371477, 375636, 379792, 383946, 388096, 392244, + 396389, 400532, 404672, 408811, 412947, 417081, 421214, 425345, 429473, + 433601, 437726, 441851, 445973, 450095, 454215, 458334, 462452, 466569, + 470684, 474799, 478912, 483025, 487137, 491248, 495359, 499468, 503577, + 507685, 511793, 515900, 520006, +}; + +void SILU_s8_s32(int8_t *data_in, int32_t *data_out, int32_t dataSize, + int32_t input_offset); + +#endif //__DEEPLOY_BASIC_MATH_SILU_KERNEL_HEADER_ \ No newline at end of file diff --git a/TargetLibraries/PULPOpen/src/RQSILU_s8.c b/TargetLibraries/PULPOpen/src/RQSILU_s8.c new file mode 100644 index 0000000000..c26cdbd4b9 --- /dev/null +++ b/TargetLibraries/PULPOpen/src/RQSILU_s8.c @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "DeeployBasicMath.h" + +void RQSILU_s8_s8(int8_t *data_in, int8_t *data_out, int32_t dataSize, + int32_t input_offset) { + for (int i = 0; i < dataSize; i++) { + int32_t x = data_in[i] + 128 - input_offset; + data_out[i] = RQSILU_lut_s8_s8[x]; + } +} diff --git a/TargetLibraries/PULPOpen/src/SILU_s8.c b/TargetLibraries/PULPOpen/src/SILU_s8.c new file mode 100644 index 0000000000..4af4d02677 --- /dev/null +++ b/TargetLibraries/PULPOpen/src/SILU_s8.c @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2022 ETH Zurich and University of Bologna + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "DeeployBasicMath.h" + +void SILU_s8_s32(int8_t *data_in, int32_t *data_out, int32_t dataSize, + int32_t input_offset) { + for (int i = 0; i < dataSize; i++) { + int32_t x = data_in[i] + 128 - input_offset; + data_out[i] = SILU_lut_s8_s32[x]; + } +} \ No newline at end of file