diff options
author | Tai Ly <tai.ly@arm.com> | 2024-03-01 20:59:32 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2024-03-06 18:27:07 +0000 |
commit | 6e1e2bc06bff785e87577f24064bbc846300f8fd (patch) | |
tree | 0a96aeac6f88799fbc297e5937cc0ffc44adcfff /reference_model | |
parent | 1d5ddeda5d853642fe3b2eade7d765386727021f (diff) | |
download | reference_model-6e1e2bc06bff785e87577f24064bbc846300f8fd.tar.gz |
[ref model] Change RescaleOp attrs to inputs
This patch implements changes required for RescaleOp's
multiplier and shift changing from attributes to inputs
Signed-off-by: Tai Ly <tai.ly@arm.com>
Change-Id: I178919727e3220c749dad0ebce141e695868fee0
Diffstat (limited to 'reference_model')
-rw-r--r-- | reference_model/src/ops/type_conversion.cc | 56 | ||||
-rw-r--r-- | reference_model/src/ops/type_conversion.h | 17 |
2 files changed, 59 insertions, 14 deletions
diff --git a/reference_model/src/ops/type_conversion.cc b/reference_model/src/ops/type_conversion.cc index 5dbc7bd..d58cfeb 100644 --- a/reference_model/src/ops/type_conversion.cc +++ b/reference_model/src/ops/type_conversion.cc @@ -35,7 +35,7 @@ template <int Rank, TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype> OpRescale<Rank, InDtype, OutDtype>::OpRescale(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) : GraphNode(sgt_, Op_RESCALE, id_) { - setRequiredOperands(1, 1); + setRequiredOperands(3, 1); INIT_ATTRIBUTE(Rescale); } @@ -68,6 +68,20 @@ int OpRescale<Rank, InDtype, OutDtype>::checkTensorAttributes() ASSERT_MEM(in && out); + multiplierI32 = dynamic_cast<TosaReference::TensorTemplate<TMultiplierI32>*>(inputs[1]); + multiplierI16 = dynamic_cast<TosaReference::TensorTemplate<TMultiplierI16>*>(inputs[1]); + shift = dynamic_cast<TosaReference::TensorTemplate<TShift>*>(inputs[2]); + ASSERT_MEM(shift); + + if (attribute->scale32()) + { + ASSERT_MEM(multiplierI32); + } + else + { + ASSERT_MEM(multiplierI16); + } + if ((InDtype != TOSA_REF_TYPE_INT8) && (InDtype != TOSA_REF_TYPE_UINT8) && (InDtype != TOSA_REF_TYPE_UINT16) && (attribute->input_zp() != 0)) { @@ -124,15 +138,15 @@ static int64_t zero_extend(int16_t val) template <int Rank, TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype> int OpRescale<Rank, InDtype, OutDtype>::eval() { - int32_t input_zp = attribute->input_zp(); - int32_t output_zp = attribute->output_zp(); - std::vector<int32_t> multiplier = attribute->multiplier(); - std::vector<int32_t> shift = attribute->shift(); - bool scale32 = attribute->scale32(); - bool double_round = attribute->double_round(); - bool per_channel = attribute->per_channel(); - bool input_unsigned = attribute->input_unsigned(); - bool output_unsigned = attribute->output_unsigned(); + int32_t input_zp = attribute->input_zp(); + int32_t output_zp = attribute->output_zp(); + std::vector<int32_t> multiplier; + std::vector<int32_t> shift; + bool scale32 = attribute->scale32(); + bool double_round = attribute->double_round(); + bool per_channel = attribute->per_channel(); + bool input_unsigned = attribute->input_unsigned(); + bool output_unsigned = attribute->output_unsigned(); // reshape [d0, d1, ..., dn] into [d0 * d1 ..., dn] Eigen::array<Eigen::Index, 2> shape_2d; @@ -153,6 +167,28 @@ int OpRescale<Rank, InDtype, OutDtype>::eval() ETensor2<OutEigenType> output_2d(shape_2d); + if (scale32) + { + auto multiplier_val = this->multiplierI32->getTensor(); + for (int i = 0; i < multiplier_val.size(); i++) + { + multiplier.push_back(static_cast<int32_t>(multiplier_val(i))); + } + } + else + { + auto multiplier_val = this->multiplierI16->getTensor(); + for (int i = 0; i < multiplier_val.size(); i++) + { + multiplier.push_back(static_cast<int32_t>(multiplier_val(i))); + } + } + auto shift_val = this->shift->getTensor(); + for (int i = 0; i < shift_val.size(); i++) + { + shift.push_back(static_cast<int32_t>(shift_val(i))); + } + if (per_channel) { ETensor2<InEigenType> curr_channel_slice_prescaled; diff --git a/reference_model/src/ops/type_conversion.h b/reference_model/src/ops/type_conversion.h index 75f244d..a06dccc 100644 --- a/reference_model/src/ops/type_conversion.h +++ b/reference_model/src/ops/type_conversion.h @@ -32,10 +32,16 @@ public: virtual int checkTensorAttributes() final; virtual int eval() final; - using InEigenType = typename GetEigenType<InDtype>::type; - using OutEigenType = typename GetEigenType<OutDtype>::type; - using TIn = Eigen::Tensor<InEigenType, Rank>; - using TOut = Eigen::Tensor<OutEigenType, Rank>; + using InEigenType = typename GetEigenType<InDtype>::type; + using OutEigenType = typename GetEigenType<OutDtype>::type; + using TIn = Eigen::Tensor<InEigenType, Rank>; + using TOut = Eigen::Tensor<OutEigenType, Rank>; + using I8EigenType = typename GetEigenType<TOSA_REF_TYPE::TOSA_REF_TYPE_INT8>::type; + using I16EigenType = typename GetEigenType<TOSA_REF_TYPE::TOSA_REF_TYPE_INT16>::type; + using I32EigenType = typename GetEigenType<TOSA_REF_TYPE::TOSA_REF_TYPE_INT32>::type; + using TMultiplierI16 = Eigen::Tensor<I16EigenType, 1>; + using TMultiplierI32 = Eigen::Tensor<I32EigenType, 1>; + using TShift = Eigen::Tensor<I8EigenType, 1>; static constexpr int32_t QMin = GetQMin<OutDtype>::value; static constexpr int32_t QMax = GetQMax<OutDtype>::value; @@ -44,6 +50,9 @@ protected: TosaRescaleAttribute* attribute; TosaReference::TensorTemplate<TIn>* in; TosaReference::TensorTemplate<TOut>* out; + TosaReference::TensorTemplate<TMultiplierI16>* multiplierI16; + TosaReference::TensorTemplate<TMultiplierI32>* multiplierI32; + TosaReference::TensorTemplate<TShift>* shift; }; template <TOSA_REF_TYPE InDtype, TOSA_REF_TYPE OutDtype> |