Skip to content

Commit

Permalink
ocl: fixed parsing list of allowed device
Browse files Browse the repository at this point in the history
* Fixed parsing list of allowed device.
* Adjusted execution environment.
  • Loading branch information
hfp committed Sep 25, 2023
1 parent 935a11e commit a38e580
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/acc/opencl/acc_opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# if !defined(ACC_OPENCL_NCCS) && 1
# define ACC_OPENCL_NCCS 4
# endif
# if !defined(ACC_OPENCL_IENV) && 1
# define ACC_OPENCL_IENV
# endif


# if defined(__cplusplus)
Expand Down Expand Up @@ -211,6 +214,10 @@ int c_dbcsr_acc_init(void) {
# if defined(ACC_OPENCL_NCCS) && (0 < ACC_OPENCL_NCCS)
const char *const env_zex = getenv("ZEX_NUMBER_OF_CCS"), *const env_nccs = getenv("ACC_OPENCL_NCCS");
const int nccs = (NULL == env_nccs ? 0 : atoi(env_nccs));
# endif
# if defined(ACC_OPENCL_IENV)
const char *const env_neo = getenv("NEOReadDebugKeys"), *const env_ienv = getenv("ACC_OPENCL_IENV");
const int neo = (NULL == env_neo ? 1 : atoi(env_neo)), ienv = neo * (NULL == env_ienv ? 1 : atoi(env_ienv));
# endif
char* const env_devids = getenv("ACC_OPENCL_DEVIDS");
int device_id = (NULL == env_device ? 0 : atoi(env_device));
Expand Down Expand Up @@ -259,6 +266,14 @@ int c_dbcsr_acc_init(void) {
if (0 < j) ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV(zex_number_of_ccs)); /* soft-error */
}
# endif
# if defined(ACC_OPENCL_IENV)
if (0 != ienv) {
if (NULL == getenv("NEOReadDebugKeys")) ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV("NEOReadDebugKeys=1"));
if (NULL == getenv("EnableRecoverablePageFaults")) {
ACC_OPENCL_EXPECT(0 == LIBXSMM_PUTENV("EnableRecoverablePageFaults=0"));
}
}
# endif
# if defined(ACC_OPENCL_CACHEDIR)
{
const char* const env_cache = getenv("ACC_OPENCL_CACHE");
Expand Down Expand Up @@ -384,11 +399,8 @@ int c_dbcsr_acc_init(void) {
/* ACC_OPENCL_DEVIDS is parsed as a list of devices (whitelist) */
if (EXIT_SUCCESS == result && NULL != env_devids && '\0' != *env_devids) {
cl_uint devids[ACC_OPENCL_DEVICES_MAXCOUNT], ndevids = 0;
const char* const end = env_devids + strlen(env_devids); /* before strtok */
char* did = strtok(env_devids, ACC_OPENCL_DELIMS);
for (; NULL != did && ndevids < ACC_OPENCL_DEVICES_MAXCOUNT;
did = ((did + 1) < end ? strtok((did + 1) + strlen(did), ACC_OPENCL_DELIMS) : NULL))
{
char* did = strtok(env_devids, ACC_OPENCL_DELIMS " ");
for (; NULL != did && ndevids < ACC_OPENCL_DEVICES_MAXCOUNT; did = strtok(NULL, ACC_OPENCL_DELIMS " ")) {
const int id = atoi(did);
if (0 <= id && id < c_dbcsr_acc_opencl_config.ndevices) devids[ndevids++] = id;
}
Expand Down

0 comments on commit a38e580

Please sign in to comment.