[NNOP] The first version of reshape layer (#566)
author김정현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh0822.kim@samsung.com>
Wed, 11 Apr 2018 05:36:37 +0000 (14:36 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 11 Apr 2018 05:36:37 +0000 (14:36 +0900)
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 <jh0822.kim@samsung.com>
src/kernel/acl/CMakeLists.txt
src/kernel/acl/src/cl/Reshape.cpp [new file with mode: 0644]
src/kernel/acl/src/cl/Reshape.test.cpp [new file with mode: 0644]

index 372a79c..cd6f3f4 100644 (file)
@@ -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 (file)
index 0000000..f32b8f4
--- /dev/null
@@ -0,0 +1,54 @@
+#include <OperationsUtils.h>
+#include <arm_compute/core/TensorShape.h>
+#include <arm_compute/core/TensorInfo.h>
+
+// 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<InputAccessor>(input, (float*)inputData, inputShape);
+
+  l.run();
+
+  arm_compute::CLScheduler::get().sync();
+
+  TensorAccess<OutputAccessor>(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 (file)
index 0000000..39e77ba
--- /dev/null
@@ -0,0 +1,36 @@
+#include <gtest/gtest.h>
+#include <OperationsUtils.h>
+#include <kernel/acl/nnfw_kernel_acl.h>
+
+// 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);
+
+}