Compute Library
 21.08
CpuFloorKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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 
30 #include "src/core/CPP/Validate.h"
33 
36 
37 namespace arm_compute
38 {
39 namespace cpu
40 {
41 namespace kernels
42 {
43 namespace
44 {
45 struct FloorSelectorData
46 {
48 };
49 
52 
53 struct FloorUKernel
54 {
55  const char *name;
56  const FloorSelectorPtr is_selected;
57  FloorUKernelPtr ukernel;
58 };
59 
60 static const FloorUKernel available_kernels[] =
61 {
62  {
63  "neon_fp16_floor",
64  [](const FloorSelectorData & data) { return data.dt == DataType::F16; },
66  },
67  {
68  "neon_fp32_floor",
69  [](const FloorSelectorData & data) { return data.dt == DataType::F32; },
71  },
72 };
73 
74 /** Micro-kernel selector
75  *
76  * @param[in] data Selection data passed to help pick the appropriate micro-kernel
77  *
78  * @return A matching micro-kernel else nullptr
79  */
80 const FloorUKernel *get_implementation(const FloorSelectorData &data)
81 {
82  for(const auto &uk : available_kernels)
83  {
84  if(uk.is_selected(data))
85  {
86  return &uk;
87  }
88  }
89  return nullptr;
90 }
91 
92 Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst)
93 {
95 
96  const auto *uk = get_implementation(FloorSelectorData{ src->data_type() });
97  ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
98 
99  // Validate in case of configured output
100  if(dst->total_size() > 0)
101  {
104  }
105 
106  return Status{};
107 }
108 } // namespace
109 
111 {
113  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst));
114 
115  auto_init_if_empty(*dst, src->tensor_shape(), 1, src->data_type());
116 
117  const auto *uk = get_implementation(FloorSelectorData{ src->data_type() });
119 
120  _run_method = uk->ukernel;
121  _name = std::string("CpuFloorKernel").append("/").append(uk->name);
122 
123  // Configure kernel window
124  const Window win = calculate_max_window(*src, Steps());
125 
126  ICPPKernel::configure(win);
127 }
128 
130 {
131  ARM_COMPUTE_UNUSED(dst);
132  ARM_COMPUTE_ERROR_ON(!bool(validate_arguments(src, dst)));
133 
134  Window win;
136  return win;
137 }
138 
140 {
141  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
142  return Status{};
143 }
144 
145 void CpuFloorKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
146 {
147  ARM_COMPUTE_UNUSED(info);
150 
151  ARM_COMPUTE_ERROR_ON(tensors.empty());
152  ARM_COMPUTE_ERROR_ON(_run_method == nullptr);
153 
156  const auto len = static_cast<int>(window.x().end()) - static_cast<int>(window.x().start());
157 
158  Window win{ window };
159  win.set(Window::DimX, Window::Dimension(0, 1, 1));
160 
161  Iterator src_it(src, win);
162  Iterator dst_it(dst, win);
163 
164  execute_window_loop(win, [&](const Coordinates &)
165  {
166  _run_method(src_it.ptr(), dst_it.ptr(), len);
167  },
168  src_it, dst_it);
169 }
170 
171 const char *CpuFloorKernel::name() const
172 {
173  return _name.c_str();
174 }
175 } // namespace kernels
176 } // namespace cpu
177 } // namespace arm_compute
Window infer_window(const ITensorInfo *src, const ITensorInfo *dst)
Infer execution window.
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 REGISTER_FP16_NEON(func_name)
Definition: Registrars.h:42
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
bool empty() const
Checks if pack is empty.
Definition: ITensorPack.cpp:80
#define REGISTER_FP32_NEON(func_name)
Definition: Registrars.h:61
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#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
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
Status class.
Definition: Error.h:52
FloorUKernelPtr ukernel
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
decltype(strategy::transforms) typedef type
Interface for CPU tensor.
Definition: ITensor.h:36
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor&#39;s dimensions to fill the window dimensions.
Definition: Window.inl:276
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
const char * name
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
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
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Coordinates of an item.
Definition: Coordinates.h:37
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
const FloorSelectorPtr is_selected
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
Definition: Helpers.inl:139
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
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:64
Information about executing thread and CPU.
Definition: CPPTypes.h:158
void fp16_neon_floor(const void *src, void *dst, int len)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
void fp32_neon_floor(const void *src, void *dst, int len)
Definition: fp32.cpp:37
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
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
const char * name() const override
Name of the kernel.
void configure(const ITensorInfo *src, ITensorInfo *dst)
Configure kernel for a given list of arguments.
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
DataType
Available data types.
Definition: Types.h:77
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
Describe a multidimensional execution window.
Definition: Window.h:39
DataType dt
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145