From 06f98b60da87ff6dd24538ac60ccbbaf7c096378 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 17 Jun 2019 19:15:56 +0900 Subject: [PATCH] Remove axis restriction on concat elimination (#5414) * Remove axis restriction on concat elimination Remove axis restruction that is allowed channel axis only on concat elimination Signed-off-by: Hyeongseok Oh * Remove old comment --- .../neurun/backend/acl_common/TemplTensorBuilder.h | 12 +--------- .../neurun/core/src/compiler/SubTensorAnalyzer.cc | 26 +++++++++++++--------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/runtimes/neurun/backend/acl_common/TemplTensorBuilder.h b/runtimes/neurun/backend/acl_common/TemplTensorBuilder.h index decc5ae..8d96aad 100644 --- a/runtimes/neurun/backend/acl_common/TemplTensorBuilder.h +++ b/runtimes/neurun/backend/acl_common/TemplTensorBuilder.h @@ -221,17 +221,7 @@ void TemplTensorBuilder::prepare(voi assert(asDataType(info.type().type()) == parent_tensor->info()->data_type()); // TODO Change to set data_layout for each front-end auto shape = asTensorShape(info.shape(), _layout, _apply_dim_correction_map[current]); - - // Only support axis: 3 (channel) - ::arm_compute::Coordinates coordinates; - coordinates.set_num_dimensions(4); - assert(info.offset()[0] == 0); - assert(info.offset()[1] == 0); - assert(info.offset()[2] == 0); - // TODO Change to set data_layout for each front-end - auto channel_index = get_data_layout_dimension_index( - parent_tensor->info()->data_layout(), ::arm_compute::DataLayoutDimension::CHANNEL); - coordinates[channel_index] = info.offset()[3]; + ::arm_compute::Coordinates coordinates = asTensorCoordinate(info.offset(), _layout); auto tensor = std::make_shared(parent_tensor.get(), shape, coordinates, true); _subtensors[current] = tensor; stack.pop(); diff --git a/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc b/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc index 5859adc..efbd558 100644 --- a/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc +++ b/runtimes/neurun/core/src/compiler/SubTensorAnalyzer.cc @@ -21,6 +21,7 @@ #include "cpp14/memory.h" #include "model/OperandIndexSequence.h" #include "util/logging.h" +#include "util/Coordinates.h" namespace neurun { @@ -42,25 +43,28 @@ void SubTensorAnalyzer::visit(const model::operation::ConcatNode &node) return; } - // NOTE This implementation assumes concat over feature depth - // TODO Remove this assumption - int32_t axis = _ctx.at(axis_index).asScalar(); - if (axis != 3) - { - VERBOSE(SUBTENSOR) << "Cannot handle axis is not channel" << std::endl; - return; - } + int32_t axis_raw = _ctx.at(axis_index).asScalar(); auto &output_index = node.getOutputs().at(0); auto &inputs = node.getInputs(); int32_t axis_point = 0; + const auto rank = _ctx.at(output_index).shape().rank(); + uint32_t axis = axis_raw < 0 ? (axis_raw + rank) : axis_raw; + assert(rank > axis); + for (auto &input_index : inputs) { auto input_shape = _ctx.at(input_index).shape(); - std::vector offset = {0, 0, 0, 0}; - offset[axis] = axis_point; - neurun::util::Coordinates coordinate_info({offset[0], offset[1], offset[2], offset[3]}); + assert(rank == input_shape.rank()); + + neurun::util::Coordinates coordinate_info{}; + for (uint32_t i = 0; i < rank; i++) + { + coordinate_info.set(i, 0); + } + coordinate_info.set(axis, axis_point); + std::unique_ptr parentInfo = nnfw::cpp14::make_unique(output_index, coordinate_info); -- 2.7.4