Selaa lähdekoodia

OpenCL driver: improve platform detection and error message system

Nathalie Furmento 14 vuotta sitten
vanhempi
commit
50ffc4e901

+ 9 - 6
include/starpu_opencl.h

@@ -30,17 +30,20 @@
 extern "C" {
 #endif
 
-void starpu_opencl_display_error(const char *func, cl_int status);
+void starpu_opencl_display_error(const char *func, const char *msg, cl_int status);
 #define STARPU_OPENCL_DISPLAY_ERROR(status) \
-	starpu_opencl_display_error(__starpu_func__, status)
+	starpu_opencl_display_error(__starpu_func__, NULL, status)
 
-static inline void starpu_opencl_report_error(const char *func, cl_int status)
+static inline void starpu_opencl_report_error(const char *func, const char *msg, cl_int status)
 {
-        starpu_opencl_display_error(func, status);
+        starpu_opencl_display_error(func, msg, status);
         assert(0);
 }
-#define STARPU_OPENCL_REPORT_ERROR(status)                              \
-	starpu_opencl_display_error(__starpu_func__, status)
+#define STARPU_OPENCL_REPORT_ERROR(status)			\
+	starpu_opencl_display_error(__starpu_func__, NULL, status)
+
+#define STARPU_OPENCL_REPORT_ERROR_WITH_MSG(msg, status)			\
+	starpu_opencl_display_error(__starpu_func__, msg, status)
 
 struct starpu_opencl_program {
         cl_program programs[STARPU_MAXOPENCLDEVS];

+ 32 - 20
src/drivers/opencl/driver_opencl.c

@@ -320,28 +320,40 @@ void _starpu_opencl_init(void)
                 {
                         for (i=0; i<nb_platforms; i++) {
                                 cl_uint num;
-
+				int platform_valid = 1;
+				char name[1024], vendor[1024];
+
+				err = clGetPlatformInfo(platform_id[i], CL_PLATFORM_NAME, 1024, name, NULL);
+				if (err != CL_SUCCESS) {
+					STARPU_OPENCL_REPORT_ERROR_WITH_MSG("clGetPlatformInfo NAME", err);
+					platform_valid = 0;
+				}
+				else {
+					err = clGetPlatformInfo(platform_id[i], CL_PLATFORM_VENDOR, 1024, vendor, NULL);
+					if (err != CL_SUCCESS) {
+						STARPU_OPENCL_REPORT_ERROR_WITH_MSG("clGetPlatformInfo VENDOR", err);
+						platform_valid = 0;
+					}
+				}
 #ifdef STARPU_VERBOSE
-                                {
-                                        char name[1024], vendor[1024];
-                                        err = clGetPlatformInfo(platform_id[i], CL_PLATFORM_NAME, 1024, name, NULL);
-                                        if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
-                                        err = clGetPlatformInfo(platform_id[i], CL_PLATFORM_VENDOR, 1024, vendor, NULL);
-                                        if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
-                                        _STARPU_DEBUG("Platform: %s - %s\n", name, vendor);
-                                }
+				if (platform_valid)
+					_STARPU_DEBUG("Platform: %s - %s\n", name, vendor);
+				else
+					_STARPU_DEBUG("Platform invalid\n");
 #endif
-                                err = clGetDeviceIDs(platform_id[i], device_type, STARPU_MAXOPENCLDEVS-nb_devices, &devices[nb_devices], &num);
-                                if (err == CL_DEVICE_NOT_FOUND) {
-                                        _STARPU_DEBUG("  No devices detected on this platform\n");
-                                }
-                                else {
-                                        if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
-                                        _STARPU_DEBUG("  %d devices detected\n", num);
-                                        nb_devices += num;
-                                }
-                        }
-                }
+				if (platform_valid) {
+					err = clGetDeviceIDs(platform_id[i], device_type, STARPU_MAXOPENCLDEVS-nb_devices, &devices[nb_devices], &num);
+					if (err == CL_DEVICE_NOT_FOUND) {
+						_STARPU_DEBUG("  No devices detected on this platform\n");
+					}
+					else {
+						if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
+						_STARPU_DEBUG("  %d devices detected\n", num);
+						nb_devices += num;
+					}
+				}
+			}
+		}
 
                 // Get location of OpenCl kernel source files
                 _starpu_opencl_program_dir = getenv("STARPU_OPENCL_PROGRAM_DIR");

+ 6 - 2
src/drivers/opencl/driver_opencl_utils.c

@@ -251,7 +251,7 @@ int starpu_opencl_collect_stats(cl_event event __attribute__((unused)))
 	return 0;
 }
 
-void starpu_opencl_display_error(const char *func, cl_int status)
+void starpu_opencl_display_error(const char *func, const char* msg, cl_int status)
 {
 	const char *errormsg;
 	switch (status) {
@@ -397,5 +397,9 @@ void starpu_opencl_display_error(const char *func, cl_int status)
 		errormsg = "unknown error";
 		break;
 	}
-	printf("oops in %s ... <%s> (%d) \n", func, errormsg, status);
+	if (msg)
+		printf("oops in %s (%s) ... <%s> (%d) \n", func, msg, errormsg, status);
+	else
+		printf("oops in %s ... <%s> (%d) \n", func, errormsg, status);
+
 }