blob: c1953cc41536d0e5363ef73e80d3518fe09c2d43 [file] [log] [blame]
Georgios Pinitas77589b52018-08-21 14:41:35 +01001/*
ramelg016d891572021-09-29 10:05:09 +01002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas77589b52018-08-21 14:41:35 +01003 *
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/CL/functions/CLStridedSlice.h"
25
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010026#include "arm_compute/core/CL/ICLTensor.h"
Georgios Pinitas77589b52018-08-21 14:41:35 +010027#include "arm_compute/core/Types.h"
Georgios Pinitas77589b52018-08-21 14:41:35 +010028
ramelg016d891572021-09-29 10:05:09 +010029#include "src/common/utils/Log.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030#include "src/core/CL/kernels/CLStridedSliceKernel.h"
ramelg016d891572021-09-29 10:05:09 +010031
Georgios Pinitas77589b52018-08-21 14:41:35 +010032namespace arm_compute
33{
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010034namespace experimental
Georgios Pinitas77589b52018-08-21 14:41:35 +010035{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010036void CLStridedSlice::configure(const CLCompileContext &compile_context,
37 const ITensorInfo *input,
38 ITensorInfo *output,
39 const Coordinates &starts,
40 const Coordinates &ends,
41 const BiStrides &strides,
42 int32_t begin_mask,
43 int32_t end_mask,
44 int32_t shrink_axis_mask)
Manuel Bottini2b84be52020-04-08 10:15:51 +010045{
ramelg016d891572021-09-29 10:05:09 +010046 ARM_COMPUTE_LOG_PARAMS(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
Georgios Pinitas40f51a62020-11-21 03:04:18 +000047 auto k = std::make_unique<CLStridedSliceKernel>();
Manuel Bottini2b84be52020-04-08 10:15:51 +010048 k->configure(compile_context, input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
Georgios Pinitas77589b52018-08-21 14:41:35 +010049 _kernel = std::move(k);
50}
51
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010052Status CLStridedSlice::validate(const ITensorInfo *input,
53 const ITensorInfo *output,
54 const Coordinates &starts,
55 const Coordinates &ends,
56 const BiStrides &strides,
57 int32_t begin_mask,
58 int32_t end_mask,
59 int32_t shrink_axis_mask)
Georgios Pinitas77589b52018-08-21 14:41:35 +010060{
61 return CLStridedSliceKernel::validate(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
62}
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010063} // namespace experimental
64
65struct CLStridedSlice::Impl
66{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010067 const ICLTensor *src{nullptr};
68 ICLTensor *dst{nullptr};
69 CLRuntimeContext *ctx{nullptr};
70 std::unique_ptr<experimental::CLStridedSlice> op{nullptr};
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010071};
72
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010073CLStridedSlice::CLStridedSlice(CLRuntimeContext *ctx) : _impl(std::make_unique<Impl>())
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010074{
75 _impl->ctx = ctx;
76}
77
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010078CLStridedSlice::CLStridedSlice(CLStridedSlice &&) = default;
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010079CLStridedSlice &CLStridedSlice::operator=(CLStridedSlice &&) = default;
80CLStridedSlice::~CLStridedSlice() = default;
81
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082void CLStridedSlice::configure(const ICLTensor *input,
83 ICLTensor *output,
84 const Coordinates &starts,
85 const Coordinates &ends,
86 const BiStrides &strides,
87 int32_t begin_mask,
88 int32_t end_mask,
89 int32_t shrink_axis_mask)
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010090{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010091 configure(CLKernelLibrary::get().get_compile_context(), input, output, starts, ends, strides, begin_mask, end_mask,
92 shrink_axis_mask);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +010093}
94
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010095void CLStridedSlice::configure(const CLCompileContext &compile_context,
96 const ICLTensor *input,
97 ICLTensor *output,
98 const Coordinates &starts,
99 const Coordinates &ends,
100 const BiStrides &strides,
101 int32_t begin_mask,
102 int32_t end_mask,
103 int32_t shrink_axis_mask)
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100104{
105 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
106
107 _impl->src = input;
108 _impl->dst = output;
109
Georgios Pinitas40f51a62020-11-21 03:04:18 +0000110 _impl->op = std::make_unique<experimental::CLStridedSlice>();
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100111 _impl->op->configure(compile_context, _impl->src->info(), _impl->dst->info(), starts, ends, strides, begin_mask,
112 end_mask, shrink_axis_mask);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100113}
114
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100115Status CLStridedSlice::validate(const ITensorInfo *input,
116 const ITensorInfo *output,
117 const Coordinates &starts,
118 const Coordinates &ends,
119 const BiStrides &strides,
120 int32_t begin_mask,
121 int32_t end_mask,
122 int32_t shrink_axis_mask)
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100123{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100124 return experimental::CLStridedSlice::validate(input, output, starts, ends, strides, begin_mask, end_mask,
125 shrink_axis_mask);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100126}
127
128void CLStridedSlice::run()
129{
Georgios Pinitas0499dff2020-07-31 22:21:38 +0100130 ITensorPack pack;
131 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
132 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
133 _impl->op->run(pack);
Michalis Spyrouf20d6d62020-07-16 17:46:51 +0100134}
Georgios Pinitas77589b52018-08-21 14:41:35 +0100135} // namespace arm_compute