blob: 12d43adc843ca7048cf81e08d4670c3322f01ae0 [file] [log] [blame]
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +00001/*
ramelg01cbbb0382021-09-17 17:36:57 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/runtime/NEON/functions/NESlice.h"
25
26#include "arm_compute/core/ITensor.h"
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000027#include "arm_compute/core/Types.h"
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000028#include "arm_compute/core/utils/helpers/tensor_transform.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029#include "arm_compute/core/Validate.h"
30
ramelg01cbbb0382021-09-17 17:36:57 +010031#include "src/common/utils/Log.h"
Michalis Spyrouebcebf12020-10-21 00:04:14 +010032#include "src/core/NEON/kernels/NEStridedSliceKernel.h"
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000033
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000034namespace arm_compute
35{
Michalis Spyrou1732da82020-06-19 12:40:46 +010036namespace experimental
37{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010038void NESlice::configure(const ITensorInfo *input,
39 ITensorInfo *output,
40 const Coordinates &starts,
41 const Coordinates &ends)
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000042{
43 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
ramelg01cbbb0382021-09-17 17:36:57 +010044 ARM_COMPUTE_LOG_PARAMS(input, output, starts, ends);
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000045
46 // Get absolute end coordinates
47 const int32_t slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(ends);
48
Georgios Pinitas40f51a62020-11-21 03:04:18 +000049 auto k = std::make_unique<NEStridedSliceKernel>();
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000050 k->configure(input, output, starts, ends, BiStrides(), 0, slice_end_mask, 0);
51 _kernel = std::move(k);
52}
53
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010054Status NESlice::validate(const ITensorInfo *input,
55 const ITensorInfo *output,
56 const Coordinates &starts,
57 const Coordinates &ends)
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000058{
59 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
60
61 // Check start dimensions for being non-negative
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 ARM_COMPUTE_RETURN_ERROR_ON(
63 std::any_of(starts.cbegin(), starts.cbegin() + starts.num_dimensions(), [](int i) { return i < 0; }));
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000064
65 // Get absolute end coordinates
66 const int32_t slice_end_mask = arm_compute::helpers::tensor_transform::construct_slice_end_mask(ends);
67
68 return NEStridedSliceKernel::validate(input, output, starts, ends, BiStrides(), 0, slice_end_mask, 0);
69}
Michalis Spyrou1732da82020-06-19 12:40:46 +010070} // namespace experimental
71
72struct NESlice::Impl
73{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010074 const ITensor *src{nullptr};
75 ITensor *dst{nullptr};
76 std::unique_ptr<experimental::NESlice> op{nullptr};
Michalis Spyrou1732da82020-06-19 12:40:46 +010077};
78
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010079NESlice::NESlice() : _impl(std::make_unique<Impl>())
Michalis Spyrou1732da82020-06-19 12:40:46 +010080{
81}
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082NESlice::NESlice(NESlice &&) = default;
Michalis Spyrou1732da82020-06-19 12:40:46 +010083NESlice &NESlice::operator=(NESlice &&) = default;
84NESlice::~NESlice() = default;
85
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010086Status NESlice::validate(const ITensorInfo *input,
87 const ITensorInfo *output,
88 const Coordinates &starts,
89 const Coordinates &ends)
Michalis Spyrou1732da82020-06-19 12:40:46 +010090{
91 return experimental::NESlice::validate(input, output, starts, ends);
92}
93
94void NESlice::configure(const ITensor *input, ITensor *output, const Coordinates &starts, const Coordinates &ends)
95{
96 _impl->src = input;
97 _impl->dst = output;
Georgios Pinitas40f51a62020-11-21 03:04:18 +000098 _impl->op = std::make_unique<experimental::NESlice>();
Michalis Spyrou1732da82020-06-19 12:40:46 +010099 _impl->op->configure(input->info(), output->info(), starts, ends);
100}
101
102void NESlice::run()
103{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100104 ITensorPack pack;
105 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
106 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
107 _impl->op->run(pack);
Michalis Spyrou1732da82020-06-19 12:40:46 +0100108}
109
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000110} // namespace arm_compute