Compute Library
 21.02
CpuFillKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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  */
25 
28 #include "arm_compute/core/Utils.h"
34 
35 namespace arm_compute
36 {
37 namespace cpu
38 {
39 namespace kernels
40 {
41 void CpuFillKernel::configure(const ITensorInfo *tensor, const PixelValue &constant_value)
42 {
44  _constant_value = constant_value;
45 
46  // Configure kernel window
47  Window win = calculate_max_window(*tensor, Steps());
48  ICpuKernel::configure(win);
49 }
50 
52 {
53  ARM_COMPUTE_UNUSED(info);
56 
57  auto inout = tensors.get_tensor(TensorType::ACL_SRC_DST);
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 
64  uint8_t *const start_valid_region = inout->ptr_to_element(inout->info()->valid_region().anchor);
65  const auto window_width = static_cast<int>(collapsed.x().end()) - static_cast<int>(collapsed.x().start());
66  const size_t element_size = inout->info()->element_size();
67 
68  // Unroll X dimension
69  collapsed.set(Window::DimX, Window::Dimension(0, 1, 1));
70 
71  Iterator tensor_it(inout, collapsed);
72  execute_window_loop(collapsed, [&](const Coordinates &)
73  {
74  uint8_t *base_addr = start_valid_region + tensor_it.offset();
75  // Set memory
76  for(int i = 0; i < window_width; ++i)
77  {
78  std::memcpy(base_addr + i * element_size, &_constant_value.value, element_size);
79  }
80 
81  },
82  tensor_it);
83 }
84 
85 const char *CpuFillKernel::name() const
86 {
87  return "CpuFillKernel";
88 }
89 } // namespace kernels
90 } // namespace cpu
91 } // namespace arm_compute
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
Copyright (c) 2017-2021 Arm Limited.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
Definition: Window.inl:68
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Coordinates of an item.
Definition: Coordinates.h:37
const char * name() const override
Name of the kernel.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
void configure(const ITensorInfo *tensor, const PixelValue &constant_value)
Configure kernel for a given list of arguments.
union arm_compute::PixelValue::@0 value
Union which describes the value of a pixel for any image format.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:50
Information about executing thread and CPU.
Definition: CPPTypes.h:235
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Tensor packing service.
Definition: ITensorPack.h:37
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77
constexpr size_t offset() const
Return the offset in bytes from the first element to the current position of the iterator.
Definition: Helpers.inl:134
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:46
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145