2 // Copyright (c) 2016-2018 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "error_handler.h"
23 void err_details::cldnn_print_error_message(const std::string& file, int line, const std::string& instance_id, std::stringstream & msg, const std::string& add_msg)
26 std::stringstream source_of_error;
27 source_of_error << file << " at line: " << line << std::endl;
28 source_of_error << "Error has occured for: " << instance_id << std::endl;
30 std::stringstream addidtional_message;
33 addidtional_message << add_msg << std::endl;
36 throw std::invalid_argument(
37 source_of_error.str() +
39 addidtional_message.str()
44 void error_message(const std::string& file, int line, const std::string& instance_id, const std::string& message)
46 std::stringstream error_msg;
47 error_msg << message << std::endl;
48 err_details::cldnn_print_error_message(file, line, instance_id, error_msg);
51 void error_on_not_supported_fp16(const std::string& file, int line, const std::string& instance_id, uint8_t supp_fp16, bool fp16_used)
53 if (!supp_fp16 && fp16_used)
55 std::stringstream error_msg;
56 error_msg << "GPU device does not support half precision floating-point formats (cl_khr_fp16 extension)" << std::endl;
57 err_details::cldnn_print_error_message(file, line, instance_id, error_msg);
61 void error_on_bool(const std::string& file, int line, const std::string& instance_id, const std::string& condition_id, bool condition, const std::string& additional_message)
65 std::stringstream error_msg;
66 auto condition_to_string = [](const bool& condi)->std::string { return condi ? "true" : "false"; };
67 error_msg << condition_id << "(" << condition_to_string(condition) << ") should be " << condition_to_string(!condition) << std::endl;
68 err_details::cldnn_print_error_message(file, line, instance_id, error_msg, additional_message);
72 void error_on_mismatching_data_types(const std::string& file, int line, const std::string& instance_id, const std::string& data_format_1_id, data_types data_format_1, const std::string& data_format_2_id, data_types data_format_2, const std::string& additional_message, bool ignore_sign)
74 if (data_format_1 != data_format_2 &&
76 ((data_format_1 == data_types::i8 && data_format_2 == data_types::u8) ||
77 (data_format_1 == data_types::u8 && data_format_2 == data_types::i8)))
79 std::stringstream error_msg;
80 error_msg << "Data formats are incompatible." << std::endl;
81 error_msg << data_format_1_id << " format is: " << data_type_traits::name(data_format_1) << ", " << data_format_2_id << " is: " << data_type_traits::name(data_format_2) << std::endl;
82 error_msg << "Data formats should be the same!" << std::endl;
83 err_details::cldnn_print_error_message(file, line, instance_id, error_msg, additional_message);
87 void error_on_tensor_dims_less_than_other_tensor_dims(const std::string& file, int line, const std::string& instance_id, const std::string& tensor_id, const tensor& tens, const std::string& tensor_to_compare_to_id, const tensor& tens_to_compre, const std::string& additional_message)
89 std::vector<std::string> errors;
90 if (tens.batch[0] < tens_to_compre.batch[0])
92 errors.push_back("Batch");
94 if (tens.feature[0] < tens_to_compre.feature[0])
96 errors.push_back("Feature");
98 if (tens.spatial[0] < tens_to_compre.spatial[0])
100 errors.push_back("Spatial x");
102 if (tens.spatial[1] < tens_to_compre.spatial[1])
104 errors.push_back("Spatial y");
109 std::stringstream error_msg;
110 error_msg << tensor_id << " sizes: " << tens << std::endl;
111 error_msg << tensor_to_compare_to_id << " sizes: " << tens_to_compre << std::endl;
112 error_msg << "All " << tensor_id << " dimensions should not be less than " << tensor_to_compare_to_id << " dimensions." << std::endl;
113 error_msg << "Mismatching dimensions: ";
114 for (size_t i = 0; i < errors.size(); i++)
116 error_msg << errors.at(i) << std::endl;
118 err_details::cldnn_print_error_message(file, line, instance_id, error_msg, additional_message);
122 void error_on_tensor_dims_greater_than_other_tensor_dims(const std::string& file, int line, const std::string& instance_id, const std::string& tensor_id, const tensor& tens, const std::string& tensor_to_compare_to_id, const tensor& tens_to_compre, const std::string& additional_message)
124 std::vector<std::string> errors;
125 if (tens.batch[0] > tens_to_compre.batch[0])
127 errors.push_back("Batch");
129 if (tens.feature[0] > tens_to_compre.feature[0])
131 errors.push_back("Feature");
133 if (tens.spatial[0] > tens_to_compre.spatial[0])
135 errors.push_back("Spatial x");
137 if (tens.spatial[1] > tens_to_compre.spatial[1])
139 errors.push_back("Spatial y");
144 std::stringstream error_msg;
145 error_msg << tensor_id << " sizes: " << tens << std::endl;
146 error_msg << tensor_to_compare_to_id << " sizes: " << tens_to_compre << std::endl;
147 error_msg << "All " << tensor_id << " dimensions should not be greater than " << tensor_to_compare_to_id << std::endl;
148 error_msg << "Mismatching dimensions: ";
149 for (size_t i = 0; i < errors.size(); i++)
151 error_msg << errors.at(i) << std::endl;
153 err_details::cldnn_print_error_message(file, line, instance_id, error_msg, additional_message);
157 void error_on_tensor_dims_not_dividable_by_other_tensor_dims(const std::string& file, int line, const std::string& instance_id, const std::string& tensor_id, const tensor& tens, const std::string& tensor_to_compare_to_id, const tensor& tens_to_compre, const std::string& additional_message)
159 std::vector<std::string> errors;
160 if (tens.batch[0] % tens_to_compre.batch[0] != 0)
162 errors.push_back("Batch");
164 if (tens.feature[0] % tens_to_compre.feature[0] != 0)
166 errors.push_back("Feature");
168 if (tens.spatial[0] % tens_to_compre.spatial[0] != 0)
170 errors.push_back("Spatial x");
172 if (tens.spatial[1] % tens_to_compre.spatial[1] != 0)
174 errors.push_back("Spatial y");
179 std::stringstream error_msg;
180 error_msg << tensor_id << " sizes: " << tens << std::endl;
181 error_msg << tensor_to_compare_to_id << " sizes: " << tens_to_compre << std::endl;
182 error_msg << "All " << tensor_id << " dimensions must be dividable by corresponding dimensions from " << tensor_to_compare_to_id << std::endl;
183 error_msg << "Mismatching dimensions: ";
184 for (size_t i = 0; i < errors.size(); i++)
186 error_msg << errors.at(i) << std::endl;
188 err_details::cldnn_print_error_message(file, line, instance_id, error_msg, additional_message);
192 void error_on_mismatch_layout(const std::string& file, int line, const std::string& instance_id, const std::string& layout_1_id, const layout& layout_1, const std::string& layout_2_id, const layout& layout_2, const std::string& additional_message)
194 if (layout_1 != layout_2)
196 std::stringstream error_msg;
197 error_msg << "Layouts mismatch." << std::endl;
199 if (layout_1.data_padding != layout_2.data_padding)
201 error_msg << layout_1_id << " data padding mismatch: " << layout_2_id << " data padding." << std::endl;
202 error_msg << layout_1_id << " upper data padding: " << layout_1.data_padding.upper_size() << ", " << layout_2_id << " upper data padding: " << layout_2.data_padding.upper_size() << std::endl;
203 error_msg << layout_1_id << " lower data padding: " << layout_1.data_padding.lower_size() << ", " << layout_2_id << " lower data padding: " << layout_2.data_padding.lower_size() << std::endl;
205 if (layout_1.data_type != layout_2.data_type)
207 error_msg << layout_1_id << " data type mismatch: " << layout_2_id << " data type." << std::endl;
208 error_msg << layout_1_id << " data type: " << data_type_traits::name(layout_1.data_type) << ", " << layout_2_id << " data type: " << data_type_traits::name(layout_2.data_type) << std::endl;
210 if (layout_1.format != layout_2.format)
212 error_msg << layout_1_id << " format mismatch: " << layout_2_id << " format." << std::endl;
213 error_msg << layout_1_id << " format: " << format::traits(layout_1.format).order << ", " << layout_2_id << " format: " << format::traits(layout_2.format).order << std::endl;
215 if (layout_1.size != layout_2.size)
217 error_msg << layout_1_id << " size mismatch : " << layout_2_id << " size." << std::endl;
218 error_msg << layout_1_id << " size: " << layout_1.size << ", " << layout_2_id << " size: " << layout_2.size << std::endl;
220 err_details::cldnn_print_error_message(file, line, instance_id, error_msg, additional_message);