From 21fffadbed7d783f0408ef560c87962fddffc50b Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 29 May 2025 08:14:49 +0200 Subject: [PATCH] vcomp/cmpto_j2k: print cl devices in help --- src/utils/opencl.c | 19 ++++++++++++------- src/utils/opencl.h | 1 + src/video_compress/cmpto_j2k.cpp | 8 +++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/utils/opencl.c b/src/utils/opencl.c index d9d19c9b6..bd7d5023f 100644 --- a/src/utils/opencl.c +++ b/src/utils/opencl.c @@ -62,9 +62,13 @@ ADD_TO_PARAM(PARAM_NAME, PARAM_HELP); erraction; \ } -static void -list_opencl_devices() +/// @param full print more info - but currently the same info is printed out, +/// !full is just more compact (using fewer linex) +void +list_opencl_devices(bool full) { + const char record_sep = full ? '\n' : ' '; + printf("Available OpenCL devices:\n"); // Get the number of available platforms cl_uint num_platforms = 0; @@ -78,13 +82,13 @@ list_opencl_devices() // Iterate through the available platforms and get the device IDs for (cl_uint i = 0; i < num_platforms; i++) { // Print the device IDs for the current platform - printf("Platform %d:\n", i); + printf("Platform %d: %c", i, record_sep); char platform_name[100]; CHECK_OPENCL(clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL), "Cannot get platform name", continue); - printf(" Name: %s\n", platform_name); + printf("%s%s\n", full ? " Name: " : "", platform_name); // Get the number of available devices for the current platform cl_uint num_devices = 0; @@ -99,13 +103,14 @@ list_opencl_devices() continue); for (cl_uint j = 0; j < num_devices; j++) { - printf(" Device %d: %p\n", j, devices[j]); + printf(" Device %d: %c", j, record_sep); char device_name[100]; CHECK_OPENCL(clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(device_name), device_name, NULL), "Cannot get device name", continue); - printf(" Name: %s\n", device_name); + printf("%s%s\n", full ? " Name: " : "", + device_name); } free((void *) devices); @@ -123,7 +128,7 @@ opencl_get_device(void **platform_id, void **device_id) const char *req_device = get_commandline_param(PARAM_NAME); if (req_device != NULL) { if (strcmp(req_device, "help") == 0) { - list_opencl_devices(); + list_opencl_devices(true); return false; } req_platform_idx = atoi(req_device); diff --git a/src/utils/opencl.h b/src/utils/opencl.h index 9a90970cc..c3a675325 100644 --- a/src/utils/opencl.h +++ b/src/utils/opencl.h @@ -41,6 +41,7 @@ extern "C" { #endif +void list_opencl_devices(bool full); /** * obtains platform_id (cl_platform_id *) and cl_device_id from given --param (or 0,0) */ diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index 28a908347..e9ac950b1 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -211,7 +211,13 @@ constexpr struct cmpto_j2k_technology technology_opencl = { "Setting OpenCL device", return false); return true; }, - [](bool) {}, + [](bool full) { +#ifdef HAVE_OPENCL + list_opencl_devices(full); +#else + (void) full; +#endif + }, }; const static struct cmpto_j2k_technology *const technologies[] = {