2015-05-12 Pierre-Marie de Rodat <derodat@adacore.com>
[official-gcc.git] / liboffloadmic / runtime / liboffload_error.c
blobeb5699d3c5cc7e19c72fb848eeecafa2deab329d
1 /*
2 Copyright (c) 2014 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <stdio.h>
32 #include <stdarg.h>
33 #ifndef va_copy
34 #define va_copy(dst, src) ((dst) = (src))
35 #endif
37 #include "liboffload_msg.h"
39 #include "liboffload_error_codes.h"
41 /***********************************************/
42 /* error-handling function, liboffload_error_support */
43 /***********************************************/
45 void __liboffload_error_support(error_types input_tag, ...)
47 va_list args;
48 va_start(args, input_tag);
50 switch (input_tag) {
51 case c_device_is_not_available:
52 write_message(stderr, msg_c_device_is_not_available, args);
53 break;
54 case c_invalid_device_number:
55 write_message(stderr, msg_c_invalid_device_number, args);
56 break;
57 case c_send_func_ptr:
58 write_message(stderr, msg_c_send_func_ptr, args);
59 break;
60 case c_receive_func_ptr:
61 write_message(stderr, msg_c_receive_func_ptr, args);
62 break;
63 case c_malloc:
64 write_message(stderr, msg_c_malloc, args);
65 break;
66 case c_offload_malloc:
67 write_message(stderr, msg_c_offload_malloc, args);
68 break;
69 case c_offload1:
70 write_message(stderr, msg_c_offload1, args);
71 break;
72 case c_unknown_var_type:
73 write_message(stderr, c_unknown_var_type, args);
74 break;
75 case c_invalid_env_var_value:
76 write_message(stderr, msg_c_invalid_env_var_value, args);
77 break;
78 case c_invalid_env_var_int_value:
79 write_message(stderr, msg_c_invalid_env_var_int_value, args);
80 break;
81 case c_invalid_env_report_value:
82 write_message(stderr, msg_c_invalid_env_report_value, args);
83 break;
84 case c_offload_signaled1:
85 write_message(stderr, msg_c_offload_signaled1, args);
86 break;
87 case c_offload_signaled2:
88 write_message(stderr, msg_c_offload_signaled2, args);
89 break;
90 case c_myowrapper_checkresult:
91 write_message(stderr, msg_c_myowrapper_checkresult, args);
92 break;
93 case c_myotarget_checkresult:
94 write_message(stderr, msg_c_myotarget_checkresult, args);
95 break;
96 case c_offload_descriptor_offload:
97 write_message(stderr, msg_c_offload_descriptor_offload, args);
98 break;
99 case c_merge_var_descs1:
100 write_message(stderr, msg_c_merge_var_descs1, args);
101 break;
102 case c_merge_var_descs2:
103 write_message(stderr, msg_c_merge_var_descs2, args);
104 break;
105 case c_mic_parse_env_var_list1:
106 write_message(stderr, msg_c_mic_parse_env_var_list1, args);
107 break;
108 case c_mic_parse_env_var_list2:
109 write_message(stderr, msg_c_mic_parse_env_var_list2, args);
110 break;
111 case c_mic_process_exit_ret:
112 write_message(stderr, msg_c_mic_process_exit_ret, args);
113 break;
114 case c_mic_process_exit_sig:
115 write_message(stderr, msg_c_mic_process_exit_sig, args);
116 break;
117 case c_mic_process_exit:
118 write_message(stderr, msg_c_mic_process_exit, args);
119 break;
120 case c_mic_init3:
121 write_message(stderr, msg_c_mic_init3, args);
122 break;
123 case c_mic_init4:
124 write_message(stderr, msg_c_mic_init4, args);
125 break;
126 case c_mic_init5:
127 write_message(stderr, msg_c_mic_init5, args);
128 break;
129 case c_mic_init6:
130 write_message(stderr, msg_c_mic_init6, args);
131 break;
132 case c_no_static_var_data:
133 write_message(stderr, msg_c_no_static_var_data, args);
134 break;
135 case c_no_ptr_data:
136 write_message(stderr, msg_c_no_ptr_data, args);
137 break;
138 case c_get_engine_handle:
139 write_message(stderr, msg_c_get_engine_handle, args);
140 break;
141 case c_get_engine_index:
142 write_message(stderr, msg_c_get_engine_index, args);
143 break;
144 case c_process_create:
145 write_message(stderr, msg_c_process_create, args);
146 break;
147 case c_process_wait_shutdown:
148 write_message(stderr, msg_c_process_wait_shutdown, args);
149 break;
150 case c_process_proxy_flush:
151 write_message(stderr, msg_c_process_proxy_flush, args);
152 break;
153 case c_process_get_func_handles:
154 write_message(stderr, msg_c_process_get_func_handles, args);
155 break;
156 case c_load_library:
157 write_message(stderr, msg_c_load_library, args);
158 break;
159 case c_coipipe_max_number:
160 write_message(stderr, msg_c_coi_pipeline_max_number, args);
161 break;
162 case c_pipeline_create:
163 write_message(stderr, msg_c_pipeline_create, args);
164 break;
165 case c_pipeline_run_func:
166 write_message(stderr, msg_c_pipeline_run_func, args);
167 break;
168 case c_pipeline_start_run_funcs:
169 write_message(stderr, msg_c_pipeline_start_run_funcs, args);
170 break;
171 case c_buf_create:
172 write_message(stderr, msg_c_buf_create, args);
173 break;
174 case c_buf_create_out_of_mem:
175 write_message(stderr, msg_c_buf_create_out_of_mem, args);
176 break;
177 case c_buf_create_from_mem:
178 write_message(stderr, msg_c_buf_create_from_mem, args);
179 break;
180 case c_buf_destroy:
181 write_message(stderr, msg_c_buf_destroy, args);
182 break;
183 case c_buf_map:
184 write_message(stderr, msg_c_buf_map, args);
185 break;
186 case c_buf_unmap:
187 write_message(stderr, msg_c_buf_unmap, args);
188 break;
189 case c_buf_read:
190 write_message(stderr, msg_c_buf_read, args);
191 break;
192 case c_buf_write:
193 write_message(stderr, msg_c_buf_write, args);
194 break;
195 case c_buf_copy:
196 write_message(stderr, msg_c_buf_copy, args);
197 break;
198 case c_buf_get_address:
199 write_message(stderr, msg_c_buf_get_address, args);
200 break;
201 case c_buf_add_ref:
202 write_message(stderr, msg_c_buf_add_ref, args);
203 break;
204 case c_buf_release_ref:
205 write_message(stderr, msg_c_buf_release_ref, args);
206 break;
207 case c_buf_set_state:
208 write_message(stderr, msg_c_buf_set_state, args);
209 break;
210 case c_event_wait:
211 write_message(stderr, msg_c_event_wait, args);
212 break;
213 case c_zero_or_neg_ptr_len:
214 write_message(stderr, msg_c_zero_or_neg_ptr_len, args);
215 break;
216 case c_zero_or_neg_transfer_size:
217 write_message(stderr, msg_c_zero_or_neg_transfer_size, args);
218 break;
219 case c_bad_ptr_mem_range:
220 write_message(stderr, msg_c_bad_ptr_mem_range, args);
221 break;
222 case c_different_src_and_dstn_sizes:
223 write_message(stderr, msg_c_different_src_and_dstn_sizes, args);
224 break;
225 case c_ranges_dont_match:
226 write_message(stderr, msg_c_ranges_dont_match, args);
227 break;
228 case c_destination_is_over:
229 write_message(stderr, msg_c_destination_is_over, args);
230 break;
231 case c_slice_of_noncont_array:
232 write_message(stderr, msg_c_slice_of_noncont_array, args);
233 break;
234 case c_non_contiguous_dope_vector:
235 write_message(stderr, msg_c_non_contiguous_dope_vector, args);
236 break;
237 case c_pointer_array_mismatch:
238 write_message(stderr, msg_c_pointer_array_mismatch, args);
239 break;
240 case c_omp_invalid_device_num_env:
241 write_message(stderr, msg_c_omp_invalid_device_num_env, args);
242 break;
243 case c_omp_invalid_device_num:
244 write_message(stderr, msg_c_omp_invalid_device_num, args);
245 break;
246 case c_unknown_binary_type:
247 write_message(stderr, msg_c_unknown_binary_type, args);
248 break;
249 case c_multiple_target_exes:
250 write_message(stderr, msg_c_multiple_target_exes, args);
251 break;
252 case c_no_target_exe:
253 write_message(stderr, msg_c_no_target_exe, args);
254 break;
255 case c_report_unknown_timer_node:
256 write_message(stderr, msg_c_report_unknown_timer_node, args);
257 break;
258 case c_report_unknown_trace_node:
259 write_message(stderr, msg_c_report_unknown_trace_node, args);
260 break;
262 va_end(args);
265 char const * report_get_message_str(error_types input_tag)
267 switch (input_tag) {
268 case c_report_title:
269 return (offload_get_message_str(msg_c_report_title));
270 case c_report_from_file:
271 return (offload_get_message_str(msg_c_report_from_file));
272 case c_report_offload:
273 return (offload_get_message_str(msg_c_report_offload));
274 case c_report_mic:
275 return (offload_get_message_str(msg_c_report_mic));
276 case c_report_file:
277 return (offload_get_message_str(msg_c_report_file));
278 case c_report_line:
279 return (offload_get_message_str(msg_c_report_line));
280 case c_report_host:
281 return (offload_get_message_str(msg_c_report_host));
282 case c_report_tag:
283 return (offload_get_message_str(msg_c_report_tag));
284 case c_report_cpu_time:
285 return (offload_get_message_str(msg_c_report_cpu_time));
286 case c_report_seconds:
287 return (offload_get_message_str(msg_c_report_seconds));
288 case c_report_cpu_to_mic_data:
289 return (offload_get_message_str(msg_c_report_cpu_to_mic_data));
290 case c_report_bytes:
291 return (offload_get_message_str(msg_c_report_bytes));
292 case c_report_mic_time:
293 return (offload_get_message_str(msg_c_report_mic_time));
294 case c_report_mic_to_cpu_data:
295 return (offload_get_message_str(msg_c_report_mic_to_cpu_data));
296 case c_report_compute:
297 return (offload_get_message_str(msg_c_report_compute));
298 case c_report_copyin_data:
299 return (offload_get_message_str(msg_c_report_copyin_data));
300 case c_report_copyout_data:
301 return (offload_get_message_str(msg_c_report_copyout_data));
302 case c_report_create_buf_host:
303 return (offload_get_message_str(c_report_create_buf_host));
304 case c_report_create_buf_mic:
305 return (offload_get_message_str(msg_c_report_create_buf_mic));
306 case c_report_destroy:
307 return (offload_get_message_str(msg_c_report_destroy));
308 case c_report_gather_copyin_data:
309 return (offload_get_message_str(msg_c_report_gather_copyin_data));
310 case c_report_gather_copyout_data:
311 return (offload_get_message_str(msg_c_report_gather_copyout_data));
312 case c_report_state_signal:
313 return (offload_get_message_str(msg_c_report_state_signal));
314 case c_report_signal:
315 return (offload_get_message_str(msg_c_report_signal));
316 case c_report_wait:
317 return (offload_get_message_str(msg_c_report_wait));
318 case c_report_init:
319 return (offload_get_message_str(msg_c_report_init));
320 case c_report_init_func:
321 return (offload_get_message_str(msg_c_report_init_func));
322 case c_report_logical_card:
323 return (offload_get_message_str(msg_c_report_logical_card));
324 case c_report_mic_myo_fptr:
325 return (offload_get_message_str(msg_c_report_mic_myo_fptr));
326 case c_report_mic_myo_shared:
327 return (offload_get_message_str(msg_c_report_mic_myo_shared));
328 case c_report_myoacquire:
329 return (offload_get_message_str(msg_c_report_myoacquire));
330 case c_report_myofini:
331 return (offload_get_message_str(msg_c_report_myofini));
332 case c_report_myoinit:
333 return (offload_get_message_str(msg_c_report_myoinit));
334 case c_report_myoregister:
335 return (offload_get_message_str(msg_c_report_myoregister));
336 case c_report_myorelease:
337 return (offload_get_message_str(msg_c_report_myorelease));
338 case c_report_myosharedalignedfree:
339 return (
340 offload_get_message_str(msg_c_report_myosharedalignedfree));
341 case c_report_myosharedalignedmalloc:
342 return (
343 offload_get_message_str(msg_c_report_myosharedalignedmalloc));
344 case c_report_myosharedfree:
345 return (offload_get_message_str(msg_c_report_myosharedfree));
346 case c_report_myosharedmalloc:
347 return (offload_get_message_str(msg_c_report_myosharedmalloc));
348 case c_report_physical_card:
349 return (offload_get_message_str(msg_c_report_physical_card));
350 case c_report_receive_pointer_data:
351 return (
352 offload_get_message_str(msg_c_report_receive_pointer_data));
353 case c_report_received_pointer_data:
354 return (
355 offload_get_message_str(msg_c_report_received_pointer_data));
356 case c_report_register:
357 return (offload_get_message_str(msg_c_report_register));
358 case c_report_scatter_copyin_data:
359 return (offload_get_message_str(msg_c_report_scatter_copyin_data));
360 case c_report_scatter_copyout_data:
361 return (
362 offload_get_message_str(msg_c_report_scatter_copyout_data));
363 case c_report_send_pointer_data:
364 return (offload_get_message_str(msg_c_report_send_pointer_data));
365 case c_report_sent_pointer_data:
366 return (offload_get_message_str(msg_c_report_sent_pointer_data));
367 case c_report_start:
368 return (offload_get_message_str(msg_c_report_start));
369 case c_report_start_target_func:
370 return (offload_get_message_str(msg_c_report_start_target_func));
371 case c_report_state:
372 return (offload_get_message_str(msg_c_report_state));
373 case c_report_unregister:
374 return (offload_get_message_str(msg_c_report_unregister));
375 case c_report_var:
376 return (offload_get_message_str(msg_c_report_var));
378 default:
379 LIBOFFLOAD_ERROR(c_report_unknown_trace_node);
380 abort();
384 char const * report_get_host_stage_str(int i)
386 switch (i) {
387 case c_offload_host_total_offload:
388 return (
389 offload_get_message_str(msg_c_report_host_total_offload_time));
390 case c_offload_host_initialize:
391 return (offload_get_message_str(msg_c_report_host_initialize));
392 case c_offload_host_target_acquire:
393 return (
394 offload_get_message_str(msg_c_report_host_target_acquire));
395 case c_offload_host_wait_deps:
396 return (offload_get_message_str(msg_c_report_host_wait_deps));
397 case c_offload_host_setup_buffers:
398 return (offload_get_message_str(msg_c_report_host_setup_buffers));
399 case c_offload_host_alloc_buffers:
400 return (offload_get_message_str(msg_c_report_host_alloc_buffers));
401 case c_offload_host_setup_misc_data:
402 return (
403 offload_get_message_str(msg_c_report_host_setup_misc_data));
404 case c_offload_host_alloc_data_buffer:
405 return (
406 offload_get_message_str(msg_c_report_host_alloc_data_buffer));
407 case c_offload_host_send_pointers:
408 return (offload_get_message_str(msg_c_report_host_send_pointers));
409 case c_offload_host_gather_inputs:
410 return (offload_get_message_str(msg_c_report_host_gather_inputs));
411 case c_offload_host_map_in_data_buffer:
412 return (
413 offload_get_message_str(msg_c_report_host_map_in_data_buffer));
414 case c_offload_host_unmap_in_data_buffer:
415 return (offload_get_message_str(
416 msg_c_report_host_unmap_in_data_buffer));
417 case c_offload_host_start_compute:
418 return (offload_get_message_str(msg_c_report_host_start_compute));
419 case c_offload_host_wait_compute:
420 return (offload_get_message_str(msg_c_report_host_wait_compute));
421 case c_offload_host_start_buffers_reads:
422 return (offload_get_message_str(
423 msg_c_report_host_start_buffers_reads));
424 case c_offload_host_scatter_outputs:
425 return (
426 offload_get_message_str(msg_c_report_host_scatter_outputs));
427 case c_offload_host_map_out_data_buffer:
428 return (offload_get_message_str(
429 msg_c_report_host_map_out_data_buffer));
430 case c_offload_host_unmap_out_data_buffer:
431 return (offload_get_message_str(
432 msg_c_report_host_unmap_out_data_buffer));
433 case c_offload_host_wait_buffers_reads:
434 return (
435 offload_get_message_str(msg_c_report_host_wait_buffers_reads));
436 case c_offload_host_destroy_buffers:
437 return (
438 offload_get_message_str(msg_c_report_host_destroy_buffers));
439 default:
440 LIBOFFLOAD_ERROR(c_report_unknown_timer_node);
441 abort();
445 char const * report_get_target_stage_str(int i)
447 switch (i) {
448 case c_offload_target_total_time:
449 return (offload_get_message_str(msg_c_report_target_total_time));
450 case c_offload_target_descriptor_setup:
451 return (
452 offload_get_message_str(msg_c_report_target_descriptor_setup));
453 case c_offload_target_func_lookup:
454 return (offload_get_message_str(msg_c_report_target_func_lookup));
455 case c_offload_target_func_time:
456 return (offload_get_message_str(msg_c_report_target_func_time));
457 case c_offload_target_scatter_inputs:
458 return (
459 offload_get_message_str(msg_c_report_target_scatter_inputs));
460 case c_offload_target_add_buffer_refs:
461 return (
462 offload_get_message_str(msg_c_report_target_add_buffer_refs));
463 case c_offload_target_compute:
464 return (offload_get_message_str(msg_c_report_target_compute));
465 case c_offload_target_gather_outputs:
466 return (offload_get_message_str
467 (msg_c_report_target_gather_outputs));
468 case c_offload_target_release_buffer_refs:
469 return (offload_get_message_str(
470 msg_c_report_target_release_buffer_refs));
471 default:
472 LIBOFFLOAD_ERROR(c_report_unknown_timer_node);
473 abort();