Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 4587594 | 2021-07-06 21:19:27 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPP_VALIDATE_H |
| 25 | #define ARM_COMPUTE_CPP_VALIDATE_H |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 26 | |
Georgios Pinitas | 4587594 | 2021-07-06 21:19:27 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/CPPTypes.h" |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Validate.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | /** Return an error if the data type of the passed tensor info is FP16 and FP16 support is not compiled in. |
| 33 | * |
| 34 | * @param[in] function Function in which the error occurred. |
| 35 | * @param[in] file Name of the file where the error occurred. |
| 36 | * @param[in] line Line on which the error occurred. |
| 37 | * @param[in] tensor_info Tensor info to validate. |
| 38 | * |
| 39 | * @return Status |
| 40 | */ |
Michalis Spyrou | e7be8a0 | 2019-12-12 16:16:09 +0000 | [diff] [blame] | 41 | inline Status error_on_unsupported_cpu_fp16(const char *function, const char *file, const int line, |
| 42 | const ITensorInfo *tensor_info) |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 43 | { |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 44 | bool fp16_kernels_enabled = false; |
| 45 | #if defined(ARM_COMPUTE_ENABLE_FP16) && defined(ENABLE_FP16_KERNELS) |
| 46 | fp16_kernels_enabled = true; |
| 47 | #endif /* defined(ARM_COMPUTE_ENABLE_FP16) && defined(ENABLE_FP16_KERNELS) */ |
| 48 | |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line); |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 50 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG((tensor_info->data_type() == DataType::F16) && (!CPUInfo::get().has_fp16() || !fp16_kernels_enabled), |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 51 | function, file, line, "This CPU architecture does not support F16 data type, you need v8.2 or above"); |
Georgios Pinitas | 4587594 | 2021-07-06 21:19:27 +0100 | [diff] [blame] | 52 | return Status{}; |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 55 | /** Return an error if the data type of the passed tensor info is BFLOAT16 and BFLOAT16 support is not compiled in. |
| 56 | * |
| 57 | * @param[in] function Function in which the error occurred. |
| 58 | * @param[in] file Name of the file where the error occurred. |
| 59 | * @param[in] line Line on which the error occurred. |
| 60 | * @param[in] tensor_info Tensor info to validate. |
| 61 | * |
| 62 | * @return Status |
| 63 | */ |
| 64 | inline Status error_on_unsupported_cpu_bf16(const char *function, const char *file, const int line, |
| 65 | const ITensorInfo *tensor_info) |
| 66 | { |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 67 | bool bf16_kernels_enabled = false; |
| 68 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
| 69 | bf16_kernels_enabled = true; |
| 70 | #endif /* defined(ARM_COMPUTE_ENABLE_BF16) */ |
| 71 | |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 72 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor_info == nullptr, function, file, line); |
Georgios Pinitas | 8e2f64f | 2021-07-28 13:18:46 +0100 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG((tensor_info->data_type() == DataType::BFLOAT16) && (!CPUInfo::get().has_bf16() || !bf16_kernels_enabled), |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 74 | function, file, line, "This CPU architecture does not support BFloat16 data type, you need v8.6 or above"); |
Georgios Pinitas | 4587594 | 2021-07-06 21:19:27 +0100 | [diff] [blame] | 75 | return Status{}; |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 78 | /** Return an error if the data type of the passed tensor is FP16 and FP16 support is not compiled in. |
| 79 | * |
| 80 | * @param[in] function Function in which the error occurred. |
| 81 | * @param[in] file Name of the file where the error occurred. |
| 82 | * @param[in] line Line on which the error occurred. |
| 83 | * @param[in] tensor Tensor to validate. |
| 84 | * |
| 85 | * @return Status |
| 86 | */ |
Michalis Spyrou | e7be8a0 | 2019-12-12 16:16:09 +0000 | [diff] [blame] | 87 | inline Status error_on_unsupported_cpu_fp16(const char *function, const char *file, const int line, |
| 88 | const ITensor *tensor) |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 89 | { |
| 90 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 91 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_fp16(function, file, line, tensor->info())); |
Michalis Spyrou | e7be8a0 | 2019-12-12 16:16:09 +0000 | [diff] [blame] | 92 | return Status{}; |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 95 | /** Return an error if the data type of the passed tensor is BFLOAT16 and BFLOAT16 support is not compiled in. |
| 96 | * |
| 97 | * @param[in] function Function in which the error occurred. |
| 98 | * @param[in] file Name of the file where the error occurred. |
| 99 | * @param[in] line Line on which the error occurred. |
| 100 | * @param[in] tensor Tensor to validate. |
| 101 | * |
| 102 | * @return Status |
| 103 | */ |
| 104 | inline Status error_on_unsupported_cpu_bf16(const char *function, const char *file, const int line, |
| 105 | const ITensor *tensor) |
| 106 | { |
| 107 | ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line); |
| 108 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_bf16(function, file, line, tensor->info())); |
| 109 | return Status{}; |
| 110 | } |
| 111 | |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 112 | #define ARM_COMPUTE_ERROR_ON_CPU_F16_UNSUPPORTED(tensor) \ |
| 113 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_unsupported_cpu_fp16(__func__, __FILE__, __LINE__, tensor)) |
| 114 | |
| 115 | #define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor) \ |
| 116 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_fp16(__func__, __FILE__, __LINE__, tensor)) |
Georgios Pinitas | e8291ac | 2020-02-26 09:58:13 +0000 | [diff] [blame] | 117 | |
| 118 | #define ARM_COMPUTE_ERROR_ON_CPU_BF16_UNSUPPORTED(tensor) \ |
| 119 | ARM_COMPUTE_ERROR_THROW_ON(::arm_compute::error_on_unsupported_cpu_bf16(__func__, __FILE__, __LINE__, tensor)) |
| 120 | |
| 121 | #define ARM_COMPUTE_RETURN_ERROR_ON_CPU_BF16_UNSUPPORTED(tensor) \ |
| 122 | ARM_COMPUTE_RETURN_ON_ERROR(::arm_compute::error_on_unsupported_cpu_bf16(__func__, __FILE__, __LINE__, tensor)) |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 123 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 124 | #endif /* ARM_COMPUTE_CPP_VALIDATE_H */ |