Introduce IExecutor interface (#4454)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 21 Feb 2019 08:37:21 +0000 (17:37 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 21 Feb 2019 08:37:21 +0000 (17:37 +0900)
* Introduce IExecutor interface

Introduce IExecutor interface
Access executor using interface on frontend

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Executor class as final

runtimes/neurun/src/exec/Executor.h
runtimes/neurun/src/exec/IExecutor.h [new file with mode: 0644]
runtimes/neurun/src/frontend/wrapper/execution.h

index 32febd3..f688cb1 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef __NEURUN_EXEC_EXECUTOR_H_
 #define __NEURUN_EXEC_EXECUTOR_H_
 
-#include "compiler/Plan.h"
+#include "IExecutor.h"
 #include "Source.h"
 #include "Sink.h"
 
@@ -34,7 +34,7 @@ namespace exec
 /**
  * @brief Class to handle execution phase
  */
-class Executor
+class Executor final : public IExecutor
 {
 public:
   /**
diff --git a/runtimes/neurun/src/exec/IExecutor.h b/runtimes/neurun/src/exec/IExecutor.h
new file mode 100644 (file)
index 0000000..48c167c
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019 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  IExecutor.h
+ * @brief This file defines interface of Executor
+ */
+#ifndef __NEURUN_EXEC_I_EXECUTOR_H_
+#define __NEURUN_EXEC_I_EXECUTOR_H_
+
+#include "compiler/Plan.h"
+
+namespace neurun
+{
+namespace exec
+{
+
+/**
+ * @brief Struct to define interface of Executor
+ */
+struct IExecutor
+{
+  /**
+   * @brief Construct a new IExecutor object
+   */
+  IExecutor() = default;
+  /**
+   * @brief Destroy the IExecutor object
+   */
+  virtual ~IExecutor() = default;
+
+  /**
+   * @brief   Return plan
+   * @return  Plan
+   */
+  virtual const neurun::compiler::Plan &plan(void) const = 0;
+  /**
+   * @brief     Set input data's information
+   * @param[in] index   Input index
+   * @param[in] type    Input data's type info
+   * @param[in] shape   Input data's shape
+   * @param[in] buffer  Input data's buffer pointer
+   * @param[in] length  Input data's length
+   */
+  virtual void setInput(const model::operand::IO::Index &index,
+                        const model::operand::TypeInfo &type, const model::operand::Shape &shape,
+                        const void *buffer, size_t length) = 0;
+  /**
+   * @brief     Set output data's information
+   * @param[in] index   Output index
+   * @param[in] type    Output data's type info
+   * @param[in] shape   Output data's shape
+   * @param[in] buffer  Output data's buffer pointer
+   * @param[in] length  Output data's length
+   */
+  virtual void setOutput(const model::operand::IO::Index &index,
+                         const model::operand::TypeInfo &type, const model::operand::Shape &shape,
+                         void *buffer, size_t length) = 0;
+  /**
+   * @brief  Start execution
+   * @note   It should be called after setting input and output buffer
+   */
+  virtual void execute(void) = 0;
+};
+
+} // namespace exec
+} // namespace neurun
+
+#endif // __NEURUN_EXEC_I_EXECUTOR_H_
index 8479ec5..aca23cc 100644 (file)
@@ -46,7 +46,7 @@ public:
   bool haveUnspecifiedDims(const neurun::model::operand::Index index) noexcept;
 
 private:
-  std::shared_ptr<neurun::exec::Executor> _executor;
+  std::shared_ptr<neurun::exec::IExecutor> _executor;
 };
 
 #endif