Cycles: attempt to recover from crashing CUDA/OpenCL drivers on Windows.

I don't know if this will actually work, needs testing. Ref T52064.
This commit is contained in:
Brecht Van Lommel 2017-08-20 22:44:17 +02:00
parent fc890cdae2
commit 43a6cf1504
2 changed files with 48 additions and 6 deletions

@ -2123,18 +2123,34 @@ Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background)
return new CUDADevice(info, stats, background);
}
static CUresult device_cuda_safe_init()
{
#ifdef _WIN32
__try {
return cuInit(0);
}
__except(EXCEPTION_EXECUTE_HANDLER) {
/* Ignore crashes inside the CUDA driver and hope we can
* survive even with corrupted CUDA installs. */
fprintf(stderr, "Cycles CUDA: driver crashed, continuing without CUDA.\n");
}
return CUDA_ERROR_NO_DEVICE;
#else
return cuInit(0);
#endif
}
void device_cuda_info(vector<DeviceInfo>& devices)
{
CUresult result;
int count = 0;
result = cuInit(0);
CUresult result = device_cuda_safe_init();
if(result != CUDA_SUCCESS) {
if(result != CUDA_ERROR_NO_DEVICE)
fprintf(stderr, "CUDA cuInit: %s\n", cuewErrorString(result));
return;
}
int count = 0;
result = cuDeviceGetCount(&count);
if(result != CUDA_SUCCESS) {
fprintf(stderr, "CUDA cuDeviceGetCount: %s\n", cuewErrorString(result));
@ -2191,7 +2207,7 @@ void device_cuda_info(vector<DeviceInfo>& devices)
string device_cuda_capabilities(void)
{
CUresult result = cuInit(0);
CUresult result = device_cuda_safe_init();
if(result != CUDA_SUCCESS) {
if(result != CUDA_ERROR_NO_DEVICE) {
return string("Error initializing CUDA: ") + cuewErrorString(result);

@ -73,8 +73,34 @@ bool device_opencl_init(void)
return result;
}
static cl_int device_opencl_get_num_platforms_safe(cl_uint *num_platforms)
{
#ifdef _WIN32
__try {
return clGetPlatformIDs(0, NULL, num_platforms);
}
__except(EXCEPTION_EXECUTE_HANDLER) {
/* Ignore crashes inside the OpenCL driver and hope we can
* survive even with corrupted OpenCL installs. */
fprintf(stderr, "Cycles OpenCL: driver crashed, continuing without OpenCL.\n");
}
*num_platforms = 0;
return CL_DEVICE_NOT_FOUND;
#else
return clGetPlatformIDs(0, NULL, num_platforms);
#endif
}
void device_opencl_info(vector<DeviceInfo>& devices)
{
cl_uint num_platforms = 0;
device_opencl_get_num_platforms_safe(&num_platforms);
if(num_platforms == 0) {
return;
}
vector<OpenCLPlatformDevice> usable_devices;
OpenCLInfo::get_usable_devices(&usable_devices);
/* Devices are numbered consecutively across platforms. */
@ -113,7 +139,7 @@ string device_opencl_capabilities(void)
* it could also be nicely reported to the console.
*/
cl_uint num_platforms = 0;
opencl_assert(clGetPlatformIDs(0, NULL, &num_platforms));
opencl_assert(device_opencl_get_num_platforms_safe(&num_platforms));
if(num_platforms == 0) {
return "No OpenCL platforms found\n";
}