From: 남궁석/On-Device Lab(SR)/Engineer/삼성전자 Date: Thu, 22 Aug 2019 08:05:04 +0000 (+0900) Subject: [loco] Introduce Tanh Operation (#6830) X-Git-Tag: accepted/tizen/unified/20190903.052428~203 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6213a391c0e2bece4c7eaa3bd542bd2358cf8781;p=platform%2Fcore%2Fml%2Fnnfw.git [loco] Introduce Tanh Operation (#6830) This commit will introduce `Tanh` operation in loco Signed-off-by: Seok NamKoong --- diff --git a/compiler/loco/include/loco/IR/CanonicalNodes.lst b/compiler/loco/include/loco/IR/CanonicalNodes.lst index 094ee81..2acc259 100644 --- a/compiler/loco/include/loco/IR/CanonicalNodes.lst +++ b/compiler/loco/include/loco/IR/CanonicalNodes.lst @@ -31,6 +31,7 @@ CANONICAL_NODE(Push, Push) CANONICAL_NODE(Pull, Pull) CANONICAL_NODE(ReLU, ReLU) CANONICAL_NODE(ReLU6, ReLU6) +CANONICAL_NODE(Tanh, Tanh) CANONICAL_NODE(TensorConcat, TensorConcat) CANONICAL_NODE(TensorBiasAdd, BiasAdd) CANONICAL_NODE(TensorSoftmax, Softmax) diff --git a/compiler/loco/include/loco/IR/Nodes.h b/compiler/loco/include/loco/IR/Nodes.h index d86ed56..9f4a73d 100644 --- a/compiler/loco/include/loco/IR/Nodes.h +++ b/compiler/loco/include/loco/IR/Nodes.h @@ -182,6 +182,19 @@ public: }; /** + * @brief Create a new value that rectifies its input by tanh + */ +class Tanh final : public CanonicalNodeDef::Mixin> +{ +public: + Tanh() = default; + +public: + Node *input(void) const { return at(0)->node(); } + void input(Node *node) { at(0)->node(node); } +}; + +/** * @brief Create a value from constant byte array * * @note ConstGen assumes "lexical memory layout". diff --git a/compiler/loco/src/Service/CanonicalShapeInferenceRule.cpp b/compiler/loco/src/Service/CanonicalShapeInferenceRule.cpp index d561878..4e6a466 100644 --- a/compiler/loco/src/Service/CanonicalShapeInferenceRule.cpp +++ b/compiler/loco/src/Service/CanonicalShapeInferenceRule.cpp @@ -409,6 +409,9 @@ public: // CASE: ReLU6 loco::NodeShape visit(const loco::ReLU6 *node) final { return loco::shape_get(node->input()); } + // CASE: Tanh + loco::NodeShape visit(const loco::Tanh *node) final { return loco::shape_get(node->input()); } + // CASE: TensorBiasAdd loco::NodeShape visit(const loco::TensorBiasAdd *node) final { diff --git a/compiler/loco/src/Service/TypeInference.cpp b/compiler/loco/src/Service/TypeInference.cpp index 2cf1716..3c47ed9 100644 --- a/compiler/loco/src/Service/TypeInference.cpp +++ b/compiler/loco/src/Service/TypeInference.cpp @@ -119,6 +119,7 @@ struct CanonicalTypeForwardAlgorithm final : public loco::CanonicalNodeVisitordtype(); } loco::DataType visit(const loco::ReLU *node) { return loco::dtype_get(node->input()); } loco::DataType visit(const loco::ReLU6 *node) { return loco::dtype_get(node->input()); } + loco::DataType visit(const loco::Tanh *node) { return loco::dtype_get(node->input()); } loco::DataType visit(const loco::TensorConcat *node) { return loco::dtype_get(node->lhs()); } loco::DataType visit(const loco::TensorBiasAdd *node) { return loco::dtype_get(node->value()); } loco::DataType visit(const loco::TensorSoftmax *node) { return loco::dtype_get(node->input()); }