[PATCH 137/144] add poclu_show_program_build_log(cl_program)
authorAndreas Beckmann <anbe@debian.org>
Tue, 30 Nov 2021 22:04:21 +0000 (23:04 +0100)
committerAndreas Beckmann <anbe@debian.org>
Fri, 7 Jan 2022 23:55:22 +0000 (23:55 +0000)
Gbp-Pq: Name 0137-add-poclu_show_program_build_log-cl_program.patch

include/poclu.h
lib/poclu/misc.c

index 383b7f443076025ddcbfdd75d8e0cbde06e36b1c..cdd20d35c475ef58a963104908924118bad36b9a 100644 (file)
@@ -124,6 +124,8 @@ int poclu_load_program_multidev (cl_context context, cl_device_id *devices,
                                  const char *explicit_binary,
                                  const char *extra_build_opts, cl_program *p);
 
+POCLU_API cl_int POCLU_CALL poclu_show_program_build_log (cl_program program);
+
 /* In case cl_err != CL_SUCCESS, prints out the error +
  * function : line to stderr, and returns 1, otherwise
  * returns 0
index 6a8d9fec30126c3741b6dd6d720f7ed86566b254..22ff4566d1ce81fffd6b7426955261092616ac6d 100644 (file)
@@ -197,6 +197,72 @@ poclu_write_file (const char *filemane, char *content, size_t size)
   return 0;
 }
 
+cl_int
+poclu_show_program_build_log (cl_program program)
+{
+  cl_int err;
+  cl_uint num_devices;
+  cl_device_id *devices;
+
+  err = clGetProgramInfo (program, CL_PROGRAM_NUM_DEVICES,
+                          sizeof (num_devices), &num_devices, NULL);
+  if (err != CL_SUCCESS)
+    goto fail;
+
+  devices = (cl_device_id *)malloc (sizeof (cl_device_id) * num_devices);
+  if (!devices)
+    {
+      err = CL_OUT_OF_HOST_MEMORY;
+      goto fail;
+    }
+
+  err = clGetProgramInfo (program, CL_PROGRAM_DEVICES,
+                          sizeof (cl_device_id) * num_devices, devices, NULL);
+  if (err != CL_SUCCESS)
+    goto fail2;
+
+  for (cl_uint i = 0; i < num_devices; ++i)
+    {
+      char *log;
+      size_t log_size;
+
+      err = clGetProgramBuildInfo (program, devices[i], CL_PROGRAM_BUILD_LOG,
+                                   0, NULL, &log_size);
+      if (err != CL_SUCCESS)
+        goto fail2;
+
+      log = (char *)malloc (log_size);
+      if (!log)
+        {
+          err = CL_OUT_OF_HOST_MEMORY;
+          goto fail2;
+        }
+
+      err = clGetProgramBuildInfo (program, devices[i], CL_PROGRAM_BUILD_LOG,
+                                   log_size, log, NULL);
+      if (err != CL_SUCCESS)
+        {
+          free (log);
+          goto fail2;
+        }
+
+      if (num_devices > 1)
+        fprintf (stderr, "device %d/%d:\n", i, num_devices);
+      fprintf (stderr, "%s\n", log);
+
+      free (log);
+    }
+
+  err = CL_SUCCESS;
+
+fail2:
+  free (devices);
+
+fail:
+  check_cl_error (err, __LINE__, __PRETTY_FUNCTION__);
+  return err;
+}
+
 #define OPENCL_ERROR_CASE(ERR) \
   case ERR:                                                             \
   { fprintf (stderr, "" #ERR " in %s on line %i\n", func_name, line);   \