[neurun] Introduce operand::LayoutSet (#2613)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 6 Sep 2018 01:33:08 +0000 (10:33 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 6 Sep 2018 01:33:08 +0000 (10:33 +0900)
LayoutSet is a set data structure for operand::Layout.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/operand/Layout.h
runtimes/neurun/src/graph/operand/LayoutSet.cc [new file with mode: 0644]
runtimes/neurun/src/graph/operand/LayoutSet.h [new file with mode: 0644]

index d35667f..4d55c53 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __NEURUN_GRAPH_OPERAND_LAYOUT_H__
 #define __NEURUN_GRAPH_OPERAND_LAYOUT_H__
 
+#include <functional>
+
 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<type>()(static_cast<type>(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 (file)
index 0000000..d0475f6
--- /dev/null
@@ -0,0 +1,20 @@
+#include "LayoutSet.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+LayoutSet::LayoutSet(std::initializer_list<Layout> 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 (file)
index 0000000..27a5c7f
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __NEURUN_GRAPH_OPERAND_LAYOUT_SET_H__
+#define __NEURUN_GRAPH_OPERAND_LAYOUT_SET_H__
+
+#include <initializer_list>
+#include <unordered_set>
+
+#include "Layout.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+class LayoutSet
+{
+public:
+  LayoutSet() = default;
+  LayoutSet(std::initializer_list<Layout> layouts);
+
+public:
+  void add(const Layout &layout) { _set.insert(layout); }
+  void remove(const Layout &layout) { _set.erase(layout); }
+
+public:
+  std::unordered_set<Layout>::const_iterator begin() const { return _set.begin(); }
+  std::unordered_set<Layout>::const_iterator end() const { return _set.end(); }
+
+private:
+  std::unordered_set<Layout> _set;
+};
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_OPERAND_LAYOUT_SET_H__