From 181962c1a1c7562f37141019777d2de29798d75d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=B2=9C=EA=B5=90/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 7 Nov 2019 15:22:49 +0900 Subject: [PATCH] [exo] Extract out FixedArityNode (#8810) This commit extracts out FixedArityNode defined in TFLNodes.h. This is mainly to use it for Circle dialect. Signed-off-by: Cheongyo Bahk --- compiler/exo/src/Dialect/IR/NodeMixins.cpp | 18 ++++++++ compiler/exo/src/Dialect/IR/NodeMixins.h | 66 ++++++++++++++++++++++++++++++ compiler/exo/src/Dialect/IR/TFLNodes.h | 38 +---------------- 3 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 compiler/exo/src/Dialect/IR/NodeMixins.cpp create mode 100644 compiler/exo/src/Dialect/IR/NodeMixins.h diff --git a/compiler/exo/src/Dialect/IR/NodeMixins.cpp b/compiler/exo/src/Dialect/IR/NodeMixins.cpp new file mode 100644 index 0000000..cdfe0d8 --- /dev/null +++ b/compiler/exo/src/Dialect/IR/NodeMixins.cpp @@ -0,0 +1,18 @@ +/* + * 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. + */ + +// This is to validate NodeMixins.h +#include "NodeMixins.h" diff --git a/compiler/exo/src/Dialect/IR/NodeMixins.h b/compiler/exo/src/Dialect/IR/NodeMixins.h new file mode 100644 index 0000000..c35daeb --- /dev/null +++ b/compiler/exo/src/Dialect/IR/NodeMixins.h @@ -0,0 +1,66 @@ +/* + * 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 __DIALECT_IR_NODEMIXINS_H__ +#define __DIALECT_IR_NODEMIXINS_H__ + +#include + +namespace locoex +{ + +/** + * @brief Nodes with the fixed number of inputs + * + * TODO Deprecated this class, and use loco::FixedArity instead + */ +template class FixedArityNode : public Base +{ +public: + FixedArityNode() + { + for (uint32_t n = 0; n < N; ++n) + { + _args[n] = std::unique_ptr(new loco::Use{this}); + } + } + + virtual ~FixedArityNode() = default; + +public: + unsigned arity(void) const final { return N; } + + loco::Node *arg(uint32_t n) const final { return _args.at(n)->node(); } + + void drop(void) final + { + for (uint32_t n = 0; n < N; ++n) + { + _args.at(n)->node(nullptr); + } + } + +protected: + // This API allows inherited classes to access "_args" field. + loco::Use *at(unsigned n) const { return _args.at(n).get(); } + +private: + std::array, N> _args; +}; + +} // namespace locoex + +#endif // __DIALECT_IR_NODEMIXINS_H__ diff --git a/compiler/exo/src/Dialect/IR/TFLNodes.h b/compiler/exo/src/Dialect/IR/TFLNodes.h index 720e2f1..579de52 100644 --- a/compiler/exo/src/Dialect/IR/TFLNodes.h +++ b/compiler/exo/src/Dialect/IR/TFLNodes.h @@ -21,6 +21,7 @@ #include "TFLOpcode.h" #include "FusedActFunc.h" +#include "NodeMixins.h" #include #include @@ -33,43 +34,6 @@ namespace locoex { -/** - * @brief Nodes with the fixed number of inputs - */ -template class FixedArityNode : public Base -{ -public: - FixedArityNode() - { - for (uint32_t n = 0; n < N; ++n) - { - _args[n] = std::unique_ptr(new loco::Use{this}); - } - } - - virtual ~FixedArityNode() = default; - -public: - unsigned arity(void) const final { return N; } - - loco::Node *arg(uint32_t n) const final { return _args.at(n)->node(); } - - void drop(void) final - { - for (uint32_t n = 0; n < N; ++n) - { - _args.at(n)->node(nullptr); - } - } - -protected: - // This API allows inherited classes to access "_args" field. - loco::Use *at(unsigned n) const { return _args.at(n).get(); } - -private: - std::array, N> _args; -}; - enum class Padding { UNDEFINED, // This is not defined by TFLite. This was added to prevent programming error. -- 2.7.4