|
1 | 1 | /* |
2 | | - * Copyright (c) 2018-2021 Arm Limited. |
| 2 | + * Copyright (c) 2018-2021, 2025 Arm Limited. |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: MIT |
5 | 5 | * |
|
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | 22 | * SOFTWARE. |
23 | 23 | */ |
24 | | -#ifndef ARM_COMPUTE_CPP_VALIDATE_H |
25 | | -#define ARM_COMPUTE_CPP_VALIDATE_H |
| 24 | +#ifndef ACL_SRC_CORE_CPP_VALIDATE_H |
| 25 | +#define ACL_SRC_CORE_CPP_VALIDATE_H |
26 | 26 |
|
27 | 27 | #include "arm_compute/core/CPP/CPPTypes.h" |
28 | 28 | #include "arm_compute/core/Validate.h" |
@@ -53,6 +53,37 @@ error_on_unsupported_cpu_fp16(const char *function, const char *file, const int |
53 | 53 | return Status{}; |
54 | 54 | } |
55 | 55 |
|
| 56 | +/** Return an error if the tensor sizes are too large. |
| 57 | + * |
| 58 | + * @param[in] function Function in which the error occurred. |
| 59 | + * @param[in] file Name of the file where the error occurred. |
| 60 | + * @param[in] line Line on which the error occurred. |
| 61 | + * @param[in] tensor_infos Tensor infos to validate. |
| 62 | + * |
| 63 | + * @return Status |
| 64 | + */ |
| 65 | +template <typename... Ts> |
| 66 | +inline Status error_on_unsupported_size(const char *function, const char *file, const int line, Ts &&...tensor_infos) |
| 67 | +{ |
| 68 | + constexpr size_t max_size_in_bytes = (1U << 31) - 1; |
| 69 | + |
| 70 | + const ITensorInfo *tensor_array[] = {std::forward<Ts>(tensor_infos)...}; |
| 71 | + |
| 72 | + for (const ITensorInfo *tensor_info : tensor_array) |
| 73 | + { |
| 74 | + if (tensor_info != nullptr && tensor_info->data_type() != DataType::UNKNOWN) |
| 75 | + { |
| 76 | + ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG( |
| 77 | + (tensor_info->total_size() > max_size_in_bytes || |
| 78 | + (tensor_info->tensor_shape().total_size() * tensor_info->element_size() * tensor_info->num_channels() > |
| 79 | + max_size_in_bytes)), |
| 80 | + function, file, line, "Maximum supported tensor size is 2^31-1 bytes"); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + return Status{}; |
| 85 | +} |
| 86 | + |
56 | 87 | /** Return an error if the data type of the passed tensor info is BFLOAT16 and BFLOAT16 support is not compiled in. |
57 | 88 | * |
58 | 89 | * @param[in] function Function in which the error occurred. |
@@ -122,5 +153,12 @@ error_on_unsupported_cpu_bf16(const char *function, const char *file, const int |
122 | 153 |
|
123 | 154 | #define ARM_COMPUTE_RETURN_ERROR_ON_CPU_BF16_UNSUPPORTED(tensor) \ |
124 | 155 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_bf16(__func__, __FILE__, __LINE__, tensor)) |
| 156 | + |
| 157 | +#define ARM_COMPUTE_ERROR_ON_SIZE_UNSUPPORTED(...) \ |
| 158 | + ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_unsupported_size(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 159 | + |
| 160 | +#define ARM_COMPUTE_RETURN_ERROR_ON_SIZE_UNSUPPORTED(...) \ |
| 161 | + ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_size(__func__, __FILE__, __LINE__, __VA_ARGS__)) |
| 162 | + |
125 | 163 | } // namespace arm_compute |
126 | | -#endif /* ARM_COMPUTE_CPP_VALIDATE_H */ |
| 164 | +#endif // ACL_SRC_CORE_CPP_VALIDATE_H |
0 commit comments