Просмотр исходного кода

Add `starpu_opencl_error_string'.

Ludovic Courtès лет назад: 13
Родитель
Сommit
84b33e48cc
3 измененных файлов с 16 добавлено и 7 удалено
  1. 5 0
      doc/chapters/basic-api.texi
  2. 1 0
      include/starpu_opencl.h
  3. 10 7
      src/drivers/opencl/driver_opencl_utils.c

+ 5 - 0
doc/chapters/basic-api.texi

@@ -2303,6 +2303,11 @@ collect statistics about the kernel execution (used cycles, consumed power).
 @node OpenCL utilities
 @subsection OpenCL utilities
 
+@deftypefun {const char *}starpu_opencl_error_string (cl_int @var{status})
+Return the error message in English corresponding to @var{status}, an
+OpenCL error code.
+@end deftypefun
+
 @deftypefun void starpu_opencl_display_error ({const char *}@var{func}, {const char *}@var{file}, int @var{line}, {const char *}@var{msg}, cl_int @var{status})
 Given a valid error @var{status}, prints the corresponding error message on
 stdout, along with the given function name @var{func}, the given filename

+ 1 - 0
include/starpu_opencl.h

@@ -31,6 +31,7 @@ extern "C"
 {
 #endif
 
+const char *starpu_opencl_error_string(cl_int status);
 void starpu_opencl_display_error(const char *func, const char *file, int line, const char *msg, cl_int status);
 #define STARPU_OPENCL_DISPLAY_ERROR(status) \
 	starpu_opencl_display_error(__starpu_func__, __FILE__, __LINE__, NULL, status)

+ 10 - 7
src/drivers/opencl/driver_opencl_utils.c

@@ -330,13 +330,13 @@ int starpu_opencl_collect_stats(cl_event event STARPU_ATTRIBUTE_UNUSED)
 	return 0;
 }
 
-void starpu_opencl_display_error(const char *func, const char *file, int line, const char* msg, cl_int status)
+const char *starpu_opencl_error_string(cl_int status)
 {
 	const char *errormsg;
 	switch (status)
 	{
 	case CL_SUCCESS:
-		errormsg = "success";
+		errormsg = "Success";
 		break;
 	case CL_DEVICE_NOT_FOUND:
 		errormsg = "Device not found";
@@ -479,13 +479,16 @@ void starpu_opencl_display_error(const char *func, const char *file, int line, c
 		break;
 #endif
 	default:
-		errormsg = "unknown error";
+		errormsg = "unknown OpenCL error";
 		break;
 	}
-	if (msg)
-		printf("oops in %s (%s:%d) (%s) ... <%s> (%d) \n", func, file, line, msg, errormsg, status);
-	else
-		printf("oops in %s (%s:%d) ... <%s> (%d) \n", func, file, line, errormsg, status);
+	return errormsg;
+}
+
+void starpu_opencl_display_error(const char *func, const char *file, int line, const char* msg, cl_int status)
+{
+	printf("oops in %s (%s:%d) (%s) ... <%s> (%d) \n", func, file, line, msg,
+	       starpu_opencl_error_string (status), status);
 
 }