From: 박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 Date: Wed, 11 Apr 2018 01:47:21 +0000 (+0900) Subject: Introduce CLUniqueTensor (#551) X-Git-Tag: 0.1~343 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d6150305ca4c4d03f9a1e3375fb5a5743f45ed5;p=platform%2Fcore%2Fml%2Fnnfw.git Introduce CLUniqueTensor (#551) This commit introduces CLUniqueTensor which initialize and allocate buffer in its constructor, and free that buffer in its destructor. Signed-off-by: Jonghyun Park --- diff --git a/src/kernel/acl/src/Conv2D_acl.cpp b/src/kernel/acl/src/Conv2D_acl.cpp index 704925d..a639e9e 100644 --- a/src/kernel/acl/src/Conv2D_acl.cpp +++ b/src/kernel/acl/src/Conv2D_acl.cpp @@ -50,6 +50,35 @@ arm_compute::TensorShape fromNNShape(const android::nn::Shape& shape) return arm_compute::TensorShape(w, h, c, n); } +class CLUniqueTensor +{ +public: + CLUniqueTensor(const ::arm_compute::TensorInfo &info) + { + _tensor.allocator()->init(info); + _tensor.allocator()->allocate(); + } + +public: + // Both copy and move are not allowed + CLUniqueTensor(const CLUniqueTensor &) = delete; + CLUniqueTensor(CLUniqueTensor &&) = delete; + +public: + ~CLUniqueTensor() + { + _tensor.allocator()->free(); + + } + +public: + ::arm_compute::CLTensor &ref(void) { return _tensor; } + ::arm_compute::CLTensor *ptr(void) { return &_tensor; } + +private: + ::arm_compute::CLTensor _tensor; +}; + bool convFloat32(const float* inputData, const android::nn::Shape& inputShape, const float* filterData, const android::nn::Shape& filterShape, const float* biasData, const android::nn::Shape& biasShape, @@ -68,30 +97,23 @@ bool convFloat32(const float* inputData, const android::nn::Shape& inputShape, padding_top, padding_bottom, arm_compute::DimensionRoundingType::FLOOR); - arm_compute::CLTensor input, output, bias, filter; - - input.allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); - output.allocator()->init(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); - bias.allocator()->init(arm_compute::TensorInfo(bias_shape, arm_compute::Format::F32)); - filter.allocator()->init(arm_compute::TensorInfo(filter_shape, arm_compute::Format::F32)); + CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); + CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); + CLUniqueTensor bias(arm_compute::TensorInfo(bias_shape, arm_compute::Format::F32)); + CLUniqueTensor filter(arm_compute::TensorInfo(filter_shape, arm_compute::Format::F32)); arm_compute::CLConvolutionLayer conv_f; - conv_f.configure(&input, &filter, &bias, &output, conv_info); - - input.allocator()->allocate(); - output.allocator()->allocate(); - bias.allocator()->allocate(); - filter.allocator()->allocate(); + conv_f.configure(input.ptr(), filter.ptr(), bias.ptr(), output.ptr(), conv_info); - TensorAccess(input, inputData, inputShape); - TensorAccess(bias, biasData, biasShape); - TensorAccess(filter, filterData, filterShape); + TensorAccess(input.ref(), inputData, inputShape); + TensorAccess(bias.ref(), biasData, biasShape); + TensorAccess(filter.ref(), filterData, filterShape); conv_f.run(); arm_compute::CLScheduler::get().sync(); - TensorAccess(output, outputData, outputShape); + TensorAccess(output.ref(), outputData, outputShape); return true; }