Compute Library
 21.02
Validate.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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  */
24 #ifndef ARM_COMPUTE_CPP_VALIDATE_H
25 #define ARM_COMPUTE_CPP_VALIDATE_H
26 
28 
29 namespace arm_compute
30 {
31 /** Return an error if the data type of the passed tensor info is FP16 and FP16 support is not compiled in.
32  *
33  * @param[in] function Function in which the error occurred.
34  * @param[in] file Name of the file where the error occurred.
35  * @param[in] line Line on which the error occurred.
36  * @param[in] tensor_info Tensor info to validate.
37  *
38  * @return Status
39  */
40 inline Status error_on_unsupported_cpu_fp16(const char *function, const char *file, const int line,
41  const ITensorInfo *tensor_info)
42 {
43  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line);
44 #ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
46  function, file, line, "This CPU architecture does not support F16 data type, you need v8.2 or above");
47 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
48  return Status {};
49 }
50 
51 /** Return an error if the data type of the passed tensor info is BFLOAT16 and BFLOAT16 support is not compiled in.
52  *
53  * @param[in] function Function in which the error occurred.
54  * @param[in] file Name of the file where the error occurred.
55  * @param[in] line Line on which the error occurred.
56  * @param[in] tensor_info Tensor info to validate.
57  *
58  * @return Status
59  */
60 inline Status error_on_unsupported_cpu_bf16(const char *function, const char *file, const int line,
61  const ITensorInfo *tensor_info)
62 {
63  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line);
64 #if !(defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16))
66  function, file, line, "This CPU architecture does not support BFloat16 data type, you need v8.6 or above");
67 #endif /* !(defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16)) */
68  return Status {};
69 }
70 
71 /** Return an error if the data type of the passed tensor is FP16 and FP16 support is not compiled in.
72  *
73  * @param[in] function Function in which the error occurred.
74  * @param[in] file Name of the file where the error occurred.
75  * @param[in] line Line on which the error occurred.
76  * @param[in] tensor Tensor to validate.
77  *
78  * @return Status
79  */
80 inline Status error_on_unsupported_cpu_fp16(const char *function, const char *file, const int line,
81  const ITensor *tensor)
82 {
83  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
85  return Status{};
86 }
87 
88 /** Return an error if the data type of the passed tensor is BFLOAT16 and BFLOAT16 support is not compiled in.
89  *
90  * @param[in] function Function in which the error occurred.
91  * @param[in] file Name of the file where the error occurred.
92  * @param[in] line Line on which the error occurred.
93  * @param[in] tensor Tensor to validate.
94  *
95  * @return Status
96  */
97 inline Status error_on_unsupported_cpu_bf16(const char *function, const char *file, const int line,
98  const ITensor *tensor)
99 {
100  ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
102  return Status{};
103 }
104 
105 #define ARM_COMPUTE_ERROR_ON_CPU_F16_UNSUPPORTED(tensor) \
106  ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_unsupported_cpu_fp16(__func__, __FILE__, __LINE__, tensor))
107 
108 #define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor) \
109  ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_fp16(__func__, __FILE__, __LINE__, tensor))
110 
111 #define ARM_COMPUTE_ERROR_ON_CPU_BF16_UNSUPPORTED(tensor) \
112  ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_unsupported_cpu_bf16(__func__, __FILE__, __LINE__, tensor))
113 
114 #define ARM_COMPUTE_RETURN_ERROR_ON_CPU_BF16_UNSUPPORTED(tensor) \
115  ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_bf16(__func__, __FILE__, __LINE__, tensor))
116 } // namespace arm_compute
117 #endif /* ARM_COMPUTE_CPP_VALIDATE_H */
#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
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC(cond, func, file, line)
If the condition is true, an error is returned.
Definition: Error.h:306
#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.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
16-bit brain floating-point number
Status error_on_unsupported_cpu_bf16(const char *function, const char *file, const int line, const ITensorInfo *tensor_info)
Return an error if the data type of the passed tensor info is BFLOAT16 and BFLOAT16 support is not co...
Definition: Validate.h:60
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Status error_on_unsupported_cpu_fp16(const char *function, const char *file, const int line, const ITensorInfo *tensor_info)
Return an error if the data type of the passed tensor info is FP16 and FP16 support is not compiled i...
Definition: Validate.h:40