From d21c9db544cc2317332da072214ab8f021877630 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9E=A5=EC=A7=80=EC=84=AD/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 3 May 2019 18:41:31 +0900 Subject: [PATCH] Support NHWC layout for calculating the offset of acl tensor (#5137) This commit supports NHWC layout for calculating the offset of acl tensor. Signed-off-by: jiseob.jang --- .../neurun/backend/acl_cl/operand/ICLTensor.cc | 25 ++++++++++++++++------ .../neurun/backend/acl_neon/operand/INETensor.cc | 25 ++++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc b/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc index 82de147..7a7915e 100644 --- a/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc +++ b/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc @@ -17,13 +17,26 @@ size_t ICLTensor::num_dimensions() const { return info()->num_dimensions(); } size_t ICLTensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) { - int32_t N = coords.n(); - int32_t C = coords.c(); - int32_t H = coords.h(); - int32_t W = coords.w(); + int32_t X, Y, Z; + int32_t W = coords.n(); + if (info()->data_layout() == arm_compute::DataLayout::NHWC) + { + X = coords.c(); + Y = coords.w(); + Z = coords.h(); + } + else if (info()->data_layout() == arm_compute::DataLayout::NCHW) + { + X = coords.w(); + Y = coords.h(); + Z = coords.c(); + } + else + { + throw std::runtime_error("Wrong Layout"); + } - ::arm_compute::Coordinates coordinates{W, H, C, N}; - return info()->offset_element_in_bytes(coordinates); + return info()->offset_element_in_bytes({X, Y, Z, W}); } bool ICLTensor::has_padding() const { return info()->has_padding(); } diff --git a/runtimes/neurun/backend/acl_neon/operand/INETensor.cc b/runtimes/neurun/backend/acl_neon/operand/INETensor.cc index b989c02..536706e 100644 --- a/runtimes/neurun/backend/acl_neon/operand/INETensor.cc +++ b/runtimes/neurun/backend/acl_neon/operand/INETensor.cc @@ -33,13 +33,26 @@ size_t INETensor::num_dimensions() const { return info()->num_dimensions(); } size_t INETensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) { - int32_t N = coords.n(); - int32_t C = coords.c(); - int32_t H = coords.h(); - int32_t W = coords.w(); + int32_t X, Y, Z; + int32_t W = coords.n(); + if (info()->data_layout() == arm_compute::DataLayout::NHWC) + { + X = coords.c(); + Y = coords.w(); + Z = coords.h(); + } + else if (info()->data_layout() == arm_compute::DataLayout::NCHW) + { + X = coords.w(); + Y = coords.h(); + Z = coords.c(); + } + else + { + throw std::runtime_error("Wrong Layout"); + } - ::arm_compute::Coordinates coordinates{W, H, C, N}; - return info()->offset_element_in_bytes(coordinates); + return info()->offset_element_in_bytes({X, Y, Z, W}); } bool INETensor::has_padding() const { return info()->has_padding(); } -- 2.7.4