Example #1
0
// select OpenCL devices by uint parameter
void
HGPU_GPU_devices_select_by_parameter_uint(HGPU_GPU_devices** devices,cl_device_info parameter,unsigned long int min_value){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(*devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    cl_uint desired_devices = 0;
    for(unsigned int i=0; i<number_of_devices; i++){
        cl_device_id device = (*devices)->devices[i];
        cl_ulong device_output;
        HGPU_GPU_error_message(clGetDeviceInfo(device,parameter,sizeof(device_output),&device_output,NULL),"clGetDeviceInfo failed");
        if (device_output>=min_value) desired_devices++;
    }
    HGPU_GPU_devices* result;
    if(desired_devices){
        result = HGPU_GPU_devices_new(desired_devices);
        int device_index=0;
        for(unsigned int i=0; i<number_of_devices; i++){
            cl_device_id device = (*devices)->devices[i];
            cl_ulong device_output;
            HGPU_GPU_error_message(clGetDeviceInfo(device,parameter,sizeof(device_output),&device_output,NULL),"clGetDeviceInfo failed");
            if (device_output>=min_value) result->devices[device_index++] = device;
        }
    } else
        result = HGPU_GPU_devices_new_empty();
    HGPU_GPU_devices_delete(devices);
    (*devices) = result;
}
Example #2
0
// select OpenCL devices by device available
void
HGPU_GPU_devices_select_by_device_and_compiler_available(HGPU_GPU_devices** devices){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(*devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    cl_uint desired_devices = 0;
    for(unsigned int i=0; i<number_of_devices; i++){
        cl_device_id device = (*devices)->devices[i];
        cl_bool device_available;
        cl_bool compiler_available;
        HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_AVAILABLE,sizeof(device_available),&device_available,NULL),"clGetDeviceInfo failed");
        HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_COMPILER_AVAILABLE,sizeof(device_available),&compiler_available,NULL),"clGetDeviceInfo failed");
        if (device_available & compiler_available) desired_devices++;
    }
    HGPU_GPU_devices* result;
    if(desired_devices){
        result = HGPU_GPU_devices_new(desired_devices);
        int device_index=0;
        for(unsigned int i=0; i<number_of_devices; i++){
            cl_device_id device = (*devices)->devices[i];
            cl_bool device_available;
            cl_bool compiler_available;
            HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_AVAILABLE,sizeof(device_available),&device_available,NULL),"clGetDeviceInfo failed");
            HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_COMPILER_AVAILABLE,sizeof(device_available),&compiler_available,NULL),"clGetDeviceInfo failed");
            if (device_available & compiler_available) result->devices[device_index++] = device;
        }
    } else
        result = HGPU_GPU_devices_new_empty();
    HGPU_GPU_devices_delete(devices);
    (*devices) = result;
}
Example #3
0
// select OpenCL devices by type
void
HGPU_GPU_devices_select_by_type(HGPU_GPU_devices** devices,cl_device_type device_type){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(*devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    cl_uint desired_devices = 0;
    for(unsigned int i=0; i<number_of_devices; i++){
        cl_device_id device = (*devices)->devices[i];
        cl_device_type dev_type;
        HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_TYPE,sizeof(dev_type),&dev_type,NULL),"clGetDeviceInfo failed");
        if (dev_type & device_type) desired_devices++;
    }
    HGPU_GPU_devices* result;
    if(desired_devices){
        result = HGPU_GPU_devices_new(desired_devices);
        int device_index=0;
        for(unsigned int i=0; i<number_of_devices; i++){
            cl_device_id device = (*devices)->devices[i];
            cl_device_type dev_type;
            HGPU_GPU_error_message(clGetDeviceInfo(device,CL_DEVICE_TYPE,sizeof(dev_type),&dev_type,NULL),"clGetDeviceInfo failed");
            if (dev_type & device_type) result->devices[device_index++] = device;
        }
    } else
        result = HGPU_GPU_devices_new_empty();
    HGPU_GPU_devices_delete(devices);
    (*devices) = result;
}
Example #4
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;
}
Example #5
0
// clone OpenCL devices
HGPU_GPU_devices*
HGPU_GPU_devices_clone(HGPU_GPU_devices* devices){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    HGPU_GPU_devices* result = HGPU_GPU_devices_new(number_of_devices);
    size_t bytes = number_of_devices * sizeof(cl_device_id);
    memcpy_s(result->devices,bytes,devices->devices,bytes);
    return result;
}
Example #6
0
// new OpenCL devices
HGPU_GPU_devices*
HGPU_GPU_devices_new(unsigned int number_of_devices){
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    if (number_of_devices>HGPU_GPU_MAX_DEVICES) HGPU_GPU_error_message(HGPU_ERROR_NO_MEMORY,"exceed maximal number of descriptions for devices");
    HGPU_GPU_devices* result = (HGPU_GPU_devices*) calloc(1,sizeof(HGPU_GPU_devices));
        result->devices           = (cl_device_id*) calloc(number_of_devices,sizeof(cl_device_id));
        result->number_of_devices = number_of_devices;
    return result;
}
Example #7
0
//get max OpenCL version of devices on platforms
HGPU_GPU_version
HGPU_GPU_devices_get_version_max(HGPU_GPU_devices* devices){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    HGPU_GPU_version version = HGPU_GPU_device_get_version(devices->devices[0]);
    for (unsigned int i=1; i<number_of_devices; i++)
        version = HGPU_GPU_version_max(version,HGPU_GPU_device_get_version(devices->devices[i]));
    return version;
}
Example #8
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;
}
Example #9
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;
}
Example #10
0
// select OpenCL devices, supporting double precision
void
HGPU_GPU_devices_select_by_double_precision(HGPU_GPU_devices** devices){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(*devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    cl_uint desired_devices = 0;
    for(unsigned int i=0; i<number_of_devices; i++)
        if (HGPU_GPU_device_check_double_precision((*devices)->devices[i])) desired_devices++;
    HGPU_GPU_devices* result;
    if(desired_devices){
        result = HGPU_GPU_devices_new(desired_devices);
        int device_index=0;
        for(unsigned int i=0; i<number_of_devices; i++)
            if (HGPU_GPU_device_check_double_precision((*devices)->devices[i])) result->devices[device_index++] = (*devices)->devices[i];
    } else
        result = HGPU_GPU_devices_new_empty();
    HGPU_GPU_devices_delete(devices);
    (*devices) = result;
}
Example #11
0
// select OpenCL devices by OpenCL version
void
HGPU_GPU_devices_select_by_version(HGPU_GPU_devices** devices,HGPU_GPU_version version){
    unsigned int number_of_devices = HGPU_GPU_devices_get_number(*devices);
    if (!number_of_devices) HGPU_GPU_error(HGPU_ERROR_NO_DEVICE);
    cl_uint desired_devices = 0;
    for(unsigned int i=0; i<number_of_devices; i++){
        cl_device_id device = (*devices)->devices[i];
        HGPU_GPU_version version_gpu = HGPU_GPU_device_get_version(device);
        if (HGPU_GPU_version_check(version_gpu,version)) desired_devices++;
    }
    HGPU_GPU_devices* result;
    if(desired_devices){
        result = HGPU_GPU_devices_new(desired_devices);
        int device_index=0;
        for(unsigned int i=0; i<number_of_devices; i++){
            cl_device_id device = (*devices)->devices[i];
            HGPU_GPU_version version_gpu = HGPU_GPU_device_get_version(device);
            if (HGPU_GPU_version_check(version_gpu,version)) result->devices[device_index++] = device;
        }
    } else
        result = HGPU_GPU_devices_new_empty();
    HGPU_GPU_devices_delete(devices);
    (*devices) = result;
}