void compile_all(const char *src, size_t src_size) { cl_uint i; // Get the platform list cl_platform_id *platforms = NULL; cl_uint num_platforms = 0; if (get_platform_list(&platforms, &num_platforms) != CL_SUCCESS) { return; } // For each platform compile binaries for each devices for (i = 0; i < num_platforms; ++i) { // Compile for each devices cl_uint num_devices = 0; cl_int err = compile_program(&num_devices, src, src_size, platforms[i], i); // Print the result char *platform_name = get_platform_info(platforms[i], CL_PLATFORM_NAME); printf("PLATFORM [%s] --> %s (%u)\n", (platform_name ? platform_name : ""), ((err == CL_SUCCESS) ? "SUCCESS" : "FAILURE"), (unsigned)num_devices); fflush(stdout); free(platform_name); } // Free the platform list free_platform_list(platforms, num_platforms); }
/* Get first platform that matches a string. */ cl_platform_id get_platform(const char *platform_string) { cl_platform_id *platforms = NULL; cl_platform_id platform; int i; int num; char *name; int len; num = get_platforms(&platforms); if (num < 1) return NULL; platform = NULL; name = NULL; len = 0; for (i = 0; i < num; i++) { get_platform_info(platforms[i], CL_PLATFORM_NAME, &name, &len); if (strstr(name, platform_string)) { platform = platforms[i]; break; } } if (name != NULL) free(name); if (platforms != NULL) free(platforms); return platform; }
/* * This will be called to intiialize the thermali subsystem. */ int onlp_thermali_init(void) { mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); mlnx_platform_info->tinfo=tinfo; mlnx_platform_info->thermal_fnames=thermal_fnames; return ONLP_STATUS_OK; }
int onlp_ledi_init(void) { mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); mlnx_platform_info->linfo = linfo; mlnx_platform_info->led_fnames = file_names; return ONLP_STATUS_OK; }
////////////////////////////////////////////////////////////////////////// // CLPlatform // CLPlatform::CLPlatform(cl_platform_id platform_) : platform(platform_) { profile = get_platform_info(platform, CL_PLATFORM_PROFILE); version = get_platform_info(platform, CL_PLATFORM_VERSION); name = get_platform_info(platform, CL_PLATFORM_NAME); vendor = get_platform_info(platform, CL_PLATFORM_VENDOR); extensions = get_platform_info(platform, CL_PLATFORM_EXTENSIONS); //cl_uint numDeviceIDs; //::clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &numDeviceIDs); //std::vector<cl_device_id> deviceIDs(numDeviceIDs); //::clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, numDeviceIDs, &deviceIDs[0], NULL); //for(size_t idx = 0; idx < numDeviceIDs; ++idx) //{ // devices.insert(DeviceMap::value_type(deviceIDs[idx], CLDevice(deviceIDs[idx]))); //} }
cl_platform_id* get_platforms() { cl_uint num_platforms; check_error(clGetPlatformIDs(0, 0, &num_platforms)); printf("Found %d platforms\n", num_platforms); if (num_platforms > 0) { cl_platform_id* platforms = new cl_platform_id[num_platforms]; check_error(clGetPlatformIDs(num_platforms, platforms, 0)); for (unsigned int i = 0; i < num_platforms; ++i) { char* profile = get_platform_info(platforms[i], CL_PLATFORM_PROFILE); printf("Platform profile: %s\n", profile); delete [] profile; char* version = get_platform_info(platforms[i], CL_PLATFORM_VERSION); printf("Platform version: %s\n", version); delete [] version; char* name = get_platform_info(platforms[i], CL_PLATFORM_NAME); printf("Platform name: %s\n", name); delete [] name; char* vendor = get_platform_info(platforms[i], CL_PLATFORM_VENDOR); printf("Platform vendor: %s\n", vendor); delete [] vendor; char* extensions = get_platform_info(platforms[i], CL_PLATFORM_EXTENSIONS); printf("Platform extensions: %s\n", extensions); delete [] extensions; } return platforms; } else { exit(EXIT_FAILURE); } }
/* * This function will be called prior to all of onlp_fani_* functions. */ int onlp_fani_init(void) { mlnx_platform_info_t* mlnx_platform_info = get_platform_info(); mlnx_platform_info->min_fan_speed = min_fan_speed; mlnx_platform_info->max_fan_speed = max_fan_speed; mlnx_platform_info->finfo = finfo; mlnx_platform_info->fan_fnames = fan_path; mlnx_platform_info->fan_type = FAN_TYPE_NO_EEPROM; mlnx_platform_info->fan_per_module = 2; mlnx_platform_info->first_psu_fan_id = FIRST_PSU_FAN_ID; return ONLP_STATUS_OK; }
int onlp_sysi_platform_set(const char* platform) { mlnx_platform_info_t* mlnx_platform; if(!strcmp(platform, "x86-64-mlnx-msn2410-r0")) { __ONL_PLATFORM_NAME = "x86-64-mlnx_msn2410-r0"; mlnx_platform = get_platform_info(); mc_get_platform_info(mlnx_platform); return ONLP_STATUS_OK; } if(!strcmp(platform, "x86-64-mlnx-msn2410b-r0")) { __ONL_PLATFORM_NAME = "x86-64-mlnx_msn2410b-r0"; mlnx_platform = get_platform_info(); mc_get_platform_info(mlnx_platform); return ONLP_STATUS_OK; } if(!strcmp(platform, "x86-64-mlnx-msn2410-all")) { __ONL_PLATFORM_NAME = "x86-64-mlnx-msn2410-all"; return ONLP_STATUS_OK; } return ONLP_STATUS_E_UNSUPPORTED; }
void print_platform_names(cl_platform_id *platforms, cl_uint num) { char *name; int len; cl_uint i; printf("Platform names:\n", num); name = NULL; len = 0; for (i = 0; i < num; i++) { get_platform_info(platforms[i], CL_PLATFORM_NAME, &name, &len); printf(" [%d] %s\n", i, name); } if (name != NULL) free(name); }