1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
|
/* $Source: bitbucket.org:berkeleylab/gasnet.git/tests/testqueue.c $
* Description: GASNet put/get injection performance test
* measures the average non-blocking put/get injection time
* for increasing number of back-to-back operations
* over varying payload size and synchronization mechanisms
* reveals software-imposed queue depth backpressure limitations
* Copyright 2002, Jaein Jeong and Dan Bonachea <bonachea@cs.berkeley.edu>
* Terms of use are as specified in license.txt
*/
#include <gasnetex.h>
int maxsz = 0;
#ifndef TEST_SEGSZ
#define TEST_SEGSZ_EXPR ((uintptr_t)(maxsz + alignup(maxsz,PAGESZ)))
#endif
#include "test.h"
static gex_Client_t myclient;
static gex_EP_t myep;
static gex_TM_t myteam;
static gex_Segment_t mysegment;
int insegment = 1;
int myproc;
int numprocs;
int peerproc = -1;
int iamsender = 0;
int iamrecver = 0;
int multisender = 0;
int min_payload;
int max_payload;
int maxdepth = 0;
char *tgtmem;
void *msgbuf;
gex_Event_t *events;
volatile gex_RMA_Value_t regval = 5551212;
#define hidx_ping_shorthandler 201
#define hidx_ping_medhandler 202
#define hidx_ping_longhandler 203
gasnett_atomic_t amcount = gasnett_atomic_init(0);
void ping_shorthandler(gex_Token_t token) {
gasnett_atomic_increment(&amcount,0);
}
void ping_medhandler(gex_Token_t token, void *buf, size_t nbytes) {
gasnett_atomic_increment(&amcount,0);
}
void ping_longhandler(gex_Token_t token, void *buf, size_t nbytes) {
gasnett_atomic_increment(&amcount,0);
}
gex_AM_Entry_t htable[] = {
{ hidx_ping_shorthandler, (gex_AM_Fn_t)ping_shorthandler, GEX_FLAG_AM_REQUEST|GEX_FLAG_AM_SHORT, 0 },
{ hidx_ping_medhandler, (gex_AM_Fn_t)ping_medhandler, GEX_FLAG_AM_REQUEST|GEX_FLAG_AM_MEDIUM, 0 },
{ hidx_ping_longhandler, (gex_AM_Fn_t)ping_longhandler, GEX_FLAG_AM_REQUEST|GEX_FLAG_AM_LONG, 0 }
};
int iters = 0;
int arg;
void *myseg;
void *alloc;
int firstlastmode = 0;
int fullduplexmode = 0;
int help = 0;
int do_puts = 0, do_gets = 0, do_amshort = 0, do_ammedium = 0, do_amlong = 0;
int numflavors = 0;
int numsync = 0;
int do_bulk = 0, do_nonbulk = 0, do_value = 0;
int do_implicit = 0, do_explicit = 0, do_blocking = 0;
void do_bulkputs(void);
void do_nonbulkputgets(void);
void do_valueputgets(void);
void do_blockingputgets(void);
void do_amtests(void);
int main(int argc, char **argv) {
/* call startup */
GASNET_Safe(gex_Client_Init(&myclient, &myep, &myteam, "testqueue", &argc, &argv, 0));
/* parse arguments */
arg = 1;
while (argc > arg) {
if (!strcmp(argv[arg], "-in")) {
insegment = 1;
++arg;
} else if (!strcmp(argv[arg], "-out")) {
insegment = 0;
++arg;
} else if (!strcmp(argv[arg], "-f")) {
firstlastmode = 1;
++arg;
} else if (!strcmp(argv[arg], "-a")) {
fullduplexmode = 1;
++arg;
} else if (!strcmp(argv[arg], "-p")) {
do_puts = 1; numflavors++;
++arg;
} else if (!strcmp(argv[arg], "-g")) {
do_gets = 1; numflavors++;
++arg;
} else if (!strcmp(argv[arg], "-s")) {
do_amshort = 1; numflavors++;
++arg;
} else if (!strcmp(argv[arg], "-m")) {
do_ammedium = 1; numflavors++;
++arg;
} else if (!strcmp(argv[arg], "-l")) {
do_amlong = 1; numflavors++;
++arg;
} else if (!strcmp(argv[arg], "-b")) {
do_bulk = 1;
++arg;
} else if (!strcmp(argv[arg], "-n")) {
do_nonbulk = 1;
++arg;
} else if (!strcmp(argv[arg], "-v")) {
do_value = 1;
++arg;
} else if (!strcmp(argv[arg], "-i")) {
do_implicit = 1; numsync++;
++arg;
} else if (!strcmp(argv[arg], "-e")) {
do_explicit = 1; numsync++;
++arg;
} else if (!strcmp(argv[arg], "-k")) {
do_blocking = 1; numsync++;
++arg;
} else if (argv[arg][0] == '-') {
help = 1;
++arg;
} else break;
}
if (fullduplexmode && firstlastmode) help = 1;
if (argc > arg+3) help = 1;
if (argc > arg) { iters = atoi(argv[arg]); arg++; }
if (!iters) iters = 10;
if (argc > arg) { maxdepth = atoi(argv[arg]); arg++; }
if (!maxdepth) maxdepth = 1024; /* 1024 default */
if (argc > arg) { maxsz = atoi(argv[arg]); arg++; }
if (!maxsz) maxsz = 2*1024*1024; /* 2 MB default */
#ifdef GASNET_SEGMENT_EVERYTHING
if (maxsz > TEST_SEGSZ) { MSG("maxsz must be <= %"PRIuPTR" on GASNET_SEGMENT_EVERYTHING",(uintptr_t)TEST_SEGSZ); gasnet_exit(1); }
#endif
GASNET_Safe(gex_Segment_Attach(&mysegment, myteam, TEST_SEGSZ_REQUEST));
GASNET_Safe(gex_EP_RegisterHandlers(myep, htable, sizeof(htable)/sizeof(gex_AM_Entry_t)));
test_init("testqueue",1,"[-in|-out|-a|-f] [type options] (iters) (maxdepth) (maxsz)\n"
" The '-in' or '-out' option selects whether the initiator-side\n"
" memory is in the GASNet segment or not (default is 'in').\n"
" The -a option enables full-duplex mode, where all nodes send.\n"
" The -f option enables 'first/last' mode, where the first node\n"
" sends to the last, while all other nodes sit idle.\n"
" Test types to run: (defaults to everything)\n"
" -p : puts\n"
" -g : gets\n"
" -s : AMShort\n"
" -m : AMMedium\n"
" -l : AMLong\n"
" -n : Test non-bulk put/gets\n"
" -b : Test bulk put/gets\n"
" -v : Test value-based put/gets\n"
" -i : Test implicit-handle put/gets/medium/long\n"
" -e : Test explicit-handle put/gets/medium/long\n"
" -k : Test blocking put/gets/medium/long\n");
if (help) test_usage();
min_payload = 1;
max_payload = maxsz;
if (numflavors == 0) { /* default to all */
do_puts = 1;
do_gets = 1;
do_amshort = 1;
do_ammedium = 1;
do_amlong = 1;
}
if (numsync == 0) { /* default to all */
do_implicit = 1;
do_explicit = 1;
do_blocking = 1;
}
if (!do_bulk && !do_nonbulk && !do_value) {
do_bulk = 1;
do_nonbulk = 1;
do_value = 1;
}
if (!do_implicit && !do_explicit && !do_blocking) {
do_implicit = 1;
do_explicit = 1;
do_blocking = 1;
}
if (max_payload < min_payload) {
printf("ERROR: maxsz must be >= %i\n",min_payload);
gasnet_exit(1);
}
/* get SPMD info */
myproc = gex_TM_QueryRank(myteam);
numprocs = gex_TM_QuerySize(myteam);
if (!firstlastmode) {
/* Only allow 1 or even number for numprocs */
if (numprocs > 1 && numprocs % 2 != 0) {
MSG0("WARNING: This test requires a unary or even number of nodes. Test skipped.\n");
gasnet_exit(0); /* exit 0 to prevent false negatives in test harnesses for smp-conduit */
}
}
/* Setting peer thread rank */
if (firstlastmode) {
peerproc = numprocs-1;
iamsender = (myproc == 0);
iamrecver = (myproc == numprocs-1);
multisender = 0;
} else if (numprocs == 1) {
peerproc = 0;
iamsender = 1;
iamrecver = 1;
multisender = 0;
} else {
peerproc = (myproc % 2) ? (myproc - 1) : (myproc + 1);
iamsender = (fullduplexmode || myproc % 2 == 0);
iamrecver = (fullduplexmode || !iamsender);
multisender = (fullduplexmode || numprocs >= 4);
}
multisender = 1; /* messes up output on some systems */
myseg = TEST_SEG(myproc);
tgtmem = (char*)TEST_SEG(peerproc) + alignup(maxsz, PAGESZ);
if (insegment) {
msgbuf = (void *) myseg;
} else {
alloc = (void *) test_calloc(maxsz+PAGESZ,1); /* use calloc to prevent valgrind warnings */
msgbuf = (void *) alignup(((uintptr_t)alloc), PAGESZ); /* ensure page alignment of base */
}
assert(((uintptr_t)msgbuf) % PAGESZ == 0);
MSG0("Running %squeue test with local addr %sside segment, iters=%i, maxdepth=%i, sz: %i...%i",
firstlastmode ? "first/last " : (fullduplexmode ? "full-duplex ": ""),
insegment ? "in" : "out",
iters,
maxdepth,
min_payload, max_payload);
MSG0("x-axis: queue depth, y-axis: message size, injection time in microseconds\n");
BARRIER();
events = (gex_Event_t *) test_malloc(sizeof(gex_Event_t) * maxdepth);
do_bulkputs();
do_nonbulkputgets();
do_valueputgets();
do_blockingputgets();
do_amtests();
BARRIER();
test_free(events);
if (!insegment) {
test_free(alloc);
}
gasnet_exit(0);
return 0;
}
#define QUEUE_TEST(OPDESC, OP, SYNC, RECVRSYNC, PAYLOAD_LIMIT) do { \
int depth, payload, last_payload; \
BARRIER(); \
MSG0("\n%s\n--------------------\n", OPDESC); \
{ char header[1024]; \
char *pheader = header; \
size_t hused = 0; \
snprintf(pheader, sizeof(header) - hused, " "); \
pheader += strlen(pheader); hused = pheader - header; \
for (depth = 1; depth <= maxdepth; depth *= 2) { \
snprintf(pheader, sizeof(header) - hused, " %7i", depth); \
pheader += strlen(pheader); hused = pheader - header; \
} \
PUTS0(header); \
} \
last_payload = (((PAYLOAD_LIMIT) <= 0) ? max_payload : \
MIN(max_payload, (PAYLOAD_LIMIT))); \
for (payload = min_payload; payload <= last_payload; payload *= 2) { \
char row[1024]; \
char *prow = row; \
size_t rused = 0; \
if (payload < 0) break; /* Overflow */ \
snprintf(prow, sizeof(row) - rused, "%-8i", payload); \
prow += strlen(prow); rused = prow - row; \
if (!multisender) { \
fputs(row,stdout); fflush(stdout); \
prow = row; rused = 0; \
} \
depth = 1; \
if (iamsender) { /* Prime i-cache, free-lists, firehose, etc. */ \
int i = 0; \
OP; \
{ SYNC; } \
} \
if (iamrecver) { RECVRSYNC; } \
for (depth = 1; depth <= maxdepth; depth *= 2) { \
BARRIER(); \
\
if (iamsender) { \
int iter,i; \
gasnett_tick_t total = 0, \
min = GASNETT_TICK_MAX, \
max = GASNETT_TICK_MIN; \
for (iter = 0; iter < iters; iter++) { \
gasnett_tick_t begin, end, thistime; \
BARRIER(); \
/* measure time to inject depth operations of payload sz */ \
begin = gasnett_ticks_now(); \
for (i = 0; i < depth; i++) { \
OP; \
} \
end = gasnett_ticks_now(); \
{ SYNC; } \
if (iamrecver) { RECVRSYNC; } \
BARRIER(); \
thistime = (end - begin); \
total += thistime; \
min = MIN(min,thistime); \
max = MAX(max,thistime); \
} \
{ double avgus = gasnett_ticks_to_ns(total) / 1000.0 / \
(double)iters / (double)depth; \
double minus = gasnett_ticks_to_ns(min) / 1000.0 / (double)depth; \
double maxus = gasnett_ticks_to_ns(max) / 1000.0 / (double)depth; \
int prec; \
if (avgus < 1000.0) prec = 3; \
else if (avgus < 10000.0) prec = 2; \
else if (avgus < 100000.0) prec = 1; \
else prec = 0; \
snprintf(prow, sizeof(row) - rused, " %7.*f", prec, avgus); \
prow += strlen(prow); rused = prow - row; \
if (!multisender) { \
fputs(row,stdout); fflush(stdout); \
prow = row; rused = 0; \
} \
} \
} else { \
int i; \
for (i = 0; i < iters; i++) { \
BARRIER(); \
if (iamrecver) { RECVRSYNC; } \
BARRIER(); \
} \
} \
} \
if (iamsender) { \
puts(row); fflush(stdout); \
} \
} \
} while (0)
void do_bulkputs(void) {
if (do_puts && do_bulk && do_explicit) {
QUEUE_TEST("gex_RMA_PutNB/bulk",
events[i] = gex_RMA_PutNB(myteam, peerproc, tgtmem, msgbuf, payload, GEX_EVENT_DEFER, 0),
gex_Event_WaitAll(events, depth, 0), (void)0, 0);
}
if (do_puts && do_bulk && do_implicit) {
QUEUE_TEST("gex_RMA_PutNBI/bulk",
gex_RMA_PutNBI(myteam, peerproc, tgtmem, msgbuf, payload, GEX_EVENT_DEFER, 0),
gex_NBI_Wait(GEX_EC_ALL,0), (void)0, 0);
}
}
void do_nonbulkputgets(void) {
if (do_puts && do_nonbulk && do_explicit) {
QUEUE_TEST("gex_RMA_PutNB",
events[i] = gex_RMA_PutNB(myteam, peerproc, tgtmem, msgbuf, payload, GEX_EVENT_NOW, 0),
gex_Event_WaitAll(events, depth, 0), (void)0, 0);
}
if (do_gets && do_explicit) {
QUEUE_TEST("gex_RMA_GetNB",
events[i] = gex_RMA_GetNB(myteam, msgbuf, peerproc, tgtmem, payload, 0),
gex_Event_WaitAll(events, depth, 0), (void)0, 0);
}
if (do_puts && do_nonbulk && do_implicit) {
QUEUE_TEST("gex_RMA_PutNBI",
gex_RMA_PutNBI(myteam, peerproc, tgtmem, msgbuf, payload, GEX_EVENT_NOW, 0),
gex_NBI_Wait(GEX_EC_ALL,0), (void)0, 0);
}
if (do_gets && do_implicit) {
QUEUE_TEST("gex_RMA_GetNBI",
gex_RMA_GetNBI(myteam, msgbuf, peerproc, tgtmem, payload, 0),
gex_NBI_Wait(GEX_EC_ALL,0), (void)0, 0);
}
}
void do_valueputgets(void) {
if (do_puts && do_value && do_explicit) {
QUEUE_TEST("gex_RMA_PutNBVal",
events[i] = gex_RMA_PutNBVal(myteam, peerproc, tgtmem, regval, payload, 0),
gex_Event_WaitAll(events, depth, 0),
(void)0, SIZEOF_GEX_RMA_VALUE_T);
}
if (do_puts && do_value && do_implicit) {
QUEUE_TEST("gex_RMA_PutNBIVal",
gex_RMA_PutNBIVal(myteam, peerproc, tgtmem, regval, payload, 0),
gex_NBI_Wait(GEX_EC_ALL,0),
(void)0, SIZEOF_GEX_RMA_VALUE_T);
}
}
void do_blockingputgets(void) {
if (do_puts && do_blocking) {
QUEUE_TEST("gex_RMA_PutBlocking (BLOCKING - represents round-trip latency)",
gex_RMA_PutBlocking(myteam, peerproc, tgtmem, msgbuf, payload, 0),
(void)0, (void)0, 0);
}
if (do_gets && do_blocking) {
QUEUE_TEST("gex_RMA_GetBlocking (BLOCKING - represents round-trip latency)",
gex_RMA_GetBlocking(myteam, msgbuf, peerproc, tgtmem, payload, 0),
(void)0, (void)0, 0);
}
if (do_puts && do_value && do_blocking) {
QUEUE_TEST("gex_RMA_PutBlockingVal (BLOCKING - represents round-trip latency)",
gex_RMA_PutBlockingVal(myteam, peerproc, tgtmem, regval, payload, 0),
(void)0, (void)0, SIZEOF_GEX_RMA_VALUE_T);
}
if (do_gets && do_value && do_blocking) {
QUEUE_TEST("gex_RMA_GetBlockingVal (BLOCKING - represents round-trip latency)",
regval ^= gex_RMA_GetBlockingVal(myteam, peerproc, tgtmem, payload, 0),
(void)0, (void)0, SIZEOF_GEX_RMA_VALUE_T);
}
}
void do_amtests(void) {
if (do_amshort) {
gasnett_atomic_set(&amcount, 0, 0);
QUEUE_TEST("gex_AM_RequestShort0",
gex_AM_RequestShort0(myteam, peerproc, hidx_ping_shorthandler, 0), (void)0,
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
min_payload);
}
if (do_ammedium && do_blocking) {
gasnett_atomic_set(&amcount, 0, 0);
QUEUE_TEST("gex_AM_RequestMedium0 (blocking for LC)",
gex_AM_RequestMedium0(myteam, peerproc, hidx_ping_medhandler,
msgbuf, payload, GEX_EVENT_NOW, 0), (void)0,
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
gex_AM_MaxRequestMedium(myteam,GEX_RANK_INVALID,GEX_EVENT_NOW,0,0));
}
if (do_ammedium && do_explicit) {
QUEUE_TEST("gex_AM_RequestMedium0 (explicit handle for LC)",
gex_AM_RequestMedium0(myteam, peerproc, hidx_ping_medhandler,
msgbuf, payload, &events[i], 0),
gex_Event_WaitAll(events, depth, 0),
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
gex_AM_MaxRequestMedium(myteam,GEX_RANK_INVALID,NULL,0,0));
}
if (do_ammedium && do_implicit) {
QUEUE_TEST("gex_AM_RequestMedium0 (implicit handle for LC)",
gex_AM_RequestMedium0(myteam, peerproc, hidx_ping_medhandler,
msgbuf, payload, GEX_EVENT_GROUP, 0),
gex_NBI_Wait(GEX_EC_ALL,0),
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
gex_AM_MaxRequestMedium(myteam,GEX_RANK_INVALID,GEX_EVENT_GROUP,0,0));
}
if (do_amlong && do_blocking) {
gasnett_atomic_set(&amcount, 0, 0);
QUEUE_TEST("gex_AM_RequestLong0 (blocking for LC)",
gex_AM_RequestLong0(myteam, peerproc, hidx_ping_longhandler,
msgbuf, payload, tgtmem, GEX_EVENT_NOW, 0), (void)0,
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
gex_AM_MaxRequestLong(myteam,GEX_RANK_INVALID,GEX_EVENT_NOW,0,0));
}
if (do_amlong && do_explicit) {
QUEUE_TEST("gex_AM_RequestLong0 (explicit handle for LC)",
gex_AM_RequestLong0(myteam, peerproc, hidx_ping_longhandler,
msgbuf, payload, tgtmem, &events[i], 0),
gex_Event_WaitAll(events, depth, 0),
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
gex_AM_MaxRequestLong(myteam,GEX_RANK_INVALID,NULL,0,0));
}
if (do_amlong && do_implicit) {
QUEUE_TEST("gex_AM_RequestLong0 (implicit handle for LC)",
gex_AM_RequestLong0(myteam, peerproc, hidx_ping_longhandler,
msgbuf, payload, tgtmem, GEX_EVENT_GROUP, 0),
gex_NBI_Wait(GEX_EC_ALL,0),
{ assert(iamrecver);
GASNET_BLOCKUNTIL(gasnett_atomic_read(&amcount,0) == depth);
gasnett_atomic_set(&amcount, 0, 0); },
gex_AM_MaxRequestLong(myteam,GEX_RANK_INVALID,GEX_EVENT_GROUP,0,0));
}
}
/* ------------------------------------------------------------------------------------ */
|