diff --git a/aidge_export_cpp/operators/CppActivation.py b/aidge_export_cpp/operators/CppActivation.py index b8c936731651dcc239acc968288833d90395485e..7d8193906dd00a844b8606d8217670046f5843f4 100644 --- a/aidge_export_cpp/operators/CppActivation.py +++ b/aidge_export_cpp/operators/CppActivation.py @@ -1,7 +1,6 @@ import aidge_core from aidge_core.export_utils import ExportNodeCpp -from aidge_export_cpp import ROOT -from aidge_export_cpp import ExportLibCpp +from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes @ExportLibCpp.register_metaop("CppActivation", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any))) class CppActivation(ExportNodeCpp): @@ -21,17 +20,8 @@ class CppActivation(ExportNodeCpp): for n in node.get_operator().get_micro_graph().get_nodes(): if n.type() == "ReLU": self.attributes["activation"] = "Rectifier" - - ## Get the scaling values - for prod in node.get_parents(): - if prod is not None: - if prod.type() == "Producer": - if prod.attributes().has_attr("quantization.ptq.ShiftAmount"): - self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount - # elif prod.attributes().has_attr("quantization.ptq.CompensationCoeff"): - # self.attributes["coef_value"] = prod.attributes().quantization.ptq.CompensationCoeff - else: - self.attributes["coef_value"] = prod.get_operator().get_output(0)[0] + elif n.type() == "Quantizer": + set_scaling_attributes(self, n) ## Set the scaling type if self.attributes["coef_value"] != 1: diff --git a/aidge_export_cpp/operators/CppConv.py b/aidge_export_cpp/operators/CppConv.py index 40b75777c3d49e9051a5a80498aa04171f2560a1..8cc28d452ba6b9cdd3b8875e93f66f69521f2994 100644 --- a/aidge_export_cpp/operators/CppConv.py +++ b/aidge_export_cpp/operators/CppConv.py @@ -1,7 +1,6 @@ import aidge_core from aidge_core.export_utils import ExportNodeCpp -from aidge_export_cpp import ROOT -from aidge_export_cpp import ExportLibCpp +from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes @ExportLibCpp.register_metaop("CppConv", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any))) class CppConv(ExportNodeCpp): @@ -27,13 +26,8 @@ class CppConv(ExportNodeCpp): self.attributes["kernel_dims"] = n.get_operator().attr.kernel_dims self.attributes["stride_dims"] = n.get_operator().attr.stride_dims self.attributes["dilation_dims"] = n.get_operator().attr.dilation_dims - - ## Get the scaling values - for prod in node.get_parents(): - if prod is not None: - if prod.type() == "Producer": - if prod.attributes().has_attr("quantization.ptq.ShiftAmount"): - self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount + elif n.type() == "Quantizer": + set_scaling_attributes(self, n) ## Set the scaling type if self.attributes["shift_value"] != 0: diff --git a/aidge_export_cpp/operators/CppElemWise.py b/aidge_export_cpp/operators/CppElemWise.py index 9f4f20a8074cabbe00c2391d74471df6cc7f18dd..fd4bb265696c6596f758b727bd46145b18a20526 100644 --- a/aidge_export_cpp/operators/CppElemWise.py +++ b/aidge_export_cpp/operators/CppElemWise.py @@ -1,8 +1,6 @@ import aidge_core from aidge_core.export_utils import ExportNodeCpp -from aidge_export_cpp import ROOT -from aidge_export_cpp import ExportLibCpp -from aidge_export_cpp import set_scaling_attributes +from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes @ExportLibCpp.register_metaop("CppElemWise", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any))) class CppElemWise(ExportNodeCpp): @@ -27,17 +25,6 @@ class CppElemWise(ExportNodeCpp): elif n.type() == "Quantizer": set_scaling_attributes(self, n) - ## Get the scaling values - # for node in node.get_parents(): - # if node is not None: - # if node.type() == "Producer": - # if node.attributes().has_attr("quantization.ptq.ShiftAmount"): - # self.attributes["shift_value"] = node.attributes().quantization.ptq.ShiftAmount - # # elif node.attributes().has_attr("quantization.ptq.CompensationCoeff"): - # # self.attributes["coef_value"] = node.attributes().quantization.ptq.CompensationCoeff - # else: - # self.attributes["coef_value"] = node.get_operator().get_output(0)[0] - ## Set the scaling type if self.attributes["coef_value"] != 1: self.attributes["rescaling"] = "FixedPointScaling" diff --git a/aidge_export_cpp/operators/CppFc.py b/aidge_export_cpp/operators/CppFc.py index 9758b1aa7d94ef5b0e07cf6bbd8007909a0b6507..8b10d914d1f15453c73bb323bf2e767e41e3ad69 100644 --- a/aidge_export_cpp/operators/CppFc.py +++ b/aidge_export_cpp/operators/CppFc.py @@ -1,7 +1,6 @@ import aidge_core from aidge_core.export_utils import ExportNodeCpp -from aidge_export_cpp import ROOT -from aidge_export_cpp import ExportLibCpp +from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes @ExportLibCpp.register_metaop("CppFc", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any))) class CppFc(ExportNodeCpp): @@ -25,13 +24,8 @@ class CppFc(ExportNodeCpp): for n in node.get_operator().get_micro_graph().get_nodes(): if n.type() == "ReLU": self.attributes["activation"] = "Rectifier" - - ## Get the scaling values - for prod in node.get_parents(): - if prod is not None: - if prod.type() == "Producer": - if prod.attributes().has_attr("quantization.ptq.ShiftAmount"): - self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount + elif n.type() == "Quantizer": + set_scaling_attributes(self, n) ## Set the scaling type if self.attributes["shift_value"] != 0: diff --git a/aidge_export_cpp/operators/CppRescaling.py b/aidge_export_cpp/operators/CppRescaling.py index 96e395ac504387258a1436c7fb749408766ae173..69c1ec50b8b23e499953b21c4b40af46bf60b641 100644 --- a/aidge_export_cpp/operators/CppRescaling.py +++ b/aidge_export_cpp/operators/CppRescaling.py @@ -1,9 +1,8 @@ import aidge_core from aidge_core.export_utils import ExportNodeCpp -from aidge_export_cpp import ROOT -from aidge_export_cpp import ExportLibCpp +from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes -@ExportLibCpp.register_metaop("CppRescaling", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any))) +@ExportLibCpp.register_metaop("Quantizer", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any))) class CppRescaling(ExportNodeCpp): def __init__(self, node, mem_info): super().__init__(node, mem_info) @@ -14,23 +13,13 @@ class CppRescaling(ExportNodeCpp): self.attributes["shift_value"] = 0 self.attributes["coef_value"] = 1 - # Browse the metaop to update kernel attributes for n in node.get_operator().get_micro_graph().get_nodes(): if n.type() == "ReLU": self.attributes["activation"] = "Rectifier" - - - ## Get the scaling values - for prod in node.get_parents(): - if prod is not None: - if prod.type() == "Producer": - if prod.attributes().has_attr("quantization.ptq.ShiftAmount"): - self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount -# elif prod.attributes().has_attr("quantization.ptq.CompensationCoeff"): -# self.attributes["coef_value"] = prod.attributes().quantization.ptq.CompensationCoeff - else: - self.attributes["coef_value"] = prod.get_operator().get_output(0)[0] + + # Set scaling attributes + set_scaling_attributes(self, node) ## Set the scaling type if self.attributes["coef_value"] != 1: