// get number of OpenCL devices on platforms unsigned int HGPU_GPU_devices_get_number_on_platforms(HGPU_GPU_platforms* platforms){ unsigned int result = 0; for (unsigned int i=0;i<HGPU_GPU_platforms_get_number(platforms);i++) result += HGPU_GPU_devices_get_number_on_platform(platforms->platforms[i]); return result; }
// get total number of OpenCL platforms unsigned int HGPU_GPU_platforms_get_total_number(void){ HGPU_GPU_platforms* platforms = HGPU_GPU_platforms_get(); unsigned int result = HGPU_GPU_platforms_get_number(platforms); HGPU_GPU_platforms_delete(&platforms); return result; }
// get total number of OpenCL devices unsigned int HGPU_GPU_devices_get_total_number(void){ HGPU_GPU_platforms* platforms = HGPU_GPU_platforms_get(); unsigned int result = 0; for (unsigned int i=0;i<HGPU_GPU_platforms_get_number(platforms);i++) result += HGPU_GPU_devices_get_number_on_platform(platforms->platforms[i]); HGPU_GPU_platforms_delete(&platforms); return result; }
// get OpenCL platforms by index cl_platform_id HGPU_GPU_platform_get_by_index(unsigned int platform_index){ cl_platform_id result; HGPU_GPU_platforms* platforms = HGPU_GPU_platforms_get(); if (HGPU_GPU_platforms_get_number(platforms)<=platform_index) { HGPU_GPU_platforms_delete(&platforms); HGPU_GPU_error_message(HGPU_ERROR_NO_PLATFORM,"there is no any desired OpenCL platform"); } result = platforms->platforms[platform_index]; HGPU_GPU_platforms_delete(&platforms); return result; }
// get index of OpenCL platform by platform unsigned int HGPU_GPU_platform_get_index_of(cl_platform_id platform){ unsigned int result = 0; HGPU_GPU_platforms* platforms = HGPU_GPU_platforms_get(); bool flag = true; while ((result<HGPU_GPU_platforms_get_number(platforms))&&(flag)){ if (platforms->platforms[result]==platform) flag = false; else result++; } HGPU_GPU_platforms_delete(&platforms); if (flag) HGPU_GPU_error_message(HGPU_ERROR_NO_PLATFORM,"there is no any desired OpenCL platform"); return result; }
// get all OpenCL devices HGPU_GPU_devices* HGPU_GPU_devices_get_on_platforms(HGPU_GPU_platforms* platforms){ unsigned int number_of_devices = HGPU_GPU_devices_get_number_on_platforms(platforms); HGPU_GPU_devices* result = HGPU_GPU_devices_new(number_of_devices); unsigned int device_index = 0; for (unsigned int i=0; i<HGPU_GPU_platforms_get_number(platforms); i++){ unsigned int number_of_devices_on_platform = HGPU_GPU_devices_get_number_on_platform(platforms->platforms[i]); if (number_of_devices_on_platform){ HGPU_GPU_devices* devices_on_platform = HGPU_GPU_devices_get_on_platform(platforms->platforms[device_index]); for (unsigned int j=0; j<number_of_devices_on_platform; j++) result->devices[device_index++] = devices_on_platform->devices[j]; HGPU_GPU_devices_delete(&devices_on_platform); } } return result; }
// select OpenCL platforms by OpenCL version void HGPU_GPU_platforms_select_by_version(HGPU_GPU_platforms** platforms,HGPU_GPU_version version){ unsigned int platforms_number = HGPU_GPU_platforms_get_number(*platforms); if (!platforms_number) HGPU_GPU_error(HGPU_ERROR_NO_PLATFORM); cl_uint desired_platforms = 0; for(unsigned int i=0; i<platforms_number; i++){ cl_platform_id platform = (*platforms)->platforms[i]; HGPU_GPU_version version_gpu = HGPU_GPU_platform_get_version(platform); if (HGPU_GPU_version_check(version_gpu,version)) desired_platforms++; } if(!desired_platforms) HGPU_GPU_error(HGPU_ERROR_NO_PLATFORM); HGPU_GPU_platforms* result = HGPU_GPU_platforms_new(desired_platforms); int j=0; for(unsigned int i=0; i<platforms_number; i++){ cl_platform_id platform = (*platforms)->platforms[i]; HGPU_GPU_version version_gpu = HGPU_GPU_platform_get_version(platform); if (HGPU_GPU_version_check(version_gpu,version)) result->platforms[j++] = platform; } HGPU_GPU_platforms_delete(platforms); (*platforms) = result; }
// select OpenCL platforms by vendor void HGPU_GPU_platforms_select_by_vendor(HGPU_GPU_platforms** platforms,HGPU_GPU_vendor vendor){ unsigned int platforms_number = HGPU_GPU_platforms_get_number(*platforms); if (!platforms_number) HGPU_GPU_error(HGPU_ERROR_NO_PLATFORM); char infobuf[HGPU_GPU_MAX_STR_INFO_LENGHT]; cl_uint desired_platforms = 0; for(unsigned int i=0; i<platforms_number; i++){ cl_platform_id GPU_platform = (*platforms)->platforms[i]; HGPU_GPU_error_message(clGetPlatformInfo(GPU_platform,CL_PLATFORM_VENDOR,sizeof(infobuf),infobuf,NULL),"clGetPlatformInfo failed"); if ((HGPU_convert_vendor_from_str(infobuf)==vendor) || (vendor==HGPU_GPU_vendor_any)) desired_platforms++; } if(!desired_platforms) HGPU_GPU_error(HGPU_ERROR_NO_PLATFORM); HGPU_GPU_platforms* result = HGPU_GPU_platforms_new(desired_platforms); int j=0; for(unsigned int i=0; i<platforms_number; i++){ cl_platform_id GPU_platform = (*platforms)->platforms[i]; HGPU_GPU_error_message(clGetPlatformInfo(GPU_platform,CL_PLATFORM_VENDOR,sizeof(infobuf),infobuf,NULL),"clGetPlatformInfo failed"); if ((HGPU_convert_vendor_from_str(infobuf)==vendor) || (vendor==HGPU_GPU_vendor_any)) result->platforms[j++] = GPU_platform; } HGPU_GPU_platforms_delete(platforms); (*platforms) = result; }
// get first available platform cl_platform_id HGPU_GPU_platform_get_first(HGPU_GPU_platforms* platforms){ if (!HGPU_GPU_platforms_get_number(platforms)) HGPU_GPU_error_message(HGPU_ERROR_NO_PLATFORM,"there is no any desired OpenCL platform"); return platforms->platforms[0]; }