[Bf-blender-cvs] [43a6cf15041] master: Cycles: attempt to recover from crashing CUDA/OpenCL drivers on Windows.

Brecht Van Lommel noreply at git.blender.org
Mon Aug 21 01:19:03 CEST 2017


Commit: 43a6cf150412594240b36e74b69f4f5f807e9b03
Author: Brecht Van Lommel
Date:   Sun Aug 20 22:44:17 2017 +0200
Branches: master
https://developer.blender.org/rB43a6cf150412594240b36e74b69f4f5f807e9b03

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

I don't know if this will actually work, needs testing. Ref T52064.

===================================================================

M	intern/cycles/device/device_cuda.cpp
M	intern/cycles/device/device_opencl.cpp

===================================================================

diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index 6769ed0229e..3b75142ee67 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -2123,18 +2123,34 @@ Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background)
 	return new CUDADevice(info, stats, background);
 }
 
-void device_cuda_info(vector<DeviceInfo>& devices)
+static CUresult device_cuda_safe_init()
 {
-	CUresult result;
-	int count = 0;
+#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
+}
 
-	result = cuInit(0);
+void device_cuda_info(vector<DeviceInfo>& devices)
+{
+	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);
diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp
index aa380ec4b94..9d89decaaaf 100644
--- a/intern/cycles/device/device_opencl.cpp
+++ b/intern/cycles/device/device_opencl.cpp
@@ -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";
 	}



More information about the Bf-blender-cvs mailing list