// 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= // 3. Else_val: Rank N, type= // 4. Result: Rank N, type= // Cond, Then_val, Else_val need to be mutually-broadcastable template 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::type; using InEigenType = typename GetEigenType::type; using TCond = Eigen::Tensor; using TIn = Eigen::Tensor; protected: TosaReference::TensorTemplate* cond; Eigen::array bcast_cond; Eigen::array bcast_then; Eigen::array bcast_else; TosaReference::TensorTemplate* then_val; TosaReference::TensorTemplate* else_val; TosaReference::TensorTemplate* out; }; // primary class template class OpSelect : public OpSelectBase { public: OpSelect(TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) : OpSelectBase(attribute_, qinfo_, id_) {} virtual int eval(); int broadcast(); using InEigenType = typename OpSelectBase::InEigenType; }; // partial specialization for rank 0 template 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