Exemple #1
0
// select OpenCL devices by vendor
void
HGPU_GPU_devices_select_by_vendor(HGPU_GPU_devices** devices,HGPU_GPU_vendor vendor){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(*devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    char infobuf[HGPU_MAX_STR_INFO_LENGHT];
    cl_uint desired_devices = 0;
    for(unsigned int i=0; i<number_of_devices; i++){
        cl_device_id GPU_device = (*devices)->devices[i];
        HGPU_GPU_error_message(clGetDeviceInfo(GPU_device,CL_DEVICE_VENDOR,sizeof(infobuf),infobuf,NULL),"clGetDeviceInfo failed");
        if ((HGPU_convert_vendor_from_str(infobuf)==vendor) || (vendor==HGPU_GPU_vendor_any)) desired_devices++;
    }
    HGPU_GPU_devices* result;
    if(desired_devices){
        result = HGPU_GPU_devices_new(desired_devices);
        int j=0;
        for(unsigned int i=0; i<number_of_devices; i++){
            cl_device_id GPU_device = (*devices)->devices[i];
            HGPU_GPU_error_message(clGetDeviceInfo(GPU_device,CL_DEVICE_VENDOR,sizeof(infobuf),infobuf,NULL),"clGetDeviceInfo failed");
            if ((HGPU_convert_vendor_from_str(infobuf)==vendor) || (vendor==HGPU_GPU_vendor_any)) result->devices[j++] = GPU_device;
        }
    } else
        result = HGPU_GPU_devices_new_empty();
    HGPU_GPU_devices_delete(devices);
    (*devices) = result;
}
Exemple #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;
}
Exemple #3
0
// get vendor of OpenCL platform
HGPU_GPU_vendor
HGPU_GPU_platform_get_vendor(cl_platform_id platform){
    size_t parameter_length;
    HGPU_GPU_error_message(clGetPlatformInfo(platform,CL_PLATFORM_VENDOR,0,NULL,&parameter_length),"clGetPlatformInfo failed");
    char* result_str = (char*) calloc(parameter_length+1,sizeof(char));
    HGPU_GPU_error_message(clGetPlatformInfo(platform,CL_PLATFORM_VENDOR,(parameter_length+1),result_str,NULL),"clGetPlatformInfo failed");
    HGPU_GPU_vendor vendor = HGPU_convert_vendor_from_str(result_str);
    free(result_str);
    return vendor;
}
Exemple #4
0
// get vendor of OpenCL device
HGPU_GPU_vendor
HGPU_GPU_device_get_vendor(cl_device_id device){
    size_t parameter_length;
    HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_VENDOR,0,NULL,&parameter_length),"clGetDeviceInfo failed");
    char* result_str = (char*) calloc(parameter_length+1,sizeof(char));
    HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_VENDOR,(parameter_length+1),result_str,NULL),"clGetDeviceInfo failed");
    HGPU_GPU_vendor vendor = HGPU_convert_vendor_from_str(result_str);
    free(result_str);
    return vendor;
}
Exemple #5
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;
}