diff options
author | 윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com> | 2019-09-17 10:37:44 +0900 |
---|---|---|
committer | 박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com> | 2019-09-17 10:37:44 +0900 |
commit | 3a5bf55117ae3a4e3755099ecc8f261b15a6e74d (patch) | |
tree | e2bb6e74d72719ca44a6565fc2d7e631907ae6ef | |
parent | 61111e53b413ae93853bc0ef60f6663a68233e2a (diff) | |
download | nnfw-3a5bf55117ae3a4e3755099ecc8f261b15a6e74d.tar.gz nnfw-3a5bf55117ae3a4e3755099ecc8f261b15a6e74d.tar.bz2 nnfw-3a5bf55117ae3a4e3755099ecc8f261b15a6e74d.zip |
[exo-tflite] adding FeatureBiasAdd converter (#7467)
* [exo-tflite] adding FeatureBiasAdd converter
This adds FeatureBiasAdd converter, which converts loco::FeatureBiasEEdd to locoex::TFLAdd.
Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
* typo
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__ |