[clinfo] 41/148: Handle errors in getWGsizes gracefully

Andreas Beckmann anbe at moszumanska.debian.org
Mon Nov 17 14:09:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

anbe pushed a commit to branch clinfo
in repository clinfo.

commit 8b53df802855751adf112ddb66a3ff8d07ec78a0
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date:   Mon Mar 10 21:35:08 2014 +0100

    Handle errors in getWGsizes gracefully
---
 src/clinfo.c | 32 +++++++++++++++++++++++---------
 src/error.h  |  6 +++---
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/clinfo.c b/src/clinfo.c
index 3ae55c2..9e70ff3 100644
--- a/src/clinfo.c
+++ b/src/clinfo.c
@@ -108,16 +108,20 @@ printPlatformInfo(cl_uint p)
 	CHECK_ERROR("get " #param); \
 } while (0)
 
-void
+int
 getWGsizes(cl_platform_id pid, cl_device_id dev)
 {
+	int ret = 0;
+// make CHECK_ERROR return instead of exit
+#define exit(val) do { ret = val; goto out; } while(0)
+
 	cl_context_properties ctxpft[] = {
 		CL_CONTEXT_PLATFORM, (cl_context_properties)pid,
 		0, 0 };
-	cl_uint cursor;
-	cl_context ctx;
-	cl_program prg;
-	cl_kernel krn;
+	cl_uint cursor = 0;
+	cl_context ctx = 0;
+	cl_program prg = 0;
+	cl_kernel krn = 0;
 
 	ctx = clCreateContext(ctxpft, 1, &dev, NULL, NULL, &error);
 	CHECK_ERROR("create context");
@@ -144,10 +148,18 @@ getWGsizes(cl_platform_id pid, cl_device_id dev)
 			sizeof(*wgm), wgm + cursor, NULL);
 		CHECK_ERROR("get kernel info");
 		clReleaseKernel(krn);
+		krn = 0;
 	}
 
-	clReleaseProgram(prg);
-	clReleaseContext(ctx);
+out:
+	if (krn)
+		clReleaseKernel(krn);
+	if (prg)
+		clReleaseProgram(prg);
+	if (ctx)
+		clReleaseContext(ctx);
+	return ret;
+#undef exit
 }
 
 void
@@ -441,8 +453,10 @@ printDeviceInfo(cl_uint d)
 	SZ_PARAM(MAX_WORK_GROUP_SIZE, "Max work group size",);
 
 	GET_PARAM(PLATFORM, pid);
-	getWGsizes(pid, dev);
-	printf(I1_STR "%zu\n", "Preferred work group size multiple", wgm[0]);
+	if (!getWGsizes(pid, dev))
+		printf(I1_STR "%zu\n", "Preferred work group size multiple", wgm[0]);
+	else
+		printf(I1_STR "%s\n", "Preferred work group size multiple", "<detection failed>");
 
 	if (*has_nv) {
 		INT_PARAM(WARP_SIZE_NV, "Warp size (NVIDIA)",);
diff --git a/src/error.h b/src/error.h
index 768ad9f..f70baf4 100644
--- a/src/error.h
+++ b/src/error.h
@@ -4,15 +4,15 @@
 
 cl_int error;
 
-void
+int
 check_ocl_error(cl_int err, const char *what, const char *func, int line)
 {
 	if (err != CL_SUCCESS) {
 		fprintf(stderr, "%s:%u: %s : error %d\n",
 			func, line, what, err);
-		exit(1);
 	}
+	return err != CL_SUCCESS;
 }
 
-#define CHECK_ERROR(what) check_ocl_error(error, what, __func__, __LINE__)
+#define CHECK_ERROR(what) if (check_ocl_error(error, what, __func__, __LINE__)) exit(1)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/clinfo.git



More information about the Pkg-opencl-commits mailing list