Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/kernels/CpuFillKernel.h" |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 25 | |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/ITensor.h" |
| 28 | #include "arm_compute/core/Utils.h" |
| 29 | #include "arm_compute/core/Validate.h" |
| 30 | #include "arm_compute/core/Window.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 31 | |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 32 | #include "src/core/helpers/AutoConfiguration.h" |
| 33 | #include "src/core/helpers/WindowHelpers.h" |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 37 | namespace cpu |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 38 | { |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 39 | namespace kernels |
| 40 | { |
| 41 | void CpuFillKernel::configure(const ITensorInfo *tensor, const PixelValue &constant_value) |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 42 | { |
| 43 | ARM_COMPUTE_ERROR_ON_NULLPTR(tensor); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 44 | _constant_value = constant_value; |
| 45 | |
| 46 | // Configure kernel window |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 47 | Window win = calculate_max_window(*tensor, Steps()); |
| 48 | ICpuKernel::configure(win); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 51 | void CpuFillKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 52 | { |
| 53 | ARM_COMPUTE_UNUSED(info); |
| 54 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 55 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICpuKernel::window(), window); |
| 56 | |
| 57 | auto inout = tensors.get_tensor(TensorType::ACL_SRC_DST); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 58 | |
| 59 | // Collapse all the batches on the third dimension |
| 60 | bool has_collapsed = true; |
| 61 | Window collapsed = window.collapse_if_possible(window, Window::DimZ, &has_collapsed); |
| 62 | ARM_COMPUTE_ERROR_ON(!has_collapsed); |
| 63 | |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 64 | uint8_t *const start_valid_region = inout->ptr_to_element(inout->info()->valid_region().anchor); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 65 | const auto window_width = static_cast<int>(collapsed.x().end()) - static_cast<int>(collapsed.x().start()); |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 66 | const size_t element_size = inout->info()->element_size(); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 67 | |
| 68 | // Unroll X dimension |
| 69 | collapsed.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 70 | |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 71 | Iterator tensor_it(inout, collapsed); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 72 | execute_window_loop( |
| 73 | collapsed, |
| 74 | [&](const Coordinates &) |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 75 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 76 | uint8_t *base_addr = start_valid_region + tensor_it.offset(); |
| 77 | // Set memory |
| 78 | for (int i = 0; i < window_width; ++i) |
| 79 | { |
| 80 | std::memcpy(base_addr + i * element_size, &_constant_value.value, element_size); |
| 81 | } |
| 82 | }, |
| 83 | tensor_it); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 84 | } |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 85 | |
| 86 | const char *CpuFillKernel::name() const |
| 87 | { |
| 88 | return "CpuFillKernel"; |
| 89 | } |
| 90 | } // namespace kernels |
| 91 | } // namespace cpu |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 92 | } // namespace arm_compute |