mirror of https://github.com/BOINC/boinc.git
client: Begin adding OpenCL support
svn path=/trunk/boinc/; revision=23251
This commit is contained in:
parent
d6c99b43d0
commit
53e92e0da0
|
@ -63,6 +63,51 @@ void segv_handler(int) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
HMODULE opencl_lib = NULL;
|
||||
|
||||
// TODO: Are these correct?
|
||||
typedef cl_int (__stdcall *CL_PLATFORMIDS) (cl_uint /* num_entries */,
|
||||
cl_platform_id * /* platforms */,
|
||||
cl_uint * /* num_platforms */);
|
||||
typedef cl_int (__stdcall *CL_DEVICEIDS) (cl_platform_id /* platform */,
|
||||
cl_device_type /* device_type */,
|
||||
cl_uint /* num_entries */,
|
||||
cl_device_id * /* devices */,
|
||||
cl_uint * /* num_devices */);
|
||||
typedef int (__stdcall *CL_INFO) (cl_device_id /* device */,
|
||||
cl_device_info /* param_name */,
|
||||
size_t /* param_value_size */,
|
||||
void * /* param_value */,
|
||||
size_t * /* param_value_size_ret */);
|
||||
|
||||
CL_PLATFORMIDS __clGetPlatformIDs = NULL;
|
||||
CL_DEVICEIDS __clGetDeviceIDs = NULL;
|
||||
CL_INFO __clGetDeviceInfo = NULL;
|
||||
|
||||
#else
|
||||
|
||||
void* opencl_lib = NULL;
|
||||
|
||||
cl_int (*__clGetPlatformIDs)(cl_uint /* num_entries */,
|
||||
cl_platform_id * /* platforms */,
|
||||
cl_uint * /* num_platforms */);
|
||||
cl_int (*__clGetDeviceIDs)(cl_platform_id /* platform */,
|
||||
cl_device_type /* device_type */,
|
||||
cl_uint /* num_entries */,
|
||||
cl_device_id * /* devices */,
|
||||
cl_uint * /* num_devices */);
|
||||
cl_int (*__clGetDeviceInfo)(cl_device_id /* device */,
|
||||
cl_device_info /* param_name */,
|
||||
size_t /* param_value_size */,
|
||||
void * /* param_value */,
|
||||
size_t * /* param_value_size_ret */);
|
||||
|
||||
#endif
|
||||
|
||||
void COPROC::get_opencl_info() {
|
||||
}
|
||||
|
||||
void COPROC::print_available_ram() {
|
||||
#ifdef MEASURE_AVAILABLE_RAM
|
||||
if (gstate.now - last_print_time < 60) return;
|
||||
|
@ -89,6 +134,79 @@ void COPROC::print_available_ram() {
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
void COPROCS::get_opencl(vector<string>&warnings) {
|
||||
cl_int ciErrNum;
|
||||
cl_platform_id platforms[1];
|
||||
cl_uint num_platforms, num_devices, device_index;
|
||||
cl_device_id devices[MAX_COPROC_INSTANCES];
|
||||
char vendor[128];
|
||||
char buf[256];
|
||||
|
||||
#ifdef _WIN32
|
||||
// TODO: Is this correct?
|
||||
opencl_lib = LoadLibrary("libOpenCL.dll");
|
||||
if (!opencl_lib) {
|
||||
warnings.push_back("No NVIDIA library found");
|
||||
return;
|
||||
}
|
||||
|
||||
__clGetPlatformIDs = (CL_PLATFORMIDS)GetProcAddress( opencl_lib, "clGetPlatformIDs" );
|
||||
__clGetDeviceIDs = (CL_DEVICEIDS)GetProcAddress( opencl_lib, "clGetDeviceIDs" );
|
||||
__clGetDeviceInfo = (CL_INFO)GetProcAddress( opencl_lib, "clGetDeviceInfo" );
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __APPLE__
|
||||
opencl_lib = dlopen("/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL", RTLD_NOW);
|
||||
#else
|
||||
// TODO: Is this correct?
|
||||
opencl_lib = dlopen("libOpenCL.so", RTLD_NOW);
|
||||
#endif
|
||||
if (!opencl_lib) {
|
||||
warnings.push_back("No NVIDIA library found");
|
||||
return;
|
||||
}
|
||||
__clGetPlatformIDs = (cl_int(*)(cl_uint, cl_platform_id*, cl_uint*)) dlsym( opencl_lib, "clGetPlatformIDs" );
|
||||
__clGetDeviceIDs = (cl_int(*)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*)) dlsym( opencl_lib, "clGetDeviceIDs" );
|
||||
__clGetDeviceInfo = (cl_int(*)(cl_device_id, cl_device_info, size_t, void*, size_t*)) dlsym( opencl_lib, "clGetDeviceInfo" );
|
||||
#endif
|
||||
if (!__clGetPlatformIDs) {
|
||||
warnings.push_back("clGetPlatformIDs() missing from OpenCL library");
|
||||
return;
|
||||
}
|
||||
if (!__clGetDeviceIDs) {
|
||||
warnings.push_back("clGetDeviceIDs() missing from OpenCL library");
|
||||
return;
|
||||
}
|
||||
if (!__clGetDeviceInfo) {
|
||||
warnings.push_back("clGetDeviceInfo() missing from OpenCL library");
|
||||
return;
|
||||
}
|
||||
|
||||
ciErrNum = (*__clGetPlatformIDs)(1, platforms, &num_platforms);
|
||||
if ((ciErrNum != CL_SUCCESS) || (num_platforms == 0)){
|
||||
warnings.push_back("clGetPlatformIDs() failed to return any OpenCL platforms");
|
||||
return;
|
||||
}
|
||||
|
||||
ciErrNum = (*__clGetDeviceIDs)(platforms[0], CL_DEVICE_TYPE_GPU, MAX_COPROC_INSTANCES, devices, &num_devices);
|
||||
if ((ciErrNum != CL_SUCCESS) || (num_devices == 0)){
|
||||
warnings.push_back("OpenCL library present but no GPUs found");
|
||||
return;
|
||||
}
|
||||
|
||||
for (device_index=0; device_index<num_devices; ++device_index) {
|
||||
ciErrNum = (*__clGetDeviceInfo)(devices[device_index], CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
|
||||
if ((ciErrNum != CL_SUCCESS) || (vendor[0] == 0)){
|
||||
sprintf(buf, "clGetDeviceInfo failed to get vendor for GPU %d", (int)device_index);
|
||||
warnings.push_back(buf);
|
||||
return;
|
||||
}
|
||||
//TODO: to be continued ....
|
||||
}
|
||||
}
|
||||
|
||||
void COPROCS::get(
|
||||
bool use_all, vector<string>&descs, vector<string>&warnings,
|
||||
vector<int>& ignore_cuda_dev,
|
||||
|
@ -122,6 +240,8 @@ void COPROCS::get(
|
|||
ati.get(use_all, descs, warnings, ignore_ati_dev);
|
||||
}
|
||||
#endif
|
||||
get_opencl(warnings);
|
||||
|
||||
signal(SIGSEGV, old_sig);
|
||||
#endif
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
10
lib/coproc.h
10
lib/coproc.h
|
@ -72,6 +72,7 @@
|
|||
|
||||
#include "miofile.h"
|
||||
#include "cal_boinc.h"
|
||||
#include "cl.h"
|
||||
|
||||
#define MAX_COPROC_INSTANCES 64
|
||||
|
||||
|
@ -85,6 +86,10 @@ struct COPROC_REQ {
|
|||
int parse(MIOFILE&);
|
||||
};
|
||||
|
||||
struct OPENCL_DEVICE_PROP {
|
||||
};
|
||||
|
||||
|
||||
// represents a set of identical coprocessors on a particular computer.
|
||||
// Abstract class;
|
||||
// objects will always be a derived class (COPROC_CUDA, COPROC_ATI)
|
||||
|
@ -116,6 +121,7 @@ struct COPROC {
|
|||
// These are not sequential if we omit instances (see above)
|
||||
//
|
||||
int device_nums[MAX_COPROC_INSTANCES];
|
||||
int open_device_ids[MAX_COPROC_INSTANCES];
|
||||
int device_num; // temp used in scan process
|
||||
bool running_graphics_app[MAX_COPROC_INSTANCES];
|
||||
// is this GPU running a graphics app (NVIDIA only)
|
||||
|
@ -125,6 +131,8 @@ struct COPROC {
|
|||
double available_ram_fake[MAX_COPROC_INSTANCES];
|
||||
|
||||
double last_print_time;
|
||||
|
||||
OPENCL_DEVICE_PROP opencl_prop;
|
||||
|
||||
#ifndef _USING_FCGI_
|
||||
virtual void write_xml(MIOFILE&);
|
||||
|
@ -160,6 +168,7 @@ struct COPROC {
|
|||
clear();
|
||||
}
|
||||
virtual ~COPROC(){}
|
||||
void get_opencl_info();
|
||||
void print_available_ram();
|
||||
};
|
||||
|
||||
|
@ -267,6 +276,7 @@ struct COPROCS {
|
|||
std::vector<int>& ignore_cuda_dev,
|
||||
std::vector<int>& ignore_ati_dev
|
||||
);
|
||||
void get_opencl(std::vector<std::string> &warnings);
|
||||
int parse(MIOFILE&);
|
||||
void summary_string(char*, int);
|
||||
|
||||
|
|
|
@ -961,6 +961,8 @@
|
|||
DDD52DC70C03CAE6009B5FC0 /* ViewTransfers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ViewTransfers.h; path = ../clientgui/ViewTransfers.h; sourceTree = SOURCE_ROOT; };
|
||||
DDD52DC80C03CAE6009B5FC0 /* ViewWork.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ViewWork.cpp; path = ../clientgui/ViewWork.cpp; sourceTree = SOURCE_ROOT; };
|
||||
DDD52DC90C03CAE6009B5FC0 /* ViewWork.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ViewWork.h; path = ../clientgui/ViewWork.h; sourceTree = SOURCE_ROOT; };
|
||||
DDD603E6133B475E00B886A4 /* cl_platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cl_platform.h; path = ../lib/cl_platform.h; sourceTree = SOURCE_ROOT; };
|
||||
DDD603E7133B475E00B886A4 /* cl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cl.h; path = ../lib/cl.h; sourceTree = SOURCE_ROOT; };
|
||||
DDD74D8707CF482E0065AC9D /* boinc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = boinc; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
DDD9C59210CCF54300A1E4CD /* coproc_detect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = coproc_detect.cpp; path = ../client/coproc_detect.cpp; sourceTree = SOURCE_ROOT; };
|
||||
DDDD6D7E12E4611300C258A0 /* sg_ProjectPanel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sg_ProjectPanel.cpp; path = ../clientgui/sg_ProjectPanel.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -1543,6 +1545,8 @@
|
|||
DD7168360AAD72040051642B /* common_defs.h */,
|
||||
DD68022E0E701ACD0067D009 /* cert_sig.cpp */,
|
||||
DD68022F0E701ACD0067D009 /* cert_sig.h */,
|
||||
DDD603E6133B475E00B886A4 /* cl_platform.h */,
|
||||
DDD603E7133B475E00B886A4 /* cl.h */,
|
||||
DD7475500D86273300860636 /* coproc.cpp */,
|
||||
DD2049DC0D862516009EEE7A /* coproc.h */,
|
||||
F51DA64D02DB97FF010E292A /* crypt.cpp */,
|
||||
|
|
Loading…
Reference in New Issue