liboffload_error.c 20 KB

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