From 652bde553f506caac4c563988dc9baf746f9584d Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 10 Jan 2018 15:33:28 +0000 Subject: COMPMID-674 - Create Google InceptionV3 example Change-Id: I389e0d4104b7dde60b7cdd612a83f3328517e44c Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115804 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- src/core/SubTensorInfo.cpp | 53 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'src/core/SubTensorInfo.cpp') diff --git a/src/core/SubTensorInfo.cpp b/src/core/SubTensorInfo.cpp index 7a4886ff60..0150a95cc6 100644 --- a/src/core/SubTensorInfo.cpp +++ b/src/core/SubTensorInfo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,17 +30,49 @@ using namespace arm_compute; +namespace +{ +/** Extends parent shape depending on subtensor's coordinates and shape + * + * @param parent_shape Parent shape + * @param shape Subtensor shape + * @param coords Subtensor coordinates inside parent tensor + * + * @return Extended parent shape + */ +TensorShape extend_parent_shape(TensorShape parent_shape, TensorShape shape, Coordinates coords) +{ + // Subtensor should not index in x, y dimensions. + ARM_COMPUTE_ERROR_ON((coords.x() != 0) || (coords.y() != 0)); + + // Cannot extend on x, y ? + ARM_COMPUTE_ERROR_ON((parent_shape.total_size() != 0) && (parent_shape.x() != shape.x()) && (parent_shape.y() != shape.y())); + + // Extend shape + for(unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i) + { + int dimension_extend = coords[i] + static_cast(shape[i]); + if((dimension_extend > static_cast(parent_shape[i])) && (dimension_extend > 0)) + { + parent_shape.set(i, static_cast(dimension_extend)); + } + } + + return parent_shape; +} +} // namespace + SubTensorInfo::SubTensorInfo() - : _parent(nullptr), _tensor_shape(), _coords(), _valid_region{ Coordinates(), _tensor_shape } + : _parent(nullptr), _tensor_shape(), _coords(), _valid_region{ Coordinates(), _tensor_shape }, _extend_parent(false) { } -SubTensorInfo::SubTensorInfo(ITensorInfo *parent, TensorShape tensor_shape, Coordinates coords) - : _parent(parent), _tensor_shape(tensor_shape), _coords(coords), _valid_region{ Coordinates(), _tensor_shape } +SubTensorInfo::SubTensorInfo(ITensorInfo *parent, TensorShape tensor_shape, Coordinates coords, bool extend_parent) + : _parent(parent), _tensor_shape(tensor_shape), _coords(coords), _valid_region{ Coordinates(), _tensor_shape }, _extend_parent(extend_parent) { ARM_COMPUTE_ERROR_ON(parent == nullptr); // Check if subtensor is valid if parent is configured - if(parent->tensor_shape().total_size() != 0) + if(parent->tensor_shape().total_size() != 0 && !_extend_parent) { ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(parent->tensor_shape(), coords, tensor_shape); } @@ -63,11 +95,19 @@ std::unique_ptr SubTensorInfo::clone() const ITensorInfo &SubTensorInfo::set_tensor_shape(TensorShape shape) { ARM_COMPUTE_ERROR_ON(_parent == nullptr); + // Check if subtensor is valid if parent is configured - if(_parent->tensor_shape().total_size() != 0) + if(_parent->tensor_shape().total_size() != 0 && !_extend_parent) { ARM_COMPUTE_ERROR_ON_INVALID_SUBTENSOR(_parent->tensor_shape(), _coords, shape); } + else if(_extend_parent) // Extend parent shape, configure if specified + { + ARM_COMPUTE_ERROR_ON((_parent->data_type() == DataType::UNKNOWN) && (_parent->format() == Format::UNKNOWN)); + TensorShape parent_extended_shape = extend_parent_shape(_parent->tensor_shape(), shape, _coords); + _parent->set_tensor_shape(parent_extended_shape); + _parent->set_valid_region(ValidRegion{ Coordinates(), parent_extended_shape }); + } _tensor_shape = shape; return *this; } @@ -76,6 +116,7 @@ bool SubTensorInfo::extend_padding(const PaddingSize &padding) { ARM_COMPUTE_ERROR_ON(_parent == nullptr); ARM_COMPUTE_ERROR_ON(!_parent->is_resizable()); + ARM_COMPUTE_ERROR_ON(_parent->total_size() == 0); // Extend parent padding if required return _parent->extend_padding(padding); -- cgit v1.2.1