blob: a0fab99c5566134b90faeb0c49e404d4b4b02ff1 [file] [log] [blame]
Georgios Pinitasdea2d2d2018-12-19 16:23:17 +00001/*
2 * Copyright (c) 2018-2019 ARM Limited.
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/core/NEON/kernels/NEMemsetKernel.h"
25
26#include "arm_compute/core/AccessWindowStatic.h"
27#include "arm_compute/core/Helpers.h"
28#include "arm_compute/core/ITensor.h"
29#include "arm_compute/core/Utils.h"
30#include "arm_compute/core/Validate.h"
31#include "arm_compute/core/Window.h"
32
33namespace arm_compute
34{
35NEMemsetKernel::NEMemsetKernel()
36 : _tensor(nullptr), _constant_value()
37{
38}
39
40void NEMemsetKernel::configure(ITensor *tensor, const PixelValue &constant_value)
41{
42 ARM_COMPUTE_ERROR_ON_NULLPTR(tensor);
43 _tensor = tensor;
44 _constant_value = constant_value;
45
46 // Configure kernel window
47 Window win = calculate_max_window(*tensor->info(), Steps());
48 INEKernel::configure(win);
49}
50
51void NEMemsetKernel::run(const Window &window, const ThreadInfo &info)
52{
53 ARM_COMPUTE_UNUSED(info);
54 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
55 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
56
57 // Collapse all the batches on the third dimension
58 bool has_collapsed = true;
59 Window collapsed = window.collapse_if_possible(window, Window::DimZ, &has_collapsed);
60 ARM_COMPUTE_ERROR_ON(!has_collapsed);
61
62 uint8_t *const start_valid_region = _tensor->ptr_to_element(_tensor->info()->valid_region().anchor);
63 const auto window_width = static_cast<int>(collapsed.x().end()) - static_cast<int>(collapsed.x().start());
64 const size_t element_size = _tensor->info()->element_size();
65
66 // Unroll X dimension
67 collapsed.set(Window::DimX, Window::Dimension(0, 1, 1));
68
69 Iterator tensor_it(_tensor, collapsed);
Michalis Spyroua4f378d2019-04-26 14:54:54 +010070 execute_window_loop(collapsed, [&](const Coordinates &)
Georgios Pinitasdea2d2d2018-12-19 16:23:17 +000071 {
72 uint8_t *base_addr = start_valid_region + tensor_it.offset();
73 // Set memory
74 for(int i = 0; i < window_width; ++i)
75 {
76 std::memcpy(base_addr + i * element_size, &_constant_value.value, element_size);
77 }
78
79 },
80 tensor_it);
81}
82} // namespace arm_compute