aboutsummaryrefslogtreecommitdiff
path: root/src/core/SubTensorInfo.cpp
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-01-10 15:33:28 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:43:42 +0000
commit652bde553f506caac4c563988dc9baf746f9584d (patch)
tree931d17bdfa70e9968cd434cfa53db8919bb534ea /src/core/SubTensorInfo.cpp
parentf72f9367d1eddee91f15a64952b99ee6b80b821d (diff)
downloadComputeLibrary-652bde553f506caac4c563988dc9baf746f9584d.tar.gz
COMPMID-674 - Create Google InceptionV3 example
Change-Id: I389e0d4104b7dde60b7cdd612a83f3328517e44c Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115804 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src/core/SubTensorInfo.cpp')
-rw-r--r--src/core/SubTensorInfo.cpp53
1 files changed, 47 insertions, 6 deletions
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<int>(shape[i]);
+ if((dimension_extend > static_cast<int>(parent_shape[i])) && (dimension_extend > 0))
+ {
+ parent_shape.set(i, static_cast<size_t>(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<ITensorInfo> 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);