Commit efebee5ab854c78e39d17da2f7e5f521ec9c1fef

Rusty Russell 2011-07-06T16:47:29

Fix the case where there are no GPUs, and exit if they give errors. If there are no GPUs, set nDevs to 0 not -1 (status is set to an unhelpful -1001 here on my laptop, so we can't rely on a particular status value). Also, if nDevs is -1, exit rather than screwing up later.

diff --git a/main.c b/main.c
index 4eb0eea..a783eac 100644
--- a/main.c
+++ b/main.c
@@ -1458,6 +1458,9 @@ int main (int argc, char *argv[])
 
 #ifdef HAVE_OPENCL
 	nDevs = clDevicesNum();
+	if (nDevs < 0)
+		return 1;
+
 #endif
 	if (nDevs)
 		opt_n_threads = 0;
diff --git a/ocl.c b/ocl.c
index 7e5294c..71f5721 100644
--- a/ocl.c
+++ b/ocl.c
@@ -58,10 +58,11 @@ int clDevicesNum() {
 	cl_uint numPlatforms;
 	cl_platform_id platform = NULL;
 	status = clGetPlatformIDs(0, NULL, &numPlatforms);
+	/* If this fails, assume no GPUs. */
 	if (status != CL_SUCCESS)
 	{
-		applog(LOG_ERR, "Error: Getting Platforms. (clGetPlatformsIDs)");
-		return -1;
+		applog(LOG_INFO, "clGetPlatformsIDs failed (no GPU?)");
+		return 0;
 	}
 
 	if (numPlatforms > 0)