From 3550f7e2fad8fb51481915f7e37ea1c3fc3fe598 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, 14 Jun 2019 17:05:45 +0900 Subject: [PATCH] Remove calcOffset methods using Coordinate4D (#5416) This commit removes calcOffset methods using Coordinate4D from classes of backend tensor Signed-off-by: jiseob.jang --- .../neurun/backend/acl_cl/operand/ICLTensor.cc | 24 ----- runtimes/neurun/backend/acl_cl/operand/ICLTensor.h | 1 - .../neurun/backend/acl_neon/operand/INETensor.cc | 24 ----- .../neurun/backend/acl_neon/operand/INETensor.h | 1 - runtimes/neurun/backend/cpu/operand/Tensor.cc | 104 --------------------- runtimes/neurun/backend/cpu/operand/Tensor.h | 1 - .../neurun/core/include/backend/operand/ITensor.h | 2 - runtimes/neurun/core/src/exec/interp/Tensor.cc | 12 --- runtimes/neurun/core/src/exec/interp/Tensor.h | 4 - 9 files changed, 173 deletions(-) diff --git a/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc b/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc index a90d7e5..2f4c89e 100644 --- a/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc +++ b/runtimes/neurun/backend/acl_cl/operand/ICLTensor.cc @@ -29,30 +29,6 @@ size_t ICLTensor::calcOffset(const neurun::util::Coordinates &coords) return info()->offset_element_in_bytes(acl_coords); } -size_t ICLTensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) -{ - 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"); - } - - return info()->offset_element_in_bytes({X, Y, Z, W}); -} - bool ICLTensor::has_padding() const { return info()->has_padding(); } neurun::graph::operand::Layout ICLTensor::layout() const diff --git a/runtimes/neurun/backend/acl_cl/operand/ICLTensor.h b/runtimes/neurun/backend/acl_cl/operand/ICLTensor.h index d5c81a1..d8d7046 100644 --- a/runtimes/neurun/backend/acl_cl/operand/ICLTensor.h +++ b/runtimes/neurun/backend/acl_cl/operand/ICLTensor.h @@ -50,7 +50,6 @@ public: size_t dimension(size_t index) const override; size_t num_dimensions() const override; size_t calcOffset(const neurun::util::Coordinates &coords) override; - size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) override; neurun::graph::operand::Layout layout() const override; bool has_padding() const override; diff --git a/runtimes/neurun/backend/acl_neon/operand/INETensor.cc b/runtimes/neurun/backend/acl_neon/operand/INETensor.cc index 2d9db25..9c239c3 100644 --- a/runtimes/neurun/backend/acl_neon/operand/INETensor.cc +++ b/runtimes/neurun/backend/acl_neon/operand/INETensor.cc @@ -45,30 +45,6 @@ size_t INETensor::calcOffset(const neurun::util::Coordinates &coords) return info()->offset_element_in_bytes(acl_coords); } -size_t INETensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) -{ - 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"); - } - - return info()->offset_element_in_bytes({X, Y, Z, W}); -} - bool INETensor::has_padding() const { return info()->has_padding(); } neurun::graph::operand::Layout INETensor::layout() const diff --git a/runtimes/neurun/backend/acl_neon/operand/INETensor.h b/runtimes/neurun/backend/acl_neon/operand/INETensor.h index ac5c6bc..1b37b3a 100644 --- a/runtimes/neurun/backend/acl_neon/operand/INETensor.h +++ b/runtimes/neurun/backend/acl_neon/operand/INETensor.h @@ -49,7 +49,6 @@ public: size_t dimension(size_t index) const override; size_t num_dimensions() const override; size_t calcOffset(const neurun::util::Coordinates &coords) override; - size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) override; neurun::graph::operand::Layout layout() const override; bool has_padding() const override; diff --git a/runtimes/neurun/backend/cpu/operand/Tensor.cc b/runtimes/neurun/backend/cpu/operand/Tensor.cc index 6900b86..106e069 100644 --- a/runtimes/neurun/backend/cpu/operand/Tensor.cc +++ b/runtimes/neurun/backend/cpu/operand/Tensor.cc @@ -37,110 +37,6 @@ size_t Tensor::calcOffset(const neurun::util::Coordinates &coords) return offset; } -size_t Tensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) -{ - size_t rank = num_dimensions(); - assert(rank >= 1 && rank <= 4); - - size_t offset = 0; - - switch (rank) - { - case 1: - { - if (layout() == neurun::graph::operand::Layout::NHWC) - { - offset += coords.c(); - } - else if (layout() == neurun::graph::operand::Layout::NCHW) - { - offset += coords.w(); - } - else - { - throw std::runtime_error("Wrong Layout"); - } - break; - } - case 2: - { - if (layout() == neurun::graph::operand::Layout::NHWC) - { - size_t C = dimension(1); - offset += coords.w() * C; - offset += coords.c(); - } - else if (layout() == neurun::graph::operand::Layout::NCHW) - { - size_t W = dimension(1); - offset += coords.h() * W; - offset += coords.w(); - } - else - { - throw std::runtime_error("Wrong Layout"); - } - break; - } - case 3: - { - if (layout() == neurun::graph::operand::Layout::NHWC) - { - size_t W = dimension(1); - size_t C = dimension(2); - offset += coords.h() * W * C; - offset += coords.w() * C; - offset += coords.c(); - } - else if (layout() == neurun::graph::operand::Layout::NCHW) - { - size_t H = dimension(1); - size_t W = dimension(2); - offset += coords.c() * H * W; - offset += coords.h() * W; - offset += coords.w(); - } - else - { - throw std::runtime_error("Wrong Layout"); - } - break; - } - case 4: - { - if (layout() == neurun::graph::operand::Layout::NHWC) - { - size_t H = dimension(1); - size_t W = dimension(2); - size_t C = dimension(3); - offset += coords.n() * H * W * C; - offset += coords.h() * W * C; - offset += coords.w() * C; - offset += coords.c(); - } - else if (layout() == neurun::graph::operand::Layout::NCHW) - { - size_t C = dimension(1); - size_t H = dimension(2); - size_t W = dimension(3); - offset += coords.n() * C * H * W; - offset += coords.c() * H * W; - offset += coords.h() * W; - offset += coords.w(); - } - else - { - throw std::runtime_error("Wrong Layout"); - } - break; - } - default: - throw std::runtime_error("Not supported rank in Tensor::calcOffset"); - } - offset *= sizeOfDataType(data_type()); - return offset; -} - } // namespace operand } // namespace cpu } // namespace backend diff --git a/runtimes/neurun/backend/cpu/operand/Tensor.h b/runtimes/neurun/backend/cpu/operand/Tensor.h index c487f16..359f121 100644 --- a/runtimes/neurun/backend/cpu/operand/Tensor.h +++ b/runtimes/neurun/backend/cpu/operand/Tensor.h @@ -60,7 +60,6 @@ public: size_t num_dimensions() const override { return _info.shape().dims().size(); } size_t total_size() const override { return _info.total_size(); } size_t calcOffset(const neurun::util::Coordinates &coords) override; - size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) override; neurun::graph::operand::Layout layout() const override { return neurun::graph::operand::Layout::NHWC; diff --git a/runtimes/neurun/core/include/backend/operand/ITensor.h b/runtimes/neurun/core/include/backend/operand/ITensor.h index 18259cb..5361138 100644 --- a/runtimes/neurun/core/include/backend/operand/ITensor.h +++ b/runtimes/neurun/core/include/backend/operand/ITensor.h @@ -22,7 +22,6 @@ #include "graph/operand/Layout.h" #include "util/Coordinates.h" -#include "util/feature/Coordinate4D.h" namespace neurun { @@ -42,7 +41,6 @@ public: virtual size_t dimension(size_t index) const = 0; virtual size_t num_dimensions() const = 0; virtual size_t calcOffset(const neurun::util::Coordinates &coords) = 0; - virtual size_t calcOffset(const neurun::util::feature::Coordinate4D &coords) = 0; virtual neurun::graph::operand::Layout layout() const = 0; virtual bool has_padding() const = 0; }; diff --git a/runtimes/neurun/core/src/exec/interp/Tensor.cc b/runtimes/neurun/core/src/exec/interp/Tensor.cc index 0bd05e2..c21c8cc 100644 --- a/runtimes/neurun/core/src/exec/interp/Tensor.cc +++ b/runtimes/neurun/core/src/exec/interp/Tensor.cc @@ -37,18 +37,6 @@ size_t Tensor::calcOffset(const neurun::util::Coordinates &coords) throw std::runtime_error("offset_element_in_bytes is not supported for cpu::Tensor now."); } -size_t ROTensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) -{ - NO_USE(coords); - throw std::runtime_error("offset_element_in_bytes is not supported for cpu::Tensor now."); -} - -size_t Tensor::calcOffset(const neurun::util::feature::Coordinate4D &coords) -{ - NO_USE(coords); - throw std::runtime_error("offset_element_in_bytes is not supported for cpu::Tensor now."); -} - neurun::graph::operand::Layout ROTensor::layout() const { // TODO Changes to return frontend layout diff --git a/runtimes/neurun/core/src/exec/interp/Tensor.h b/runtimes/neurun/core/src/exec/interp/Tensor.h index 8cfc8cd..1a4723d 100644 --- a/runtimes/neurun/core/src/exec/interp/Tensor.h +++ b/runtimes/neurun/core/src/exec/interp/Tensor.h @@ -21,7 +21,6 @@ #ifndef __NEURUN_EXEC_INTERP_TENSOR_H__ #define __NEURUN_EXEC_INTERP_TENSOR_H__ -#include "util/feature/Coordinate4D.h" #include "model/OperandInfo.h" #include "backend/operand/ITensor.h" #include "graph/operand/Layout.h" @@ -62,7 +61,6 @@ public: virtual size_t dimension(size_t index) const = 0; virtual size_t num_dimensions() const = 0; virtual size_t calcOffset(const util::Coordinates &coords) = 0; - virtual size_t calcOffset(const util::feature::Coordinate4D &coords) = 0; virtual neurun::graph::operand::Layout layout() const = 0; virtual bool has_padding() const = 0; @@ -104,7 +102,6 @@ public: size_t dimension(size_t index) const override { return _info.shape().dim(index); } size_t num_dimensions() const override { return _info.shape().dims().size(); } size_t calcOffset(const util::Coordinates &coords) override; - size_t calcOffset(const util::feature::Coordinate4D &coords) override; neurun::graph::operand::Layout layout() const override; bool has_padding() const override { return false; } model::DataType data_type() const override { return _info.typeInfo().type(); } @@ -137,7 +134,6 @@ public: size_t dimension(size_t index) const override { return _info.shape().dim(index); } size_t num_dimensions() const override { return _info.shape().dims().size(); } size_t calcOffset(const util::Coordinates &coords) override; - size_t calcOffset(const util::feature::Coordinate4D &coords) override; neurun::graph::operand::Layout layout() const override; bool has_padding() const override { return false; } model::DataType data_type() const override { return _info.typeInfo().type(); } -- 2.7.4