Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
Jerry Ge | a682749 | 2022-11-16 10:41:55 -0800 | [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 | #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: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 31 | OpClamp(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 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 | } |
Jerry Ge | a682749 | 2022-11-16 10:41:55 -0800 | [diff] [blame] | 37 | virtual ~OpClamp(); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 38 | static constexpr int32_t QMin = GetQMin<Dtype>::value; |
| 39 | static constexpr int32_t QMax = GetQMax<Dtype>::value; |
| 40 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 41 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 42 | virtual int register_fcn(); |
| 43 | |
| 44 | protected: |
| 45 | TosaClampAttribute* attribute; |
| 46 | }; |
| 47 | |
| 48 | template <int Rank, DType Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 49 | class OpSigmoid : public UnaryNode<Rank, Dtype> |
| 50 | { |
| 51 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 52 | OpSigmoid(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 53 | : UnaryNode<Rank, Dtype>(sgt_, Op_SIGMOID, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 54 | { |
| 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 | |
| 64 | template <int Rank, DType Dtype> |
| 65 | class OpTanh : public UnaryNode<Rank, Dtype> |
| 66 | { |
| 67 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 68 | OpTanh(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 69 | : UnaryNode<Rank, Dtype>(sgt_, Op_TANH, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 70 | { |
| 71 | register_fcn(); |
| 72 | } |
| 73 | static constexpr int32_t QMin = GetQMin<Dtype>::value; |
| 74 | static constexpr int32_t QMax = GetQMax<Dtype>::value; |
| 75 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 76 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 77 | virtual int register_fcn(); |
| 78 | }; |
| 79 | |
| 80 | }; // namespace TosaReference |
| 81 | |
| 82 | #endif |