From 0c8c36b737cec47552fa19bca6c0943534640709 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: Thu, 25 Jul 2019 07:43:02 +0900 Subject: [PATCH] [locoex/custom op] enhancing locoex custom op (#5810) Now customop node can store dtype info. Two methods are defined as const. Signed-off-by: Hyun Sik Yoon --- compiler/locoex-customop/include/locoex/COpCall.h | 7 ++++--- compiler/locoex-customop/src/COpCall.cpp | 17 +++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/compiler/locoex-customop/include/locoex/COpCall.h b/compiler/locoex-customop/include/locoex/COpCall.h index 716377f..197fd8d 100644 --- a/compiler/locoex-customop/include/locoex/COpCall.h +++ b/compiler/locoex-customop/include/locoex/COpCall.h @@ -33,7 +33,8 @@ namespace locoex * @brief Class to calls custom operation */ class COpCall final : public VariadicArityNode, - public loco::NodeMixin + public loco::NodeMixin, + public loco::NodeMixin { public: COpCall(unsigned arity) : VariadicArityNode(arity) {} @@ -53,10 +54,10 @@ public: /// @brief Retrieve attr_data stored with attr_name template - const typename AttrTypeTrait::Type *attr(const std::string &attr_name); + const typename AttrTypeTrait::Type *attr(const std::string &attr_name) const; /// @brief get all the names of attr - std::vector attr_names(); + std::vector attr_names() const; private: std::string _op; diff --git a/compiler/locoex-customop/src/COpCall.cpp b/compiler/locoex-customop/src/COpCall.cpp index 527e0d4..0299147 100644 --- a/compiler/locoex-customop/src/COpCall.cpp +++ b/compiler/locoex-customop/src/COpCall.cpp @@ -22,12 +22,13 @@ namespace locoex { template -const typename AttrTypeTrait::Type *COpCall::attr(const std::string &attr_name) +const typename AttrTypeTrait::Type *COpCall::attr(const std::string &attr_name) const { COpAttrData *attr_data; - if (_attrs.find(attr_name) != _attrs.end()) + auto found = _attrs.find(attr_name); + if (found != _attrs.end()) { - attr_data = _attrs[attr_name].get(); + attr_data = found->second.get(); return dynamic_cast::Type *>(attr_data); } else @@ -42,12 +43,11 @@ void COpCall::attr(const std::string &attr_name, std::unique_ptr && throw std::runtime_error("Attr already inserted"); } -std::vector COpCall::attr_names() +std::vector COpCall::attr_names() const { std::vector attr_names; - for (std::map>::iterator it = _attrs.begin(); - it != _attrs.end(); ++it) + for (auto it = _attrs.cbegin(); it != _attrs.cend(); ++it) { attr_names.emplace_back(it->first); } @@ -55,8 +55,9 @@ std::vector COpCall::attr_names() return attr_names; } -#define INSTANTIATE(AT) \ - template const typename AttrTypeTrait::Type *COpCall::attr(const std::string &attr_name); +#define INSTANTIATE(AT) \ + template const typename AttrTypeTrait::Type *COpCall::attr(const std::string &attr_name) \ + const; INSTANTIATE(COpAttrType::Float) INSTANTIATE(COpAttrType::Int) -- 2.7.4