From b3e7377de249c87e6cc10c2d51c98c4f47874281 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 28 Aug 2019 15:54:14 +0900 Subject: [PATCH] [exo-tflite] introducing TFLConverter class (#6986) * [exo-tflite] introducing TFLConverter class Children of this class will convert a loco node to TFL node. This class is a parent of those children. Signed-off-by: Hyun Sik Yoon * remove graph param from --- .../exo-tflite/src/Conversion/TFLConverter.cpp | 49 ++++++++++++++++++++++ compiler/exo-tflite/src/Conversion/TFLConverter.h | 45 ++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 compiler/exo-tflite/src/Conversion/TFLConverter.cpp create mode 100644 compiler/exo-tflite/src/Conversion/TFLConverter.h diff --git a/compiler/exo-tflite/src/Conversion/TFLConverter.cpp b/compiler/exo-tflite/src/Conversion/TFLConverter.cpp new file mode 100644 index 0000000..7637cdf --- /dev/null +++ b/compiler/exo-tflite/src/Conversion/TFLConverter.cpp @@ -0,0 +1,49 @@ +/* + * 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 "TFLConverter.h" + +#include +#include + +namespace exo +{ + +template bool TFLConverter::run(loco::Graph *graph) +{ + auto active_nodes = loco::active_nodes(loco::output_nodes(graph)); + bool changed = false; + + for (auto node : active_nodes) + { + if (node->dialect() == loco::CanonicalDialect::get()) + { + auto the_node = dynamic_cast(node); + if (the_node != nullptr) + { + if (convert(the_node)) + changed = true; + } + } + } + + return changed; +} + +// Add template instantiation of subclasses +// E.g., +// template bool TFLConverter::run(loco::Graph *graph); + +} // namespace exo diff --git a/compiler/exo-tflite/src/Conversion/TFLConverter.h b/compiler/exo-tflite/src/Conversion/TFLConverter.h new file mode 100644 index 0000000..c08396f --- /dev/null +++ b/compiler/exo-tflite/src/Conversion/TFLConverter.h @@ -0,0 +1,45 @@ +/* + * 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_TFLCONVERTER_H__ +#define __CONVERSION_TFLCONVERTER_H__ + +#include "Convert.h" + +#include +#include + +namespace exo +{ + +/** + * @brief Class to convert a canonical node to TFL node + */ +template class TFLConverter : public logo::Pass +{ +public: + virtual const char *name(void) const { return nullptr; } + +public: + bool run(loco::Graph *graph); + +protected: + virtual bool convert(CanonicalType *node) = 0; +}; + +} // namespace exo + +#endif //__CONVERSION_TFLCONVERTER_H__ -- 2.7.4