Compute Library
 21.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 
26 arm_compute::Status arm_compute::error_on_mismatching_windows(const char *function, const char *file, const int line,
27  const arm_compute::Window &full, const arm_compute::Window &win)
28 {
29  full.validate();
30  win.validate();
31 
32  for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
33  {
34  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line);
35  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line);
36  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line);
37  }
38  return arm_compute::Status{};
39 }
40 
41 arm_compute::Status arm_compute::error_on_invalid_subwindow(const char *function, const char *file, const int line,
42  const arm_compute::Window &full, const arm_compute::Window &sub)
43 {
44  full.validate();
45  sub.validate();
46 
47  for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
48  {
49  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line);
50  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line);
51  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line);
52  ARM_COMPUTE_RETURN_ERROR_ON_LOC((sub[i].start() - full[i].start()) % sub[i].step(), function, file, line);
53  }
54  return arm_compute::Status{};
55 }
56 
57 arm_compute::Status arm_compute::error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line,
58  const arm_compute::Window &full, const arm_compute::Window &window, const int dim)
59 {
60  full.validate();
61  window.validate();
62 
63  ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != 0, function, file, line);
64  ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line);
65  ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line);
66 
67  return arm_compute::Status{};
68 }
69 
70 arm_compute::Status arm_compute::error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
71  const arm_compute::Coordinates &pos, unsigned int max_dim)
72 {
73  for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
74  {
75  ARM_COMPUTE_RETURN_ERROR_ON_LOC(pos[i] != 0, function, file, line);
76  }
77  return arm_compute::Status{};
78 }
79 
80 arm_compute::Status arm_compute::error_on_window_dimensions_gte(const char *function, const char *file, const int line,
81  const arm_compute::Window &win, 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_MSG_VAR((win[i].start() != 0) || (win[i].end() != win[i].step()),
86  function, file, line,
87  "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i);
88  }
89  return arm_compute::Status{};
90 }
91 
92 arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line,
93  const arm_compute::ITensor *tensor)
94 {
95  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
96  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor->info() == nullptr, function, file, line);
98  function, file, line,
99  "Only 2D Tensors are supported by this kernel (%zu passed)", tensor->info()->num_dimensions());
100  return arm_compute::Status{};
101 }
102 
103 arm_compute::Status arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line,
104  const arm_compute::ITensorInfo *tensor)
105 {
106  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
108  function, file, line,
109  "Only 2D Tensors are supported by this kernel (%zu passed)", tensor->num_dimensions());
110  return arm_compute::Status{};
111 }
112 
113 arm_compute::Status arm_compute::error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
115 {
118 
119  switch(fmt)
120  {
123  break;
126  break;
129  break;
137  break;
138  default:
139  ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format.");
140  }
141  return arm_compute::Status{};
142 }
143 
144 arm_compute::Status arm_compute::error_on_unconfigured_kernel(const char *function, const char *file, const int line,
145  const arm_compute::IKernel *kernel)
146 {
147  ARM_COMPUTE_RETURN_ERROR_ON_LOC(kernel == nullptr, function, file, line);
149  function, file, line,
150  "This kernel hasn't been configured.");
151  return arm_compute::Status{};
152 }
153 
154 arm_compute::Status arm_compute::error_on_invalid_subtensor(const char *function, const char *file, const int line,
155  const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape)
156 {
157  // Check dimensions
158  for(unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i)
159  {
160  const bool invalid_idx = coords[i] >= static_cast<int>(parent_shape[i]);
161  const bool out_of_bounds_size = coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]);
162  ARM_COMPUTE_RETURN_ERROR_ON_LOC(invalid_idx || out_of_bounds_size, function, file, line);
163  }
164  return arm_compute::Status{};
165 }
166 
167 arm_compute::Status arm_compute::error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
168  const ValidRegion &parent_valid_region, const ValidRegion &valid_region)
169 {
170  // Check valid regions
171  for(unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d)
172  {
173  ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line);
174  ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] + static_cast<int>(parent_valid_region.shape[d])) < (valid_region.anchor[d] + static_cast<int>(valid_region.shape[d])),
175  function, file, line);
176  }
177 
178  return arm_compute::Status{};
179 }
Common information for all the kernels.
Definition: IKernel.h:33
bool is_window_configured() const
Function to check if the embedded window of this kernel has been configured.
Definition: IKernel.cpp:51
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
Shape of a tensor.
Definition: TensorShape.h:39
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:113
#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:283
TensorShape shape
Shape of the valid region.
Definition: Types.h:257
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:144
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:80
Cr/V/Value channel.
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC(cond, func, file, line)
If the condition is true, an error is returned.
Definition: Error.h:306
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
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:92
void validate() const
Will validate all the window&#39;s dimensions&#39; values when asserts are enabled.
Definition: Window.inl:173
Status class.
Definition: Error.h:52
const ValidRegion valid_region
Definition: Scale.cpp:214
Interface for CPU tensor.
Definition: ITensor.h:36
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
3 channels, 1 U8 per channel
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
Channel
Available channels.
Definition: Types.h:446
Format
Image colour formats.
Definition: Types.h:56
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:869
Coordinates of an item.
Definition: Coordinates.h:37
#define ARM_COMPUTE_ERROR_LOC(func, file, line, msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:372
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
#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:263
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:154
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
4 channels, 1 U8 per channel
constexpr int step
Definition: fp32.cpp:35
2 channel, 1 U8 per channel
Container for valid region of a window.
Definition: Types.h:184
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46
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:70
Describe a multidimensional execution window.
Definition: Window.h:39
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:41
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:167
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:256
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&#39;t be collapsed at the given dimension.
Definition: Validate.cpp:57