Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 2 | // Copyright (c) 2020-2022, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | #include "data_nodes.h" |
| 17 | |
| 18 | using namespace TosaReference; |
| 19 | using namespace Eigen; |
| 20 | using namespace tosa; |
| 21 | |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 22 | OpConst::OpConst(SubgraphTraverser* sgt_, uint64_t id_) |
| 23 | : GraphNode(sgt_, Op_CONST, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 24 | { |
| 25 | setRequiredOperands(0, 1); |
| 26 | } |
| 27 | |
| 28 | OpConst::~OpConst() |
| 29 | {} |
| 30 | |
| 31 | int OpConst::checkTensorAttributes() |
| 32 | { |
| 33 | if (validateRequiredOperands()) |
| 34 | return 1; |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | int OpConst::eval() |
| 40 | { |
| 41 | // Evaluation is trivial for constants |
| 42 | return GraphNode::eval(); |
| 43 | } |
| 44 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 45 | template <int Rank, DType Dtype> |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 46 | OpIdentity<Rank, Dtype>::OpIdentity(SubgraphTraverser* sgt_, |
| 47 | TosaAttributeBase* attribute_, |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 48 | uint64_t id_) |
| 49 | : GraphNode(sgt_, Op_IDENTITY, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 50 | { |
| 51 | setRequiredOperands(1, 1); |
| 52 | setRequiredRank(0, 6); |
| 53 | } |
| 54 | |
| 55 | template <int Rank, DType Dtype> |
| 56 | OpIdentity<Rank, Dtype>::~OpIdentity() |
| 57 | {} |
| 58 | |
| 59 | template <int Rank, DType Dtype> |
| 60 | int OpIdentity<Rank, Dtype>::checkTensorAttributes() |
| 61 | { |
| 62 | |
| 63 | if (inputs.size() != outputs.size()) |
| 64 | { |
| 65 | printNodeValidationError("Input and output tensor list lengths are not equal"); |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | in = dynamic_cast<TosaReference::TensorTemplate<TIn>*>(inputs[0]); |
| 70 | out = dynamic_cast<TosaReference::TensorTemplate<TOut>*>(outputs[0]); |
| 71 | |
| 72 | if (in->matchRankTypeShape(*out)) |
| 73 | { |
| 74 | printNodeValidationError("Input and output tensor rank, type, or shape do not match"); |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | template <int Rank, DType Dtype> |
| 82 | int OpIdentity<Rank, Dtype>::eval() |
| 83 | { |
| 84 | out->getTensor() = in->getTensor(); |
| 85 | |
| 86 | return GraphNode::eval(); |
| 87 | } |
| 88 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 89 | // template explicit instantiation |
Kevin Cheng | 14d7f7a | 2021-05-12 10:44:49 -0700 | [diff] [blame] | 90 | // note OpConst is not templated |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 91 | |
James Ward | 8b39043 | 2022-08-12 20:48:56 +0100 | [diff] [blame] | 92 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, FP16); |
James Ward | 24dbc42 | 2022-10-19 12:20:31 +0100 | [diff] [blame] | 93 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, BF16); |
Jeremy Johnson | bc2a3db | 2022-09-27 13:50:00 +0100 | [diff] [blame] | 94 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, FP32); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 95 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, INT8); |
| 96 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, INT16); |
| 97 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, INT32); |
| 98 | DEF_INSTANTIATE_RANK0_6_ONE_RANK_ONE_TYPE(OpIdentity, BOOL); |