-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgasnet_am.c
More file actions
1105 lines (970 loc) · 45.5 KB
/
gasnet_am.c
File metadata and controls
1105 lines (970 loc) · 45.5 KB
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Source: github.com:BerkeleyLab/gasnet.git/gasnet_am.c $
* Description: GASNet conduit-independent code for Active Messages
* Copyright 2002, Dan Bonachea <bonachea@cs.berkeley.edu>
* Copyright 2018, The Regents of the University of California
* Terms of use are as specified in license.txt
*/
#include <gasnet_internal.h>
#include <gasnet_am.h>
/* ------------------------------------------------------------------------------------ */
extern void gasneti_defaultAMHandler(gex_Token_t token) {
gex_Token_Info_t info;
info.gex_srcrank = GEX_RANK_INVALID; // to print -1 if query were to fail
gex_TI_t rc = gex_Token_Info(token, &info, GEX_TI_SRCRANK | GEX_TI_ENTRY);
gex_Rank_t srcnode = info.gex_srcrank;
if (rc & GEX_TI_ENTRY) gasneti_assert(info.gex_entry);
gasneti_fatalerror("GASNet node %i/%i received an AM message from node %i for a handler index%s "
"with no associated AM handler function registered",
(int)gasneti_mynode, (int)gasneti_nodes, (int)srcnode,
(rc & GEX_TI_ENTRY)
? gasneti_dynsprintf(" %d", (int)(uintptr_t)info.gex_entry->gex_cdata)
: "");
}
/* ------------------------------------------------------------------------------------ */
// Validate a handler table prior to registration
static void gasneti_am_validate(
const gex_AM_Entry_t *table,
int numentries)
{
if (!numentries) return;
// Internally-constructed legacy table should be all-or-nothing.
if (table[0].gex_nargs == GASNETI_HANDLER_NARGS_UNK ||
table[0].gex_flags & GASNETI_FLAG_INIT_LEGACY) {
for (int i = 0; i < numentries; ++i) {
gasneti_assert_always_uint(table[i].gex_nargs ,==, GASNETI_HANDLER_NARGS_UNK);
gasneti_assert_always_uint(table[i].gex_flags ,==, (GASNETI_FLAG_AM_ANY | GASNETI_FLAG_INIT_LEGACY));
}
return;
}
// Normal tables have several rules to check:
for (int i = 0; i < numentries; ++i) {
int idx = table[i].gex_index;
if_pf (table[i].gex_nargs > gex_AM_MaxArgs()) {
gasneti_fatalerror("AM Handler table entry %d: invalid gex_nargs: %d (Max %d)",
i, (int)table[i].gex_nargs, (int)gex_AM_MaxArgs());
}
if_pf (0 == (table[i].gex_flags & (GEX_FLAG_AM_REQUEST|GEX_FLAG_AM_REPLY))) {
gasneti_fatalerror("AM Handler table entry %d(idx=%d): invalid gex_flags: contains neither GEX_FLAG_AM_REQUEST nor GEX_FLAG_AM_REPLY", i, idx);
}
gex_Flags_t category = table[i].gex_flags & (GEX_FLAG_AM_SHORT|GEX_FLAG_AM_MEDIUM|GEX_FLAG_AM_LONG);
const char *cat_msg = NULL;
switch (category) {
case 0:
cat_msg = "none of GEX_FLAG_AM_SHORT, GEX_FLAG_AM_MEDIUM, or GEX_FLAG_AM_LONG";
break;
case GEX_FLAG_AM_SHORT|GEX_FLAG_AM_MEDIUM|GEX_FLAG_AM_LONG:
cat_msg = "invalid combination (GEX_FLAG_AM_SHORT | GEX_FLAG_AM_MEDIUM | GEX_FLAG_AM_LONG)";
break;
case GEX_FLAG_AM_SHORT|GEX_FLAG_AM_MEDIUM:
cat_msg = "invalid combination (GEX_FLAG_AM_SHORT | GEX_FLAG_AM_MEDIUM )";
break;
case GEX_FLAG_AM_SHORT|GEX_FLAG_AM_LONG:
cat_msg = "invalid combination (GEX_FLAG_AM_SHORT | GEX_FLAG_AM_LONG)";
break;
}
if_pf (cat_msg) {
gasneti_fatalerror("AM Handler table entry %d(idx=%d): invalid gex_flags: contains %s", i, idx, cat_msg);
}
}
}
#if GASNETC_AMREGISTER
/* Use a conduit-specific hook at registration */
extern int gasnetc_amregister(gex_AM_Index_t, gex_AM_Entry_t *);
#endif
// Register handlers in the range [lowlimit,highlimit)
// Thread-safety is the caller's responsibility
extern int gasneti_amregister( gasneti_EP_t i_ep,
gex_AM_Entry_t *input, int numentries,
int lowlimit, int highlimit,
int dontcare, int *numregistered) {
int i;
*numregistered = 0;
gasneti_am_validate(input, numentries);
gex_AM_Entry_t *output = i_ep->_amtbl;
for (i = 0; i < numentries; i++) {
int newindex;
if ((input[i].gex_index == 0 && !dontcare) ||
(input[i].gex_index && dontcare)) continue;
else if (input[i].gex_index) newindex = input[i].gex_index;
else { /* deterministic assignment of dontcare indexes from top down */
for (newindex = highlimit-1; newindex >= lowlimit; newindex--) {
if (!output[newindex].gex_index) break; // 0 index marks free entry
}
if (newindex < lowlimit) {
char s[255];
snprintf(s, sizeof(s), "Too many handlers. (limit=%i)", highlimit - lowlimit);
GASNETI_RETURN_ERRR(BAD_ARG, s);
}
}
/* ensure handlers fall into the proper range of pre-assigned values */
if (newindex < lowlimit || newindex >= highlimit) {
char s[255];
snprintf(s, sizeof(s), "handler index (%i) out of range [%i..%i)", newindex, lowlimit, highlimit);
GASNETI_RETURN_ERRR(BAD_ARG, s);
}
/* discover duplicates */
if (output[newindex].gex_index) // entry is taken
GASNETI_RETURN_ERRR(BAD_ARG, "handler index not unique");
/* register a single handler with conduit-specifc hook, if any */
#if GASNETC_AMREGISTER
int rc = gasnetc_amregister((gex_AM_Index_t)newindex, &input[i]);
if (GASNET_OK != rc) return rc;
#endif
/* The check below for !input[i].index is redundant and present
* only to defeat the over-aggressive optimizer in pathcc 2.1
*/
if (dontcare && !input[i].gex_index) input[i].gex_index = newindex;
/* Install the entire table entry */
gasneti_assert(! output[newindex].gex_index);
output[newindex] = input[i];
#if GASNET_TRACE
{
const char *name = input[i].gex_name
? gasneti_dynsprintf(", name='%s'", input[i].gex_name) : "";
void *fnptr = *(void**)&input[i].gex_fnptr; // level of indirection avoids -pedantic warning
char *flags = gasneti_malloc(gasneti_format_flags_amreg(NULL, input[i].gex_flags));
gasneti_format_flags_amreg(flags, input[i].gex_flags);
const char *nargs = (input[i].gex_nargs == GASNETI_HANDLER_NARGS_UNK)
? "" : gasneti_dynsprintf(", nargs=%u", input[i].gex_nargs);
if (newindex >= GASNETI_CLIENT_HANDLER_BASE) {
GASNETI_TRACE_PRINTF(O,("Registered AM handler %d: client table entry=%d, flags=%s%s, fnptr=%p%s%s",
newindex, i, flags, nargs, fnptr, name,
dontcare ? ", input index was zero" : ""));
} else {
gasneti_static_assert(GASNETE_HANDLER_BASE > GASNETC_HANDLER_BASE);
const char *api = (newindex >= GASNETE_HANDLER_BASE) ? "extended" : "core";
GASNETI_TRACE_PRINTF(D,("Registered AM handler %d: %s API, flags=%s%s, fnptr=%p%s",
newindex, api, flags, nargs, fnptr, name));
}
gasneti_free(flags);
}
#endif
(*numregistered)++;
}
return GASNET_OK;
}
// Register client handlers
// This function backs gex_EP_RegisterHandlers() and gasnet_attach()
// and provides per-EP serialization of such calls.
// Internal calls occuring within gex_Client_Init() and gex_Client_Create()
// do not participate in this serialization, since they operated exclusively
// on an EP prior to returning it to the client.
extern int gasneti_amregister_client(
gasneti_EP_t i_ep,
gex_AM_Entry_t *input,
size_t numentries)
{
if_pf (numentries == 0) return GASNET_OK;
if_pf (numentries > GASNETC_MAX_NUMHANDLERS - GEX_AM_INDEX_BASE)
GASNETI_RETURN_ERRR(BAD_ARG,"Tried to register too many handlers");
if_pf (input == NULL)
GASNETI_RETURN_ERRR(BAD_ARG,"Invalid AM handler table");
gasneti_mutex_lock(&i_ep->_amtbl_lock);
/* first pass - assign all fixed-index handlers */
int numreg1 = 0;
if (gasneti_amregister(i_ep, input, numentries,
GASNETI_CLIENT_HANDLER_BASE, GASNETC_MAX_NUMHANDLERS,
0, &numreg1) != GASNET_OK) {
gasneti_mutex_unlock(&i_ep->_amtbl_lock);
GASNETI_RETURN_ERRR(RESOURCE,"Error registering fixed-index client handlers");
}
/* second pass - fill in dontcare-index handlers */
int numreg2 = 0;
if (gasneti_amregister(i_ep, input, numentries,
GASNETI_CLIENT_HANDLER_BASE, GASNETC_MAX_NUMHANDLERS,
1, &numreg2) != GASNET_OK) {
gasneti_mutex_unlock(&i_ep->_amtbl_lock);
GASNETI_RETURN_ERRR(RESOURCE,"Error registering variable-index client handlers");
}
gasneti_mutex_unlock(&i_ep->_amtbl_lock);
gasneti_assert_uint(numreg1 + numreg2 ,==, numentries);
return GASNET_OK;
}
// Wrapper to provide continued support for GASNet-1 legacy handler tables,
// such as through gasnet_attach(). Only supports the clients's index range.
// TODO-EX: should be absorbed into an eventual conduit-indep gasnet_attach()
extern int gasneti_amregister_legacy( gasneti_EP_t i_ep,
gasnet_handlerentry_t *table, int numentries) {
if_pf (numentries == 0) return GASNET_OK;
if_pf (numentries > GASNETC_MAX_NUMHANDLERS - GEX_AM_INDEX_BASE)
GASNETI_RETURN_ERRR(BAD_ARG,"Tried to register too many handlers");
if_pf (numentries < 0)
GASNETI_RETURN_ERRR(BAD_ARG,"Invalid AM handler table size");
if_pf (table == NULL)
GASNETI_RETURN_ERRR(BAD_ARG,"Invalid AM handler table");
/* create temporary ex-compatible table */
gex_AM_Entry_t *extable = gasneti_calloc(numentries, sizeof(gex_AM_Entry_t));
for (int i = 0; i < numentries; ++i) {
extable[i].gex_index = table[i].index;
extable[i].gex_fnptr = table[i].fnptr;
extable[i].gex_nargs = GASNETI_HANDLER_NARGS_UNK;
extable[i].gex_flags = GASNETI_FLAG_AM_ANY | GASNETI_FLAG_INIT_LEGACY;
}
/* register */
if (gasneti_amregister_client(i_ep, extable, numentries) != GASNET_OK) {
gasneti_free(extable);
GASNETI_RETURN_ERRR(RESOURCE,"Error registering client handlers");
}
/* copy back from temporary ex-compatible table */
for (int i = 0; i < numentries; ++i) {
table[i].index = extable[i].gex_index;
}
gasneti_free(extable);
return GASNET_OK;
}
// Initialize handler table in a given EP
extern int gasneti_amtbl_init(gasneti_EP_t i_ep) {
gex_AM_Entry_t *output = i_ep->_amtbl;
static const char *fnname = "gasneti_defaultAMHandler";
for (int i = 0; i < GASNETC_MAX_NUMHANDLERS; i++) {
output[i].gex_index = 0; // marks an unused entry
output[i].gex_nargs = GASNETI_HANDLER_NARGS_UNK;
output[i].gex_flags = GASNETI_FLAG_AM_ANY;
output[i].gex_fnptr = (gex_AM_Fn_t)gasneti_defaultAMHandler;
output[i].gex_cdata = (void *)(uintptr_t)i;
output[i].gex_name = fnname;
}
gasneti_mutex_init(&i_ep->_amtbl_lock);
return GASNET_OK;
}
#if GASNET_DEBUG && !defined(gasneti_amtbl_check)
// Validate call to a handler
extern void gasneti_amtbl_check(const gex_AM_Entry_t *entry, int nargs,
gasneti_category_t category, int isReq) {
char buf[128] = {'\0'};
const char *msg = NULL;
if ((entry->gex_nargs != nargs) && (entry->gex_nargs != GASNETI_HANDLER_NARGS_UNK)) {
snprintf(buf, sizeof(buf), "registered with nargs=%d but called with %d", entry->gex_nargs, nargs);
msg = buf;
} else if (isReq && !(entry->gex_flags & GEX_FLAG_AM_REQUEST)) {
msg = "invoked as a Request handler, but not registered with GEX_FLAG_AM_REQUEST";
} else if (!isReq && !(entry->gex_flags & GEX_FLAG_AM_REPLY)) {
msg = "invoked as a Reply handler, but not registered with GEX_FLAG_AM_REPLY";
} else if (category == gasneti_Short && !(entry->gex_flags & GEX_FLAG_AM_SHORT)) {
msg = "invoked as a Short handler, but not registered with GEX_FLAG_AM_SHORT";
} else if (category == gasneti_Medium && !(entry->gex_flags & GEX_FLAG_AM_MEDIUM)) {
msg = "invoked as a Medium handler, but not registered with GEX_FLAG_AM_MEDIUM";
} else if (category == gasneti_Long && !(entry->gex_flags & GEX_FLAG_AM_LONG)) {
msg = "invoked as a Long handler, but not registered with GEX_FLAG_AM_LONG";
}
if (msg) {
char fnaddr[32];
const char *fnname = entry->gex_name;
if (!fnname) {
(void) snprintf(fnaddr, sizeof(fnaddr), "%p",
*(void**)&entry->gex_fnptr); // level of indirection avoids -pedantic warning
fnname = fnaddr;
}
gasneti_fatalerror("AM handler %d (%s) %s", entry->gex_index, fnname, msg);
}
}
#endif
/* ------------------------------------------------------------------------------------ */
extern int gex_EP_RegisterHandlers(
gex_EP_t ep,
gex_AM_Entry_t *table,
size_t numentries)
{
GASNETI_TRACE_PRINTF(O,("gex_EP_RegisterHandlers: ep=%p table=%p numentries=%"PRIuSZ,
(void*)ep, (void*)table, numentries));
return gasneti_amregister_client(gasneti_import_ep_valid(ep), table, numentries);
}
/* ------------------------------------------------------------------------------------ */
#if GASNET_DEBUG
// Post processing of gex_Token_Info() results
extern gex_TI_t gasneti_token_info_return(gex_TI_t result, gex_Token_Info_t *info, gex_TI_t mask) {
// Validate client's requested mask
if (mask & ~GEX_TI_ALL) {
gasneti_fatalerror("Mask argument to gex_Token_Info() includes unknown bits");
}
// Validate conduit's returned mask (any requested+required fields missing?);
gasneti_assert_uint( (~result & (mask & GASNETI_TI_REQUIRED)) ,==, 0);
#if GASNET_SUPPORTS_TI_ENTRY
gasneti_assert_uint( (~result & (mask & GEX_TI_ENTRY)) ,==, 0);
#endif
#if GASNET_SUPPORTS_TI_IS_REQ
gasneti_assert_uint( (~result & (mask & GEX_TI_IS_REQ)) ,==, 0);
#endif
#if GASNET_SUPPORTS_TI_IS_LONG
gasneti_assert_uint( (~result & (mask & GEX_TI_IS_LONG)) ,==, 0);
#endif
// For each field set: validate
if (result & GEX_TI_SRCRANK) {
gasneti_assert_uint(info->gex_srcrank ,<, gasneti_nodes);
}
if (result & GEX_TI_EP) {
// TODO-EX: will need some means to validate in conduit-independent manner
// NULL THUNK_TM may occur in bootstrap collectives before ep0 exists
gasneti_assert(!gasneti_THUNK_TM || info->gex_ep == gasneti_THUNK_EP);
}
if (result & GEX_TI_ENTRY) {
gasneti_assert(info->gex_entry);
gasneti_am_validate(info->gex_entry, 1);
}
if (result & GEX_TI_IS_REQ) {
gasneti_assert_uint(info->gex_is_req ,==, !!info->gex_is_req); // Is 0 or 1
if (result & GEX_TI_ENTRY) {
gasneti_assert(info->gex_entry->gex_flags &
(info->gex_is_req ? GEX_FLAG_AM_REQUEST : GEX_FLAG_AM_REPLY));
}
}
if (result & GEX_TI_IS_LONG) {
gasneti_assert_uint(info->gex_is_long ,==, !!info->gex_is_long); // Is 0 or 1
if (result & GEX_TI_ENTRY) {
gasneti_assert(info->gex_entry->gex_flags &
(info->gex_is_long ? GEX_FLAG_AM_LONG : GEX_FLAG_AM_SHORT|GEX_FLAG_AM_MEDIUM));
}
}
// From here forward, consider only the requested subset of the conduit-provided result
result &= mask;
// For each field not requested or requested but not set: INvalidate
if (!(result & GEX_TI_SRCRANK)) {
info->gex_srcrank = GEX_RANK_INVALID;
}
if (!(result & GEX_TI_EP)) {
info->gex_ep = NULL;
}
if (!(result & GEX_TI_ENTRY)) {
info->gex_entry = NULL;
}
if (!(result & GEX_TI_IS_REQ)) {
info->gex_is_req = 2; // true invalidation not possible for a boolean
}
if (!(result & GEX_TI_IS_LONG)) {
info->gex_is_long = 2; // true invalidation not possible for a boolean
}
return result;
}
#endif
/* ------------------------------------------------------------------------------------ */
// Error checking for AM payload queries
#if GASNET_DEBUG
// TODO-EX: are there any additional checks still possible here?
static void check_max_payload_args(
const char *fname, gasneti_category_t category, int isReq,
const gex_Event_t *lc_opt, gex_Flags_t flags,
unsigned int nargs)
{
if (lc_opt == GEX_EVENT_DEFER) {
gasneti_fatalerror("Call to %s() with invalid lc_opt=GEX_EVENT_DEFER", fname);
}
if (!isReq && (lc_opt == GEX_EVENT_GROUP)) {
gasneti_fatalerror("Call to %s() with invalid lc_opt=GEX_EVENT_GROUP", fname);
}
if (lc_opt && gasneti_leaf_is_pointer(lc_opt)) {
// Following assumes minimum 4-byte alignment of gex_Event_t
if (0x3 & (uintptr_t)lc_opt) {
gasneti_fatalerror("Call to %s() with invalid lc_opt=%p", fname, (void *)lc_opt);
}
// Following attempts to elicit SIGSEGV/SIGBUS/SIGILL on bogus pointers
static uintptr_t dummy;
dummy += (uintptr_t) *(volatile gex_Event_t *)lc_opt;
}
if ((flags & GEX_FLAG_AM_PREPARE_LEAST_CLIENT) &&
(flags & GEX_FLAG_AM_PREPARE_LEAST_ALLOC)) {
gasneti_fatalerror("Call to %s() with mutually-exclusive "
"GEX_FLAG_AM_PREPARE_LEAST_CLIENT and "
"GEX_FLAG_AM_PREPARE_LEAST_ALLOC both set in flags argument",
fname);
}
if (nargs > gex_AM_MaxArgs()) {
gasneti_fatalerror("Call to %s() with nargs=%u greater than gex_AM_MaxArgs()=%u",
fname, nargs, (unsigned int)gex_AM_MaxArgs());
}
}
static void check_max_payload_result(gex_Flags_t flags, size_t lub, size_t result)
{
gasneti_assert_uint(result ,>=, 512);
gasneti_assert((result >= lub) ||
(flags & GEX_FLAG_AM_PREPARE_LEAST_CLIENT) ||
(flags & GEX_FLAG_AM_PREPARE_LEAST_ALLOC));
}
#define GASNETC_IS_REQ(reqrep) _GASNETC_IS_REQ_##reqrep
#define _GASNETC_IS_REQ_Request 1
#define _GASNETC_IS_REQ_Reply 0
#define DEFN_AM_MAX_FN(reqrep,cat) \
size_t gex_AM_Max##reqrep##cat( \
gex_TM_t tm, gex_Rank_t rank, \
const gex_Event_t *lc_opt, gex_Flags_t flags, \
unsigned int nargs) \
{ \
const char *fname = "gex_AM_Max" #reqrep #cat; \
gasneti_TM_t real_tm = gasneti_import_tm(tm); \
/* TODO-EX: remove allowance for real_tm == NULL */ \
gex_Rank_t tm_size = gasneti_i_tm_size(real_tm); \
if (real_tm && (rank != GEX_RANK_INVALID) && (rank >= tm_size)) { \
gasneti_fatalerror("Call to %s() with invalid rank=%i", \
fname, (int)rank); \
} \
gasneti_category_t category = gasneti_##cat; \
int isReq = GASNETC_IS_REQ(reqrep); \
check_max_payload_args(fname, category, isReq,lc_opt, flags, nargs); \
size_t result = gasnetc_AM_Max##reqrep##cat(tm,rank,lc_opt,flags,nargs); \
check_max_payload_result(flags, gex_AM_LUB##reqrep##cat(), result); \
return result; \
}
#define DEFN_TOKEN_MAX_FN(reqrep,cat) \
size_t gex_Token_Max##reqrep##cat( \
gex_Token_t token, \
const gex_Event_t *lc_opt, gex_Flags_t flags, \
unsigned int nargs) \
{ \
const char *fname = "gex_Token_Max" #reqrep #cat; \
gasneti_category_t category = gasneti_##cat; \
int isReq = GASNETC_IS_REQ(reqrep); \
check_max_payload_args(fname, category, isReq,lc_opt, flags, nargs); \
size_t result = gasnetc_Token_Max##reqrep##cat(token,lc_opt,flags,nargs); \
check_max_payload_result(flags, gex_AM_LUB##reqrep##cat(), result); \
return result; \
}
DEFN_AM_MAX_FN(Request,Medium)
DEFN_AM_MAX_FN(Request,Long)
DEFN_AM_MAX_FN(Reply,Medium)
DEFN_AM_MAX_FN(Reply,Long)
DEFN_TOKEN_MAX_FN(Reply,Medium)
DEFN_TOKEN_MAX_FN(Reply,Long)
#undef DEFN_AM_MAX_FN
#undef DEFN_TOKEN_MAX_FN
#endif
/* ------------------------------------------------------------------------------------ */
// Implementation of Negotiated-Payload AMs
//
// For conduit's without specialization of NP-AM, this provides the entire
// default implementation, using malloc() to obtain gasnet-owned buffers (if
// any) at Prepare and using gasneti_AM{Request,Reply}{Medium,Long}V() to
// perform the AM injection at Commit.
//
// TODO-EX: This default is not a "good" implementation for any conduit.
// TODO-EX: Native conduits should provide their own negotiated-payload and
// ideally implement it and fixed-payload in terms of a common base.
// TODO-EX: This default's use of GEX_EVENT_NOW for gasnet-owned buffers could
// be replaced with &event, *if* a progress function (or dependent
// operation) were available to reap them and free buffers. However,
// that is only fruitful with a conduit which can provide asynchronous
// local completion other than by copying the payload.
// Conduits can enable build (possibly name-shifted?) of the four pieces of the
// reference implementation by defining GASNETC_BUILD_NP_{REQ,REP}_{MEDIUM,LONG}
// to '1'; or they may disable them by defining to '0'.
// Otherwise, these default to following !GASNET_NATIVE_NP_ALLOC_*.
//
#ifdef GASNETC_BUILD_NP_REQ_MEDIUM
// Keep conduit's definition
#elif !GASNET_NATIVE_NP_ALLOC_REQ_MEDIUM
#define GASNETC_BUILD_NP_REQ_MEDIUM 1
#endif
#ifdef GASNETC_BUILD_NP_REP_MEDIUM
// Keep conduit's definition
#elif !GASNET_NATIVE_NP_ALLOC_REP_MEDIUM
#define GASNETC_BUILD_NP_REP_MEDIUM 1
#endif
#ifdef GASNETC_BUILD_NP_REQ_LONG
// Keep conduit's definition
#elif !GASNET_NATIVE_NP_ALLOC_REQ_LONG
#define GASNETC_BUILD_NP_REQ_LONG 1
#endif
#ifdef GASNETC_BUILD_NP_REP_LONG
// Keep conduit's definition
#elif !GASNET_NATIVE_NP_ALLOC_REP_LONG
#define GASNETC_BUILD_NP_REP_LONG 1
#endif
#ifndef _GEX_AM_SRCDESC_T
#ifndef gasneti_import_srcdesc
gasneti_AM_SrcDesc_t gasneti_import_srcdesc(gex_AM_SrcDesc_t _srcdesc) {
const gasneti_AM_SrcDesc_t _real_srcdesc = GASNETI_IMPORT_POINTER(gasneti_AM_SrcDesc_t,_srcdesc);
GASNETI_CHECK_MAGIC(_real_srcdesc, GASNETI_AM_SRCDESC_MAGIC);
gasneti_assert(!_real_srcdesc || (_real_srcdesc->_thread == _gasneti_mythread_slow()));
return _real_srcdesc;
}
gasneti_AM_SrcDesc_t gasneti_import_srcdesc_valid(gex_AM_SrcDesc_t srcdesc) {
gasneti_assert(srcdesc != GEX_AM_SRCDESC_NO_OP);
return gasneti_import_srcdesc(srcdesc);
}
#endif
#ifndef gasneti_export_srcdesc
gex_AM_SrcDesc_t gasneti_export_srcdesc(gasneti_AM_SrcDesc_t _real_srcdesc) {
GASNETI_CHECK_MAGIC(_real_srcdesc, GASNETI_AM_SRCDESC_MAGIC);
return GASNETI_EXPORT_POINTER(gex_AM_SrcDesc_t, _real_srcdesc);
}
#endif
#if GASNETI_NEED_INIT_SRCDESC
void gasneti_init_srcdesc(GASNETI_THREAD_FARG_ALONE)
{
gasneti_threaddata_t * const mythread = GASNETI_MYTHREAD;
gasneti_assert(! mythread->sd_is_init);
// Yes, we start "BAD":
GASNETI_INIT_MAGIC(&mythread->request_sd, GASNETI_AM_SRCDESC_BAD_MAGIC);
GASNETI_INIT_MAGIC(&mythread->reply_sd, GASNETI_AM_SRCDESC_BAD_MAGIC);
mythread->request_sd._thread = mythread;
mythread->reply_sd._thread = mythread;
#if GASNET_DEBUG
mythread->request_sd._isreq = 1;
mythread->reply_sd._isreq = 0;
#endif
gasneti_assert( mythread->request_sd._tofree == NULL );
gasneti_assert( mythread->reply_sd._tofree == NULL );
mythread->sd_is_init = 1;
}
#endif // GASNETI_NEED_INIT_SRCDESC
#if GASNET_DEBUG
void gasneti_checknpam(int for_reply GASNETI_THREAD_FARG) {
gasneti_threaddata_t * const mythread = GASNETI_MYTHREAD;
if (mythread->sd_is_init) {
// Never valid to communicate between Prepare/Commit of Reply
if (mythread->reply_sd._magic._u == GASNETI_AM_SRCDESC_MAGIC) {
gasneti_fatalerror("Invalid GASNet call (communication injection or poll) between gex_AM_PrepareReply() and the corresponding Commit on this thread");
}
// It *is* valid to send a Reply which may dynamically run
// *within* the execution of gex_AM_{Prepare,Commit}Request()
if (!for_reply && mythread->request_sd._magic._u == GASNETI_AM_SRCDESC_MAGIC) {
gasneti_fatalerror("Invalid GASNet call (communication injection or poll) between gex_AM_PrepareRequest() and the corresponding Commit on this thread");
}
}
}
// Conduits can call this from gasnet_exit() to disarm gasneti_checknpam() to
// enable use of AM for exit coordination even if exiting between a Prepare
// and the following Commit.
//
// TODO: Opt-in use of gex_AM_Cancel*() when available and safe.
void gasneti_checknpam_disarm(void) {
GASNET_BEGIN_FUNCTION(); // OK - not a critical-path
gasneti_threaddata_t * const mythread = GASNETI_MYTHREAD;
if (mythread->sd_is_init) {
GASNETI_INIT_MAGIC(&mythread->request_sd, GASNETI_AM_SRCDESC_BAD_MAGIC);
GASNETI_INIT_MAGIC(&mythread->reply_sd, GASNETI_AM_SRCDESC_BAD_MAGIC);
}
}
#endif // GASNET_DEBUG
#endif // _GEX_AM_SRCDESC_T
#if GASNETC_BUILD_NP_REQ_MEDIUM
extern gex_AM_SrcDesc_t gasnetc_AM_PrepareRequestMedium(
gex_TM_t tm,
gex_Rank_t rank,
const void *client_buf,
size_t least_payload,
size_t most_payload,
gex_Event_t *lc_opt,
gex_Flags_t flags
GASNETI_THREAD_FARG,
unsigned int nargs)
{
GASNETI_TRACE_PREP_REQUESTMEDIUM(tm,rank,client_buf,least_payload,most_payload,flags,nargs);
gex_Rank_t jobrank = gasneti_e_tm_rank_to_jobrank(tm, rank);
// Ensure at least one poll upon Request injection (exactly one if possible)
#if GASNETC_REQUESTV_POLLS // Conduit's Request{Medium,Long}V will AMPoll in Commit
if (GASNETI_NBRHD_JOBRANK_IS_LOCAL(jobrank)) GASNETC_IMMEDIATE_MAYBE_POLL(flags);
#else
GASNETC_IMMEDIATE_MAYBE_POLL(flags);
#endif
gasneti_AM_SrcDesc_t sd = gasneti_init_request_srcdesc(GASNETI_THREAD_PASS_ALONE);
GASNETI_COMMON_PREP_REQ(sd,tm,rank,client_buf,least_payload,most_payload,NULL,lc_opt,flags,nargs,Medium);
flags &= ~(GEX_FLAG_AM_PREPARE_LEAST_CLIENT | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
if (GASNETI_NBRHD_JOBRANK_IS_LOCAL(jobrank)) {
sd = gasnetc_nbrhd_PrepareRequest(sd, gasneti_Medium, jobrank,
client_buf, least_payload, most_payload,
NULL, lc_opt, flags, nargs);
} else {
// In reference implementation, GEX_FLAG_AM_PREPARE_LEAST_ALLOC is also the MAX we allocate
gex_Flags_t limit_flags = client_buf ? flags : (flags | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
size_t limit = gex_AM_MaxRequestMedium(tm, rank, lc_opt, limit_flags, nargs);
size_t size = MIN(most_payload, limit);
sd->_tofree = gasneti_prepare_request_common(sd, tm, rank, client_buf, size, lc_opt, flags, nargs);
gasneti_init_sd_poison(sd);
}
GASNETI_TRACE_PREP_RETURN(REQUEST_MEDIUM, sd);
GASNETI_CHECK_SD(client_buf, least_payload, most_payload, sd);
return gasneti_export_srcdesc(sd);
}
#endif // GASNETC_BUILD_NP_REQ_MEDIUM
#if GASNETC_BUILD_NP_REP_MEDIUM
extern gex_AM_SrcDesc_t gasnetc_AM_PrepareReplyMedium(
gex_Token_t token,
const void *client_buf,
size_t least_payload,
size_t most_payload,
gex_Event_t *lc_opt,
gex_Flags_t flags,
unsigned int nargs)
{
GASNETI_TRACE_PREP_REPLYMEDIUM(token,client_buf,least_payload,most_payload,flags,nargs);
gasneti_AM_SrcDesc_t sd;
flags &= ~(GEX_FLAG_AM_PREPARE_LEAST_CLIENT | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
if (gasnetc_token_in_nbrhd(token)) {
sd = gasnetc_nbrhd_PrepareReply(gasneti_Medium, token,
client_buf, least_payload, most_payload,
NULL, lc_opt, flags, nargs);
} else {
GASNET_BEGIN_FUNCTION(); // conduit-specialization should post from token instead
sd = gasneti_init_reply_srcdesc(GASNETI_THREAD_PASS_ALONE);
GASNETI_COMMON_PREP_REP(sd,token,client_buf,least_payload,most_payload,NULL,lc_opt,flags,nargs,Medium);
// In reference implementation, GEX_FLAG_AM_PREPARE_LEAST_ALLOC is also the MAX we allocate
gex_Flags_t limit_flags = client_buf ? flags : (flags | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
size_t limit = gex_Token_MaxReplyMedium(token, lc_opt, limit_flags, nargs);
size_t size = MIN(most_payload, limit);
sd->_tofree = gasneti_prepare_reply_common(sd, token, client_buf, size, lc_opt, flags, nargs);
gasneti_init_sd_poison(sd);
}
GASNETI_TRACE_PREP_RETURN(REPLY_MEDIUM, sd);
GASNETI_CHECK_SD(client_buf, least_payload, most_payload, sd);
return gasneti_export_srcdesc(sd);
}
#endif // GASNETC_BUILD_NP_REP_MEDIUM
#if GASNETC_BUILD_NP_REQ_LONG
extern gex_AM_SrcDesc_t gasnetc_AM_PrepareRequestLong(
gex_TM_t tm,
gex_Rank_t rank,
const void *client_buf,
size_t least_payload,
size_t most_payload,
void *dest_addr,
gex_Event_t *lc_opt,
gex_Flags_t flags
GASNETI_THREAD_FARG,
unsigned int nargs)
{
GASNETI_TRACE_PREP_REQUESTLONG(tm,rank,client_buf,least_payload,most_payload,dest_addr,flags,nargs);
gex_Rank_t jobrank = gasneti_e_tm_rank_to_jobrank(tm, rank);
// Ensure at least one poll upon Request injection (exactly one if possible)
#if GASNETC_REQUESTV_POLLS // Conduit's Request{Medium,Long}V will AMPoll in Commit
if (GASNETI_NBRHD_JOBRANK_IS_LOCAL(jobrank)) GASNETC_IMMEDIATE_MAYBE_POLL(flags);
#else
GASNETC_IMMEDIATE_MAYBE_POLL(flags);
#endif
gasneti_AM_SrcDesc_t sd = gasneti_init_request_srcdesc(GASNETI_THREAD_PASS_ALONE);
GASNETI_COMMON_PREP_REQ(sd,tm,rank,client_buf,least_payload,most_payload,dest_addr,lc_opt,flags,nargs,Long);
flags &= ~(GEX_FLAG_AM_PREPARE_LEAST_CLIENT | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
if (GASNETI_NBRHD_JOBRANK_IS_LOCAL(jobrank)) {
sd = gasnetc_nbrhd_PrepareRequest(sd, gasneti_Long, jobrank,
client_buf, least_payload, most_payload,
dest_addr, lc_opt, flags, nargs);
} else {
// In reference implementation, GEX_FLAG_AM_PREPARE_LEAST_ALLOC is also the MAX we allocate
gex_Flags_t limit_flags = client_buf ? flags : (flags | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
size_t limit = gex_AM_MaxRequestLong(tm, rank, lc_opt, limit_flags, nargs);
size_t size = MIN(most_payload, limit);
sd->_tofree = gasneti_prepare_request_common(sd, tm, rank, client_buf, size, lc_opt, flags, nargs);
sd->_dest_addr = dest_addr;
gasneti_init_sd_poison(sd);
}
GASNETI_TRACE_PREP_RETURN(REQUEST_LONG, sd);
GASNETI_CHECK_SD(client_buf, least_payload, most_payload, sd);
return gasneti_export_srcdesc(sd);
}
#endif // GASNETC_BUILD_NP_REQ_LONG
#if GASNETC_BUILD_NP_REP_LONG
extern gex_AM_SrcDesc_t gasnetc_AM_PrepareReplyLong(
gex_Token_t token,
const void *client_buf,
size_t least_payload,
size_t most_payload,
void *dest_addr,
gex_Event_t *lc_opt,
gex_Flags_t flags,
unsigned int nargs)
{
GASNETI_TRACE_PREP_REPLYLONG(token,client_buf,least_payload,most_payload,dest_addr,flags,nargs);
gasneti_AM_SrcDesc_t sd;
flags &= ~(GEX_FLAG_AM_PREPARE_LEAST_CLIENT | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
if (gasnetc_token_in_nbrhd(token)) {
sd = gasnetc_nbrhd_PrepareReply(gasneti_Long, token,
client_buf, least_payload, most_payload,
dest_addr, lc_opt, flags, nargs);
} else {
GASNET_BEGIN_FUNCTION(); // conduit-specialization should post from token instead
sd = gasneti_init_reply_srcdesc(GASNETI_THREAD_PASS_ALONE);
GASNETI_COMMON_PREP_REP(sd,token,client_buf,least_payload,most_payload,dest_addr,lc_opt,flags,nargs,Long);
// In reference implementation, GEX_FLAG_AM_PREPARE_LEAST_ALLOC is also the MAX we allocate
gex_Flags_t limit_flags = client_buf ? flags : (flags | GEX_FLAG_AM_PREPARE_LEAST_ALLOC);
size_t limit = gex_Token_MaxReplyLong(token, lc_opt, limit_flags, nargs);
size_t size = MIN(most_payload, limit);
sd->_tofree = gasneti_prepare_reply_common(sd, token, client_buf, size, lc_opt, flags, nargs);
sd->_dest_addr = dest_addr;
gasneti_init_sd_poison(sd);
}
GASNETI_TRACE_PREP_RETURN(REPLY_LONG, sd);
GASNETI_CHECK_SD(client_buf, least_payload, most_payload, sd);
return gasneti_export_srcdesc(sd);
}
#endif // GASNETC_BUILD_NP_REP_LONG
#if GASNETC_BUILD_NP_REQ_MEDIUM
int gasnetc_AM_CommitRequestMediumM(
gex_AM_Index_t handler,
size_t nbytes,
gex_Flags_t commit_flags
GASNETI_THREAD_FARG,
#if GASNET_DEBUG
unsigned int nargs_arg,
#endif
gex_AM_SrcDesc_t sd_arg, ...)
{
// Conduit authors are cautioned against use of gasneti_consume_srcdesc() in native
// NPAM implementations. See the comment preceding its definition in gasnet_am.h.
gasneti_AM_SrcDesc_t sd = gasneti_consume_srcdesc(sd_arg);
GASNETI_COMMON_COMMIT_REQ(sd,handler,nbytes,NULL,commit_flags,nargs_arg,Medium);
int retval = GASNET_OK; // assume success
va_list argptr;
va_start(argptr, sd_arg);
if (sd->_is_nbrhd) {
gasnetc_nbrhd_CommitRequest(sd, gasneti_Medium, handler, nbytes, NULL, argptr);
} else { GASNET_POST_THREADINFO(GASNETI_THREAD_PASS_ALONE);
gex_TM_t tm = sd->_dest._request._tm;
gex_Rank_t rank = sd->_dest._request._rank;
void *src_addr = sd->_addr;
gex_Event_t *lc_opt = sd->_lc_opt ? sd->_lc_opt : /* GASNet-owned buffer: */ GEX_EVENT_NOW;
gex_Flags_t flags = (sd->_flags & ~(GEX_FLAG_IMMEDIATE |
GEX_FLAG_AM_PREPARE_LEAST_CLIENT |
GEX_FLAG_AM_PREPARE_LEAST_ALLOC))
| (commit_flags & GEX_FLAG_IMMEDIATE);
unsigned int nargs = sd->_nargs;
retval = gasneti_AMRequestMediumV(tm, rank, handler, src_addr, nbytes, lc_opt, flags, nargs, argptr);
if (retval) {
gasneti_assert(commit_flags & GEX_FLAG_IMMEDIATE); // only permissible reason to return non-zero
#if GASNET_DEBUG
GASNETI_INIT_MAGIC(sd, GASNETI_AM_SRCDESC_MAGIC); // reverse part of "consume"
#endif
} else if (sd->_tofree) {
gasneti_free_npam_buffer(sd);
}
}
va_end(argptr);
return retval;
}
#endif // GASNETC_BUILD_NP_REQ_MEDIUM
#if GASNETC_BUILD_NP_REP_MEDIUM
int gasnetc_AM_CommitReplyMediumM(
gex_AM_Index_t handler,
size_t nbytes,
gex_Flags_t commit_flags,
#if GASNET_DEBUG
unsigned int nargs_arg,
#endif
gex_AM_SrcDesc_t sd_arg, ...)
{
// Conduit authors are cautioned against use of gasneti_consume_srcdesc() in native
// NPAM implementations. See the comment preceding its definition in gasnet_am.h.
gasneti_AM_SrcDesc_t sd = gasneti_consume_srcdesc(sd_arg);
GASNETI_COMMON_COMMIT_REP(sd,handler,nbytes,NULL,commit_flags,nargs_arg,Medium);
int retval = GASNET_OK; // assume success
va_list argptr;
va_start(argptr, sd_arg);
if (sd->_is_nbrhd) {
gasnetc_nbrhd_CommitReply(sd, gasneti_Medium, handler, nbytes, NULL, argptr);
} else {
gex_Token_t token = sd->_dest._reply._token;
void *src_addr = sd->_addr;
gex_Event_t *lc_opt = sd->_lc_opt ? sd->_lc_opt : /* GASNet-owned buffer: */ GEX_EVENT_NOW;
gex_Flags_t flags = (sd->_flags & ~(GEX_FLAG_IMMEDIATE |
GEX_FLAG_AM_PREPARE_LEAST_CLIENT |
GEX_FLAG_AM_PREPARE_LEAST_ALLOC))
| (commit_flags & GEX_FLAG_IMMEDIATE);
unsigned int nargs = sd->_nargs;
retval = gasneti_AMReplyMediumV(token, handler, src_addr, nbytes, lc_opt, flags, nargs, argptr);
if (retval) {
gasneti_assert(commit_flags & GEX_FLAG_IMMEDIATE); // only permissible reason to return non-zero
#if GASNET_DEBUG
GASNETI_INIT_MAGIC(sd, GASNETI_AM_SRCDESC_MAGIC); // reverse part of "consume"
#endif
} else if (sd->_tofree) {
gasneti_free_npam_buffer(sd);
}
}
va_end(argptr);
return retval;
}
#endif // GASNETC_BUILD_NP_REP_MEDIUM
#if GASNETC_BUILD_NP_REQ_LONG
int gasnetc_AM_CommitRequestLongM(
gex_AM_Index_t handler,
size_t nbytes,
void *dest_addr,
gex_Flags_t commit_flags
GASNETI_THREAD_FARG,
#if GASNET_DEBUG
unsigned int nargs_arg,
#endif
gex_AM_SrcDesc_t sd_arg, ...)
{
// Conduit authors are cautioned against use of gasneti_consume_srcdesc() in native
// NPAM implementations. See the comment preceding its definition in gasnet_am.h.
gasneti_AM_SrcDesc_t sd = gasneti_consume_srcdesc(sd_arg);
GASNETI_COMMON_COMMIT_REQ(sd,handler,nbytes,dest_addr,commit_flags,nargs_arg,Long);
int retval = GASNET_OK; // assume success
va_list argptr;
va_start(argptr, sd_arg);
if (sd->_is_nbrhd) {
gasnetc_nbrhd_CommitRequest(sd, gasneti_Long, handler, nbytes, dest_addr, argptr);
} else { GASNET_POST_THREADINFO(GASNETI_THREAD_PASS_ALONE);
gex_TM_t tm = sd->_dest._request._tm;
gex_Rank_t rank = sd->_dest._request._rank;
void *src_addr = sd->_addr;
gex_Event_t *lc_opt = sd->_lc_opt ? sd->_lc_opt : /* GASNet-owned buffer: */ GEX_EVENT_NOW;
gex_Flags_t flags = (sd->_flags & ~(GEX_FLAG_IMMEDIATE |
GEX_FLAG_AM_PREPARE_LEAST_CLIENT |
GEX_FLAG_AM_PREPARE_LEAST_ALLOC))
| (commit_flags & GEX_FLAG_IMMEDIATE);
unsigned int nargs = sd->_nargs;
retval = gasneti_AMRequestLongV(tm, rank, handler, src_addr, nbytes, dest_addr, lc_opt, flags, nargs, argptr);
if (retval) {
gasneti_assert(commit_flags & GEX_FLAG_IMMEDIATE); // only permissible reason to return non-zero
#if GASNET_DEBUG
GASNETI_INIT_MAGIC(sd, GASNETI_AM_SRCDESC_MAGIC); // reverse part of "consume"
#endif
} else if (sd->_tofree) {
gasneti_free_npam_buffer(sd);
}
}
va_end(argptr);
return retval;
}
#endif // GASNETC_BUILD_NP_REQ_LONG
#if GASNETC_BUILD_NP_REP_LONG
int gasnetc_AM_CommitReplyLongM(
gex_AM_Index_t handler,
size_t nbytes,
void *dest_addr,
gex_Flags_t commit_flags,
#if GASNET_DEBUG
unsigned int nargs_arg,
#endif
gex_AM_SrcDesc_t sd_arg, ...)
{
// Conduit authors are cautioned against use of gasneti_consume_srcdesc() in native
// NPAM implementations. See the comment preceding its definition in gasnet_am.h.
gasneti_AM_SrcDesc_t sd = gasneti_consume_srcdesc(sd_arg);
GASNETI_COMMON_COMMIT_REP(sd,handler,nbytes,dest_addr,commit_flags,nargs_arg,Long);
int retval = GASNET_OK; // assume success
va_list argptr;
va_start(argptr, sd_arg);
if (sd->_is_nbrhd) {
gasnetc_nbrhd_CommitReply(sd, gasneti_Long, handler, nbytes, dest_addr, argptr);
} else {
gex_Token_t token = sd->_dest._reply._token;
void *src_addr = sd->_addr;
gex_Event_t *lc_opt = sd->_lc_opt ? sd->_lc_opt : /* GASNet-owned buffer: */ GEX_EVENT_NOW;
gex_Flags_t flags = (sd->_flags & ~(GEX_FLAG_IMMEDIATE |
GEX_FLAG_AM_PREPARE_LEAST_CLIENT |
GEX_FLAG_AM_PREPARE_LEAST_ALLOC))
| (commit_flags & GEX_FLAG_IMMEDIATE);
unsigned int nargs = sd->_nargs;
retval = gasneti_AMReplyLongV(token, handler, src_addr, nbytes, dest_addr, lc_opt, flags, nargs, argptr);
if (retval) {
gasneti_assert(commit_flags & GEX_FLAG_IMMEDIATE); // only permissible reason to return non-zero
#if GASNET_DEBUG
GASNETI_INIT_MAGIC(sd, GASNETI_AM_SRCDESC_MAGIC); // reverse part of "consume"
#endif
} else if (sd->_tofree) {
gasneti_free_npam_buffer(sd);
}
}
va_end(argptr);
return retval;
}
#endif // GASNETC_BUILD_NP_REP_LONG
#if GASNETC_BUILD_NP_REQ_MEDIUM
int gasnetc_AM_CancelRequestMedium(
gex_AM_SrcDesc_t sd_arg,
gex_Flags_t flags)
{
gasneti_AM_SrcDesc_t sd = gasneti_import_srcdesc(sd_arg);
GASNETI_COMMON_CANCEL_REQ(sd,flags,Medium);
if (sd->_is_nbrhd) {
gasnetc_nbrhd_CancelRequest(sd, gasneti_Medium, flags);
} else if (sd->_tofree) {
gasneti_free_npam_buffer(sd);
}
gasneti_reset_srcdesc(sd);
return GASNET_OK;
}
#endif // GASNETC_BUILD_NP_REQ_MEDIUM
#if GASNETC_BUILD_NP_REP_MEDIUM
int gasnetc_AM_CancelReplyMedium(
gex_AM_SrcDesc_t sd_arg,
gex_Flags_t flags)
{
gasneti_AM_SrcDesc_t sd = gasneti_import_srcdesc(sd_arg);