Compute Library
 23.11
Validate.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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 
27  const char *file,
28  const int line,
29  const arm_compute::Window &full,
30  const arm_compute::Window &win)
31 {
32  full.validate();
33  win.validate();
34 
35  for (size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
36  {
37  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line);
38  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line);
39  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line);
40  }
41  return arm_compute::Status{};
42 }
43 
45  const char *file,
46  const int line,
47  const arm_compute::Window &full,
48  const arm_compute::Window &sub)
49 {
50  full.validate();
51  sub.validate();
52 
53  for (size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
54  {
55  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line);
56  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line);
57  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line);
58  ARM_COMPUTE_RETURN_ERROR_ON_LOC((sub[i].start() - full[i].start()) % sub[i].step(), function, file, line);
59  }
60  return arm_compute::Status{};
61 }
62 
64  const char *file,
65  const int line,
66  const arm_compute::Window &full,
67  const arm_compute::Window &window,
68  const int dim)
69 {
70  full.validate();
71  window.validate();
72 
73  ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != 0, function, file, line);
74  ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line);
75  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line);
76 
77  return arm_compute::Status{};
78 }
79 
81  const char *function, const char *file, const int line, const arm_compute::Coordinates &pos, unsigned int max_dim)
82 {
83  for (unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
84  {
85  ARM_COMPUTE_RETURN_ERROR_ON_LOC(pos[i] != 0, function, file, line);
86  }
87  return arm_compute::Status{};
88 }
89 
91  const char *function, const char *file, const int line, const arm_compute::Window &win, unsigned int max_dim)
92 {
93  for (unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
94  {
96  (win[i].start() != 0) || (win[i].end() != win[i].step()), function, file, line,
97  "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i);
98  }
99  return arm_compute::Status{};
100 }
101 
103  const char *file,
104  const int line,
106 {
107  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
108  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor->info() == nullptr, function, file, line);
109  ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(tensor->info()->num_dimensions() != 2, function, file, line,
110  "Only 2D Tensors are supported by this kernel (%zu passed)",
111  tensor->info()->num_dimensions());
112  return arm_compute::Status{};
113 }
114 
116  const char *file,
117  const int line,
119 {
120  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
121  ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(tensor->num_dimensions() != 2, function, file, line,
122  "Only 2D Tensors are supported by this kernel (%zu passed)",
123  tensor->num_dimensions());
124  return arm_compute::Status{};
125 }
126 
128  const char *function, const char *file, const int line, arm_compute::Format fmt, arm_compute::Channel cn)
129 {
132 
133  switch (fmt)
134  {
138  break;
143  break;
147  break;
156  break;
157  default:
158  ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format.");
159  }
160  return arm_compute::Status{};
161 }
162 
164  const char *file,
165  const int line,
166  const arm_compute::IKernel *kernel)
167 {
168  ARM_COMPUTE_RETURN_ERROR_ON_LOC(kernel == nullptr, function, file, line);
169  ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(!kernel->is_window_configured(), function, file, line,
170  "This kernel hasn't been configured.");
171  return arm_compute::Status{};
172 }
173 
175  const char *file,
176  const int line,
177  const TensorShape &parent_shape,
178  const Coordinates &coords,
179  const TensorShape &shape)
180 {
181  // Check dimensions
182  for (unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i)
183  {
184  const bool invalid_idx = coords[i] >= static_cast<int>(parent_shape[i]);
185  const bool out_of_bounds_size = coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]);
186  ARM_COMPUTE_RETURN_ERROR_ON_LOC(invalid_idx || out_of_bounds_size, function, file, line);
187  }
188  return arm_compute::Status{};
189 }
190 
192  const char *file,
193  const int line,
194  const ValidRegion &parent_valid_region,
195  const ValidRegion &valid_region)
196 {
197  // Check valid regions
198  for (unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d)
199  {
200  ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line);
202  (parent_valid_region.anchor[d] + static_cast<int>(parent_valid_region.shape[d])) <
203  (valid_region.anchor[d] + static_cast<int>(valid_region.shape[d])),
204  function, file, line);
205  }
206 
207  return arm_compute::Status{};
208 }
arm_compute::Channel::V
@ V
Cr/V/Value channel.
arm_compute::Format::RGB888
@ RGB888
3 channels, 1 U8 per channel
arm_compute::Format::UNKNOWN
@ UNKNOWN
Unknown image format.
arm_compute::error_on_coordinates_dimensions_gte
arm_compute::Status error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line, const Coordinates &pos, unsigned int max_dim)
Return an error if the passed coordinates have too many dimensions.
Definition: Validate.cpp:80
arm_compute::error_on_window_dimensions_gte
arm_compute::Status error_on_window_dimensions_gte(const char *function, const char *file, const int line, const Window &win, unsigned int max_dim)
Return an error if the passed window has too many dimensions.
Definition: Validate.cpp:90
arm_compute::error_on_unconfigured_kernel
arm_compute::Status error_on_unconfigured_kernel(const char *function, const char *file, const int line, const IKernel *kernel)
Return an error if the kernel is not configured.
Definition: Validate.cpp:163
arm_compute::error_on_invalid_subwindow
arm_compute::Status error_on_invalid_subwindow(const char *function, const char *file, const int line, const Window &full, const Window &sub)
Return an error if the passed subwindow is invalid.
Definition: Validate.cpp:44
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::error_on_channel_not_in_known_format
arm_compute::Status error_on_channel_not_in_known_format(const char *function, const char *file, const int line, Format fmt, Channel cn)
Return an error if the channel is not in format.
Definition: Validate.cpp:127
arm_compute::Channel::Y
@ Y
Luma channel.
arm_compute::ITensor
Interface for CPU tensor.
Definition: ITensor.h:36
arm_compute::Channel::G
@ G
Green channel.
arm_compute::Format::UV88
@ UV88
2 channel, 1 U8 per channel
arm_compute::test::validation::valid_region
const ValidRegion valid_region
Definition: Scale.cpp:214
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
arm_compute::error_on_mismatching_windows
arm_compute::Status error_on_mismatching_windows(const char *function, const char *file, const int line, const Window &full, const Window &win)
Return an error if the passed window is invalid.
Definition: Validate.cpp:26
arm_compute::error_on_tensor_not_2d
arm_compute::Status error_on_tensor_not_2d(const char *function, const char *file, const int line, const ITensor *tensor)
Return an error if the tensor is not 2D.
Definition: Validate.cpp:102
arm_compute::Channel::B
@ B
Blue channel.
arm_compute::IKernel
Common information for all the kernels.
Definition: IKernel.h:33
arm_compute::ValidRegion
Container for valid region of a window.
Definition: Types.h:143
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::Window::validate
void validate() const
Will validate all the window's dimensions' values when asserts are enabled.
Definition: Window.inl:187
arm_compute::Format::IYUV
@ IYUV
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
arm_compute::IKernel::is_window_configured
bool is_window_configured() const
Function to check if the embedded window of this kernel has been configured.
Definition: IKernel.cpp:50
arm_compute::Format::RGBA8888
@ RGBA8888
4 channels, 1 U8 per channel
ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(cond, func, file, line, msg,...)
If the condition is true, an error is thrown.
Definition: Error.h:265
arm_compute::Coordinates
Coordinates of an item.
Definition: Coordinates.h:37
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:67
arm_compute::Format
Format
Image colour formats.
Definition: CoreTypes.h:58
arm_compute::Channel
Channel
Available channels.
Definition: CoreTypes.h:41
arm_compute::Format::YUYV422
@ YUYV422
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
ARM_COMPUTE_ERROR_LOC
#define ARM_COMPUTE_ERROR_LOC(func, file, line, msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:375
arm_compute::Format::YUV444
@ YUV444
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes.
arm_compute::Format::UYVY422
@ UYVY422
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
arm_compute::Channel::UNKNOWN
@ UNKNOWN
arm_compute::Window
Describe a multidimensional execution window.
Definition: Window.h:39
arm_compute::ValidRegion::shape
TensorShape shape
Shape of the valid region.
Definition: Types.h:223
arm_compute::Channel::A
@ A
Alpha channel.
arm_compute::Format::NV12
@ NV12
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
arm_compute::error_on_invalid_subtensor_valid_region
arm_compute::Status error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line, const ValidRegion &parent_valid_region, const ValidRegion &valid_region)
Return an error if the valid region of a subtensor is not inside the valid region of the parent tenso...
Definition: Validate.cpp:191
arm_compute::Channel::R
@ R
Red channel.
arm_compute::mlgo::parser::end
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:283
arm_compute::Channel::U
@ U
Cb/U channel.
arm_compute::error_on_invalid_subtensor
arm_compute::Status error_on_invalid_subtensor(const char *function, const char *file, const int line, const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape)
Return an error if if the coordinates and shape of the subtensor are within the parent tensor.
Definition: Validate.cpp:174
arm_compute::error_on_window_not_collapsable_at_dimension
arm_compute::Status error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line, const Window &full, const Window &window, const int dim)
Return an error if the window can't be collapsed at the given dimension.
Definition: Validate.cpp:63
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:44
arm_compute::cpu::step
constexpr int step
Definition: fp32.cpp:35
Validate.h
arm_compute::Format::NV21
@ NV21
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, msg)
If the condition is true, an error is thrown.
Definition: Error.h:285
arm_compute::Dimensions< int >::num_max_dimensions
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46
arm_compute::ValidRegion::anchor
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:222
arm_compute::error_on_channel_not_in
arm_compute::Status error_on_channel_not_in(const char *function, const char *file, const int line, T cn, T &&channel, Ts &&...channels)
Return an error if the channel is not in channels.
Definition: Validate.h:1036
ARM_COMPUTE_RETURN_ERROR_ON_LOC
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC(cond, func, file, line)
If the condition is true, an error is returned.
Definition: Error.h:307