-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathofi_rma.h
1337 lines (1176 loc) · 57.5 KB
/
ofi_rma.h
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
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#ifndef OFI_RMA_H_INCLUDED
#define OFI_RMA_H_INCLUDED
#include "ofi_impl.h"
/*
=== BEGIN_MPI_T_CVAR_INFO_BLOCK ===
cvars:
- name : MPIR_CVAR_CH4_OFI_DISABLE_INJECT_WRITE
category : CH4_OFI
type : boolean
default : false
class : none
verbosity : MPI_T_VERBOSITY_USER_BASIC
scope : MPI_T_SCOPE_LOCAL
description : >-
Avoid use fi_inject_write. For some provider, e.g. tcp;ofi_rxm,
inject write may break the synchronization.
=== END_MPI_T_CVAR_INFO_BLOCK ===
*/
#define MPIDI_OFI_QUERY_ATOMIC_COUNT 0
#define MPIDI_OFI_QUERY_FETCH_ATOMIC_COUNT 1
#define MPIDI_OFI_QUERY_COMPARE_ATOMIC_COUNT 2
#define MPIDI_OFI_GET_BASIC_TYPE(a,b) \
do { \
if (MPIR_DATATYPE_IS_PREDEFINED(a)) \
b = a; \
else { \
MPIR_Datatype *dt_ptr; \
MPIR_Datatype_get_ptr(a,dt_ptr); \
MPIR_Assert(dt_ptr != NULL); \
b = dt_ptr->basic_type; \
} \
} while (0)
MPL_STATIC_INLINE_PREFIX int MPIDI_OFI_gpu_rma_enabled(const void *ptr)
{
if (ENABLE_GPU) {
MPL_pointer_attr_t attr;
MPIR_GPU_query_pointer_attr(ptr, &attr);
if (MPL_gpu_attr_is_dev(&attr)) {
if (MPIDI_OFI_ENABLE_HMEM && MPL_gpu_attr_is_strict_dev(&attr)) {
return 1;
} else
return 0;
}
}
return 1;
}
MPL_STATIC_INLINE_PREFIX void MPIDI_OFI_query_acc_atomic_support(MPI_Datatype dt, int query_type,
MPI_Op op,
MPIR_Win * win,
MPIDI_winattr_t winattr,
enum fi_datatype *fi_dt,
enum fi_op *fi_op,
MPI_Aint * count,
MPI_Aint * dtsize)
{
MPIR_FUNC_ENTER;
int ret1 = MPIDI_OFI_datatype_to_ofi(dt, fi_dt);
int ret2 = MPIDI_OFI_op_to_ofi(op, fi_op);
if (ret1 == -1 || ret2 == -1) {
*count = 0;
return;
}
int op_index, dt_index;
dt_index = (int) *fi_dt;
op_index = (int) *fi_op;
*dtsize = MPIDI_OFI_global.win_op_table[dt_index][op_index].dtsize;
switch (query_type) {
case MPIDI_OFI_QUERY_ATOMIC_COUNT:
*count = MPIDI_OFI_global.win_op_table[dt_index][op_index].max_atomic_count;
break;
case MPIDI_OFI_QUERY_FETCH_ATOMIC_COUNT:
*count = MPIDI_OFI_global.win_op_table[dt_index][op_index].max_fetch_atomic_count;
break;
case MPIDI_OFI_QUERY_COMPARE_ATOMIC_COUNT:
*count = MPIDI_OFI_global.win_op_table[dt_index][op_index].max_compare_atomic_count;
break;
default:
MPIR_Assert(query_type == MPIDI_OFI_QUERY_ATOMIC_COUNT ||
query_type == MPIDI_OFI_QUERY_FETCH_ATOMIC_COUNT ||
query_type == MPIDI_OFI_QUERY_COMPARE_ATOMIC_COUNT);
break;
}
/* If same_op_no_op is set, we also check other processes' atomic status.
* We have to always fallback to AM unless all possible reduce and cswap
* operations are supported by provider. This is because the noop process
* does not know what the same_op is on the other processes, which might be
* unsupported (e.g., maxloc). Thus, the noop process has to always use AM, and
* other processes have to also only use AM in order to ensure atomicity with
* atomic get. The user can use which_accumulate_ops hint to specify used reduce
* and cswap operations.
* We calculate the max count of all specified ops for each datatype at window
* creation or info set. dtypes_max_count[dt_index] is the provider allowed
* count for all possible ops. It is 0 if any of the op is not supported and
* is a positive value if all ops are supported.
* Current <datatype, op> can become hw atomic only when both local op and all
* possible remote op are atomic. */
/* We use the minimal max_count of local op and any possible remote op as the limit
* to validate dt_size in later check. We assume the limit should be symmetric on
* all processes as long as the hint correctly contains the local op.*/
MPIR_Assert(*count >= (size_t) MPIDI_OFI_WIN(win).acc_hint->dtypes_max_count[dt_index]);
if (winattr & MPIDI_WINATTR_ACCU_SAME_OP_NO_OP)
*count = (size_t) MPIDI_OFI_WIN(win).acc_hint->dtypes_max_count[dt_index];
MPL_DBG_MSG_FMT(MPIDI_CH4_DBG_GENERAL, VERBOSE,
(MPL_DBG_FDEST, "Query atomics support: max_count 0x%lx, dtsize 0x%lx", *count,
*dtsize));
MPIR_FUNC_EXIT;
}
MPL_STATIC_INLINE_PREFIX bool MPIDI_OFI_prepare_target_mr(int target_rank,
MPI_Aint target_disp,
MPI_Aint target_extent,
MPI_Aint target_true_lb, MPIR_Win * win,
MPIDI_winattr_t winattr,
MPIDI_OFI_target_mr_t * target_mr)
{
size_t offset;
if (winattr & MPIDI_WINATTR_NM_DYNAMIC_MR) {
/* Special path for dynamic window with per-attach memory registration. */
offset = target_disp; /* dynamic win is always with disp_unit=1 */
uint64_t target_addr = (uintptr_t) MPI_BOTTOM + offset;
/* Return valid node only when [target_addr:target_extent] matches within a
* single region. If it crosses two regions, NULL is returned. */
void *target_mr_found =
MPL_gavl_tree_search(MPIDI_OFI_WIN(win).dwin_target_mrs[target_rank],
(const void *) (uintptr_t) target_addr, target_extent);
MPL_DBG_MSG_FMT(MPIDI_CH4_DBG_GENERAL, VERBOSE,
(MPL_DBG_FDEST, "target_mr found %d addr 0x%" PRIx64 ", extent 0x%lx",
target_mr_found ? 1 : 0, target_addr, target_extent));
if (target_mr_found) {
if (MPIDI_OFI_ENABLE_MR_VIRT_ADDRESS) {
target_mr->addr = target_addr;
} else {
/* Unlikely hit this path. It happens only when provider is without
* FI_VIRT_ADDRESS but fails to register MPI_BOTTOM at win creation time */
target_mr->addr = target_addr - ((MPIDI_OFI_target_mr_t *) target_mr_found)->addr;
}
target_mr->mr_key = ((MPIDI_OFI_target_mr_t *) target_mr_found)->mr_key;
return true;
} else {
return false;
}
} else {
offset = target_disp * MPIDI_OFI_winfo_disp_unit(win, target_rank);
target_mr->addr = MPIDI_OFI_winfo_base(win, target_rank) + offset;
target_mr->mr_key = MPIDI_OFI_winfo_mr_key(win, target_rank);
return true; /* always found */
}
}
MPL_STATIC_INLINE_PREFIX int MPIDI_OFI_do_put(const void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count,
MPI_Datatype target_datatype,
MPIR_Win * win, MPIDI_av_entry_t * addr,
MPIDI_winattr_t winattr, MPIR_Request ** sigreq)
{
int mpi_errno = MPI_SUCCESS;
uint64_t flags;
struct fi_msg_rma msg;
int target_contig, origin_contig;
MPI_Aint target_bytes, origin_bytes, target_extent;
MPI_Aint origin_true_lb, target_true_lb;
struct iovec iov;
struct fi_rma_iov riov;
int nic_target = MPIDI_OFI_get_pref_nic(win->comm_ptr, target_rank);
MPIR_FUNC_ENTER;
MPIDIG_RMA_OP_CHECK_SYNC(target_rank, win);
MPIDI_Datatype_check_contig_size_lb(origin_datatype, origin_count, origin_contig,
origin_bytes, origin_true_lb);
MPIDI_Datatype_check_contig_size_extent_lb(target_datatype, target_count, target_contig,
target_bytes, target_extent, target_true_lb);
int vci = MPIDI_WIN(win, am_vci);
int vci_target = MPIDI_WIN_TARGET_VCI(win, target_rank);
/* zero-byte messages */
if (unlikely(origin_bytes == 0))
goto null_op_exit;
/* self messages */
if (target_rank == MPIDIU_win_comm_rank(win, winattr)) {
MPI_Aint offset = target_disp * MPIDI_OFI_winfo_disp_unit(win, target_rank);
mpi_errno = MPIR_Localcopy(origin_addr,
origin_count,
origin_datatype,
(char *) win->base + offset, target_count, target_datatype);
goto null_op_exit;
}
/* determine preferred physical NIC number for the rank */
MPIDI_OFI_nic_info_t *nics = MPIDI_OFI_global.nic_info;
MPIR_T_PVAR_COUNTER_INC(MULTINIC, rma_pref_phy_nic_put_bytes_count[nics[nic_target].id],
target_bytes);
/* prepare remote addr and mr key.
* Continue native path only when all segments are in the same registered memory region */
bool target_mr_found;
MPIDI_OFI_target_mr_t target_mr;
target_mr_found = MPIDI_OFI_prepare_target_mr(target_rank,
target_disp, target_extent, target_true_lb,
win, winattr, &target_mr);
if (unlikely(!target_mr_found))
goto am_fallback;
void *origin_ptr = MPIR_get_contig_ptr(origin_addr, origin_true_lb);
MPL_pointer_attr_t attr;
MPIR_GPU_query_pointer_attr(origin_ptr, &attr);
/* small contiguous messages */
/* skip fi_inject path for GPU messages because this path can be
* very slow */
if (origin_contig && target_contig &&
(origin_bytes <= MPIDI_OFI_global.max_buffered_write && !MPL_gpu_attr_is_dev(&attr))) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
MPIDI_OFI_win_cntr_incr(win);
MPIDI_OFI_CALL_RETRY(fi_inject_write(MPIDI_OFI_WIN(win).ep,
MPIR_get_contig_ptr(origin_addr, origin_true_lb),
target_bytes,
MPIDI_OFI_av_to_phys(addr, nic_target, vci_target),
target_mr.addr + target_true_lb,
target_mr.mr_key), vci, rdma_inject_write);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto null_op_exit;
}
/* large contiguous messages */
if (origin_contig && target_contig) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
if (sigreq) {
MPIDI_OFI_REQUEST_CREATE(*sigreq, MPIR_REQUEST_KIND__RMA, 0);
flags = FI_COMPLETION | FI_DELIVERY_COMPLETE;
} else {
flags = FI_DELIVERY_COMPLETE;
}
iov.iov_base = MPIR_get_contig_ptr(origin_addr, origin_true_lb);
iov.iov_len = target_bytes;
void *desc = NULL;
if (MPL_gpu_attr_is_strict_dev(&attr))
MPIDI_OFI_gpu_rma_register(iov.iov_base, iov.iov_len, &attr, win, nic_target, &desc);
msg.desc = desc;
msg.addr = MPIDI_OFI_av_to_phys(addr, nic_target, vci_target);
msg.context = NULL;
msg.data = 0;
msg.msg_iov = &iov;
msg.iov_count = 1;
msg.rma_iov = &riov;
msg.rma_iov_count = 1;
riov.addr = target_mr.addr + target_true_lb;
riov.len = target_bytes;
riov.key = target_mr.mr_key;
MPIDI_OFI_INIT_CHUNK_CONTEXT(win, sigreq);
MPIDI_OFI_CALL_RETRY(fi_writemsg(MPIDI_OFI_WIN(win).ep, &msg, flags), vci, rdma_write);
/* Complete signal request to inform completion to user. */
MPIDI_OFI_sigreq_complete(sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
/* noncontiguous messages */
MPI_Aint origin_density, target_density;
MPIR_Datatype_get_density(origin_datatype, origin_density);
MPIR_Datatype_get_density(target_datatype, target_density);
if (origin_density >= MPIR_CVAR_CH4_IOV_DENSITY_MIN &&
target_density >= MPIR_CVAR_CH4_IOV_DENSITY_MIN) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
mpi_errno =
MPIDI_OFI_nopack_putget(origin_addr, origin_count, origin_datatype, target_rank,
target_count, target_datatype, target_mr, win, addr,
MPIDI_OFI_PUT, sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
if (origin_density < MPIR_CVAR_CH4_IOV_DENSITY_MIN &&
target_density >= MPIR_CVAR_CH4_IOV_DENSITY_MIN) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
mpi_errno =
MPIDI_OFI_pack_put(origin_addr, origin_count, origin_datatype, target_rank,
target_count, target_datatype, target_mr, win, addr, sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
am_fallback:
if (sigreq)
mpi_errno =
MPIDIG_mpi_rput(origin_addr, origin_count, origin_datatype, target_rank, target_disp,
target_count, target_datatype, win, sigreq);
else
mpi_errno =
MPIDIG_mpi_put(origin_addr, origin_count, origin_datatype, target_rank, target_disp,
target_count, target_datatype, win);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
fn_fail:
goto fn_exit;
null_op_exit:
mpi_errno = MPI_SUCCESS;
if (sigreq)
*sigreq = MPIR_Request_create_complete(MPIR_REQUEST_KIND__RMA);
goto fn_exit;
}
MPL_STATIC_INLINE_PREFIX int MPIDI_NM_mpi_put(const void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count, MPI_Datatype target_datatype,
MPIR_Win * win, MPIDI_av_entry_t * av,
MPIDI_winattr_t winattr)
{
MPIR_FUNC_ENTER;
int mpi_errno = MPI_SUCCESS;
if (!MPIDI_OFI_ENABLE_RMA || !(winattr & MPIDI_WINATTR_NM_REACHABLE) ||
!MPIDI_OFI_gpu_rma_enabled(origin_addr)) {
MPIDI_OFI_register_am_bufs();
mpi_errno = MPIDIG_mpi_put(origin_addr, origin_count, origin_datatype, target_rank,
target_disp, target_count, target_datatype, win);
goto fn_exit;
}
mpi_errno = MPIDI_OFI_do_put(origin_addr,
origin_count,
origin_datatype,
target_rank,
target_disp, target_count, target_datatype, win, av,
winattr, NULL);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
}
MPL_STATIC_INLINE_PREFIX int MPIDI_OFI_do_get(void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count,
MPI_Datatype target_datatype,
MPIR_Win * win, MPIDI_av_entry_t * addr,
MPIDI_winattr_t winattr, MPIR_Request ** sigreq)
{
int mpi_errno = MPI_SUCCESS;
uint64_t flags;
struct fi_msg_rma msg;
int origin_contig, target_contig;
MPI_Aint origin_true_lb, target_true_lb;
MPI_Aint target_bytes, target_extent;
struct fi_rma_iov riov;
struct iovec iov;
int nic_target = MPIDI_OFI_get_pref_nic(win->comm_ptr, target_rank);
MPIR_FUNC_ENTER;
MPIDIG_RMA_OP_CHECK_SYNC(target_rank, win);
MPIDI_Datatype_check_contig_lb(origin_datatype, origin_contig, origin_true_lb);
MPIDI_Datatype_check_contig_size_extent_lb(target_datatype, target_count, target_contig,
target_bytes, target_extent, target_true_lb);
int vci = MPIDI_WIN(win, am_vci);
int vci_target = MPIDI_WIN_TARGET_VCI(win, target_rank);
/* zero-byte messages */
if (unlikely(target_bytes == 0))
goto null_op_exit;
/* self messages */
if (target_rank == MPIDIU_win_comm_rank(win, winattr)) {
MPI_Aint offset = target_disp * MPIDI_OFI_winfo_disp_unit(win, target_rank);
mpi_errno = MPIR_Localcopy((char *) win->base + offset,
target_count,
target_datatype, origin_addr, origin_count, origin_datatype);
goto null_op_exit;
}
/* determine preferred physical NIC number for the rank */
MPIDI_OFI_nic_info_t *nics = MPIDI_OFI_global.nic_info;
MPIR_T_PVAR_COUNTER_INC(MULTINIC, rma_pref_phy_nic_get_bytes_count[nics[nic_target].id],
target_bytes);
/* prepare remote addr and mr key.
* Continue native path only when all segments are in the same registered memory region */
bool target_mr_found;
MPIDI_OFI_target_mr_t target_mr;
target_mr_found = MPIDI_OFI_prepare_target_mr(target_rank,
target_disp, target_extent, target_true_lb,
win, winattr, &target_mr);
if (unlikely(!target_mr_found))
goto am_fallback;
/* contiguous messages */
if (origin_contig && target_contig) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
if (sigreq) {
MPIDI_OFI_REQUEST_CREATE(*sigreq, MPIR_REQUEST_KIND__RMA, 0);
flags = FI_COMPLETION | FI_DELIVERY_COMPLETE;
} else {
flags = 0;
}
iov.iov_base = MPIR_get_contig_ptr(origin_addr, origin_true_lb);
iov.iov_len = target_bytes;
void *desc = NULL;
MPL_pointer_attr_t attr;
MPIR_GPU_query_pointer_attr(iov.iov_base, &attr);
if (MPL_gpu_attr_is_strict_dev(&attr))
MPIDI_OFI_gpu_rma_register(iov.iov_base, iov.iov_len, NULL, win, nic_target, &desc);
msg.desc = desc;
msg.msg_iov = &iov;
msg.iov_count = 1;
msg.addr = MPIDI_OFI_av_to_phys(addr, nic_target, vci_target);
msg.rma_iov = &riov;
msg.rma_iov_count = 1;
msg.context = NULL;
msg.data = 0;
riov.addr = target_mr.addr + target_true_lb;
riov.len = target_bytes;
riov.key = target_mr.mr_key;
MPIDI_OFI_INIT_CHUNK_CONTEXT(win, sigreq);
MPIDI_OFI_CALL_RETRY(fi_readmsg(MPIDI_OFI_WIN(win).ep, &msg, flags), vci, rdma_write);
/* Complete signal request to inform completion to user. */
MPIDI_OFI_sigreq_complete(sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
/* noncontiguous messages */
MPI_Aint origin_density, target_density;
MPIR_Datatype_get_density(origin_datatype, origin_density);
MPIR_Datatype_get_density(target_datatype, target_density);
if (origin_density >= MPIR_CVAR_CH4_IOV_DENSITY_MIN &&
target_density >= MPIR_CVAR_CH4_IOV_DENSITY_MIN) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
mpi_errno =
MPIDI_OFI_nopack_putget(origin_addr, origin_count, origin_datatype, target_rank,
target_count, target_datatype, target_mr, win, addr,
MPIDI_OFI_GET, sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
if (origin_density < MPIR_CVAR_CH4_IOV_DENSITY_MIN &&
target_density >= MPIR_CVAR_CH4_IOV_DENSITY_MIN) {
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
mpi_errno =
MPIDI_OFI_pack_get(origin_addr, origin_count, origin_datatype, target_rank,
target_count, target_datatype, target_mr, win, addr, sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
am_fallback:
if (sigreq)
mpi_errno =
MPIDIG_mpi_rget(origin_addr, origin_count, origin_datatype, target_rank, target_disp,
target_count, target_datatype, win, sigreq);
else
mpi_errno =
MPIDIG_mpi_get(origin_addr, origin_count, origin_datatype, target_rank, target_disp,
target_count, target_datatype, win);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
fn_fail:
goto fn_exit;
null_op_exit:
mpi_errno = MPI_SUCCESS;
if (sigreq)
*sigreq = MPIR_Request_create_complete(MPIR_REQUEST_KIND__RMA);
goto fn_exit;
}
MPL_STATIC_INLINE_PREFIX int MPIDI_NM_mpi_get(void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count, MPI_Datatype target_datatype,
MPIR_Win * win, MPIDI_av_entry_t * av,
MPIDI_winattr_t winattr)
{
int mpi_errno = MPI_SUCCESS;
MPIR_FUNC_ENTER;
if (!MPIDI_OFI_ENABLE_RMA || !(winattr & MPIDI_WINATTR_NM_REACHABLE) ||
!MPIDI_OFI_gpu_rma_enabled(origin_addr)) {
MPIDI_OFI_register_am_bufs();
mpi_errno = MPIDIG_mpi_get(origin_addr, origin_count, origin_datatype, target_rank,
target_disp, target_count, target_datatype, win);
goto fn_exit;
}
mpi_errno = MPIDI_OFI_do_get(origin_addr,
origin_count,
origin_datatype,
target_rank,
target_disp, target_count, target_datatype, win, av, winattr,
NULL);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
}
MPL_STATIC_INLINE_PREFIX int MPIDI_NM_mpi_rput(const void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count,
MPI_Datatype target_datatype,
MPIR_Win * win, MPIDI_av_entry_t * av,
MPIDI_winattr_t winattr, MPIR_Request ** request)
{
MPIR_FUNC_ENTER;
int mpi_errno = MPI_SUCCESS;
if (!MPIDI_OFI_ENABLE_RMA || !(winattr & MPIDI_WINATTR_NM_REACHABLE) ||
!MPIDI_OFI_gpu_rma_enabled(origin_addr)) {
MPIDI_OFI_register_am_bufs();
mpi_errno = MPIDIG_mpi_rput(origin_addr, origin_count, origin_datatype, target_rank,
target_disp, target_count, target_datatype, win, request);
goto fn_exit;
}
mpi_errno = MPIDI_OFI_do_put((void *) origin_addr,
origin_count,
origin_datatype,
target_rank,
target_disp, target_count, target_datatype, win, av, winattr,
request);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
}
MPL_STATIC_INLINE_PREFIX int MPIDI_NM_mpi_compare_and_swap(const void *origin_addr,
const void *compare_addr,
void *result_addr,
MPI_Datatype datatype,
int target_rank, MPI_Aint target_disp,
MPIR_Win * win, MPIDI_av_entry_t * av,
MPIDI_winattr_t winattr)
{
int mpi_errno = MPI_SUCCESS;
enum fi_op fi_op;
enum fi_datatype fi_dt;
MPI_Aint max_count, max_size, dt_size, bytes;
MPI_Aint true_lb;
void *buffer, *rbuffer;
struct fi_ioc originv;
struct fi_ioc resultv;
struct fi_ioc comparev;
struct fi_rma_ioc targetv;
struct fi_msg_atomic msg;
int nic_target = MPIDI_OFI_get_pref_nic(win->comm_ptr, target_rank);
int vci = MPIDI_WIN(win, am_vci);
int vci_target = MPIDI_WIN_TARGET_VCI(win, target_rank);
if (
#ifndef MPIDI_CH4_DIRECT_NETMOD
/* We have to disable network-based atomics in auto mode.
* Because concurrent atomics may be performed by CPU (e.g., op
* over shared memory, or op issues to process-self.
* If ACCU_NO_SHM is set, then all above ops are issued
* via network thus we can safely use network-based atomics. */
!(winattr & MPIDI_WINATTR_ACCU_NO_SHM) ||
#endif
!MPIDI_OFI_ENABLE_RMA || !MPIDI_OFI_ENABLE_ATOMICS ||
!(winattr & MPIDI_WINATTR_NM_REACHABLE) ||
!MPIDI_OFI_gpu_rma_enabled(origin_addr) ||
!MPIDI_OFI_gpu_rma_enabled(compare_addr) || !MPIDI_OFI_gpu_rma_enabled(result_addr)) {
MPIDI_OFI_register_am_bufs();
mpi_errno =
MPIDIG_mpi_compare_and_swap(origin_addr, compare_addr, result_addr, datatype,
target_rank, target_disp, win);
goto fn_exit;
}
MPIR_FUNC_ENTER;
MPIDIG_RMA_OP_CHECK_SYNC(target_rank, win);
MPIDI_Datatype_check_size_lb(datatype, 1, bytes, true_lb);
if (bytes == 0)
goto fn_exit;
/* prepare remote addr and mr key.
* Continue native path only when all segments are in the same registered memory region */
bool target_mr_found;
MPIDI_OFI_target_mr_t target_mr;
target_mr_found = MPIDI_OFI_prepare_target_mr(target_rank, target_disp, bytes, 0,
win, winattr, &target_mr);
if (unlikely(!target_mr_found))
goto am_fallback;
buffer = MPIR_get_contig_ptr(origin_addr, true_lb);
rbuffer = MPIR_get_contig_ptr(result_addr, true_lb);
MPIDI_OFI_query_acc_atomic_support(datatype, MPIDI_OFI_QUERY_COMPARE_ATOMIC_COUNT, MPI_OP_NULL,
win, winattr, &fi_dt, &fi_op, &max_count, &dt_size);
if (max_count == 0)
goto am_fallback;
max_size = MPIDI_OFI_check_acc_order_size(win, dt_size);
/* It's impossible to transfer data if buffer size is smaller than basic datatype size.
* TODO: we assume all processes should use the same max_size and dt_size, true ? */
if (max_size < dt_size)
goto am_fallback;
/* Ensure completion of outstanding AMs for atomicity. */
MPIDIG_wait_am_acc(win, target_rank);
originv.addr = (void *) buffer;
originv.count = 1;
resultv.addr = (void *) rbuffer;
resultv.count = 1;
comparev.addr = (void *) compare_addr;
comparev.count = 1;
targetv.addr = target_mr.addr;
targetv.count = 1;
targetv.key = target_mr.mr_key;
void *desc = NULL;
MPIDI_OFI_gpu_rma_register(originv.addr, dt_size, NULL, win, nic_target, &desc);
void *compare_desc = NULL;
MPIDI_OFI_gpu_rma_register(comparev.addr, dt_size, NULL, win, nic_target, &compare_desc);
void *result_desc = NULL;
MPIDI_OFI_gpu_rma_register(resultv.addr, dt_size, NULL, win, nic_target, &result_desc);
msg.msg_iov = &originv;
msg.desc = desc;
msg.iov_count = 1;
msg.addr = MPIDI_OFI_av_to_phys(av, nic_target, vci_target);
msg.rma_iov = &targetv;
msg.rma_iov_count = 1;
msg.datatype = fi_dt;
msg.op = fi_op;
msg.context = NULL;
msg.data = 0;
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
MPIDI_OFI_win_cntr_incr(win);
MPIDI_OFI_CALL_RETRY(fi_compare_atomicmsg(MPIDI_OFI_WIN(win).ep, &msg,
&comparev, compare_desc, 1, &resultv, result_desc, 1,
0), vci, atomicto);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
fn_fail:
goto fn_exit;
am_fallback:
/* Wait for OFI case to complete for atomicity.
* For now, there is no FI flag to track atomic only ops, we use RMA level cntr. */
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
MPIDI_OFI_win_do_progress(win, vci);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
return MPIDIG_mpi_compare_and_swap(origin_addr, compare_addr, result_addr, datatype,
target_rank, target_disp, win);
}
MPL_STATIC_INLINE_PREFIX int MPIDI_OFI_do_accumulate(const void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count,
MPI_Datatype target_datatype,
MPI_Op op, MPIR_Win * win,
MPIDI_av_entry_t * addr,
MPIDI_winattr_t winattr,
MPIR_Request ** sigreq)
{
int mpi_errno = MPI_SUCCESS;
int target_contig, origin_contig;
MPI_Aint target_bytes, origin_bytes, target_extent;
MPI_Aint origin_true_lb, target_true_lb;
int nic_target = MPIDI_OFI_get_pref_nic(win->comm_ptr, target_rank);
MPIR_FUNC_ENTER;
MPIDIG_RMA_OP_CHECK_SYNC(target_rank, win);
MPIDI_Datatype_check_contig_size_lb(origin_datatype, origin_count, origin_contig,
origin_bytes, origin_true_lb);
MPIDI_Datatype_check_contig_size_extent_lb(target_datatype, target_count, target_contig,
target_bytes, target_extent, target_true_lb);
if (origin_bytes == 0)
goto null_op_exit;
int vci = MPIDI_WIN(win, am_vci);
int vci_target = MPIDI_WIN_TARGET_VCI(win, target_rank);
/* prepare remote addr and mr key.
* Continue native path only when all segments are in the same registered memory region */
bool target_mr_found;
MPIDI_OFI_target_mr_t target_mr;
target_mr_found = MPIDI_OFI_prepare_target_mr(target_rank,
target_disp, target_extent, target_true_lb,
win, winattr, &target_mr);
if (unlikely(!target_mr_found))
goto am_fallback;
/* contiguous messages */
if (origin_contig && target_contig) {
MPI_Datatype basic_type;
enum fi_op fi_op;
enum fi_datatype fi_dt;
MPI_Aint max_count, max_size, dt_size, basic_count;
/* accept only same predefined basic datatype */
MPIDI_OFI_GET_BASIC_TYPE(target_datatype, basic_type);
MPIR_Assert(basic_type != MPI_DATATYPE_NULL);
/* query atomics max count support */
MPIDI_OFI_query_acc_atomic_support(basic_type, MPIDI_OFI_QUERY_ATOMIC_COUNT,
op, win, winattr, &fi_dt, &fi_op, &max_count, &dt_size);
if (max_count == 0)
goto am_fallback;
/* query ordering max size support */
max_size = MPIDI_OFI_check_acc_order_size(win, max_count * dt_size);
max_size = MPL_MIN(max_size, MPIDI_OFI_global.max_msg_size);
/* fall back to active message if cannot send all data in one message */
if (max_size < target_bytes)
goto am_fallback;
basic_count = target_bytes / dt_size;
MPIR_Assert(target_bytes % dt_size == 0);
/* Ensure completion of outstanding AMs for atomicity. */
MPIDIG_wait_am_acc(win, target_rank);
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
uint64_t flags;
if (sigreq) {
MPIDI_OFI_REQUEST_CREATE(*sigreq, MPIR_REQUEST_KIND__RMA, 0);
flags = FI_COMPLETION | FI_DELIVERY_COMPLETE;
} else {
flags = FI_DELIVERY_COMPLETE;
}
struct fi_ioc originv;
struct fi_rma_ioc targetv;
struct fi_msg_atomic msg;
originv.addr = MPIR_get_contig_ptr(origin_addr, origin_true_lb);
originv.count = basic_count;
targetv.addr = target_mr.addr + target_true_lb;
targetv.count = basic_count;
targetv.key = target_mr.mr_key;
void *desc = NULL;
MPIDI_OFI_gpu_rma_register(originv.addr, dt_size * basic_count, NULL, win, nic_target,
&desc);
msg.msg_iov = &originv;
msg.desc = desc;
msg.iov_count = 1;
msg.addr = MPIDI_OFI_av_to_phys(addr, nic_target, vci_target);
msg.rma_iov = &targetv;
msg.rma_iov_count = 1;
msg.datatype = fi_dt;
msg.op = fi_op;
msg.context = NULL;
msg.data = 0;
MPIDI_OFI_INIT_CHUNK_CONTEXT(win, sigreq);
MPIDI_OFI_CALL_RETRY(fi_atomicmsg(MPIDI_OFI_WIN(win).ep, &msg, flags), vci, rdma_atomicto);
/* Complete signal request to inform completion to user. */
MPIDI_OFI_sigreq_complete(sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
am_fallback:
/* Wait for OFI acc to complete for atomicity.
* For now, there is no FI flag to track atomic only ops, we use RMA level cntr. */
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
MPIDI_OFI_win_do_progress(win, vci);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
if (sigreq)
mpi_errno = MPIDIG_mpi_raccumulate(origin_addr, origin_count, origin_datatype, target_rank,
target_disp, target_count, target_datatype, op, win,
sigreq);
else
mpi_errno = MPIDIG_mpi_accumulate(origin_addr, origin_count, origin_datatype, target_rank,
target_disp, target_count, target_datatype, op, win);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
fn_fail:
goto fn_exit;
null_op_exit:
mpi_errno = MPI_SUCCESS;
if (sigreq)
*sigreq = MPIR_Request_create_complete(MPIR_REQUEST_KIND__RMA);
goto fn_exit;
}
MPL_STATIC_INLINE_PREFIX int MPIDI_OFI_do_get_accumulate(const void *origin_addr,
MPI_Aint origin_count,
MPI_Datatype origin_datatype,
void *result_addr,
MPI_Aint result_count,
MPI_Datatype result_datatype,
int target_rank,
MPI_Aint target_disp,
MPI_Aint target_count,
MPI_Datatype target_datatype,
MPI_Op op, MPIR_Win * win,
MPIDI_av_entry_t * addr,
MPIDI_winattr_t winattr,
MPIR_Request ** sigreq)
{
int mpi_errno = MPI_SUCCESS;
int target_contig, origin_contig, result_contig;
MPI_Aint target_bytes, target_extent;
MPI_Aint origin_true_lb, target_true_lb, result_true_lb;
int nic_target = MPIDI_OFI_get_pref_nic(win->comm_ptr, target_rank);
MPIR_FUNC_ENTER;
MPIDIG_RMA_OP_CHECK_SYNC(target_rank, win);
MPIDI_Datatype_check_contig_lb(origin_datatype, origin_contig, origin_true_lb);
MPIDI_Datatype_check_contig_lb(result_datatype, result_contig, result_true_lb);
MPIDI_Datatype_check_contig_size_extent_lb(target_datatype, target_count, target_contig,
target_bytes, target_extent, target_true_lb);
if (target_bytes == 0)
goto null_op_exit;
int vci = MPIDI_WIN(win, am_vci);
int vci_target = MPIDI_WIN_TARGET_VCI(win, target_rank);
/* contiguous messages */
if (origin_contig && target_contig && result_contig) {
/* prepare remote addr and mr key.
* Continue native path only when all segments are in the same registered memory region */
bool target_mr_found;
MPIDI_OFI_target_mr_t target_mr;
target_mr_found = MPIDI_OFI_prepare_target_mr(target_rank,
target_disp, target_extent, target_true_lb,
win, winattr, &target_mr);
if (unlikely(!target_mr_found))
goto am_fallback;
MPI_Datatype basic_type;
enum fi_op fi_op;
enum fi_datatype fi_dt;
MPI_Aint max_count, max_size, dt_size, basic_count;
/* accept only same predefined basic datatype */
MPIDI_OFI_GET_BASIC_TYPE(target_datatype, basic_type);
MPIR_Assert(basic_type != MPI_DATATYPE_NULL);
/* query atomics max count support */
MPIDI_OFI_query_acc_atomic_support(basic_type, MPIDI_OFI_QUERY_FETCH_ATOMIC_COUNT,
op, win, winattr, &fi_dt, &fi_op, &max_count, &dt_size);
if (max_count == 0)
goto am_fallback;
/* query ordering max size support */
max_size = MPIDI_OFI_check_acc_order_size(win, max_count * dt_size);
max_size = MPL_MIN(max_size, MPIDI_OFI_global.max_msg_size);
/* fall back to active message if cannot send all data in one message */
if (max_size < target_bytes)
goto am_fallback;
basic_count = target_bytes / dt_size;
MPIR_Assert(target_bytes % dt_size == 0);
/* Ensure completion of outstanding AMs for atomicity. */
MPIDIG_wait_am_acc(win, target_rank);
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
uint64_t flags;
if (sigreq) {
MPIDI_OFI_REQUEST_CREATE(*sigreq, MPIR_REQUEST_KIND__RMA, 0);
flags = FI_COMPLETION | FI_DELIVERY_COMPLETE;
} else {
flags = FI_DELIVERY_COMPLETE;
}
struct fi_ioc originv, resultv;
struct fi_rma_ioc targetv;
struct fi_msg_atomic msg;
originv.addr = MPIR_get_contig_ptr(origin_addr, origin_true_lb);
originv.count = basic_count;
resultv.addr = MPIR_get_contig_ptr(result_addr, result_true_lb);
resultv.count = basic_count;
targetv.addr = target_mr.addr + target_true_lb;
targetv.count = basic_count;
targetv.key = target_mr.mr_key;
void *desc = NULL;
MPIDI_OFI_gpu_rma_register(originv.addr, dt_size * basic_count, NULL, win, nic_target,
&desc);
void *result_desc = NULL;
MPIDI_OFI_gpu_rma_register(resultv.addr, dt_size * basic_count, NULL, win, nic_target,
&result_desc);
msg.msg_iov = &originv;
msg.desc = desc;
msg.iov_count = 1;
msg.addr = MPIDI_OFI_av_to_phys(addr, nic_target, vci_target);
msg.rma_iov = &targetv;
msg.rma_iov_count = 1;
msg.datatype = fi_dt;
msg.op = fi_op;
msg.context = NULL;
msg.data = 0;
MPIDI_OFI_INIT_CHUNK_CONTEXT(win, sigreq);
MPIDI_OFI_CALL_RETRY(fi_fetch_atomicmsg(MPIDI_OFI_WIN(win).ep, &msg, &resultv,
result_desc, 1, flags), vci, rdma_readfrom);
/* Complete signal request to inform completion to user. */
MPIDI_OFI_sigreq_complete(sigreq);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
goto fn_exit;
}
am_fallback:
/* Wait for OFI getacc to complete for atomicity.
* For now, there is no FI flag to track atomic only ops, we use RMA level cntr. */
MPID_THREAD_CS_ENTER(VCI, MPIDI_VCI(vci).lock);
MPIDI_OFI_win_do_progress(win, vci);
MPID_THREAD_CS_EXIT(VCI, MPIDI_VCI(vci).lock);
if (sigreq)
mpi_errno =
MPIDIG_mpi_rget_accumulate(origin_addr, origin_count, origin_datatype, result_addr,
result_count, result_datatype, target_rank, target_disp,
target_count, target_datatype, op, win, sigreq);
else
mpi_errno =
MPIDIG_mpi_get_accumulate(origin_addr, origin_count, origin_datatype, result_addr,
result_count, result_datatype, target_rank, target_disp,
target_count, target_datatype, op, win);
fn_exit:
MPIR_FUNC_EXIT;
return mpi_errno;
fn_fail:
goto fn_exit;
null_op_exit:
mpi_errno = MPI_SUCCESS;
if (sigreq) {
*sigreq = MPIR_Request_create_complete(MPIR_REQUEST_KIND__RMA);
}
goto fn_exit;
}