From 44dc2df81d4926d3df3932637ad283fd8c532d0b Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Tue, 29 Mar 2011 18:35:27 +0000 Subject: [PATCH] - client: prevent client from crashing in OpenCL code - client: fix function prototypes for dynamically calling OpenCL functions. client/ coproc_detect.cpp svn path=/trunk/boinc/; revision=23292 --- checkin_notes | 8 ++++++++ client/coproc_detect.cpp | 27 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/checkin_notes b/checkin_notes index 85a03a94bc..eb99113d92 100644 --- a/checkin_notes +++ b/checkin_notes @@ -1922,3 +1922,11 @@ Charlie 29 Mar 2011 coproc_detect.cpp lib/ coproc.cpp.h + +Rom 29 Mar 2011 + - client: prevent client from crashing in OpenCL code + - client: fix function prototypes for dynamically calling + OpenCL functions. + + client/ + coproc_detect.cpp diff --git a/client/coproc_detect.cpp b/client/coproc_detect.cpp index 6bc78496f0..a22d4394a9 100644 --- a/client/coproc_detect.cpp +++ b/client/coproc_detect.cpp @@ -64,13 +64,13 @@ void segv_handler(int) { #endif #ifdef _WIN32 + HMODULE opencl_lib = NULL; -// TODO: Are these correct? typedef cl_int (__stdcall *CL_PLATFORMIDS) (cl_uint, cl_platform_id*, cl_uint*); typedef cl_int (__stdcall *CL_PLATFORMINFO) (cl_platform_id, cl_platform_info, size_t, void*, size_t*); -typedef cl_int (__stdcall *CL_DEVICEIDS) (cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*); -typedef int (__stdcall *CL_INFO) (cl_device_id, cl_device_info, size_t, void*, size_t*); +typedef cl_int (__stdcall *CL_DEVICEIDS)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*); +typedef cl_int (__stdcall *CL_INFO) (cl_device_id, cl_device_info, size_t, void*, size_t*); CL_PLATFORMIDS __clGetPlatformIDs = NULL; CL_PLATFORMINFO __clGetPlatformInfo = NULL; @@ -171,6 +171,8 @@ void COPROCS::get_opencl(bool use_all, vector&warnings) { cl_uint num_platforms, num_devices, device_index; cl_device_id devices[MAX_COPROC_INSTANCES]; OPENCL_DEVICE_PROP prop; + vector nvidia_opencls; + vector ati_opencls; unsigned int i; #ifdef _WIN32 @@ -184,9 +186,7 @@ void COPROCS::get_opencl(bool use_all, vector&warnings) { __clGetPlatformInfo = (CL_PLATFORMINFO)( opencl_lib, "clGetPlatformInfo" ); __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 @@ -202,10 +202,15 @@ void COPROCS::get_opencl(bool use_all, vector&warnings) { __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 (!__clGetPlatformInfo) { + warnings.push_back("clGetPlatformInfo() missing from OpenCL library"); + return; + } if (!__clGetDeviceIDs) { warnings.push_back("clGetDeviceIDs() missing from OpenCL library"); return; @@ -222,21 +227,21 @@ void COPROCS::get_opencl(bool use_all, vector&warnings) { return; } - ciErrNum = (*__clGetDeviceIDs)(platforms[0], CL_DEVICE_TYPE_GPU, MAX_COPROC_INSTANCES, devices, &num_devices); + 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; } - vector nvidia_opencls; - vector ati_opencls; - for (device_index=0; device_index