From: Andreas Beckmann Date: Tue, 30 Nov 2021 22:04:21 +0000 (+0100) Subject: [PATCH 137/144] add poclu_show_program_build_log(cl_program) X-Git-Tag: archive/raspbian/1.8-3+rpi1^2~17 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ffc4224dbb4a8c402c9dc5f69c87c8a13f19aed5;p=pocl.git [PATCH 137/144] add poclu_show_program_build_log(cl_program) Gbp-Pq: Name 0137-add-poclu_show_program_build_log-cl_program.patch --- diff --git a/include/poclu.h b/include/poclu.h index 383b7f4..cdd20d3 100644 --- a/include/poclu.h +++ b/include/poclu.h @@ -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 diff --git a/lib/poclu/misc.c b/lib/poclu/misc.c index 6a8d9fe..22ff456 100644 --- a/lib/poclu/misc.c +++ b/lib/poclu/misc.c @@ -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); \