[neurun] Introduce OperationPass (#3403)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 31 Oct 2018 03:59:34 +0000 (12:59 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 31 Oct 2018 03:59:34 +0000 (12:59 +0900)
Introduce `OperationPass` class which iterates over `operation::Node`s.
This is the same manner with `OperandPass`.

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

diff --git a/runtimes/neurun/src/graph/pass/OperationPass.cc b/runtimes/neurun/src/graph/pass/OperationPass.cc
new file mode 100644 (file)
index 0000000..0164a1a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include "OperationPass.h"
+
+#include "graph/Graph.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace pass
+{
+
+void OperationPass::run()
+{
+  _graph.operations().iterate(
+      [&](const operation::Index &index, operation::Node &node) { callback(index, node); });
+}
+
+} // namespace pass
+} // namespace graph
+} // namespace neurun
diff --git a/runtimes/neurun/src/graph/pass/OperationPass.h b/runtimes/neurun/src/graph/pass/OperationPass.h
new file mode 100644 (file)
index 0000000..c05a0fc
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+/**
+ * @file  OperationPass.h
+ * @brief This file contains OperationPass class
+ */
+
+#ifndef __NEURUN_GRAPH_PASS_OPERATION_PASS_H__
+#define __NEURUN_GRAPH_PASS_OPERATION_PASS_H__
+
+#include "Pass.h"
+
+#include "graph/operation/Index.h"
+#include "graph/operation/Node.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace pass
+{
+
+/**
+ * @brief  Class to iterate over operations and calls callback() method
+ */
+class OperationPass : public Pass
+{
+public:
+  using Pass::Pass;
+
+public:
+  /**
+   * @brief Returns string id for this pass. Same with class name.
+   *
+   * @return string id
+   */
+  virtual std::string id() = 0;
+
+  /**
+   * @brief Run the pass
+   */
+  virtual void run() override final;
+
+  /**
+   * @brief The function that will be executed for each operations
+   *
+   * @param i[in] Index of the operation node
+   * @param n[in] The operation node
+   */
+  virtual void callback(const operation::Index &i, operation::Node &n) = 0;
+};
+
+} // namespace pass
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_PASS_OPERATION_PASS_H__