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 <jh0822.kim@samsung.com>
--- /dev/null
+#ifndef __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__
+#define __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__
+#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"
+#include "shape.h"
+
+namespace nnfw {
+namespace kernel {
+namespace acl {
+
+namespace common {
+
+typedef std::function<void (void)> sync_scheduler_f;
+
+template<class TensorT, class LayerT>
+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<InputAccessor>(input.ref(), (float*)inputData, inputShape);
+
+ l.run();
+
+ sync_scheduler();
+
+ TensorAccess<OutputAccessor>(output.ref(), (float*)outputData, outputShape);
+
+ return true;
+}
+
+} // namespace common
+
+} // namespace acl
+} // namespace kernel
+} // namespace nnfw
+
+#endif // __NNFW_KERNEL_ACL_RESHAPE_COMMON_H__
// 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<InputAccessor>(input, (float*)inputData, inputShape);
-
- l.run();
-
+static void sync_scheduler() {
arm_compute::CLScheduler::get().sync();
+}
- TensorAccess<OutputAccessor>(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<CLUniqueTensor, arm_compute::CLReshapeLayer>
+ (inputData, inputShape, outputData, outputShape, sync_scheduler);
}
} // namespace acl
// 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<InputAccessor>(input, (float*)inputData, inputShape);
-
- l.run();
-
- TensorAccess<OutputAccessor>(output, (float*)outputData, outputShape);
-
- return true;
+ return common::reshapeGeneric<NEUniqueTensor, arm_compute::NEReshapeLayer>
+ (inputData, inputShape, outputData, outputShape, sync_scheduler);
}
} // namespace neon
+
} // namespace acl
} // namespace kernel
} // namespace nnfw
+