Ejemplo n.º 1
0
// get all OpenCL platforms
HGPU_GPU_platforms*
HGPU_GPU_platforms_get(void){
    cl_uint GPU_platforms_number = 0;
	HGPU_GPU_error_message(clGetPlatformIDs(0,NULL,&GPU_platforms_number),"clGetPlatformIDs failed");
    if(!GPU_platforms_number) HGPU_GPU_error_message(HGPU_ERROR_NO_PLATFORM,"there are no any available OpenCL platforms");

    HGPU_GPU_platforms* result = HGPU_GPU_platforms_new(GPU_platforms_number);
    HGPU_GPU_error_message(clGetPlatformIDs(GPU_platforms_number,result->platforms,&result->number_of_platforms),"clGetPlatformIDs failed");
    if(!result->number_of_platforms) HGPU_GPU_error_message(HGPU_ERROR_NO_PLATFORM,"there are no any available OpenCL platforms");

    return result;
}
Ejemplo n.º 2
0
// automatically select OpenCL devices according to (HGPU_parameter) parameters
HGPU_GPU_devices*
HGPU_GPU_devices_select_auto(HGPU_parameter** parameters){
    HGPU_GPU_platforms* platforms = NULL;
    HGPU_GPU_devices*   devices   = NULL;
    HGPU_parameter* parameter_device      = HGPU_parameters_get_by_name(parameters,(char*) HGPU_PARAMETER_DEVICE);
    HGPU_parameter* parameter_device_type = HGPU_parameters_get_by_name(parameters,(char*) HGPU_PARAMETER_DEVICE_TYPE);
    HGPU_parameter* parameter_platform    = HGPU_parameters_get_by_name(parameters,(char*) HGPU_PARAMETER_PLATFORM);

    if (parameter_platform) {
        unsigned int platform_id = parameter_platform->value_integer;
        if ((!platform_id) && (strlen(parameter_platform->value_text)>1)){
            // get platforms by vendor
            platforms = HGPU_GPU_platforms_get();
            HGPU_GPU_vendor platform_vendor = HGPU_convert_vendor_from_str(parameter_platform->value_text);
            HGPU_GPU_platforms_select_by_vendor(&platforms,platform_vendor);
        } else {
            platforms = HGPU_GPU_platforms_new(1);
            platforms[0].platforms[0] = HGPU_GPU_platform_get_by_index(platform_id);
        }
        devices = HGPU_GPU_devices_get_on_platforms(platforms);
    }

    if (parameter_device) {
        unsigned int device_id = parameter_device->value_integer;
        if ((!device_id) && (strlen(parameter_device->value_text)>1)){
            HGPU_GPU_vendor device_vendor = HGPU_convert_vendor_from_str(parameter_device->value_text);
            // get devices by vendor
            if (parameter_platform)
                HGPU_GPU_devices_select_by_vendor(&devices,device_vendor);
            else
                devices = HGPU_GPU_devices_get_by_vendor(device_vendor);
        } else {
            devices = HGPU_GPU_devices_new(1);
            if (parameter_platform)
                devices[0].devices[0] = HGPU_GPU_device_get_by_index_on_platform(platforms[0].platforms[0],device_id);
            else
                devices[0].devices[0] = HGPU_GPU_device_get_by_index(device_id);
        }
    }

    if ((!parameter_platform) && (!parameter_device))
        devices = HGPU_GPU_devices_get();

    if (parameter_device_type) {
        if (!strcmp(parameter_device_type->value_text,"GPU")) HGPU_GPU_devices_select_by_type(&devices,CL_DEVICE_TYPE_GPU);
        if (!strcmp(parameter_device_type->value_text,"CPU")) HGPU_GPU_devices_select_by_type(&devices,CL_DEVICE_TYPE_CPU);
        if (!strcmp(parameter_device_type->value_text,"ACCELERATOR")) HGPU_GPU_devices_select_by_type(&devices,CL_DEVICE_TYPE_ACCELERATOR);
    }

    HGPU_GPU_devices_sort(&devices);

    return devices;
}
Ejemplo n.º 3
0
// 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;
}
Ejemplo n.º 4
0
// 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;
}