From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Thu, 6 Sep 2018 01:33:08 +0000 (+0900) Subject: [neurun] Introduce operand::LayoutSet (#2613) X-Git-Tag: 0.2~73 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37af33e3ea4bce2a472310dd6fc62e1a1ae68a6c;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce operand::LayoutSet (#2613) LayoutSet is a set data structure for operand::Layout. Signed-off-by: Hanjoung Lee --- diff --git a/runtimes/neurun/src/graph/operand/Layout.h b/runtimes/neurun/src/graph/operand/Layout.h index d35667f..4d55c53 100644 --- a/runtimes/neurun/src/graph/operand/Layout.h +++ b/runtimes/neurun/src/graph/operand/Layout.h @@ -1,6 +1,8 @@ #ifndef __NEURUN_GRAPH_OPERAND_LAYOUT_H__ #define __NEURUN_GRAPH_OPERAND_LAYOUT_H__ +#include + namespace neurun { namespace graph @@ -19,4 +21,18 @@ enum class Layout } // namespace graph } // namespace neurun +namespace std +{ + +template <> struct hash<::neurun::graph::operand::Layout> +{ + size_t operator()(const ::neurun::graph::operand::Layout &value) const noexcept + { + using type = typename std::underlying_type<::neurun::graph::operand::Layout>::type; + return hash()(static_cast(value)); + } +}; + +} // namespace std + #endif // __NEURUN_GRAPH_OPERAND_LAYOUT_H__ diff --git a/runtimes/neurun/src/graph/operand/LayoutSet.cc b/runtimes/neurun/src/graph/operand/LayoutSet.cc new file mode 100644 index 0000000..d0475f6 --- /dev/null +++ b/runtimes/neurun/src/graph/operand/LayoutSet.cc @@ -0,0 +1,20 @@ +#include "LayoutSet.h" + +namespace neurun +{ +namespace graph +{ +namespace operand +{ + +LayoutSet::LayoutSet(std::initializer_list layouts) +{ + for (auto layout : layouts) + { + _set.insert(layout); + } +} + +} // namespace operand +} // namespace graph +} // namespace neurun diff --git a/runtimes/neurun/src/graph/operand/LayoutSet.h b/runtimes/neurun/src/graph/operand/LayoutSet.h new file mode 100644 index 0000000..27a5c7f --- /dev/null +++ b/runtimes/neurun/src/graph/operand/LayoutSet.h @@ -0,0 +1,38 @@ +#ifndef __NEURUN_GRAPH_OPERAND_LAYOUT_SET_H__ +#define __NEURUN_GRAPH_OPERAND_LAYOUT_SET_H__ + +#include +#include + +#include "Layout.h" + +namespace neurun +{ +namespace graph +{ +namespace operand +{ + +class LayoutSet +{ +public: + LayoutSet() = default; + LayoutSet(std::initializer_list layouts); + +public: + void add(const Layout &layout) { _set.insert(layout); } + void remove(const Layout &layout) { _set.erase(layout); } + +public: + std::unordered_set::const_iterator begin() const { return _set.begin(); } + std::unordered_set::const_iterator end() const { return _set.end(); } + +private: + std::unordered_set _set; +}; + +} // namespace operand +} // namespace graph +} // namespace neurun + +#endif // __NEURUN_GRAPH_OPERAND_LAYOUT_SET_H__