From 0a70e934e58b01e7b5900796c372d211706da9b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EA=B9=80=EC=A0=95=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Senior=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 11 Apr 2018 14:36:37 +0900 Subject: [PATCH] [NNOP] The first version of reshape layer (#566) This commit introduces the first version of reshape layer using ACL. Unit test will be added more in later commits. Signed-off-by: Junghyun Kim --- src/kernel/acl/CMakeLists.txt | 2 ++ src/kernel/acl/src/cl/Reshape.cpp | 54 ++++++++++++++++++++++++++++++++++ src/kernel/acl/src/cl/Reshape.test.cpp | 36 +++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/kernel/acl/src/cl/Reshape.cpp create mode 100644 src/kernel/acl/src/cl/Reshape.test.cpp diff --git a/src/kernel/acl/CMakeLists.txt b/src/kernel/acl/CMakeLists.txt index 372a79c..cd6f3f4 100644 --- a/src/kernel/acl/CMakeLists.txt +++ b/src/kernel/acl/CMakeLists.txt @@ -28,6 +28,7 @@ set(KERNELACL_SRCS "src/Init_acl.cpp" "src/IO_accessor.cpp" "src/cl/Conv2D_acl.cpp" "src/cl/FullyConnected.cpp" + "src/cl/Reshape.cpp" ) add_library(${LIB_KERNELACL} SHARED ${KERNELACL_SRCS}) @@ -49,6 +50,7 @@ set(KERNELACL_TEST_SRCS "src/cl/Conv2D_acl.test.cpp" "src/util.cpp" "src/gtest_env.cpp" "src/cl/FullyConnected.test.cpp" + "src/cl/Reshape.test.cpp" ) add_executable(${LIB_KERNELACL_TEST} ${KERNELACL_TEST_SRCS}) diff --git a/src/kernel/acl/src/cl/Reshape.cpp b/src/kernel/acl/src/cl/Reshape.cpp new file mode 100644 index 0000000..f32b8f4 --- /dev/null +++ b/src/kernel/acl/src/cl/Reshape.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +// TODO: fix include path in CMakeFiles +#include "../IO_accessor.h" + +namespace android { +namespace nn { + +// TODO remove from this source and use it from runtime +uint32_t getSizeOfDimension(const Shape& shape, uint32_t dimensionIdx); + +} // namespace nn +} // namespace android + +namespace nnfw { +namespace kernel { +namespace acl { + +arm_compute::TensorShape fromNNShape(const android::nn::Shape& shape); + +bool reshapeGeneric(const void* inputData, const android::nn::Shape& inputShape, + void* outputData, const android::nn::Shape& outputShape) { + + auto input_shape = fromNNShape(inputShape); + auto output_shape = 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(); + + arm_compute::CLScheduler::get().sync(); + + TensorAccess(output, (float*)outputData, outputShape); + + return true; +} + +} // namespace acl +} // namespace kernel +} // namespace nnfw diff --git a/src/kernel/acl/src/cl/Reshape.test.cpp b/src/kernel/acl/src/cl/Reshape.test.cpp new file mode 100644 index 0000000..39e77ba --- /dev/null +++ b/src/kernel/acl/src/cl/Reshape.test.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +// TODO: fix include path in CMakeFiles +#include "../util.h" + +namespace nnfw { +namespace kernel { +namespace acl { + +bool reshapeGeneric(const void* inputData, const android::nn::Shape& inputShape, + void* outputData, const android::nn::Shape& outputShape); +} // namespace acl +} // namespace kernel +} // namespace nnfw + +using namespace nnfw::kernel::acl; + +TEST(KernelACL_TC, reshape_1) { + const android::nn::Shape inputShape = {OperandType::FLOAT32, {1,1,9,1}, 1.0, 0}; + float inputData[9] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + + const android::nn::Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + float outputData[9] = {0}; + + bool bret = reshapeGeneric(inputData, inputShape, + outputData, outputShape); + + EXPECT_EQ(bret, true); + + float expectData[9] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; + bret = util::compareData(outputData, expectData, outputShape); + EXPECT_EQ(bret, true); + +} -- 2.7.4