diff options
author | Viet-Hoa Do <viet-hoa.do@arm.com> | 2023-02-24 15:52:21 +0000 |
---|---|---|
committer | Viet-Hoa Do <viet-hoa.do@arm.com> | 2023-03-08 15:09:25 +0000 |
commit | 37c989a58a04985dfdc21089c7dacc7e1925a4d0 (patch) | |
tree | 6e60ada38ceaf2b651cc44a481004abbb89ceae4 /arm_compute/core/Helpers.inl | |
parent | 98aca0fda7f7c7c16bd2d1cf5386246ad796d9de (diff) | |
download | ComputeLibrary-37c989a58a04985dfdc21089c7dacc7e1925a4d0.tar.gz |
Add support for arbitrary parameters for CPU Gather
* The shape of input and indices tensors, and the gather axis
can be any number, as long as these are valid and the output
tensor doesn't have more dimensions than the library supports.
* Update the reference code to be more generic and straightforward.
* Add necessary test cases.
Signed-off-by: Viet-Hoa Do <viet-hoa.do@arm.com>
Resolves: COMPMID-5919
Change-Id: Ic7e2032777aa97ecc147f61d5388528697508ab1
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9199
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core/Helpers.inl')
-rw-r--r-- | arm_compute/core/Helpers.inl | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/arm_compute/core/Helpers.inl b/arm_compute/core/Helpers.inl index a910521f94..ff902bba20 100644 --- a/arm_compute/core/Helpers.inl +++ b/arm_compute/core/Helpers.inl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2021 Arm Limited. + * Copyright (c) 2016-2021, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -98,13 +98,23 @@ inline Iterator::Iterator(const ITensor *tensor, const Window &win) ARM_COMPUTE_ERROR_ON(tensor == nullptr); ARM_COMPUTE_ERROR_ON(tensor->info() == nullptr); - const ITensorInfo *info = tensor->info(); - const Strides &strides = info->strides_in_bytes(); + initialize(tensor->info()->num_dimensions(), tensor->info()->strides_in_bytes(), tensor->buffer(), tensor->info()->offset_first_element_in_bytes(), win); +} + +inline Iterator::Iterator(size_t num_dims, const Strides &strides, uint8_t *buffer, size_t offset, const Window &win) + : Iterator() +{ + initialize(num_dims, strides, buffer, offset, win); +} + +inline void Iterator::initialize(size_t num_dims, const Strides &strides, uint8_t *buffer, size_t offset, const Window &win) +{ + ARM_COMPUTE_ERROR_ON(buffer == nullptr); - _ptr = tensor->buffer() + info->offset_first_element_in_bytes(); + _ptr = buffer + offset; //Initialize the stride for each dimension and calculate the position of the first element of the iteration: - for(unsigned int n = 0; n < info->num_dimensions(); ++n) + for(unsigned int n = 0; n < num_dims; ++n) { _dims[n]._stride = win[n].step() * strides[n]; std::get<0>(_dims)._dim_start += static_cast<size_t>(strides[n]) * win[n].start(); @@ -116,7 +126,7 @@ inline Iterator::Iterator(const ITensor *tensor, const Window &win) _dims[n]._dim_start = std::get<0>(_dims)._dim_start; } - ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(win, info->num_dimensions()); + ARM_COMPUTE_ERROR_ON_WINDOW_DIMENSIONS_GTE(win, num_dims); } inline void Iterator::increment(const size_t dimension) |