From: 김정현/동작제어Lab(SR)/Senior Engineer/삼성전자 Date: Thu, 19 Apr 2018 03:57:33 +0000 (+0900) Subject: Unify NEON and OpenCL implementation of reshape layer (#800) X-Git-Tag: 0.1~178 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce8845e1a047721f2ab8bf41a9b70d9947ca7fc7;p=platform%2Fcore%2Fml%2Fnnfw.git Unify NEON and OpenCL implementation of reshape layer (#800) NEON and OpenCL implementations of reshape layer are very similar. This commit - extracts common features to `src/Reshape.h` - implement different parts into `neon/Reshape.cpp` and `cl/Reshape.cpp`. Signed-off-by: Junghyun Kim --- diff --git a/src/kernel/acl/src/Reshape.h b/src/kernel/acl/src/Reshape.h new file mode 100644 index 0000000..1d4d5dc --- /dev/null +++ b/src/kernel/acl/src/Reshape.h @@ -0,0 +1,54 @@ +#ifndef __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__ +#define __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__ +#include +#include +#include + +// TODO: fix include path in CMakeFiles +#include "IO_accessor.h" +#include "shape.h" + +namespace nnfw { +namespace kernel { +namespace acl { + +namespace common { + +typedef std::function sync_scheduler_f; + +template +bool reshapeGeneric(const void* inputData, const android::nn::Shape& inputShape, + void* outputData, const android::nn::Shape& outputShape, + sync_scheduler_f sync_scheduler) { + + auto input_shape = util::fromNNShape(inputShape); + auto output_shape = util::fromNNShape(outputShape); + + TensorT input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); + TensorT output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); + + LayerT l; + + l.configure(input.ptr(), output.ptr()); + + input.allocate(); + output.allocate(); + + TensorAccess(input.ref(), (float*)inputData, inputShape); + + l.run(); + + sync_scheduler(); + + TensorAccess(output.ref(), (float*)outputData, outputShape); + + return true; +} + +} // namespace common + +} // namespace acl +} // namespace kernel +} // namespace nnfw + +#endif // __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__ diff --git a/src/kernel/acl/src/cl/Reshape.cpp b/src/kernel/acl/src/cl/Reshape.cpp index d6a3b87..c51fc20 100644 --- a/src/kernel/acl/src/cl/Reshape.cpp +++ b/src/kernel/acl/src/cl/Reshape.cpp @@ -5,38 +5,21 @@ // TODO: fix include path in CMakeFiles #include "../IO_accessor.h" #include "../shape.h" +#include "../CLUniqueTensor.h" +#include "../Reshape.h" namespace nnfw { namespace kernel { namespace acl { -bool reshapeGeneric(const void* inputData, const android::nn::Shape& inputShape, - void* outputData, const android::nn::Shape& outputShape) { - - auto input_shape = util::fromNNShape(inputShape); - auto output_shape = util::fromNNShape(outputShape); - - arm_compute::CLTensor input, output; - - input.allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - output.allocator()->init(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - arm_compute::CLReshapeLayer l; - - l.configure(&input, &output); - - input.allocator()->allocate(); - output.allocator()->allocate(); - - TensorAccess(input, (float*)inputData, inputShape); - - l.run(); - +static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); +} - TensorAccess(output, (float*)outputData, outputShape); - - return true; +bool reshapeGeneric(const void* inputData, const android::nn::Shape& inputShape, + void* outputData, const android::nn::Shape& outputShape) { + return common::reshapeGeneric + (inputData, inputShape, outputData, outputShape, sync_scheduler); } } // namespace acl diff --git a/src/kernel/acl/src/neon/Reshape.cpp b/src/kernel/acl/src/neon/Reshape.cpp index 6ac181e..a126fe3 100644 --- a/src/kernel/acl/src/neon/Reshape.cpp +++ b/src/kernel/acl/src/neon/Reshape.cpp @@ -5,40 +5,28 @@ // TODO: fix include path in CMakeFiles #include "../IO_accessor.h" #include "../shape.h" +#include "../NEUniqueTensor.h" +#include "../Reshape.h" namespace nnfw { namespace kernel { namespace acl { + namespace neon { +static void sync_scheduler() { + arm_compute::CLScheduler::get().sync(); +} + bool reshapeGeneric(const void* inputData, const android::nn::Shape& inputShape, void* outputData, const android::nn::Shape& outputShape) { - - auto input_shape = util::fromNNShape(inputShape); - auto output_shape = util::fromNNShape(outputShape); - - arm_compute::Tensor input, output; - - input.allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - output.allocator()->init(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - - arm_compute::NEReshapeLayer l; - - l.configure(&input, &output); - - input.allocator()->allocate(); - output.allocator()->allocate(); - - TensorAccess(input, (float*)inputData, inputShape); - - l.run(); - - TensorAccess(output, (float*)outputData, outputShape); - - return true; + return common::reshapeGeneric + (inputData, inputShape, outputData, outputShape, sync_scheduler); } } // namespace neon + } // namespace acl } // namespace kernel } // namespace nnfw +