From 55ec8a66067d827acfdabca7af67e8c834703109 Mon Sep 17 00:00:00 2001 From: Hans Pabst Date: Wed, 27 Sep 2023 20:35:59 +0200 Subject: [PATCH] ocl: device name cleanup, revised/custom split into sub-devices * Split device name among certain separators (cleanup) - AMD Mi-GPUs expose OpenCL device names like "gfx90a:sramecc+:xnack-" denoting certain machine states (ECC, UMA, etc). - Use part(s) of device name which should map to parameters. * Revised custom device split --- src/acc/opencl/acc_opencl.c | 22 ++++++++++++++-------- src/acc/opencl/acc_opencl.h | 3 ++- src/acc/opencl/smm/opencl_libsmm.c | 8 ++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/acc/opencl/acc_opencl.c b/src/acc/opencl/acc_opencl.c index 2a08cde517e..e0217897055 100644 --- a/src/acc/opencl/acc_opencl.c +++ b/src/acc/opencl/acc_opencl.c @@ -332,10 +332,11 @@ int c_dbcsr_acc_init(void) { CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN, CL_DEVICE_AFFINITY_DOMAIN_NUMA, /*terminator*/ 0}; cl_uint nunits = 0; if (1 < devsplit && - CL_SUCCESS == clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &nunits, NULL)) + CL_SUCCESS == clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &nunits, NULL) && + 0 < nunits) { properties[0] = CL_DEVICE_PARTITION_EQUALLY; - properties[1] = nunits / devsplit; + properties[1] = (nunits + devsplit - 1) / devsplit; } if ((NULL != env_devsplit && '0' == *env_devsplit) || (c_dbcsr_acc_opencl_config.ndevices + 1) == ACC_OPENCL_DEVICES_MAXCOUNT || @@ -490,7 +491,7 @@ int c_dbcsr_acc_init(void) { char platform_name[ACC_OPENCL_BUFFERSIZE]; for (i = 0; i < (cl_uint)c_dbcsr_acc_opencl_config.ndevices; ++i) { if (EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name(c_dbcsr_acc_opencl_config.devices[i], buffer, - ACC_OPENCL_BUFFERSIZE, platform_name, ACC_OPENCL_BUFFERSIZE)) + ACC_OPENCL_BUFFERSIZE, platform_name, ACC_OPENCL_BUFFERSIZE, /*cleanup*/ 0)) { fprintf(stderr, "INFO ACC/OpenCL: DEVICE -> \"%s : %s\"\n", platform_name, buffer); } @@ -774,11 +775,16 @@ int c_dbcsr_acc_opencl_device_uid(cl_device_id device, const char devname[], uns } -int c_dbcsr_acc_opencl_device_name(cl_device_id device, char name[], size_t name_maxlen, char platform[], size_t platform_maxlen) { +int c_dbcsr_acc_opencl_device_name( + cl_device_id device, char name[], size_t name_maxlen, char platform[], size_t platform_maxlen, int cleanup) { int result_name = 0, result_platform = 0; assert(NULL != name || NULL != platform); if (NULL != name && 0 != name_maxlen) { result_name = clGetDeviceInfo(device, CL_DEVICE_NAME, name_maxlen, name, NULL); + if (0 != cleanup && CL_SUCCESS == result_name) { + char* const part = strchr(name, ':'); + if (NULL != part) *part = '\0'; + } } if (NULL != platform && 0 != platform_maxlen) { cl_platform_id platform_id; @@ -909,8 +915,8 @@ int c_dbcsr_acc_opencl_create_context(int thread_id, cl_device_id active_id) { if (0 != c_dbcsr_acc_opencl_config.verbosity) { char buffer[ACC_OPENCL_BUFFERSIZE]; int global_id = 0; - if (EXIT_SUCCESS == - c_dbcsr_acc_opencl_device_name(active_id, buffer, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, 0 /*platform_maxlen*/) && + if (EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name( + active_id, buffer, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, 0 /*platform_maxlen*/, /*cleanup*/ 1) && EXIT_SUCCESS == c_dbcsr_acc_opencl_device_id(active_id, NULL /*devid*/, &global_id)) { const size_t size = strlen(buffer); @@ -983,8 +989,8 @@ int c_dbcsr_acc_opencl_set_active_device(int thread_id, int device_id) { { c_dbcsr_acc_opencl_config.device[thread_id].unified = CL_FALSE; } - if (EXIT_SUCCESS != c_dbcsr_acc_opencl_device_name( - active_id, devname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, 0 /*platform_maxlen*/) || + if (EXIT_SUCCESS != c_dbcsr_acc_opencl_device_name(active_id, devname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, + 0 /*platform_maxlen*/, /*cleanup*/ 1) || EXIT_SUCCESS != c_dbcsr_acc_opencl_device_uid(active_id, devname, &c_dbcsr_acc_opencl_config.device[thread_id].uid)) { c_dbcsr_acc_opencl_config.device[thread_id].uid = (cl_uint)-1; diff --git a/src/acc/opencl/acc_opencl.h b/src/acc/opencl/acc_opencl.h index e0ce920d239..533b5964dbd 100644 --- a/src/acc/opencl/acc_opencl.h +++ b/src/acc/opencl/acc_opencl.h @@ -305,7 +305,8 @@ int c_dbcsr_acc_opencl_device_vendor(cl_device_id device, const char vendor[]); /** Capture or calculate UID based on the device-name. */ int c_dbcsr_acc_opencl_device_uid(cl_device_id device, const char devname[], unsigned int* uid); /** Based on the device-ID, return the device's UID (capture or calculate), device name, and platform name. */ -int c_dbcsr_acc_opencl_device_name(cl_device_id device, char name[], size_t name_maxlen, char platform[], size_t platform_maxlen); +int c_dbcsr_acc_opencl_device_name( + cl_device_id device, char name[], size_t name_maxlen, char platform[], size_t platform_maxlen, int cleanup); /** Return the OpenCL support level for the given device. */ int c_dbcsr_acc_opencl_device_level(cl_device_id device, int* level_major, int* level_minor, char cl_std[16], cl_device_type* type); /** Check if given device supports the extensions. */ diff --git a/src/acc/opencl/smm/opencl_libsmm.c b/src/acc/opencl/smm/opencl_libsmm.c index cbda4bf0acb..4e0c5fcb3e6 100644 --- a/src/acc/opencl/smm/opencl_libsmm.c +++ b/src/acc/opencl/smm/opencl_libsmm.c @@ -491,8 +491,8 @@ int libsmm_acc_init(void) { unsigned int active_uid; int active_match = -1; if (EXIT_SUCCESS == c_dbcsr_acc_opencl_device(ACC_OPENCL_OMP_TID(), &active_id) && - EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name( - active_id, bufname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, 0 /*platform_maxlen*/) && + EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name(active_id, bufname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, + 0 /*platform_maxlen*/, /*cleanup*/ 1) && EXIT_SUCCESS == c_dbcsr_acc_opencl_device_uid(active_id, bufname, &active_uid)) { int i = 0, best = 0; @@ -545,8 +545,8 @@ int libsmm_acc_init(void) { if (NULL == config_init && NULL != libxsmm_xregister(&key, sizeof(key), sizeof(config), &config)) { static int info = 0; if (0 == info && 0 != c_dbcsr_acc_opencl_config.verbosity && - EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name( - active_id, bufname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, 0 /*platform_maxlen*/)) + EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name(active_id, bufname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, + 0 /*platform_maxlen*/, /*cleanup*/ 0)) { fprintf(stderr, "INFO ACC/OpenCL: PARAMS of \"%s\" used for \"%s\"\n", OPENCL_LIBSMM_DEVICES[i], bufname); info = 1;