diff --git a/Deeploy/Targets/Generic/Templates/RQAddTemplate.py b/Deeploy/Targets/Generic/Templates/RQAddTemplate.py new file mode 100644 index 00000000..cfdf1548 --- /dev/null +++ b/Deeploy/Targets/Generic/Templates/RQAddTemplate.py @@ -0,0 +1,46 @@ +# ---------------------------------------------------------------------- +# +# File: RQAddTemplate.py +# +# Last edited: 11.11.2023 +# +# Copyright (C) 2023, ETH Zurich and University of Bologna. +# +# Author: Moritz Scherer, ETH Zurich +# +# ---------------------------------------------------------------------- +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the License); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an AS IS BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import Dict, List, Tuple + +from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation + + +class RQAddTemplate(NodeTemplate): + + def __init__(self, templateStr): + super().__init__(templateStr) + + def alignToContext(self, ctxt: NetworkContext, + operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: + # Extract signedness information of input, weights and output + signedI2 = ctxt.lookup(operatorRepresentation['data_in_2'])._type.referencedType.typeMin < 0 + signedI = ctxt.lookup(operatorRepresentation['data_in_1'])._type.referencedType.typeMin < 0 + signedO = ctxt.lookup(operatorRepresentation['data_out'])._type.referencedType.typeMin < 0 + operatorRepresentation['input_2_signed'] = signedI2 + operatorRepresentation['input_signed'] = signedI + operatorRepresentation['output_signed'] = signedO + + return ctxt, operatorRepresentation, [] \ No newline at end of file diff --git a/Deeploy/Targets/PULPOpen/Templates/RQAddTemplate.py b/Deeploy/Targets/PULPOpen/Templates/RQAddTemplate.py index 49ede2b6..f8a79dab 100644 --- a/Deeploy/Targets/PULPOpen/Templates/RQAddTemplate.py +++ b/Deeploy/Targets/PULPOpen/Templates/RQAddTemplate.py @@ -23,30 +23,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict, List, Tuple -from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation +from Deeploy.Targets.Generic.Templates.RQAddTemplate import RQAddTemplate - -class PULPRQAddTemplate(NodeTemplate): - - def __init__(self, templateStr): - super().__init__(templateStr) - - def alignToContext(self, ctxt: NetworkContext, - operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: - # Extract signedness information of input, weights and output - signedI2 = ctxt.lookup(operatorRepresentation['data_in_2'])._type.referencedType.typeMin < 0 - signedI = ctxt.lookup(operatorRepresentation['data_in_1'])._type.referencedType.typeMin < 0 - signedO = ctxt.lookup(operatorRepresentation['data_out'])._type.referencedType.typeMin < 0 - operatorRepresentation['input_2_signed'] = signedI2 - operatorRepresentation['input_signed'] = signedI - operatorRepresentation['output_signed'] = signedO - - return ctxt, operatorRepresentation, [] - - -RQAddTemplate = PULPRQAddTemplate(""" +referenceTemplate = RQAddTemplate(""" <% signatureString = '' diff --git a/Deeploy/Targets/Snitch/Parser.py b/Deeploy/Targets/Snitch/Parsers.py similarity index 100% rename from Deeploy/Targets/Snitch/Parser.py rename to Deeploy/Targets/Snitch/Parsers.py diff --git a/Deeploy/Targets/Snitch/Templates/RQAddTemplate.py b/Deeploy/Targets/Snitch/Templates/RQAddTemplate.py index 2a49a3b4..aa1d090d 100644 --- a/Deeploy/Targets/Snitch/Templates/RQAddTemplate.py +++ b/Deeploy/Targets/Snitch/Templates/RQAddTemplate.py @@ -25,30 +25,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict, List, Tuple +from Deeploy.Targets.Generic.Templates.RQAddTemplate import RQAddTemplate -from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation - -class SnitchRQAddTemplate(NodeTemplate): - - def __init__(self, templateStr): - super().__init__(templateStr) - - def alignToContext(self, ctxt: NetworkContext, - operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: - # Extract signedness information of input, weights and output - signedI2 = ctxt.lookup(operatorRepresentation['data_in_2'])._type.referencedType.typeMin < 0 - signedI = ctxt.lookup(operatorRepresentation['data_in_1'])._type.referencedType.typeMin < 0 - signedO = ctxt.lookup(operatorRepresentation['data_out'])._type.referencedType.typeMin < 0 - operatorRepresentation['input_2_signed'] = signedI2 - operatorRepresentation['input_signed'] = signedI - operatorRepresentation['output_signed'] = signedO - - return ctxt, operatorRepresentation, [] - - -referenceTemplate = SnitchRQAddTemplate(""" +referenceTemplate = RQAddTemplate(""" <% signatureString = '' @@ -67,5 +47,5 @@ def alignToContext(self, ctxt: NetworkContext, %> // PULP NN RQADD -pulp_nn_add${signatureString}(${data_in_1}, ${data_in_2}, ${data_out}, ${rqs1_mul}, ${rqs1_add}, ${rqs1_log2D}, ${rqs2_mul}, ${rqs2_add}, ${rqs2_log2D}, ${rqsOut_mul}, ${rqsOut_add}, ${rqsOut_log2D}, 1, ${size}, 1, 1); +snitch_add${signatureString}(${data_in_1}, ${data_in_2}, ${data_out}, ${rqs1_mul}, ${rqs1_add}, ${rqs1_log2D}, ${rqs2_mul}, ${rqs2_add}, ${rqs2_log2D}, ${rqsOut_mul}, ${rqsOut_add}, ${rqsOut_log2D}, 1, ${size}, 1, 1); """)