int omp_get_num_devices() { __offload_init_library(); return mic_engines_total; }
extern "C" OFFLOAD OFFLOAD_TARGET_ACQUIRE1( const int* device_num, const char* file, uint64_t line ) { int target_number; // make sure libray is initialized and at least one device is available if (!__offload_init_library()) { LIBOFFLOAD_ERROR(c_device_is_not_available); exit(1); } // OFFLOAD_TIMER_INIT must follow call to __offload_init_library OffloadHostTimerData * timer_data = OFFLOAD_TIMER_INIT(file, line); OFFLOAD_TIMER_START(timer_data, c_offload_host_total_offload); OFFLOAD_TIMER_START(timer_data, c_offload_host_initialize); if (__offload_init_type == c_init_on_offload_all) { for (int i = 0; i < mic_engines_total; i++) { mic_engines[i].init(); } } OFFLOAD_TIMER_STOP(timer_data, c_offload_host_initialize); OFFLOAD_TIMER_START(timer_data, c_offload_host_target_acquire); // use default device number if it is not provided if (device_num != 0) { target_number = *device_num; } else { target_number = __omp_device_num; } // device number should be a non-negative integer value if (target_number < 0) { LIBOFFLOAD_ERROR(c_omp_invalid_device_num); exit(1); } // should we do this for OpenMP? target_number %= mic_engines_total; // reserve device in ORSL if (!ORSL::reserve(target_number)) { LIBOFFLOAD_ERROR(c_device_is_not_available); exit(1); } // initialize device(s) OFFLOAD_TIMER_START(timer_data, c_offload_host_initialize); if (__offload_init_type == c_init_on_offload) { mic_engines[target_number].init(); } OFFLOAD_TIMER_STOP(timer_data, c_offload_host_initialize); OFFLOAD ofld = new OffloadDescriptor(target_number, 0, true, true, timer_data); OFFLOAD_TIMER_HOST_MIC_NUM(timer_data, target_number); Offload_Report_Prolog(timer_data); OFFLOAD_DEBUG_TRACE_1(2, timer_data->offload_number, c_offload_start, "Starting OpenMP offload, device = %d\n", target_number); OFFLOAD_TIMER_STOP(timer_data, c_offload_host_target_acquire); return ofld; }
extern "C" OFFLOAD OFFLOAD_TARGET_ACQUIRE( TARGET_TYPE target_type, int target_number, int is_optional, _Offload_status* status, const char* file, uint64_t line ) { bool retval; OFFLOAD ofld; // initialize status if (status != 0) { status->result = OFFLOAD_UNAVAILABLE; status->device_number = -1; status->data_sent = 0; status->data_received = 0; } // make sure libray is initialized retval = __offload_init_library(); // OFFLOAD_TIMER_INIT must follow call to __offload_init_library OffloadHostTimerData * timer_data = OFFLOAD_TIMER_INIT(file, line); OFFLOAD_TIMER_START(timer_data, c_offload_host_total_offload); OFFLOAD_TIMER_START(timer_data, c_offload_host_initialize); // initialize all devices is init_type is on_offload_all if (retval && __offload_init_type == c_init_on_offload_all) { for (int i = 0; i < mic_engines_total; i++) { mic_engines[i].init(); } } OFFLOAD_TIMER_STOP(timer_data, c_offload_host_initialize); OFFLOAD_TIMER_START(timer_data, c_offload_host_target_acquire); if (target_type == TARGET_HOST) { // Host always available retval = true; } else if (target_type == TARGET_MIC) { if (target_number >= -1) { if (retval) { if (target_number >= 0) { // User provided the device number target_number = target_number % mic_engines_total; } else { // use device 0 target_number = 0; } // reserve device in ORSL if (is_optional) { if (!ORSL::try_reserve(target_number)) { target_number = -1; } } else { if (!ORSL::reserve(target_number)) { target_number = -1; } } // initialize device if (target_number >= 0 && __offload_init_type == c_init_on_offload) { OFFLOAD_TIMER_START(timer_data, c_offload_host_initialize); mic_engines[target_number].init(); OFFLOAD_TIMER_STOP(timer_data, c_offload_host_initialize); } } else { // fallback to CPU target_number = -1; } if (target_number < 0 || !retval) { if (!is_optional && status == 0) { LIBOFFLOAD_ERROR(c_device_is_not_available); exit(1); } retval = false; } } else { LIBOFFLOAD_ERROR(c_invalid_device_number); exit(1); } } if (retval) { ofld = new OffloadDescriptor(target_number, status, !is_optional, false, timer_data); OFFLOAD_TIMER_HOST_MIC_NUM(timer_data, target_number); Offload_Report_Prolog(timer_data); OFFLOAD_DEBUG_TRACE_1(2, timer_data->offload_number, c_offload_start, "Starting offload: target_type = %d, " "number = %d, is_optional = %d\n", target_type, target_number, is_optional); OFFLOAD_TIMER_STOP(timer_data, c_offload_host_target_acquire); } else { ofld = NULL; OFFLOAD_TIMER_STOP(timer_data, c_offload_host_target_acquire); OFFLOAD_TIMER_STOP(timer_data, c_offload_host_total_offload); offload_report_free_data(timer_data); } return ofld; }
static void __offload_myoLoadLibrary_once(void) { if (__offload_init_library()) { myo_wrapper.LoadLibrary(); } }