Skip to content

Commit eb39246

Browse files
committed
Improved matching a device with a parameter set
- Implemented device-parameter match based on relative score. - Avoid potential warnings about unused variables. - Updated tuned parameters.
1 parent 4bc70e9 commit eb39246

File tree

5 files changed

+100
-21
lines changed

5 files changed

+100
-21
lines changed

src/acc/acc_bench.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ static size_t parse_nbytes(const char* nbytes, size_t* nelems) {
200200

201201

202202
int main(int argc, char* argv[]) {
203-
const char *const env_check = getenv("CHECK"), *const env_check_h2d = getenv("CHECK_H2D");
204-
const char *const env_check_dev = getenv("CHECK_DEV"), *const env_check_hst = getenv("CHECK_HST");
203+
const char* const env_check = getenv("CHECK");
205204
const double check = (NULL == env_check ? -1 : fabs(atof(env_check) * ACC_BENCH_SMM_EPSILON(ELEM_TYPE)));
206205
#if defined(WARMUP) && (0 < WARMUP) && !defined(_DEBUG)
207206
const int warmup = MAX(WARMUP, 2) / 2 * 2;
@@ -217,6 +216,9 @@ int main(int argc, char* argv[]) {
217216
const int nrepeat_h2d = (NULL == env_nrepeat_h2d ? 1 : MAX(atoi(env_nrepeat_h2d), 1));
218217
#if defined(USE_LIBXSMM)
219218
double perf_h2d = 0, perf_dev = 0, perf_hst = 0;
219+
const char* const env_check_h2d = getenv("CHECK_H2D");
220+
const char* const env_check_dev = getenv("CHECK_DEV");
221+
const char* const env_check_hst = getenv("CHECK_HST");
220222
# if defined(__OPENCL)
221223
const char* const env_nrepeat_smm = getenv("NREPEAT_SMM");
222224
const int nrepeat_smm = (NULL == env_nrepeat_smm ? 1 : MAX(atoi(env_nrepeat_smm), 1));

src/acc/opencl/acc_opencl.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,69 @@ void c_dbcsr_acc_opencl_hist_free(void* hist) {
19621962
}
19631963
}
19641964

1965+
1966+
const char* c_dbcsr_acc_opencl_stristrn(const char a[], const char b[], size_t maxlen) {
1967+
const char* result = NULL;
1968+
if (NULL != a && NULL != b && '\0' != *a && '\0' != *b && 0 != maxlen) {
1969+
do {
1970+
if (tolower(*a) != tolower(*b)) ++a;
1971+
else {
1972+
const char* c = b;
1973+
size_t i = 0;
1974+
result = a;
1975+
while ('\0' != c[++i] && i != maxlen && '\0' != *++a) {
1976+
if (tolower(*a) != tolower(c[i])) {
1977+
result = NULL;
1978+
break;
1979+
}
1980+
}
1981+
if ('\0' != c[i] && '\0' != c[i + 1] && c[i] != c[i + 1] && i != maxlen) {
1982+
result = NULL;
1983+
}
1984+
else break;
1985+
}
1986+
} while ('\0' != *a);
1987+
}
1988+
return result;
1989+
}
1990+
1991+
1992+
int c_dbcsr_acc_opencl_strimatch(const char a[], const char b[], const char delims[], int* count) {
1993+
int result = 0, na = 0, nb = 0;
1994+
if (NULL != a && NULL != b && '\0' != *a && '\0' != *b) {
1995+
const char* const sep = ((NULL == delims || '\0' == *delims) ? " \t;,:-" : delims);
1996+
const char *c, *tmp;
1997+
char s[2] = {'\0'};
1998+
size_t m, n;
1999+
for (;;) {
2000+
while (*s = *b, NULL != strpbrk(s, sep)) ++b; /* left-trim */
2001+
if ('\0' != *b && '[' != *b) ++nb; /* count words */
2002+
else break;
2003+
tmp = b;
2004+
while ('\0' != *tmp && (*s = *tmp, NULL == strpbrk(s, sep))) ++tmp;
2005+
m = tmp - b;
2006+
c = c_dbcsr_acc_opencl_stristrn(a, b, LIBXSMM_MIN(1, m));
2007+
if (NULL != c) {
2008+
const char* d = c;
2009+
while ('\0' != *d && (*s = *d, NULL == strpbrk(s, sep))) ++d;
2010+
n = d - c;
2011+
if (1 >= n || NULL != c_dbcsr_acc_opencl_stristrn(c, b, LIBXSMM_MIN(m, n))) ++result;
2012+
}
2013+
b = tmp;
2014+
}
2015+
for (;;) { /* count number of words */
2016+
while (*s = *a, NULL != strpbrk(s, sep)) ++a; /* left-trim */
2017+
if ('\0' != *a && '[' != *a) ++na; /* count words */
2018+
else break;
2019+
while ('\0' != *a && (*s = *a, NULL == strpbrk(s, sep))) ++a;
2020+
}
2021+
if (na < result) result = na;
2022+
}
2023+
else result = -1;
2024+
if (NULL != count) *count = LIBXSMM_MAX(na, nb);
2025+
return result;
2026+
}
2027+
19652028
# if defined(__cplusplus)
19662029
}
19672030
# endif

src/acc/opencl/acc_opencl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ void c_dbcsr_acc_opencl_hist_print(
430430
FILE* stream, void* hist, const char title[], const int prec[], const c_dbcsr_acc_opencl_hist_adjust_fn adjust[]);
431431
void c_dbcsr_acc_opencl_hist_free(void* hist);
432432

433+
/** Return the pointer to the 1st match of "b" in "a", or NULL (no match). */
434+
const char* c_dbcsr_acc_opencl_stristrn(const char a[], const char b[], size_t maxlen);
435+
436+
/**
437+
* Count the number of words in A (or B) with match in B (or A) respectively (case-insensitive).
438+
* Can be used to score the equality of A and B on a word-basis. The result is independent of
439+
* A-B or B-A order (symmetry). The score cannot exceed the number of words in A or B.
440+
* Optional delimiters determine characters splitting words (can be NULL).
441+
* Optional count yields total number of words.
442+
*/
443+
int c_dbcsr_acc_opencl_strimatch(const char a[], const char b[], const char delims[], int* count);
444+
433445
#if defined(__cplusplus)
434446
}
435447
#endif

src/acc/opencl/smm/opencl_libsmm.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,29 +443,31 @@ int libsmm_acc_init(void) {
443443
}
444444
# if defined(OPENCL_KERNELS_PARAMS_SMM) && defined(OPENCL_KERNELS_DEVICES)
445445
if (EXIT_SUCCESS == result && (0 == ntuned || 0 != key_direct_skip)) {
446-
const cl_device_id device_id = c_dbcsr_acc_opencl_config.devices[c_dbcsr_acc_opencl_config.device_id];
447-
const c_dbcsr_acc_opencl_device_t* const devinfo = &c_dbcsr_acc_opencl_config.device;
448-
unsigned int default_uid = devinfo->uid;
449446
const char *line = OPENCL_KERNELS_PARAMS_SMM, *next;
450447
# if LIBXSMM_VERSION4(1, 17, 0, 0) < LIBXSMM_VERSION_NUMBER
448+
const cl_device_id device_id = c_dbcsr_acc_opencl_config.devices[c_dbcsr_acc_opencl_config.device_id];
449+
unsigned int default_uid = c_dbcsr_acc_opencl_config.device.uid;
451450
int active_match = -1;
452451
if (EXIT_SUCCESS == c_dbcsr_acc_opencl_device_name(
453452
device_id, bufname, ACC_OPENCL_BUFFERSIZE, NULL /*platform*/, 0 /*platform_maxlen*/, /*cleanup*/ 1))
454453
{ /* determine best-matching parameters based on name of device */
455-
int i = 0, best = 0;
454+
int i = 0, count = 0;
455+
double best = 0;
456456
if (1 >= c_dbcsr_acc_opencl_config.devmatch) {
457457
c_dbcsr_acc_opencl_device_uid(device_id, bufname, &default_uid);
458458
}
459459
for (; i < ndevices_params; ++i) {
460-
const int score = libxsmm_strimatch(bufname, OPENCL_KERNELS_DEVICES[i], NULL);
461-
unsigned int uid;
462-
if (best < score ||
463-
((best == score) &&
464-
EXIT_SUCCESS == c_dbcsr_acc_opencl_device_uid(NULL /*device*/, OPENCL_KERNELS_DEVICES[i], &uid) &&
465-
uid == default_uid))
466-
{
467-
active_match = i;
468-
best = score;
460+
const int n = c_dbcsr_acc_opencl_strimatch(bufname, OPENCL_KERNELS_DEVICES[i], NULL, &count);
461+
if (0 != n && 0 != count) {
462+
const double score = (double)n / count;
463+
unsigned int uid;
464+
if (best < score ||
465+
(EXIT_SUCCESS == c_dbcsr_acc_opencl_device_uid(NULL /*device*/, OPENCL_KERNELS_DEVICES[i], &uid) &&
466+
uid == default_uid))
467+
{
468+
active_match = i;
469+
best = score;
470+
}
469471
}
470472
}
471473
}

src/acc/opencl/smm/params/tune_multiply_GH200.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NVIDIA GH200 480GB [0x3528];3;4;4;32;30000;0;3;4;1;2;4;-2;-2;0;0;0;1;0;1;0;0;0
1717
NVIDIA GH200 480GB [0x3528];3;4;5;4;30000;0;10;4;1;1;5;-2;-2;0;1;0;1;0;0;2;0;0
1818
NVIDIA GH200 480GB [0x3528];3;4;5;5;30000;0;11;4;1;3;5;1;-2;0;0;0;1;0;2;2;0;0
1919
NVIDIA GH200 480GB [0x3528];3;4;5;7;30000;0;13;4;1;4;5;1;-1;0;0;0;1;0;0;2;0;0
20-
NVIDIA GH200 480GB [0x3528];3;4;5;9;30000;0;10;4;1;2;5;-2;-2;0;0;0;1;0;1;0;0;0
20+
NVIDIA GH200 480GB [0x3528];3;4;5;9;30000;0;13;4;1;2;5;1;-1;0;0;0;1;0;0;0;0;0
2121
NVIDIA GH200 480GB [0x3528];3;4;5;13;30000;0;5;4;1;2;5;1;-2;0;0;0;1;0;1;2;0;0
2222
NVIDIA GH200 480GB [0x3528];3;4;5;17;30000;0;4;4;1;4;5;-1;-1;0;0;0;1;0;1;0;0;0
2323
NVIDIA GH200 480GB [0x3528];3;4;5;25;30000;0;12;4;1;2;5;-1;-1;0;0;0;1;0;1;2;0;0
@@ -27,7 +27,7 @@ NVIDIA GH200 480GB [0x3528];3;4;7;5;30000;0;11;4;1;3;7;0;0;0;0;0;1;0;2;2;0;0
2727
NVIDIA GH200 480GB [0x3528];3;4;7;7;30000;0;13;4;1;2;7;0;0;0;0;0;1;0;2;2;0;0
2828
NVIDIA GH200 480GB [0x3528];3;4;7;9;30000;0;5;4;1;4;7;1;-1;0;0;0;1;0;1;2;0;0
2929
NVIDIA GH200 480GB [0x3528];3;4;7;13;30000;0;4;4;1;4;7;-2;-2;0;0;0;1;0;1;2;0;0
30-
NVIDIA GH200 480GB [0x3528];3;4;9;4;30000;0;13;4;1;3;9;1;-2;0;0;0;1;0;0;0;0;0
30+
NVIDIA GH200 480GB [0x3528];3;4;9;4;30000;0;11;4;1;2;9;-2;-1;0;0;0;1;0;2;0;0;0
3131
NVIDIA GH200 480GB [0x3528];3;4;9;5;30000;0;11;4;1;2;9;-2;1;0;1;0;1;0;2;2;0;0
3232
NVIDIA GH200 480GB [0x3528];3;4;9;7;30000;0;13;4;1;4;9;0;0;0;0;0;1;0;2;2;0;0
3333
NVIDIA GH200 480GB [0x3528];3;4;9;9;30000;0;10;4;1;2;9;-2;-2;0;0;0;1;0;1;0;0;0
@@ -52,7 +52,7 @@ NVIDIA GH200 480GB [0x3528];3;4;25;5;30000;0;14;4;1;2;25;-2;1;0;1;0;1;0;2;2;0;0
5252
NVIDIA GH200 480GB [0x3528];3;4;26;4;30000;0;13;4;1;2;1;-1;1;0;1;0;1;0;0;2;0;0
5353
NVIDIA GH200 480GB [0x3528];3;4;28;4;30000;0;14;4;1;3;1;-1;-2;0;0;0;1;0;2;0;0;0
5454
NVIDIA GH200 480GB [0x3528];3;4;32;4;30000;0;18;4;1;1;1;0;-2;0;0;0;1;0;0;2;0;0
55-
NVIDIA GH200 480GB [0x3528];3;4;32;5;30000;0;14;4;1;1;1;-1;0;0;1;0;1;0;0;0;0;0
55+
NVIDIA GH200 480GB [0x3528];3;4;32;5;30000;0;14;4;1;1;1;-1;0;0;0;0;1;0;0;0;0;0
5656
NVIDIA GH200 480GB [0x3528];3;4;32;13;30000;0;11;4;1;2;1;1;1;0;0;0;1;0;1;0;0;0
5757
NVIDIA GH200 480GB [0x3528];3;4;32;17;30000;0;8;4;1;2;1;0;-1;0;0;0;1;0;1;0;0;0
5858
NVIDIA GH200 480GB [0x3528];3;4;32;32;30000;0;13;4;1;4;1;1;-2;0;0;0;1;0;1;2;0;0
@@ -64,7 +64,7 @@ NVIDIA GH200 480GB [0x3528];3;5;4;13;30000;0;12;5;1;4;5;-1;-1;0;0;0;1;0;0;0;0;0
6464
NVIDIA GH200 480GB [0x3528];3;5;4;17;30000;0;12;5;1;2;5;1;0;0;0;0;1;0;0;2;0;0
6565
NVIDIA GH200 480GB [0x3528];3;5;4;25;30000;0;12;5;1;4;5;0;-1;0;0;0;1;0;0;0;0;0
6666
NVIDIA GH200 480GB [0x3528];3;5;4;32;30000;0;12;5;1;2;5;-1;1;0;0;0;1;0;2;0;0;0
67-
NVIDIA GH200 480GB [0x3528];3;5;5;4;30000;0;15;5;1;2;1;-2;-1;0;0;0;1;0;2;0;0;0
67+
NVIDIA GH200 480GB [0x3528];3;5;5;4;30000;0;11;5;1;1;1;1;-1;0;0;0;1;0;2;0;0;0
6868
NVIDIA GH200 480GB [0x3528];3;5;5;5;30000;0;12;5;1;4;1;1;-2;0;1;0;1;0;1;0;0;0
6969
NVIDIA GH200 480GB [0x3528];3;5;5;7;30000;0;12;5;1;3;1;-1;-2;0;0;0;1;0;1;2;0;0
7070
NVIDIA GH200 480GB [0x3528];3;5;5;9;30000;0;12;5;1;2;1;-2;1;0;0;0;1;0;1;2;0;0
@@ -324,7 +324,7 @@ NVIDIA GH200 480GB [0x3528];3;22;22;32;30000;0;30;22;1;7;1;0;-1;0;0;0;1;0;1;2;0;
324324
NVIDIA GH200 480GB [0x3528];3;22;32;9;30000;0;17;22;1;20;32;-1;0;0;0;0;1;0;1;2;0;0
325325
NVIDIA GH200 480GB [0x3528];3;22;32;22;30000;0;20;22;1;9;32;0;-1;0;0;0;1;0;1;2;0;0
326326
NVIDIA GH200 480GB [0x3528];3;22;32;32;30000;0;40;8;1;3;32;-1;3;0;1;0;1;0;1;2;0;0
327-
NVIDIA GH200 480GB [0x3528];3;23;23;23;30000;0;20;23;1;19;23;1;0;0;0;0;1;0;1;2;0;0
327+
NVIDIA GH200 480GB [0x3528];3;23;23;23;30000;0;20;23;1;17;23;1;0;0;0;0;1;0;1;2;0;0
328328
NVIDIA GH200 480GB [0x3528];3;24;24;24;30000;0;20;24;1;16;1;-2;-2;0;0;0;1;0;1;0;0;0
329329
NVIDIA GH200 480GB [0x3528];3;24;24;26;30000;0;30;8;1;18;24;1;2;0;1;0;1;0;1;2;0;0
330330
NVIDIA GH200 480GB [0x3528];3;24;26;24;30000;0;19;8;1;24;26;0;0;0;0;0;1;0;1;2;0;0
@@ -345,7 +345,7 @@ NVIDIA GH200 480GB [0x3528];3;29;29;29;30000;0;46;8;1;2;29;-2;-2;0;1;0;1;0;1;2;0
345345
NVIDIA GH200 480GB [0x3528];3;29;29;55;30000;0;19;16;1;24;29;-2;0;0;0;0;1;0;1;2;0;0
346346
NVIDIA GH200 480GB [0x3528];3;29;55;16;30000;0;58;8;1;26;55;1;-2;0;0;0;1;0;1;2;0;0
347347
NVIDIA GH200 480GB [0x3528];3;29;55;29;30000;0;19;8;1;25;55;-2;4;0;1;0;1;0;1;2;0;0
348-
NVIDIA GH200 480GB [0x3528];3;29;55;55;30000;0;39;29;1;2;55;-1;1;0;1;0;1;0;0;1;0;0
348+
NVIDIA GH200 480GB [0x3528];3;29;55;55;30000;0;13;29;1;8;55;0;0;0;0;0;1;0;1;0;0;0
349349
NVIDIA GH200 480GB [0x3528];3;30;30;30;30000;0;30;30;1;11;1;0;-2;0;0;0;1;0;1;0;0;0
350350
NVIDIA GH200 480GB [0x3528];3;32;4;4;30000;0;11;8;1;15;32;-1;-2;0;0;0;1;0;0;0;0;0
351351
NVIDIA GH200 480GB [0x3528];3;32;4;5;30000;0;11;8;1;16;32;1;0;0;0;0;1;0;0;2;0;0

0 commit comments

Comments
 (0)