[neurun] Introduce internal IFunction class (#3672)
author김수진/동작제어Lab(SR)/Engineer/삼성전자 <sjsujin.kim@samsung.com>
Thu, 22 Nov 2018 08:21:34 +0000 (17:21 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 22 Nov 2018 08:21:34 +0000 (17:21 +0900)
* [neurun] Introduce internal IFunction class

Related : #3273
Part of : #3484

This commit introduces internal `IFunction` class.

Signed-off-by: sjsujinkim <sjsujin.kim@samsung.com>
* Change directory

14 files changed:
runtimes/neurun/src/backend/acl_cl/StageGenerator.cc
runtimes/neurun/src/backend/interface/IStageGenerator.h
runtimes/neurun/src/codegen/operation/Sequence.h
runtimes/neurun/src/compiler/PlanBuilder.h
runtimes/neurun/src/exec/interface/IFunction.h [new file with mode: 0644]
runtimes/neurun/src/kernel/acl_cl/CLFunction.h [new file with mode: 0644]
runtimes/neurun/src/kernel/cpu/AvgPoolLayer.h
runtimes/neurun/src/kernel/cpu/ConcatLayer.h
runtimes/neurun/src/kernel/cpu/ConvolutionLayer.h
runtimes/neurun/src/kernel/cpu/FullyConnectedLayer.h
runtimes/neurun/src/kernel/cpu/MaxPoolLayer.h
runtimes/neurun/src/kernel/cpu/PermuteLayer.h
runtimes/neurun/src/kernel/cpu/ReshapeLayer.h
runtimes/neurun/src/kernel/cpu/SoftMaxLayer.h

index 4bc975d..eb2fe62 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "backend/acl_cl/StageGenerator.h"
 
+#include "kernel/acl_cl/CLFunction.h"
+
 #include <arm_compute/runtime/CL/functions/CLConvolutionLayer.h>
 #include <arm_compute/runtime/CL/functions/CLPoolingLayer.h>
 #include <arm_compute/runtime/CL/functions/CLActivationLayer.h>
 
 template <typename T> std::unique_ptr<T> make_layer(void) { return std::unique_ptr<T>{new T}; }
 
+std::unique_ptr<::neurun::kernel::acl_cl::CLFunction>
+make_cl_function(std::unique_ptr<::arm_compute::IFunction> &&layer)
+{
+  return std::unique_ptr<::neurun::kernel::acl_cl::CLFunction>(
+      new ::neurun::kernel::acl_cl::CLFunction(std::move(layer)));
+}
+
 ::arm_compute::PadStrideInfo asPadStringInfo(const ::internal::Padding &padding,
                                              const ::internal::Stride &stride)
 {
@@ -86,7 +95,9 @@ void ActivationBuilder::appendReLU(::arm_compute::ICLTensor *ifm_alloc)
 
   fn->configure(ifm_alloc, nullptr, act_info);
 
-  _builder.append(std::move(fn));
+  auto acl_fn = make_cl_function(std::move(fn));
+
+  _builder.append(std::move(acl_fn));
 }
 
 void ActivationBuilder::append(FuseCode code, ::arm_compute::ICLTensor *ifm_alloc)
@@ -193,7 +204,9 @@ void StageGenerator::visit(const graph::operation::Conv2DNode &node)
 
     fn->configure(ifm_alloc, ker_alloc, bias_alloc, ofm_alloc, conv_info);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append(std::move(acl_fn));
 
     ActivationBuilder{builder}.append(param.activation, ofm_alloc);
   });
@@ -281,7 +294,9 @@ void StageGenerator::visit(const graph::operation::MaxPool2DNode &node)
 
     fn->configure(ifm_alloc, ofm_alloc, info);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append((std::move(acl_fn)));
   });
 }
 
@@ -371,7 +386,9 @@ void StageGenerator::visit(const graph::operation::AvgPool2DNode &node)
 
     fn->configure(ifm_alloc, ofm_alloc, info);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append((std::move(acl_fn)));
   });
 }
 
@@ -429,7 +446,9 @@ void StageGenerator::visit(const graph::operation::ConcatNode &node)
 
     fn->configure(input_allocs, param.axis, output_alloc);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append(std::move(acl_fn));
   });
 }
 
@@ -476,7 +495,9 @@ void StageGenerator::visit(const graph::operation::FullyConnectedNode &node)
 
     fn->configure(input_alloc, weight_alloc, bias_alloc, output_alloc);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append((std::move(acl_fn)));
 
     ActivationBuilder{builder}.append(param.activation, output_alloc);
   });
@@ -508,7 +529,9 @@ void StageGenerator::visit(const graph::operation::ReshapeNode &node)
 
     fn->configure(input_alloc, output_alloc);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append((std::move(acl_fn)));
   });
 }
 
@@ -543,7 +566,9 @@ void StageGenerator::visit(const graph::operation::SoftmaxNode &node)
 
     fn->configure(input_alloc, output_alloc, param.scale);
 
-    builder.append(std::move(fn));
+    auto acl_fn = make_cl_function(std::move(fn));
+
+    builder.append((std::move(acl_fn)));
   });
 }
 
index 383dd06..4a6a7d2 100644 (file)
@@ -20,7 +20,7 @@
 #include <memory>
 #include <functional>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "backend/interface/ITensorBuilder.h"
 #include "graph/operation/NodeVisitor.h"
@@ -29,7 +29,7 @@ struct IExecutionBuilder
 {
   virtual ~IExecutionBuilder() = default;
 
-  virtual void append(std::unique_ptr<::arm_compute::IFunction> &&f) = 0;
+  virtual void append(std::unique_ptr<::neurun::exec::IFunction> &&f) = 0;
 };
 
 using Stage = std::function<void(IExecutionBuilder &)>;
index 83403fe..36a7aa7 100644 (file)
@@ -18,7 +18,7 @@
 #define __NEURUN_CODEGEN_OPERATION_SEQUENCE_H__
 
 #include <stdint.h>
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 #include <memory>
 #include <vector>
 
@@ -35,17 +35,17 @@ public:
   uint32_t size(void) const { return _functions.size(); }
 
 public:
-  Sequence &append(std::unique_ptr<::arm_compute::IFunction> &&func)
+  Sequence &append(std::unique_ptr<::neurun::exec::IFunction> &&func)
   {
     _functions.emplace_back(std::move(func));
     return (*this);
   }
 
 public:
-  ::arm_compute::IFunction &at(uint32_t n) const { return *(_functions.at(n)); }
+  ::neurun::exec::IFunction &at(uint32_t n) const { return *(_functions.at(n)); }
 
 private:
-  std::vector<std::unique_ptr<::arm_compute::IFunction>> _functions;
+  std::vector<std::unique_ptr<::neurun::exec::IFunction>> _functions;
 };
 
 } // namespace operation
index 60413cd..68caae8 100644 (file)
@@ -35,7 +35,7 @@ public:
   }
 
 public:
-  void append(std::unique_ptr<::arm_compute::IFunction> &&f) override
+  void append(std::unique_ptr<::neurun::exec::IFunction> &&f) override
   {
     _plan.operations().append(std::move(f));
   }
diff --git a/runtimes/neurun/src/exec/interface/IFunction.h b/runtimes/neurun/src/exec/interface/IFunction.h
new file mode 100644 (file)
index 0000000..b7a721d
--- /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.
+ */
+
+#ifndef __NEURUN_EXEC_I_FUNCTION_H__
+#define __NEURUN_EXEC_I_FUNCTION_H__
+
+namespace neurun
+{
+namespace exec
+{
+
+class IFunction
+{
+public:
+  virtual ~IFunction() = default;
+  virtual void run() = 0;
+  virtual void prepare() {}
+};
+
+} // namespace exec
+} // namespace neurun
+
+#endif // __NEURUN_EXEC_I_FUNCTION_H__
diff --git a/runtimes/neurun/src/kernel/acl_cl/CLFunction.h b/runtimes/neurun/src/kernel/acl_cl/CLFunction.h
new file mode 100644 (file)
index 0000000..f34210c
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+#ifndef __NEURUN_KERNEL_ACL_CL_CL_FUNCTION_H__
+#define __NEURUN_KERNEL_ACL_CL_CL_FUNCTION_H__
+
+#include "exec/interface/IFunction.h"
+#include <arm_compute/runtime/IFunction.h>
+#include <memory>
+
+namespace neurun
+{
+namespace kernel
+{
+namespace acl_cl
+{
+
+class CLFunction : public ::neurun::exec::IFunction
+{
+public:
+  CLFunction() = delete;
+
+public:
+  CLFunction(std::unique_ptr<::arm_compute::IFunction> &&func)
+      : _func(std::forward<std::unique_ptr<::arm_compute::IFunction>>(func))
+  {
+    // DO NOTHING
+  }
+
+public:
+  void run() override { _func->run(); }
+  void prepare() override { _func->prepare(); }
+
+private:
+  std::unique_ptr<::arm_compute::IFunction> _func;
+};
+
+} // namespace acl_cl
+} // namespace kernel
+} // namespace neurun
+
+#endif // __NEURUN_KERNEL_ACL_CL_CL_FUNCTION_H__
index 9f390a9..280f7ae 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -30,7 +30,7 @@ namespace kernel
 namespace cpu
 {
 
-class AvgPoolLayer : public ::arm_compute::IFunction
+class AvgPoolLayer : public ::neurun::exec::IFunction
 {
 public:
   AvgPoolLayer();
index 9aacab5..64f8135 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -31,7 +31,7 @@ namespace kernel
 namespace cpu
 {
 
-class ConcatLayer : public ::arm_compute::IFunction
+class ConcatLayer : public ::neurun::exec::IFunction
 {
 public:
   ConcatLayer();
index b7afbce..9b7f55f 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -30,7 +30,7 @@ namespace kernel
 namespace cpu
 {
 
-class ConvolutionLayer : public ::arm_compute::IFunction
+class ConvolutionLayer : public ::neurun::exec::IFunction
 {
 public:
   ConvolutionLayer();
index b1ba172..20a3883 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -30,7 +30,7 @@ namespace kernel
 namespace cpu
 {
 
-class FullyConnectedLayer : public ::arm_compute::IFunction
+class FullyConnectedLayer : public ::neurun::exec::IFunction
 {
 public:
   FullyConnectedLayer();
index b42efb9..2b18555 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -30,7 +30,7 @@ namespace kernel
 namespace cpu
 {
 
-class MaxPoolLayer : public ::arm_compute::IFunction
+class MaxPoolLayer : public ::neurun::exec::IFunction
 {
 public:
   MaxPoolLayer();
index e4836f8..293e995 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 #include <arm_compute/core/ITensor.h>
 
 #include "util/feature/nhwc/View.h"
@@ -32,7 +32,7 @@ namespace kernel
 namespace cpu
 {
 
-class PermuteLayer : public ::arm_compute::IFunction
+class PermuteLayer : public ::neurun::exec::IFunction
 {
 public:
   enum class Type
index 395cc1d..51d0bac 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -30,7 +30,7 @@ namespace kernel
 namespace cpu
 {
 
-class ReshapeLayer : public ::arm_compute::IFunction
+class ReshapeLayer : public ::neurun::exec::IFunction
 {
 public:
   ReshapeLayer();
index 8057be5..df1aa40 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <NeuralNetworks.h>
 
-#include <arm_compute/runtime/IFunction.h>
+#include "exec/interface/IFunction.h"
 
 #include "kernel/cpu/OperationUtils.h"
 
@@ -30,7 +30,7 @@ namespace kernel
 namespace cpu
 {
 
-class SoftMaxLayer : public ::arm_compute::IFunction
+class SoftMaxLayer : public ::neurun::exec::IFunction
 {
 public:
   SoftMaxLayer();