summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp2
-rw-r--r--compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.cpp78
-rw-r--r--compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.h38
3 files changed, 117 insertions, 1 deletions
diff --git a/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp b/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp
index 86dd4a0eb..ac98c6a7c 100644
--- a/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp
+++ b/compiler/exo-tflite/src/Conversion/CanonicalNodeConverter.cpp
@@ -55,7 +55,7 @@ template bool CanonicalNodeConverter<loco::EltwiseAdd>::run(loco::Graph *graph);
template bool CanonicalNodeConverter<loco::EltwiseMul>::run(loco::Graph *graph);
// TODO loco::EltwiseSqrt
// TODO loco::EltwiseSub
-// TODO loco::FeatureBiasAdd
+template bool CanonicalNodeConverter<loco::FeatureBiasAdd>::run(loco::Graph *graph);
// TODO loco::FixedReshape
template bool CanonicalNodeConverter<loco::MaxPool2D>::run(loco::Graph *graph);
template bool CanonicalNodeConverter<loco::ReLU>::run(loco::Graph *graph);
diff --git a/compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.cpp b/compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.cpp
new file mode 100644
index 000000000..1163f0e3c
--- /dev/null
+++ b/compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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 "FeatureBiasAddConverter.h"
+
+#include "Dialect/IR/TFLNodes.h"
+
+#include "GraphBlock.h"
+
+#include <loco.h>
+#include <loco/Service/ShapeInference.h>
+
+#include <cassert>
+
+namespace exo
+{
+
+/**
+ * @brief Converts loco::FeatureBiasAdd to locoex::TFLAdd
+ *
+ * Before:
+ * Foo ---+
+ * |
+ * loco::FeatureBiasAdd - FeatureDecode - ...
+ * |
+ * Bar - BiasEncode --+
+ *
+ * After:
+ *
+ * Foo - loco::FeatureDecode --+ loco::FeatureBiasAdd
+ * |(x)
+ * TFLAdd -- loco::FeatureEncode - FeatureDecode - ...
+ * |(y)
+ * Bar - BiasEncode - loco::BiasDecode --+
+ */
+bool FeatureBiasAddConverter::convert(loco::FeatureBiasAdd *origin)
+{
+ auto *graph = origin->graph();
+
+ auto tfl_add = graph->nodes()->create<locoex::TFLAdd>();
+
+ // handling input x
+ assert(loco::shape_get(origin->value()).domain() == loco::Domain::Feature);
+
+ auto fea_dec = make_feature_decode<DefaultLayout::NHWC>(origin->value());
+ tfl_add->x(fea_dec);
+
+ // handling input y
+ auto bias_dec = graph->nodes()->create<loco::BiasDecode>();
+ assert(bias_dec != nullptr);
+
+ bias_dec->input(origin->bias());
+
+ tfl_add->y(bias_dec);
+
+ // handling output
+ auto fea_enc = make_feature_encode<DefaultLayout::NHWC>(tfl_add);
+
+ loco::replace(origin).with(fea_enc);
+ origin->value(nullptr);
+
+ return true;
+}
+
+} // namespace exo
diff --git a/compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.h b/compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.h
new file mode 100644
index 000000000..5c4f10213
--- /dev/null
+++ b/compiler/exo-tflite/src/Conversion/FeatureBiasAddConverter.h
@@ -0,0 +1,38 @@
+/*
+ * 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_FEATUREBIASADD_CONVERTER__
+#define __CONVERSION_FEATUREBIASADD_CONVERTER__
+
+#include "CanonicalNodeConverter.h"
+
+#include <loco.h>
+
+namespace exo
+{
+
+class FeatureBiasAddConverter : public CanonicalNodeConverter<loco::FeatureBiasAdd>
+{
+public:
+ const char *name(void) const final { return "exo::TFLAddConverter"; }
+
+public:
+ bool convert(loco::FeatureBiasAdd *origin) final;
+};
+
+} // namespace exo
+
+#endif // __CONVERSION_FEATUREBIASADD_CONVERTER__