Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
| 2 | // Copyright (c) 2020, ARM Limited. |
| 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 | #ifndef OPS_ACTIVATION_FUNCS_H |
| 17 | #define OPS_ACTIVATION_FUNCS_H |
| 18 | |
| 19 | #include "ewise_unary.h" |
| 20 | #include "graph_node.h" |
| 21 | |
| 22 | using namespace tosa; |
| 23 | |
| 24 | namespace TosaReference |
| 25 | { |
| 26 | |
| 27 | template <int Rank, DType Dtype> |
| 28 | class OpClamp : public UnaryNode<Rank, Dtype> |
| 29 | { |
| 30 | public: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame^] | 31 | OpClamp(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) |
| 32 | : UnaryNode<Rank, Dtype>(sgt_, Op_CLAMP, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 33 | { |
| 34 | INIT_ATTRIBUTE(Clamp); |
| 35 | register_fcn(); |
| 36 | } |
| 37 | static constexpr int32_t QMin = GetQMin<Dtype>::value; |
| 38 | static constexpr int32_t QMax = GetQMax<Dtype>::value; |
| 39 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 40 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 41 | virtual int register_fcn(); |
| 42 | |
| 43 | protected: |
| 44 | TosaClampAttribute* attribute; |
| 45 | }; |
| 46 | |
| 47 | template <int Rank, DType Dtype> |
| 48 | class OpReluN : public UnaryNode<Rank, Dtype> |
| 49 | { |
| 50 | public: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame^] | 51 | OpReluN(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) |
| 52 | : UnaryNode<Rank, Dtype>(sgt_, Op_RELUN, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 53 | { |
| 54 | INIT_ATTRIBUTE(ReluN); |
| 55 | register_fcn(); |
| 56 | } |
| 57 | static constexpr int32_t QMin = GetQMin<Dtype>::value; |
| 58 | static constexpr int32_t QMax = GetQMax<Dtype>::value; |
| 59 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 60 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 61 | virtual int register_fcn(); |
| 62 | |
| 63 | protected: |
| 64 | TosaReluNAttribute* attribute; |
| 65 | }; |
| 66 | |
| 67 | template <int Rank, DType Dtype> |
| 68 | class OpSigmoid : public UnaryNode<Rank, Dtype> |
| 69 | { |
| 70 | public: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame^] | 71 | OpSigmoid(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) |
| 72 | : UnaryNode<Rank, Dtype>(sgt_, Op_SIGMOID, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 73 | { |
| 74 | register_fcn(); |
| 75 | } |
| 76 | static constexpr int32_t QMin = GetQMin<Dtype>::value; |
| 77 | static constexpr int32_t QMax = GetQMax<Dtype>::value; |
| 78 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 79 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 80 | virtual int register_fcn(); |
| 81 | }; |
| 82 | |
| 83 | template <int Rank, DType Dtype> |
| 84 | class OpTanh : public UnaryNode<Rank, Dtype> |
| 85 | { |
| 86 | public: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame^] | 87 | OpTanh(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, TosaQuantInfoBase* qinfo_, uint64_t id_) |
| 88 | : UnaryNode<Rank, Dtype>(sgt_, Op_TANH, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 89 | { |
| 90 | register_fcn(); |
| 91 | } |
| 92 | static constexpr int32_t QMin = GetQMin<Dtype>::value; |
| 93 | static constexpr int32_t QMax = GetQMax<Dtype>::value; |
| 94 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 95 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 96 | virtual int register_fcn(); |
| 97 | }; |
| 98 | |
| 99 | }; // namespace TosaReference |
| 100 | |
| 101 | #endif |