Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 1 | /* |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 3 | * |
| 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 Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/ICLTensor.h" |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Types.h" |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 28 | |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 29 | #include "src/common/utils/Log.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 30 | #include "src/core/CL/kernels/CLStridedSliceKernel.h" |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 31 | |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 32 | namespace arm_compute |
| 33 | { |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 34 | namespace experimental |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 35 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 36 | void 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 Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 45 | { |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 46 | ARM_COMPUTE_LOG_PARAMS(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 47 | auto k = std::make_unique<CLStridedSliceKernel>(); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 48 | k->configure(compile_context, input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 49 | _kernel = std::move(k); |
| 50 | } |
| 51 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 52 | Status 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 Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 60 | { |
| 61 | return CLStridedSliceKernel::validate(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask); |
| 62 | } |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 63 | } // namespace experimental |
| 64 | |
| 65 | struct CLStridedSlice::Impl |
| 66 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 67 | const ICLTensor *src{nullptr}; |
| 68 | ICLTensor *dst{nullptr}; |
| 69 | CLRuntimeContext *ctx{nullptr}; |
| 70 | std::unique_ptr<experimental::CLStridedSlice> op{nullptr}; |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 73 | CLStridedSlice::CLStridedSlice(CLRuntimeContext *ctx) : _impl(std::make_unique<Impl>()) |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 74 | { |
| 75 | _impl->ctx = ctx; |
| 76 | } |
| 77 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 78 | CLStridedSlice::CLStridedSlice(CLStridedSlice &&) = default; |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 79 | CLStridedSlice &CLStridedSlice::operator=(CLStridedSlice &&) = default; |
| 80 | CLStridedSlice::~CLStridedSlice() = default; |
| 81 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | void 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 Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 90 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 91 | configure(CLKernelLibrary::get().get_compile_context(), input, output, starts, ends, strides, begin_mask, end_mask, |
| 92 | shrink_axis_mask); |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 95 | void 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 Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 104 | { |
| 105 | ARM_COMPUTE_ERROR_ON_NULLPTR(input); |
| 106 | |
| 107 | _impl->src = input; |
| 108 | _impl->dst = output; |
| 109 | |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 110 | _impl->op = std::make_unique<experimental::CLStridedSlice>(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 111 | _impl->op->configure(compile_context, _impl->src->info(), _impl->dst->info(), starts, ends, strides, begin_mask, |
| 112 | end_mask, shrink_axis_mask); |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 115 | Status 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 Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 123 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 124 | return experimental::CLStridedSlice::validate(input, output, starts, ends, strides, begin_mask, end_mask, |
| 125 | shrink_axis_mask); |
Michalis Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void CLStridedSlice::run() |
| 129 | { |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 130 | 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 Spyrou | f20d6d6 | 2020-07-16 17:46:51 +0100 | [diff] [blame] | 134 | } |
Georgios Pinitas | 77589b5 | 2018-08-21 14:41:35 +0100 | [diff] [blame] | 135 | } // namespace arm_compute |