Skip to content

Commit

Permalink
ocl: device name cleanup, revised/custom split into sub-devices
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hfp committed Sep 27, 2023
1 parent 9545971 commit 55ec8a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
22 changes: 14 additions & 8 deletions src/acc/opencl/acc_opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/acc/opencl/acc_opencl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 4 additions & 4 deletions src/acc/opencl/smm/opencl_libsmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 55ec8a6

Please sign in to comment.