summaryrefslogtreecommitdiff
path: root/compiler/exo-tflite
diff options
context:
space:
mode:
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>2019-09-16 17:23:13 +0900
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-09-16 17:23:13 +0900
commit74958097c4a0de495fda45e7226f74d9eb65f326 (patch)
treed6ed2e1e9168cc1a5513888a08d90d59fa9a558c /compiler/exo-tflite
parentddf7a27b59078bde5b0bd3fb25c60cfc1e41c71a (diff)
downloadnnfw-74958097c4a0de495fda45e7226f74d9eb65f326.tar.gz
nnfw-74958097c4a0de495fda45e7226f74d9eb65f326.tar.bz2
nnfw-74958097c4a0de495fda45e7226f74d9eb65f326.zip
[exo-tflite] Convert EltwiseMul (#7459)
This will introduce EltwiseMulConverter that converts EltwiseMul to TFLMul Signed-off-by: SaeHie Park <saehie.park@samsung.com>
Diffstat (limited to 'compiler/exo-tflite')
-rw-r--r--compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp2
-rw-r--r--compiler/exo-tflite/src/Conversion/EltwiseMulConverter.cpp82
-rw-r--r--compiler/exo-tflite/src/Conversion/EltwiseMulConverter.h41
3 files changed, 124 insertions, 1 deletions
diff --git a/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp b/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp
index 0586d6178..86dd4a0eb 100644
--- a/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp
+++ b/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp
@@ -52,7 +52,7 @@ template bool CanonicalNodeConverter<loco::AvgPool2D>::run(loco::Graph *graph);
// TODO loco::DepthwiseFilterEncode
template bool CanonicalNodeConverter<loco::EltwiseAdd>::run(loco::Graph *graph);
// TODO loco::EltwiseDiv
-// TODO loco::EltwiseMul
+template bool CanonicalNodeConverter<loco::EltwiseMul>::run(loco::Graph *graph);
// TODO loco::EltwiseSqrt
// TODO loco::EltwiseSub
// TODO loco::FeatureBiasAdd
diff --git a/compiler/exo-tflite/src/Conversion/EltwiseMulConverter.cpp b/compiler/exo-tflite/src/Conversion/EltwiseMulConverter.cpp
new file mode 100644
index 000000000..5b48838c1
--- /dev/null
+++ b/compiler/exo-tflite/src/Conversion/EltwiseMulConverter.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * 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.
+ */
+
+#include "EltwiseMulConverter.h"
+
+#include "GraphBlock.h"
+#include "Check.h"
+
+#include "Dialect/IR/TFLNodes.h"
+
+#include <loco/Service/ShapeInference.h>
+
+namespace exo
+{
+
+bool EltwiseMulConverter::convert(loco::EltwiseMul *origin)
+{
+ if (!loco::shape_known(origin))
+ {
+ return false;
+ }
+
+ if (loco::shape_get(origin).domain() == loco::Domain::Tensor)
+ {
+ auto tfl_mul = origin->graph()->nodes()->create<locoex::TFLMul>();
+ tfl_mul->x(origin->lhs());
+ tfl_mul->y(origin->rhs());
+
+ loco::replace(origin).with(tfl_mul);
+ origin->lhs(nullptr);
+ origin->rhs(nullptr);
+
+ return true;
+ }
+ else if (loco::shape_get(origin).domain() == loco::Domain::Feature)
+ {
+ /*
+ if EltwiseMul's domain is Feature, EltwiseMul is replaced with
+ FeatureDecoder-TFLMul-FeatureEncoder.
+
+ Before :
+ A (output: feature) -- loco::EltwiseMul --- B (input:feature)
+
+ After :
+ A -- loco::FeatureDecode -- locoex::TFLMul -- loco::FeatureEncode --- B
+
+ loco::EltwiseMul (dead node)
+ */
+ auto graph = origin->graph();
+ auto dec_l = make_feature_decode<DefaultLayout::NHWC>(origin->lhs());
+ auto dec_r = make_feature_decode<DefaultLayout::NHWC>(origin->rhs());
+ auto tfl_mul = graph->nodes()->create<locoex::TFLMul>();
+ {
+ tfl_mul->x(dec_l);
+ tfl_mul->y(dec_r);
+ }
+ auto enc = make_feature_encode<DefaultLayout::NHWC>(tfl_mul);
+
+ loco::replace(origin).with(enc);
+ origin->lhs(nullptr);
+ origin->rhs(nullptr);
+
+ return true;
+ }
+ else
+ EXO_THROW("Not yet supported loco::Domain");
+}
+
+} // namespace exo
diff --git a/compiler/exo-tflite/src/Conversion/EltwiseMulConverter.h b/compiler/exo-tflite/src/Conversion/EltwiseMulConverter.h
new file mode 100644
index 000000000..4f73484c0
--- /dev/null
+++ b/compiler/exo-tflite/src/Conversion/EltwiseMulConverter.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * 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 __CONVERSION_ELTWISEMUL_CONVERTER_H__
+#define __CONVERSION_ELTWISEMUL_CONVERTER_H__
+
+#include "CanonicalNodeConverter.h"
+
+#include <loco.h>
+
+namespace exo
+{
+
+/**
+ * @brief Convert loco::EltwiseMul to TFLMul
+ */
+class EltwiseMulConverter : public CanonicalNodeConverter<loco::EltwiseMul>
+{
+public:
+ const char *name(void) const final { return "exo::EltwiseMulConverter"; }
+
+public:
+ bool convert(loco::EltwiseMul *origin) final;
+};
+
+} // namespace exo
+
+#endif // __CONVERSION_ELTWISEMUL_CONVERTER_H__