diff options
Diffstat (limited to 'reference_model/src/ops/ewise_ternary.h')
-rw-r--r-- | reference_model/src/ops/ewise_ternary.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/reference_model/src/ops/ewise_ternary.h b/reference_model/src/ops/ewise_ternary.h new file mode 100644 index 0000000..b354247 --- /dev/null +++ b/reference_model/src/ops/ewise_ternary.h @@ -0,0 +1,83 @@ + +// Copyright (c) 2020, ARM Limited. +// +// 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 +// +// http://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. + +#ifndef OPS_TERNARY_H +#define OPS_TERNARY_H + +#include "graph_node.h" + +using namespace tosa; + +namespace TosaReference +{ + +// The Ternary Select op has the following operands: +// 1. Cond: rank N, type=bool +// 2. Then_val: Rank N, type=<V> +// 3. Else_val: Rank N, type=<V> +// 4. Result: Rank N, type=<V> +// Cond, Then_val, Else_val need to be mutually-broadcastable +template <int Rank, DType Dtype> +class OpSelectBase : public GraphNode +{ +public: + OpSelectBase(TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_); + virtual ~OpSelectBase(); + + virtual int checkTensorAttributes(); + virtual int eval(); + + using CondEigenType = typename GetEigenType<DType_BOOL>::type; + using InEigenType = typename GetEigenType<Dtype>::type; + using TCond = Eigen::Tensor<CondEigenType, Rank>; + using TIn = Eigen::Tensor<InEigenType, Rank>; + +protected: + TosaReference::TensorTemplate<TCond>* cond; + Eigen::array<int, Rank> bcast_cond; + Eigen::array<int, Rank> bcast_then; + Eigen::array<int, Rank> bcast_else; + TosaReference::TensorTemplate<TIn>* then_val; + TosaReference::TensorTemplate<TIn>* else_val; + TosaReference::TensorTemplate<TIn>* out; +}; + +// primary class +template <int Rank, DType Dtype> +class OpSelect : public OpSelectBase<Rank, Dtype> +{ +public: + OpSelect(TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) + : OpSelectBase<Rank, Dtype>(attribute_, qinfo_, id_) + {} + virtual int eval(); + int broadcast(); + + using InEigenType = typename OpSelectBase<Rank, Dtype>::InEigenType; +}; + +// partial specialization for rank 0 +template <DType Dtype> +class OpSelect<0, Dtype> : public OpSelectBase<0, Dtype> +{ +public: + OpSelect(TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) + : OpSelectBase<0, Dtype>(attribute_, qinfo_, id_) + {} + virtual int eval(); +}; +}; // namespace TosaReference + +#endif |