1 /* 2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions 6 are met: 7 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. 16 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. 28 */ 29 30 31 #if !defined(LIBOFFLOAD_ERROR_CODES_H) 32 #define LIBOFFLOAD_ERROR_CODES_H 33 #include <stdarg.h> 34 #include <stdlib.h> 35 #include <stdio.h> 36 37 typedef enum 38 { 39 c_device_is_not_available = 0, 40 c_invalid_device_number, 41 c_offload1, 42 c_unknown_var_type, 43 c_send_func_ptr, 44 c_receive_func_ptr, 45 c_malloc, 46 c_unknown_mic_device_type, 47 c_offload_malloc, 48 c_invalid_env_var_value, 49 c_invalid_env_var_int_value, 50 c_invalid_env_report_value, 51 c_offload_signaled1, 52 c_offload_signaled2, 53 c_myotarget_checkresult, 54 c_myowrapper_checkresult, 55 c_offload_descriptor_offload, 56 c_merge_var_descs1, 57 c_merge_var_descs2, 58 c_mic_parse_env_var_list1, 59 c_mic_parse_env_var_list2, 60 c_mic_process_exit_ret, 61 c_mic_process_exit_sig, 62 c_mic_process_exit, 63 c_mic_init3, 64 c_mic_init4, 65 c_mic_init5, 66 c_mic_init6, 67 c_mic_init7, 68 c_mic_init8, 69 c_mic_init9, 70 c_mic_init10, 71 c_mic_init11, 72 c_no_static_var_data, 73 c_no_ptr_data, 74 c_get_engine_handle, 75 c_get_engine_index, 76 c_process_create, 77 c_process_set_cache_size, 78 c_process_get_func_handles, 79 c_process_wait_shutdown, 80 c_process_proxy_flush, 81 c_load_library, 82 c_pipeline_create, 83 c_pipeline_run_func, 84 c_pipeline_start_run_funcs, 85 c_buf_create, 86 c_buf_create_out_of_mem, 87 c_buf_create_from_mem, 88 c_buf_destroy, 89 c_buf_map, 90 c_buf_unmap, 91 c_buf_read, 92 c_buf_write, 93 c_buf_copy, 94 c_buf_get_address, 95 c_buf_add_ref, 96 c_buf_release_ref, 97 c_buf_set_state, 98 c_event_wait, 99 c_zero_or_neg_ptr_len, 100 c_zero_or_neg_transfer_size, 101 c_bad_ptr_mem_alloc, 102 c_bad_ptr_mem_range, 103 c_different_src_and_dstn_sizes, 104 c_ranges_dont_match, 105 c_destination_is_over, 106 c_slice_of_noncont_array, 107 c_non_contiguous_dope_vector, 108 c_pointer_array_mismatch, 109 c_omp_invalid_device_num_env, 110 c_omp_invalid_device_num, 111 c_unknown_binary_type, 112 c_multiple_target_exes, 113 c_no_target_exe, 114 c_incorrect_affinity, 115 c_cannot_set_affinity, 116 c_mixed_versions, 117 c_report_host, 118 c_report_target, 119 c_report_title, 120 c_report_from_file, 121 c_report_file, 122 c_report_line, 123 c_report_tag, 124 c_report_seconds, 125 c_report_bytes, 126 c_report_mic, 127 c_report_cpu_time, 128 c_report_cpu_to_mic_data, 129 c_report_mic_time, 130 c_report_mic_to_cpu_data, 131 c_report_unknown_timer_node, 132 c_report_unknown_trace_node, 133 c_report_offload, 134 c_report_w_tag, 135 c_report_state, 136 c_report_start, 137 c_report_init, 138 c_report_logical_card, 139 c_report_physical_card, 140 c_report_register, 141 c_report_init_func, 142 c_report_create_buf_host, 143 c_report_create_buf_mic, 144 c_report_send_pointer_data, 145 c_report_sent_pointer_data, 146 c_report_gather_copyin_data, 147 c_report_copyin_data, 148 c_report_state_signal, 149 c_report_signal, 150 c_report_wait, 151 c_report_compute, 152 c_report_receive_pointer_data, 153 c_report_received_pointer_data, 154 c_report_start_target_func, 155 c_report_var, 156 c_report_scatter_copyin_data, 157 c_report_gather_copyout_data, 158 c_report_scatter_copyout_data, 159 c_report_copyout_data, 160 c_report_unregister, 161 c_report_destroy, 162 c_report_myoinit, 163 c_report_myoregister, 164 c_report_myofini, 165 c_report_mic_myo_shared, 166 c_report_mic_myo_fptr, 167 c_report_myosharedmalloc, 168 c_report_myosharedfree, 169 c_report_myosharedalignedmalloc, 170 c_report_myosharedalignedfree, 171 c_report_myoacquire, 172 c_report_myorelease, 173 c_report_myosupportsfeature, 174 c_report_myosharedarenacreate, 175 c_report_myosharedalignedarenamalloc, 176 c_report_myosharedalignedarenafree, 177 c_report_myoarenaacquire, 178 c_report_myoarenarelease, 179 c_coipipe_max_number, 180 c_in_with_preallocated, 181 c_report_no_host_exe, 182 c_report_no_target_exe, 183 c_report_path_buff_overflow, 184 c_create_pipeline_for_stream, 185 c_offload_no_stream, 186 c_offload_device_doesnt_match_to_stream, 187 c_offload_streams_are_absent, 188 c_get_engine_info, 189 c_clear_cpu_mask, 190 c_set_cpu_mask, 191 c_report_state_stream, 192 c_report_stream, 193 c_unload_library, 194 c_target_myo_library, 195 c_myo_dl_sym, 196 c_bad_myo_free 197 } error_types; 198 199 enum OffloadHostPhase { 200 // Total time on host for entire offload 201 c_offload_host_total_offload = 0, 202 203 // Time to load target binary 204 c_offload_host_initialize, 205 206 // Time to acquire lrb availability dynamically 207 c_offload_host_target_acquire, 208 209 // Time to wait for dependencies 210 c_offload_host_wait_deps, 211 212 // Time to allocate pointer buffers, initiate writes for pointers 213 // and calculate size of copyin/copyout buffer 214 c_offload_host_setup_buffers, 215 216 // Time to allocate pointer buffers 217 c_offload_host_alloc_buffers, 218 219 // Time to initialize misc data 220 c_offload_host_setup_misc_data, 221 222 // Time to allocate copyin/copyout buffer 223 c_offload_host_alloc_data_buffer, 224 225 // Time to initiate writes from host pointers to buffers 226 c_offload_host_send_pointers, 227 228 // Time to Gather IN data of offload into buffer 229 c_offload_host_gather_inputs, 230 231 // Time to map buffer 232 c_offload_host_map_in_data_buffer, 233 234 // Time to unmap buffer 235 c_offload_host_unmap_in_data_buffer, 236 237 // Time to start remote function call that does computation on lrb 238 c_offload_host_start_compute, 239 240 // Time to wait for compute to finish 241 c_offload_host_wait_compute, 242 243 // Time to initiate reads from pointer buffers 244 c_offload_host_start_buffers_reads, 245 246 // Time to update host variabels with OUT data from buffer 247 c_offload_host_scatter_outputs, 248 249 // Time to map buffer 250 c_offload_host_map_out_data_buffer, 251 252 // Time to unmap buffer 253 c_offload_host_unmap_out_data_buffer, 254 255 // Time to wait reads from buffers to finish 256 c_offload_host_wait_buffers_reads, 257 258 // Time to destroy buffers that are no longer needed 259 c_offload_host_destroy_buffers, 260 261 // LAST TIME MONITOR 262 c_offload_host_max_phase 263 }; 264 265 enum OffloadTargetPhase { 266 // Total time spent on the target 267 c_offload_target_total_time = 0, 268 269 // Time to initialize offload descriptor 270 c_offload_target_descriptor_setup, 271 272 // Time to find target entry point in lookup table 273 c_offload_target_func_lookup, 274 275 // Total time spend executing offload entry 276 c_offload_target_func_time, 277 278 // Time to initialize target variables with IN values from buffer 279 c_offload_target_scatter_inputs, 280 281 // Time to add buffer reference for pointer buffers 282 c_offload_target_add_buffer_refs, 283 284 // Total time on lrb for computation 285 c_offload_target_compute, 286 287 // On lrb, time to copy OUT into buffer 288 c_offload_target_gather_outputs, 289 290 // Time to release buffer references 291 c_offload_target_release_buffer_refs, 292 293 // LAST TIME MONITOR 294 c_offload_target_max_phase 295 }; 296 297 #ifdef TARGET_WINNT 298 #define DLL_LOCAL 299 #else 300 #define DLL_LOCAL __attribute__((visibility("hidden"))) 301 #endif 302 303 #ifdef __cplusplus 304 extern "C" { 305 #endif 306 DLL_LOCAL void __liboffload_error_support(error_types input_tag, ...); 307 DLL_LOCAL void __liboffload_report_support(error_types input_tag, ...); 308 DLL_LOCAL char const *offload_get_message_str(int msgCode); 309 DLL_LOCAL char const * report_get_message_str(error_types input_tag); 310 DLL_LOCAL char const * report_get_host_stage_str(int i); 311 DLL_LOCAL char const * report_get_target_stage_str(int i); 312 #ifdef __cplusplus 313 } 314 #endif 315 316 #define test_msg_cat(nm, msg) \ 317 fprintf(stderr, "\t TEST for %s \n \t", nm); \ 318 __liboffload_error_support(msg); 319 320 #define test_msg_cat1(nm, msg, ...) \ 321 fprintf(stderr, "\t TEST for %s \n \t", nm); \ 322 __liboffload_error_support(msg, __VA_ARGS__); 323 324 DLL_LOCAL void write_message(FILE * file, int msgCode, va_list args_p); 325 326 #define LIBOFFLOAD_ERROR __liboffload_error_support 327 328 #ifdef TARGET_WINNT 329 #define LIBOFFLOAD_ABORT \ 330 _set_abort_behavior(0, _WRITE_ABORT_MSG); \ 331 abort() 332 #else 333 #define LIBOFFLOAD_ABORT \ 334 abort() 335 #endif 336 337 #endif // !defined(LIBOFFLOAD_ERROR_CODES_H) 338