From ba3acbce0ab0624e2f726cd23bc247ef49e95cb7 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sun, 9 Mar 2025 18:29:32 +0100 Subject: [PATCH] Add cl_print_build_errors to handle OpenCL build errors This function logs detailed build failure information, including the status and build log retrieved from OpenCL. It provides better debugging support for diagnosing issues with OpenCL program compilation. --- sunnypilot/modeld/SConscript | 1 + sunnypilot/modeld/thneed/clutil_legacy.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/sunnypilot/modeld/SConscript b/sunnypilot/modeld/SConscript index 90fb80975f..1a54fe1e32 100644 --- a/sunnypilot/modeld/SConscript +++ b/sunnypilot/modeld/SConscript @@ -14,6 +14,7 @@ common_src = [ ] thneed_src_common = [ + "thneed/clutil_legacy.cc", "thneed/thneed_common.cc", "thneed/serialize.cc", ] diff --git a/sunnypilot/modeld/thneed/clutil_legacy.cc b/sunnypilot/modeld/thneed/clutil_legacy.cc index 42a4c14675..3bf9316432 100644 --- a/sunnypilot/modeld/thneed/clutil_legacy.cc +++ b/sunnypilot/modeld/thneed/clutil_legacy.cc @@ -8,6 +8,17 @@ #include "common/swaglog.h" #include "sunnypilot/modeld/thneed/clutil_legacy.h" +void cl_print_build_errors(cl_program program, cl_device_id device) { + cl_build_status status; + clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS, sizeof(status), &status, NULL); + size_t log_size; + clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size); + std::string log(log_size, '\0'); + clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, log_size, &log[0], NULL); + + LOGE("build failed; status=%d, log: %s", status, log.c_str()); +} + cl_program cl_program_from_binary(cl_context ctx, cl_device_id device_id, const uint8_t* binary, size_t length, const char* args) { cl_program prg = CL_CHECK_ERR(clCreateProgramWithBinary(ctx, 1, &device_id, &length, &binary, NULL, &err)); if (int err = clBuildProgram(prg, 1, &device_id, args, NULL, NULL); err != 0) {