Michalis Spyrou | ed194b1 | 2017-10-31 15:04:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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_GRAPH_ERROR_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_ERROR_H__ |
| 26 | |
| 27 | #include "arm_compute/graph/ITensorObject.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace graph |
| 32 | { |
| 33 | /** Evaluate if a tensor object is null. If the condition is true then an error message is printed and an exception thrown |
| 34 | * |
| 35 | * @param[in] function Function in which the error occurred. |
| 36 | * @param[in] file Name of the file where the error occurred. |
| 37 | * @param[in] line Line on which the error occurred. |
| 38 | * @param[in] tensor_object Tensor object to evaluate |
| 39 | * @param[in] tensor_objects (Optional) Further allowed tensor objects. |
| 40 | */ |
| 41 | template <typename... Ts> |
| 42 | void error_on_unallocated_tensor_object(const char *function, const char *file, int line, |
| 43 | const ITensorObject *tensor_object, Ts... tensor_objects) |
| 44 | { |
| 45 | ARM_COMPUTE_UNUSED(function); |
| 46 | ARM_COMPUTE_UNUSED(file); |
| 47 | ARM_COMPUTE_UNUSED(line); |
| 48 | ARM_COMPUTE_UNUSED(tensor_object); |
| 49 | |
| 50 | ARM_COMPUTE_ERROR_ON_LOC(tensor_object == nullptr || tensor_object->tensor() == nullptr, function, file, line); |
| 51 | |
| 52 | const std::array<const ITensorObject *, sizeof...(Ts)> tensor_objects_array{ { std::forward<Ts>(tensor_objects)... } }; |
| 53 | ARM_COMPUTE_UNUSED(tensor_objects_array); |
| 54 | |
| 55 | ARM_COMPUTE_ERROR_ON_LOC(std::any_of(tensor_objects_array.begin(), tensor_objects_array.end(), [&](const ITensorObject * tensor_obj) |
| 56 | { |
| 57 | return (tensor_obj == nullptr || tensor_object->tensor() == nullptr); |
| 58 | }), |
| 59 | function, file, line); |
| 60 | } |
| 61 | #define ARM_COMPUTE_ERROR_ON_UNALLOCATED_TENSOR_OBJECT(...) ::arm_compute::graph::error_on_unallocated_tensor_object(__func__, __FILE__, __LINE__, __VA_ARGS__) |
| 62 | } // namespace graph |
| 63 | } // namespace arm_compute |
| 64 | #endif /* __ARM_COMPUTE_GRAPH_ERROR_H__ */ |