--- /dev/null
+#include "BackendSet.h"
+
+#include <cassert>
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+BackendSet::BackendSet(std::initializer_list<const backend::Backend *> backends)
+{
+ for (auto backend : backends)
+ {
+ _set.insert(backend);
+ }
+}
+
+const backend::Backend *BackendSet::getOnlyElement() const
+{
+ assert(_set.size() == 1u);
+ return *_set.begin();
+}
+
+BackendSet BackendSet::operator|(const BackendSet &other) const
+{
+ auto ret = *this;
+ for (auto backend : other)
+ {
+ ret.add(backend);
+ }
+ return ret;
+}
+
+BackendSet BackendSet::operator&(const BackendSet &other) const
+{
+ BackendSet ret;
+ for (auto backend : other)
+ {
+ if (contains(backend))
+ {
+ ret.add(backend);
+ }
+ }
+ return ret;
+}
+
+BackendSet BackendSet::operator-(const BackendSet &other) const
+{
+ auto ret = *this;
+ for (auto backend : other)
+ {
+ ret.remove(backend);
+ }
+ return ret;
+}
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
--- /dev/null
+#ifndef __NEURUN_GRAPH_OPERAND_BACKEND_SET_H__
+#define __NEURUN_GRAPH_OPERAND_BACKEND_SET_H__
+
+#include <initializer_list>
+#include <unordered_set>
+
+namespace neurun
+{
+namespace backend
+{
+class Backend;
+} // namespace backend
+} // namespace neurun
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+class BackendSet
+{
+public:
+ BackendSet() = default;
+ BackendSet(std::initializer_list<const backend::Backend *> backends);
+
+public:
+ void add(const backend::Backend *backend) { _set.insert(backend); }
+ void remove(const backend::Backend *backend) { _set.erase(backend); }
+ uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
+ bool empty() const { return _set.empty(); }
+ bool contains(const backend::Backend *backend) const { return _set.find(backend) != _set.end(); }
+ const backend::Backend *getOnlyElement() const;
+
+public:
+ BackendSet operator|(const BackendSet &other) const; // Union
+ BackendSet operator&(const BackendSet &other) const; // Intersect
+ BackendSet operator-(const BackendSet &other) const; // Minus
+
+public:
+ std::unordered_set<const backend::Backend *>::const_iterator begin() const
+ {
+ return _set.begin();
+ }
+ std::unordered_set<const backend::Backend *>::const_iterator end() const { return _set.end(); }
+
+private:
+ std::unordered_set<const backend::Backend *> _set;
+};
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_OPERAND_BACKEND_SET_H__