-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathselect.c
More file actions
2974 lines (2599 loc) · 124 KB
/
Copy pathselect.c
File metadata and controls
2974 lines (2599 loc) · 124 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
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2026. ALL RIGHTS RESERVED.
* Copyright (C) Los Alamos National Security, LLC. 2019 ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "wireup.h"
#include "wireup_cm.h"
#include "address.h"
#include <ucs/algorithm/qsort_r.h>
#include <ucs/datastruct/array.h>
#include <ucs/datastruct/queue.h>
#include <ucs/sys/sock.h>
#include <ucp/core/ucp_ep.inl>
#include <string.h>
#include <inttypes.h>
#include <math.h>
#define UCP_WIREUP_RMA_BW_TEST_MSG_SIZE 262144
#define UCP_WIREUP_MAX_FLAGS_STRING_SIZE 50
#define UCP_WIREUP_PATH_INDEX_UNDEFINED UINT_MAX
#define UCP_WIREUP_SCORE_MAX_DIFF 0.02
#define UCP_WIREUP_NO_SCORE_TIEBREAK (-1.0)
/* 6 for the string format constant length */
#define UCP_WIREUP_TLS_INFO_SIZE (UCP_WIREUP_UCT_INFO_SIZE + \
UCT_TL_NAME_MAX + UCT_DEVICE_NAME_MAX + 6)
#define UCP_WIREUP_CHECK_AMO_FLAGS(_ae, _criteria, _context, _addr_index, _op, _size) \
if (!ucs_test_all_flags((_ae)->iface_attr.atomic.atomic##_size._op##_flags, \
(_criteria)->remote_atomic_flags.atomic##_size._op##_flags)) { \
char desc[256]; \
ucs_trace("addr[%d] %s: no %s", (_addr_index), \
ucp_find_tl_name_by_csum((_context), (_ae)->tl_name_csum), \
ucp_wireup_get_missing_amo_flag_desc_##_op( \
(_ae)->iface_attr.atomic.atomic##_size._op##_flags, \
(_criteria)->remote_atomic_flags.atomic##_size._op##_flags, \
(_size), desc, sizeof(desc))); \
continue; \
}
typedef struct ucp_wireup_atomic_flag {
const char *name;
const char *fetch;
} ucp_wireup_atomic_flag_t;
typedef struct {
ucp_rsc_index_t rsc_index;
unsigned addr_index;
unsigned path_index;
ucp_md_index_t dst_md_index;
ucs_sys_device_t dst_sys_dev;
ucp_lane_type_mask_t lane_types;
uint8_t port_speed;
size_t seg_size;
double score[UCP_LANE_TYPE_LAST];
} ucp_wireup_lane_desc_t;
typedef struct {
ucp_wireup_criteria_t criteria;
uint64_t local_dev_bitmap;
uint64_t remote_dev_bitmap;
unsigned max_lanes;
} ucp_wireup_select_bw_info_t;
typedef struct {
unsigned local[UCP_MAX_RESOURCES];
unsigned remote[UCP_MAX_RESOURCES];
unsigned local_skip[UCP_MAX_RESOURCES];
unsigned remote_skip[UCP_MAX_RESOURCES];
} ucp_wireup_dev_usage_count;
/**
* Global parameters for lanes selection during UCP wireup procedure
*/
typedef struct {
ucp_ep_h ep; /* UCP Endpoint */
unsigned ep_init_flags; /* Endpoint init flags */
ucp_tl_bitmap_t tl_bitmap; /* TLs bitmap which can be selected */
const ucp_unpacked_address_t *address; /* Remote addresses */
int allow_am; /* Shows whether emulation over AM
* is allowed or not for RMA/AMO */
int show_error; /* Global flag that controls showing
* errors from a selecting transport
* procedure */
} ucp_wireup_select_params_t;
/**
* Context for lanes selection during UCP wireup procedure
*/
typedef struct {
ucp_wireup_lane_desc_t lane_descs[UCP_MAX_LANES]; /* Array of active lanes that are
* found during selection */
ucp_lane_index_t num_lanes; /* Number of active lanes */
unsigned ucp_ep_init_flags; /* Endpoint init extra flags */
ucp_tl_bitmap_t tl_bitmap; /* TL bitmap of selected resources */
} ucp_wireup_select_context_t;
UCS_ARRAY_DECLARE_TYPE(ucp_proto_select_info_array_t, unsigned,
ucp_wireup_select_info_t);
static const char *ucp_wireup_cmpt_flags[] = {
[ucs_ilog2(UCT_COMPONENT_FLAG_RKEY_PTR)] = "obtain remote memory pointer",
};
static const char *ucp_wireup_md_flags[] = {
[ucs_ilog2(UCT_MD_FLAG_ALLOC)] = "memory allocation",
[ucs_ilog2(UCT_MD_FLAG_REG)] = "memory registration",
[ucs_ilog2(UCT_MD_FLAG_INVALIDATE)] = "memory invalidation",
[ucs_ilog2(UCT_MD_FLAG_INVALIDATE_RMA)] = "RMA memory invalidation"
};
static const char *ucp_wireup_iface_flags[] = {
[ucs_ilog2(UCT_IFACE_FLAG_AM_SHORT)] = "am short",
[ucs_ilog2(UCT_IFACE_FLAG_AM_BCOPY)] = "am bcopy",
[ucs_ilog2(UCT_IFACE_FLAG_AM_ZCOPY)] = "am zcopy",
[ucs_ilog2(UCT_IFACE_FLAG_PUT_SHORT)] = "put short",
[ucs_ilog2(UCT_IFACE_FLAG_PUT_BCOPY)] = "put bcopy",
[ucs_ilog2(UCT_IFACE_FLAG_PUT_ZCOPY)] = "put zcopy",
[ucs_ilog2(UCT_IFACE_FLAG_GET_SHORT)] = "get short",
[ucs_ilog2(UCT_IFACE_FLAG_GET_BCOPY)] = "get bcopy",
[ucs_ilog2(UCT_IFACE_FLAG_GET_ZCOPY)] = "get zcopy",
[ucs_ilog2(UCT_IFACE_FLAG_ERRHANDLE_PEER_FAILURE)] = "peer failure handler",
[ucs_ilog2(UCT_IFACE_FLAG_CONNECT_TO_IFACE)] = "connect to iface",
[ucs_ilog2(UCT_IFACE_FLAG_CONNECT_TO_EP)] = "connect to ep",
[ucs_ilog2(UCT_IFACE_FLAG_AM_DUP)] = "full reliability",
[ucs_ilog2(UCT_IFACE_FLAG_CB_SYNC)] = "sync callback",
[ucs_ilog2(UCT_IFACE_FLAG_CB_ASYNC)] = "async callback",
[ucs_ilog2(UCT_IFACE_FLAG_PENDING)] = "pending",
[ucs_ilog2(UCT_IFACE_FLAG_TAG_EAGER_SHORT)] = "tag eager short",
[ucs_ilog2(UCT_IFACE_FLAG_TAG_EAGER_BCOPY)] = "tag eager bcopy",
[ucs_ilog2(UCT_IFACE_FLAG_TAG_EAGER_ZCOPY)] = "tag eager zcopy",
[ucs_ilog2(UCT_IFACE_FLAG_TAG_RNDV_ZCOPY)] = "tag rndv zcopy",
[ucs_ilog2(UCT_IFACE_FLAG_EP_CHECK)] = "ep check",
[ucs_ilog2(UCT_IFACE_FLAG_EP_KEEPALIVE)] = "ep keepalive",
[ucs_ilog2(UCT_IFACE_FLAG_DEVICE_EP)] = "device ep",
[ucs_ilog2(UCT_IFACE_FLAG_ATOMIC_DEVICE)] = "device atomic"
};
static const char *ucp_wireup_event_flags[] = {
[ucs_ilog2(UCT_IFACE_FLAG_EVENT_SEND_COMP)] = "send completion event",
[ucs_ilog2(UCT_IFACE_FLAG_EVENT_RECV)] = "tag or active message event",
[ucs_ilog2(UCT_IFACE_FLAG_EVENT_RECV_SIG)] = "signaled message event"
};
static const char *ucp_wireup_peer_flags[] = {
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_CONNECT_TO_IFACE)] = "connect to iface",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_AM_SYNC)] = "am sync callback",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_CB_ASYNC)] = "async callback",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_PUT)] = "put",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_GET)] = "get",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_TAG_EAGER)] = "tag_eager",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_TAG_RNDV)] = "tag_rndv",
[ucs_ilog2(UCP_ADDR_IFACE_FLAG_EVENT_RECV)] = "tag_am_recv_event"
};
static ucp_wireup_atomic_flag_t ucp_wireup_atomic_desc[] = {
[UCT_ATOMIC_OP_ADD] = {.name = "add", .fetch = "fetch-"},
[UCT_ATOMIC_OP_AND] = {.name = "and", .fetch = "fetch-"},
[UCT_ATOMIC_OP_OR] = {.name = "or", .fetch = "fetch-"},
[UCT_ATOMIC_OP_XOR] = {.name = "xor", .fetch = "fetch-"},
[UCT_ATOMIC_OP_SWAP] = {.name = "swap", .fetch = ""},
[UCT_ATOMIC_OP_CSWAP] = {.name = "cswap", .fetch = ""}
};
static const char *
ucp_wireup_get_missing_flag_desc(uint64_t flags, uint64_t required_flags,
const char ** flag_descs)
{
ucs_assert((required_flags & (~flags)) != 0);
return flag_descs[ucs_ffs64(required_flags & (~flags))];
}
static const char *
ucp_wireup_get_missing_amo_flag_desc(uint64_t flags, uint64_t required_flags,
int op_size, int fetch, char *buf, size_t len)
{
int idx;
ucs_assert((required_flags & (~flags)) != 0);
idx = ucs_ffs64(required_flags & (~flags));
snprintf(buf, len, "%d-bit atomic %s%s", op_size,
fetch ? ucp_wireup_atomic_desc[idx].fetch : "",
ucp_wireup_atomic_desc[idx].name);
return buf;
}
static const char *
ucp_wireup_get_missing_amo_flag_desc_op(uint64_t flags, uint64_t required_flags,
int op_size, char *buf, size_t len)
{
return ucp_wireup_get_missing_amo_flag_desc(flags, required_flags, op_size, 0, buf, len);
}
static const char *
ucp_wireup_get_missing_amo_flag_desc_fop(uint64_t flags, uint64_t required_flags,
int op_size, char *buf, size_t len)
{
return ucp_wireup_get_missing_amo_flag_desc(flags, required_flags, op_size, 1, buf, len);
}
static void ucp_wireup_init_select_flags(ucp_wireup_select_flags_t *flags,
uint64_t mandatory, uint64_t optional)
{
flags->mandatory = mandatory;
flags->optional = optional;
}
static int
ucp_wireup_test_select_flags(const ucp_wireup_select_flags_t *select_flags,
uint64_t flags, const char **flag_descs,
ucs_string_buffer_t *missing_flags_str)
{
/* Check all mandatory flags are set */
if (!ucs_test_all_flags(flags, select_flags->mandatory)) {
const char *desc = ucp_wireup_get_missing_flag_desc(
flags, select_flags->mandatory, flag_descs);
/* Format message with the first missing flag */
ucs_string_buffer_appendf(missing_flags_str, "no %s", desc);
return 0;
}
/* Check if any optional flags are set */
if (select_flags->optional && !(select_flags->optional & flags)) {
/* Format message with a list of missing flags */
ucs_string_buffer_appendf(missing_flags_str, "no ");
ucs_string_buffer_append_flags(missing_flags_str,
select_flags->optional, flag_descs);
return 0;
}
return 1;
}
static int
ucp_wireup_check_select_flags(const uct_tl_resource_desc_t *resource,
uint64_t flags,
const ucp_wireup_select_flags_t *select_flags,
const char *title, const char **flag_descs,
char *reason, size_t max)
{
UCS_STRING_BUFFER_ONSTACK(missing_flags_str,
UCP_WIREUP_MAX_FLAGS_STRING_SIZE);
if (!ucp_wireup_test_select_flags(select_flags, flags, flag_descs,
&missing_flags_str)) {
ucs_trace(UCT_TL_RESOURCE_DESC_FMT " : not suitable for %s, %s",
UCT_TL_RESOURCE_DESC_ARG(resource), title,
ucs_string_buffer_cstr(&missing_flags_str));
ucs_snprintf_safe(reason, max, UCT_TL_RESOURCE_DESC_FMT " - %s",
UCT_TL_RESOURCE_DESC_ARG(resource),
ucs_string_buffer_cstr(&missing_flags_str));
return 0;
}
return 1;
}
static int ucp_wireup_check_flags(const uct_tl_resource_desc_t *resource,
uint64_t flags, uint64_t select_flags,
const char *title, const char **flag_descs,
char *reason, size_t max)
{
ucp_wireup_select_flags_t req;
ucp_wireup_init_select_flags(&req, select_flags, 0);
return ucp_wireup_check_select_flags(resource, flags, &req, title,
flag_descs, reason, max);
}
static int ucp_wireup_check_amo_flags(const uct_tl_resource_desc_t *resource,
uint64_t flags, uint64_t required_flags,
int op_size, int fetch,
const char *title, char *reason,
size_t max)
{
char missing_flag_desc[256];
if (ucs_test_all_flags(flags, required_flags)) {
return 1;
}
if (required_flags) {
ucp_wireup_get_missing_amo_flag_desc(flags, required_flags,
op_size, fetch, missing_flag_desc,
sizeof(missing_flag_desc));
ucs_trace(UCT_TL_RESOURCE_DESC_FMT " : not suitable for %s, no %s",
UCT_TL_RESOURCE_DESC_ARG(resource), title,
missing_flag_desc);
snprintf(reason, max, UCT_TL_RESOURCE_DESC_FMT" - no %s",
UCT_TL_RESOURCE_DESC_ARG(resource), missing_flag_desc);
}
return 0;
}
static int
ucp_wireup_check_keepalive(const ucp_wireup_select_params_t *select_params,
ucp_rsc_index_t rsc_index, uint64_t flags,
const char *title, int is_keepalive,
const char **flag_descs, char *reason, size_t max)
{
ucp_worker_h worker = select_params->ep->worker;
ucp_context_h context = worker->context;
const uct_tl_resource_desc_t *resource = &context->tl_rscs[rsc_index].tl_rsc;
char title_keepalive[128];
char title_ep_check[128];
char title_am_based[128];
if (!is_keepalive) {
/* Keepalive is not needed */
return 1;
}
ucs_snprintf_safe(title_keepalive, sizeof(title_keepalive),
"%s with keepalive", title);
ucs_snprintf_safe(title_ep_check, sizeof(title_ep_check),
"%s with ep_check", title);
ucs_snprintf_safe(title_am_based, sizeof(title_am_based),
"%s with am-based keepalive", title);
return /* Either built-in keepalive (i.e. UCT_IFACE_FLAG_EP_KEEPALIVE) or
* EP checking (i.e. UCT_IFACE_FLAG_EP_CHECK) with CONNECT_TO_EP or
* CONNECT_TO_IFACE and AM_BCOPY for AM-based keepalive */
ucp_wireup_check_flags(resource, flags,
UCT_IFACE_FLAG_EP_KEEPALIVE |
UCT_IFACE_FLAG_CONNECT_TO_EP,
title_keepalive, ucp_wireup_iface_flags,
reason, max) ||
ucp_wireup_check_flags(resource, flags,
UCT_IFACE_FLAG_EP_CHECK |
UCT_IFACE_FLAG_CONNECT_TO_EP,
title_ep_check, ucp_wireup_iface_flags,
reason, max) ||
ucp_wireup_check_flags(resource, flags,
UCT_IFACE_FLAG_CONNECT_TO_IFACE |
UCT_IFACE_FLAG_AM_BCOPY,
title_am_based, ucp_wireup_iface_flags,
reason, max);
}
static void
ucp_wireup_init_select_info(double score, double tiebreak, unsigned addr_index,
ucp_rsc_index_t rsc_index, uint8_t priority,
ucp_wireup_select_info_t *select_info)
{
/* score == 0.0 could be specified only when initializing a selection info
* to add CM lane (rsc_index == UCP_NULL_RESOURCE in this case) */
ucs_assert((score >= 0.0) || (rsc_index == UCP_NULL_RESOURCE));
select_info->score = score;
select_info->tiebreak = tiebreak;
select_info->addr_index = addr_index;
select_info->path_index = UCP_WIREUP_PATH_INDEX_UNDEFINED;
select_info->rsc_index = rsc_index;
select_info->priority = priority;
}
/*
* Compare a candidate transport against the currently selected one. When the
* candidate has a tiebreak and its score is within UCP_WIREUP_SCORE_MAX_DIFF of
* the lower score, the tiebreak (then priority) decides; otherwise the score
* (then priority) decides. Returns >0 if the candidate is better, <0 if worse,
* 0 if equal.
*/
static int ucp_wireup_candidate_cmp(double cand_score, double cand_tiebreak,
int cand_prio,
const ucp_wireup_select_info_t *sel)
{
double ref_score = ucs_min(cand_score, sel->score);
if ((cand_tiebreak >= 0.0) && (fabs(cand_score - sel->score) <=
(UCP_WIREUP_SCORE_MAX_DIFF * ref_score))) {
return ucp_score_prio_cmp(cand_tiebreak, cand_prio, sel->tiebreak,
sel->priority);
}
return ucp_score_prio_cmp(cand_score, cand_prio, sel->score, sel->priority);
}
static size_t
ucp_wireup_bw_max_lanes(const ucp_wireup_select_params_t *select_params)
{
return (select_params->address->dst_version < 18) ? UCP_MAX_LANES_LEGACY :
UCP_MAX_LANES;
}
static size_t
ucp_wireup_max_lanes(const ucp_wireup_select_params_t *select_params,
ucp_lane_type_t lane_type)
{
return ucp_wireup_lane_type_is_fast_path(lane_type) ?
UCP_MAX_FAST_PATH_LANES :
ucp_wireup_bw_max_lanes(select_params);
}
/**
* Select a local and remote transport
*/
static UCS_F_NOINLINE ucs_status_t ucp_wireup_select_transport(
const ucp_wireup_select_context_t *select_ctx,
const ucp_wireup_select_params_t *select_params,
const ucp_wireup_criteria_t *criteria, ucp_tl_bitmap_t tl_bitmap,
uint64_t remote_md_map, uint64_t local_dev_bitmap,
uint64_t remote_dev_bitmap, int show_error,
ucp_wireup_select_info_t *select_info)
{
UCS_STRING_BUFFER_ONSTACK(missing_flags_str,
UCP_WIREUP_MAX_FLAGS_STRING_SIZE);
const ucp_unpacked_address_t *address = select_params->address;
ucp_ep_h ep = select_params->ep;
ucp_worker_h worker = ep->worker;
ucp_context_h context = worker->context;
ucp_wireup_select_info_t sinfo = {0};
int found = 0;
ucp_wireup_select_flags_t local_iface_flags = criteria->local_iface_flags;
int has_cm;
uint64_t local_md_flags;
ucp_tl_addr_bitmap_t addr_index_map, rsc_addr_index_map;
const ucp_wireup_lane_desc_t *lane_desc;
unsigned addr_index;
uct_tl_resource_desc_t *resource;
const ucp_address_entry_t *ae;
ucp_worker_iface_t *wiface;
ucp_rsc_index_t rsc_index;
ucp_rsc_index_t dev_index;
ucp_lane_index_t lane;
char tls_info[UCP_WIREUP_TLS_INFO_SIZE];
char uct_info[UCP_WIREUP_UCT_INFO_SIZE];
char *p, *endp;
uct_iface_attr_t *iface_attr;
uct_md_attr_v2_t *md_attr;
const uct_component_attr_t *cmpt_attr;
int is_reachable;
double score, tiebreak;
uint8_t priority;
int score_cmp;
ucp_md_index_t md_index;
p = tls_info;
endp = tls_info + sizeof(tls_info) - 1;
tls_info[0] = '\0';
UCS_STATIC_BITMAP_AND_INPLACE(&tl_bitmap, select_params->tl_bitmap);
UCS_STATIC_BITMAP_AND_INPLACE(&tl_bitmap, context->tl_bitmap);
show_error = (select_params->show_error && show_error);
/* Check which remote addresses satisfy the criteria */
UCS_STATIC_BITMAP_RESET_ALL(&addr_index_map);
ucp_unpacked_address_for_each(ae, address) {
addr_index = ucp_unpacked_address_index(address, ae);
if (!(remote_dev_bitmap & UCS_BIT(ae->dev_index))) {
ucs_trace("addr[%d]: not in use, because on device[%d]",
addr_index, ae->dev_index);
continue;
} else if ((ae->md_index != UCP_NULL_RESOURCE) &&
!(remote_md_map & UCS_BIT(ae->md_index))) {
ucs_trace("addr[%d]: not in use, because on md[%d]", addr_index,
ae->md_index);
continue;
}
/* Make sure we are indeed passing all flags required by the criteria in
* ucp packed address */
ucs_assert(ucs_test_all_flags(UCP_ADDRESS_IFACE_EVENT_FLAGS,
criteria->remote_event_flags));
ucs_string_buffer_reset(&missing_flags_str);
if (!ucp_wireup_test_select_flags(&criteria->remote_iface_flags,
ae->iface_attr.flags,
ucp_wireup_peer_flags,
&missing_flags_str)) {
ucs_trace("addr[%d] %s: %s", addr_index,
ucp_find_tl_name_by_csum(context, ae->tl_name_csum),
ucs_string_buffer_cstr(&missing_flags_str));
continue;
}
if (!ucs_test_all_flags(ae->iface_attr.flags, criteria->remote_event_flags)) {
ucs_trace("addr[%d] %s: no %s", addr_index,
ucp_find_tl_name_by_csum(context, ae->tl_name_csum),
ucp_wireup_get_missing_flag_desc(ae->iface_attr.flags,
criteria->remote_event_flags,
ucp_wireup_peer_flags));
continue;
}
UCP_WIREUP_CHECK_AMO_FLAGS(ae, criteria, context, addr_index, op, 32);
UCP_WIREUP_CHECK_AMO_FLAGS(ae, criteria, context, addr_index, op, 64);
UCP_WIREUP_CHECK_AMO_FLAGS(ae, criteria, context, addr_index, fop, 32);
UCP_WIREUP_CHECK_AMO_FLAGS(ae, criteria, context, addr_index, fop, 64);
UCS_STATIC_BITMAP_SET(&addr_index_map, addr_index);
}
if (UCS_STATIC_BITMAP_IS_ZERO(addr_index_map)) {
snprintf(p, endp - p, "%s ", ucs_status_string(UCS_ERR_UNSUPPORTED));
p += strlen(p);
goto out;
}
/* For each local resource try to find the best remote address to connect to.
* Pick the best local resource to satisfy the criteria.
* best one has the highest score (from the dedicated score_func) and
* has a reachable tl on the remote peer */
UCS_STATIC_BITMAP_FOR_EACH_BIT(rsc_index, &tl_bitmap) {
local_md_flags = criteria->local_md_flags;
resource = &context->tl_rscs[rsc_index].tl_rsc;
dev_index = context->tl_rscs[rsc_index].dev_index;
wiface = ucp_worker_iface(worker, rsc_index);
iface_attr = ucp_worker_iface_get_attr(worker, rsc_index);
md_index = context->tl_rscs[rsc_index].md_index;
md_attr = &context->tl_mds[md_index].attr;
cmpt_attr = ucp_cmpt_attr_by_md_index(context, md_index);
if ((context->tl_rscs[rsc_index].flags & UCP_TL_RSC_FLAG_AUX) &&
!(criteria->tl_rsc_flags & UCP_TL_RSC_FLAG_AUX)) {
continue;
}
if (!context->config.ext.memtype_copy_enable &&
(md_attr->flags & UCT_MD_FLAG_MEMTYPE_COPY) &&
(md_attr->access_mem_types & ~UCS_BIT(UCS_MEMORY_TYPE_HOST))) {
ucs_trace(UCT_TL_RESOURCE_DESC_FMT
" : disabled to avoid memory type copies",
UCT_TL_RESOURCE_DESC_ARG(resource));
continue;
}
has_cm = ucp_ep_init_flags_has_cm(select_params->ep_init_flags);
if (select_params->ep_init_flags & UCP_EP_INIT_CONNECT_TO_IFACE_ONLY) {
local_iface_flags.mandatory |= UCT_IFACE_FLAG_CONNECT_TO_IFACE;
} else if (ucp_wireup_connect_p2p(worker, rsc_index, has_cm)) {
/* We should not need MD invalidate support for p2p lanes, since
* both sides close the connection in case of error */
local_md_flags &= ~(UCT_MD_FLAG_INVALIDATE |
UCT_MD_FLAG_INVALIDATE_RMA |
UCT_MD_FLAG_INVALIDATE_AMO);
}
/* Check that local md and interface satisfy the criteria */
if (!ucp_wireup_check_flags(resource, md_attr->flags, local_md_flags,
criteria->title, ucp_wireup_md_flags, p,
endp - p) ||
!ucp_wireup_check_flags(resource, cmpt_attr->flags,
criteria->local_cmpt_flags, criteria->title,
ucp_wireup_cmpt_flags, p, endp - p) ||
!ucp_wireup_check_flags(resource, md_attr->alloc_mem_types,
criteria->alloc_mem_types, criteria->title,
ucs_memory_type_names, p, endp - p) ||
!ucp_wireup_check_select_flags(resource, iface_attr->cap.flags,
&local_iface_flags, criteria->title,
ucp_wireup_iface_flags, p,
endp - p) ||
!ucp_wireup_check_keepalive(select_params, rsc_index,
iface_attr->cap.flags,
criteria->title,
criteria->is_keepalive,
ucp_wireup_iface_flags, p,
endp - p) ||
!ucp_wireup_check_flags(resource, iface_attr->cap.event_flags,
criteria->local_event_flags, criteria->title,
ucp_wireup_event_flags, p, endp - p) ||
!ucp_wireup_check_amo_flags(resource, iface_attr->cap.atomic32.op_flags,
criteria->local_atomic_flags.atomic32.op_flags,
32, 0, criteria->title, p, endp - p) ||
!ucp_wireup_check_amo_flags(resource, iface_attr->cap.atomic64.op_flags,
criteria->local_atomic_flags.atomic64.op_flags,
64, 0, criteria->title, p, endp - p) ||
!ucp_wireup_check_amo_flags(resource, iface_attr->cap.atomic32.fop_flags,
criteria->local_atomic_flags.atomic32.fop_flags,
32, 1, criteria->title, p, endp - p) ||
!ucp_wireup_check_amo_flags(resource, iface_attr->cap.atomic64.fop_flags,
criteria->local_atomic_flags.atomic64.fop_flags,
64, 1, criteria->title, p, endp - p))
{
p += strlen(p);
snprintf(p, endp - p, ", ");
p += strlen(p);
continue;
}
/* Check supplied tl & device bitmap */
if (!UCS_STATIC_BITMAP_GET(tl_bitmap, rsc_index)) {
ucs_trace(UCT_TL_RESOURCE_DESC_FMT " : disabled by tl_bitmap",
UCT_TL_RESOURCE_DESC_ARG(resource));
snprintf(p, endp - p, UCT_TL_RESOURCE_DESC_FMT" - disabled for %s, ",
UCT_TL_RESOURCE_DESC_ARG(resource), criteria->title);
p += strlen(p);
continue;
} else if (!(local_dev_bitmap & UCS_BIT(dev_index))) {
ucs_trace(UCT_TL_RESOURCE_DESC_FMT " : disabled by device bitmap",
UCT_TL_RESOURCE_DESC_ARG(resource));
snprintf(p, endp - p, UCT_TL_RESOURCE_DESC_FMT" - disabled for %s, ",
UCT_TL_RESOURCE_DESC_ARG(resource), criteria->title);
p += strlen(p);
continue;
}
if (select_ctx->num_lanes <
ucp_wireup_max_lanes(select_params, criteria->lane_type)) {
/* If we have not reached the lanes limit, we can select any
combination of rsc_index/addr_index */
rsc_addr_index_map = addr_index_map;
} else {
/* If we reached the lanes limit, select only existing combinations
* of rsc_index/addr_index, to make sure lane selection result will
* be the same when connecting to worker address and when connecting
* to a remote ep by wireup protocol.
*/
UCS_STATIC_BITMAP_RESET_ALL(&rsc_addr_index_map);
for (lane = 0; lane < select_ctx->num_lanes; ++lane) {
lane_desc = &select_ctx->lane_descs[lane];
if (lane_desc->rsc_index == rsc_index) {
UCS_STATIC_BITMAP_SET(&rsc_addr_index_map,
lane_desc->addr_index);
}
}
UCS_STATIC_BITMAP_AND_INPLACE(&rsc_addr_index_map, addr_index_map);
}
/* ucp_wireup_is_reachable() can fail without filling uct_info string if
* none of the remote transports match the local one */
snprintf(uct_info, sizeof(uct_info), "not available");
is_reachable = 0;
UCS_STATIC_BITMAP_FOR_EACH_BIT(addr_index, &rsc_addr_index_map) {
ae = &address->address_list[addr_index];
if (!ucp_wireup_is_reachable(ep, select_params->ep_init_flags,
rsc_index, ae, uct_info,
sizeof(uct_info))) {
/* Must be reachable device address, on same transport */
continue;
}
score = criteria->calc_score(wiface, md_attr, address, ae,
0, criteria->arg);
tiebreak = (criteria->calc_tiebreak == NULL) ?
UCP_WIREUP_NO_SCORE_TIEBREAK :
criteria->calc_tiebreak(wiface, md_attr,
address, ae, 0,
criteria->tiebreak_arg);
priority = iface_attr->priority + ae->iface_attr.priority;
score_cmp = found ?
ucp_wireup_candidate_cmp(score, tiebreak, priority,
&sinfo) : 1;
is_reachable = 1;
if (!found || (score_cmp > 0)) {
ucp_wireup_init_select_info(score, tiebreak, addr_index, rsc_index,
priority, &sinfo);
found = 1;
}
}
/* If a local resource cannot reach any of the remote addresses,
* generate debug message. */
if (!is_reachable) {
snprintf(p, endp - p, UCT_TL_RESOURCE_DESC_FMT " - %s, ",
UCT_TL_RESOURCE_DESC_ARG(resource), uct_info);
p += strlen(p);
}
}
out:
if (p >= tls_info + 2) {
*(p - 2) = '\0'; /* trim last "," */
}
if (!found) {
if (show_error) {
ucs_error("no %s transport to %s: %s", criteria->title,
address->name, tls_info);
}
return UCS_ERR_UNREACHABLE;
}
ucs_trace("ep %p: selected for %s: " UCT_TL_RESOURCE_DESC_FMT " md[%d]"
" -> '%s' address[%d],md[%d] score %.2f tiebreak %.2f",
ep, criteria->title,
UCT_TL_RESOURCE_DESC_ARG(
&context->tl_rscs[sinfo.rsc_index].tl_rsc),
context->tl_rscs[sinfo.rsc_index].md_index, ucp_ep_peer_name(ep),
sinfo.addr_index,
address->address_list[sinfo.addr_index].md_index, sinfo.score,
sinfo.tiebreak);
*select_info = sinfo;
return UCS_OK;
}
static inline double
ucp_wireup_tl_iface_latency(const ucp_worker_iface_t *wiface,
const ucp_unpacked_address_t *unpacked_addr,
const ucp_address_iface_attr_t *remote_iface_attr,
int is_prioritized_ep)
{
ucp_context_h context = wiface->worker->context;
ucs_linear_func_t lat_v1 = {0, wiface->attr.latency.m};
double local_lat, lat_lossy;
if (unpacked_addr->addr_version == UCP_OBJECT_VERSION_V1) {
local_lat = ucp_wireup_iface_lat_distance_v1(wiface);
/* Address v1 contains just latency overhead */
lat_v1.c = (local_lat + remote_iface_attr->lat_ovh) / 2;
return ucp_tl_iface_latency_with_priority(context, &lat_v1,
is_prioritized_ep);
} else {
local_lat = ucp_wireup_iface_lat_distance_v2(wiface, is_prioritized_ep);
/* FP8 is a lossy compression method, so in order to create a symmetric
* calculation we pack/unpack the local latency as well */
lat_lossy = ucp_wireup_fp8_pack_unpack_latency(local_lat);
return (remote_iface_attr->lat_ovh + lat_lossy) / 2;
}
}
static int ucp_wireup_has_slow_lanes(ucp_wireup_select_context_t *select_ctx)
{
ucp_wireup_lane_desc_t *lane_desc;
ucs_carray_for_each(lane_desc, select_ctx->lane_descs,
select_ctx->num_lanes) {
if (!ucp_wireup_lane_types_has_fast_path(lane_desc->lane_types)) {
return 1;
}
}
return 0;
}
static int
ucp_wireup_path_index_is_equal(unsigned path_index1, unsigned path_index2)
{
return (path_index1 == UCP_WIREUP_PATH_INDEX_UNDEFINED) ||
(path_index2 == UCP_WIREUP_PATH_INDEX_UNDEFINED) ||
(path_index1 == path_index2);
}
static UCS_F_NOINLINE ucs_status_t ucp_wireup_add_lane_desc(
const ucp_wireup_select_params_t *select_params,
const ucp_wireup_select_info_t *select_info,
ucp_md_index_t dst_md_index, ucs_sys_device_t dst_sys_dev,
ucp_lane_type_t lane_type, unsigned seg_size,
ucp_wireup_select_context_t *select_ctx, int show_error)
{
ucp_worker_h worker = select_params->ep->worker;
ucp_worker_iface_t *wiface;
ucp_wireup_lane_desc_t *lane_desc;
ucp_lane_type_t lane_type_iter;
ucp_lane_index_t lane;
ucs_log_level_t log_level;
/* Add a new lane, but try to reuse already added lanes which are selected
* on the same transport resources.
*/
for (lane_desc = select_ctx->lane_descs;
lane_desc < select_ctx->lane_descs + select_ctx->num_lanes; ++lane_desc) {
if ((lane_desc->rsc_index == select_info->rsc_index) &&
(lane_desc->addr_index == select_info->addr_index) &&
ucp_wireup_path_index_is_equal(lane_desc->path_index,
select_info->path_index)) {
lane = lane_desc - select_ctx->lane_descs;
ucs_assertv_always(dst_md_index == lane_desc->dst_md_index,
"lane[%d].dst_md_index=%d, dst_md_index=%d",
lane, lane_desc->dst_md_index, dst_md_index);
/* The same pair of local/remote resource is already selected but
* with a different usage - update the score and path (if needed)
* and exit
*/
if (!(lane_desc->lane_types & UCS_BIT(lane_type))) {
goto out_update;
}
/* If adding same lane type and usage, expect same score */
ucs_assertv_always(
ucs_fp_compare(lane_desc->score[lane_type],
select_info->score) == 0,
"usage=%s lane_desc->score=%.2f select->score=%.2f",
ucp_lane_type_info[lane_type].short_name,
lane_desc->score[lane_type], select_info->score);
goto out;
}
}
/* We rely on 'ucp_wireup_search_lanes' to add fast lanes before slow
* lanes, so that all fast lanes are inserted to the cached ucp_ep
* structure */
if (ucp_wireup_lane_type_is_fast_path(lane_type)) {
/* assert we don't have slow lanes until we finished with fast lanes */
ucs_assert_always(!ucp_wireup_has_slow_lanes(select_ctx));
}
if (select_ctx->num_lanes >=
ucp_wireup_max_lanes(select_params, lane_type)) {
log_level = show_error ? UCS_LOG_LEVEL_ERROR : UCS_LOG_LEVEL_DEBUG;
ucs_log(log_level, "cannot add %s lane - reached limit (%d)",
ucp_lane_type_info[lane_type].short_name,
select_ctx->num_lanes);
return UCS_ERR_EXCEEDS_LIMIT;
}
lane_desc = &select_ctx->lane_descs[select_ctx->num_lanes];
++select_ctx->num_lanes;
lane_desc->rsc_index = select_info->rsc_index;
lane_desc->addr_index = select_info->addr_index;
lane_desc->path_index = select_info->path_index;
lane_desc->dst_md_index = dst_md_index;
lane_desc->dst_sys_dev = dst_sys_dev;
lane_desc->lane_types = UCS_BIT(lane_type);
wiface = ucp_worker_iface(worker, select_info->rsc_index);
lane_desc->port_speed = (wiface != NULL) ? wiface->port_speed : 0;
lane_desc->seg_size = seg_size;
for (lane_type_iter = UCP_LANE_TYPE_FIRST;
lane_type_iter < UCP_LANE_TYPE_LAST;
++lane_type_iter) {
lane_desc->score[lane_type_iter] = 0.0;
}
if (select_info->rsc_index != UCP_NULL_RESOURCE) {
UCS_STATIC_BITMAP_SET(&select_ctx->tl_bitmap, select_info->rsc_index);
}
out_update:
if (lane_desc->path_index == UCP_WIREUP_PATH_INDEX_UNDEFINED) {
lane_desc->path_index = select_info->path_index;
}
lane_desc->score[lane_type] = select_info->score;
lane_desc->lane_types |= UCS_BIT(lane_type);
out:
return UCS_OK;
}
static UCS_F_NOINLINE ucs_status_t
ucp_wireup_add_lane(const ucp_wireup_select_params_t *select_params,
const ucp_wireup_select_info_t *select_info,
ucp_lane_type_t lane_type, int show_error,
ucp_wireup_select_context_t *select_ctx)
{
ucp_address_entry_t *addr_list = select_params->address->address_list;
unsigned addr_index = select_info->addr_index;
return ucp_wireup_add_lane_desc(select_params, select_info,
addr_list[addr_index].md_index,
addr_list[addr_index].sys_dev, lane_type,
addr_list[addr_index].iface_attr.seg_size,
select_ctx,
select_params->show_error && show_error);
}
static int ucp_wireup_compare_score(const void *elem1, const void *elem2,
void *arg, ucp_lane_type_t lane_type)
{
const ucp_lane_index_t *lane1 = elem1;
const ucp_lane_index_t *lane2 = elem2;
const ucp_wireup_lane_desc_t *lanes = arg;
double score1, score2;
score1 = (*lane1 == UCP_NULL_LANE) ? 0.0 : lanes[*lane1].score[lane_type];
score2 = (*lane2 == UCP_NULL_LANE) ? 0.0 : lanes[*lane2].score[lane_type];
/* reverse the value of ucs_fp_compare to sort scores in descending order */
return -ucs_fp_compare(score1, score2);
}
static int ucp_wireup_compare_lane_am_bw_score(const void *elem1, const void *elem2,
void *arg)
{
return ucp_wireup_compare_score(elem1, elem2, arg, UCP_LANE_TYPE_AM_BW);
}
static int ucp_wireup_compare_lane_rma_score(const void *elem1, const void *elem2,
void *arg)
{
return ucp_wireup_compare_score(elem1, elem2, arg, UCP_LANE_TYPE_RMA);
}
static int ucp_wireup_compare_lane_rma_bw_score(const void *elem1, const void *elem2,
void *arg)
{
return ucp_wireup_compare_score(elem1, elem2, arg, UCP_LANE_TYPE_RMA_BW);
}
static int ucp_wireup_compare_lane_amo_score(const void *elem1, const void *elem2,
void *arg)
{
return ucp_wireup_compare_score(elem1, elem2, arg, UCP_LANE_TYPE_AMO);
}
static void ucp_wireup_unset_tl_by_md(const ucp_wireup_select_params_t *sparams,
const ucp_wireup_select_info_t *sinfo,
ucp_tl_bitmap_t *tl_bitmap,
uint64_t *remote_md_map)
{
ucp_context_h context = sparams->ep->worker->context;
const ucp_address_entry_t *ae = &sparams->address->
address_list[sinfo->addr_index];
ucp_md_index_t md_index = context->tl_rscs[sinfo->rsc_index].md_index;
ucp_md_index_t dst_md_index = ae->md_index;
ucp_rsc_index_t i;
*remote_md_map &= ~UCS_BIT(dst_md_index);
UCS_STATIC_BITMAP_FOR_EACH_BIT(i, &context->tl_bitmap) {
if (context->tl_rscs[i].md_index == md_index) {
UCS_STATIC_BITMAP_RESET(tl_bitmap, i);
}
}
}
static void ucp_wireup_memaccess_bitmap(ucp_context_h context,
uint64_t mem_type_bitmap,
ucp_tl_bitmap_t *tl_bitmap)
{
const uint64_t md_reg_flags = UCT_MD_FLAG_NEED_MEMH | UCT_MD_FLAG_NEED_RKEY;
/* If a local or a remote key is needed, the memory domain has to be able
to register. Otherwise, it must be able to access. */
ucp_context_memaccess_tl_bitmap(context, mem_type_bitmap, md_reg_flags,
tl_bitmap);
}
static UCS_F_NOINLINE ucs_status_t ucp_wireup_add_memaccess_lanes(
const ucp_wireup_select_params_t *select_params, unsigned ep_init_flags,
const ucp_wireup_criteria_t *criteria, ucs_memory_type_t mem_type,
ucp_tl_bitmap_t tl_bitmap, ucp_lane_type_t lane_type,
ucp_wireup_select_context_t *select_ctx)
{
ucp_context_h context = select_params->ep->worker->context;
ucp_wireup_criteria_t mem_criteria = *criteria;
ucp_wireup_select_info_t select_info = {0};
double reg_score = 0;
ucp_tl_bitmap_t mem_type_tl_bitmap;
int allow_am;
uint64_t remote_md_map;
ucs_status_t status;
char title[64];
allow_am = select_params->allow_am &&
!((lane_type == UCP_LANE_TYPE_RMA) &&
(context->config.features & UCP_FEATURE_EXPORTED_MEMH));
remote_md_map = UINT64_MAX;
/* Select best transport which can reach registered memory */
snprintf(title, sizeof(title), criteria->title, "registered");
mem_criteria.title = title;
mem_criteria.alloc_mem_types = 0;
mem_criteria.lane_type = lane_type;
ucp_wireup_memaccess_bitmap(context, UCS_BIT(mem_type),
&mem_type_tl_bitmap);
UCS_STATIC_BITMAP_AND_INPLACE(&mem_type_tl_bitmap, tl_bitmap);
status = ucp_wireup_select_transport(select_ctx, select_params,
&mem_criteria, mem_type_tl_bitmap,
remote_md_map, UINT64_MAX, UINT64_MAX,
!allow_am, &select_info);
if (status == UCS_OK) {
/* Add to the list of lanes */
status = ucp_wireup_add_lane(select_params, &select_info, lane_type,
!allow_am, select_ctx);
if (status == UCS_OK) {
/* Remove all occurrences of the remote md from the address list,
* to avoid selecting the same remote md again. */
ucp_wireup_unset_tl_by_md(select_params, &select_info, &tl_bitmap,
&remote_md_map);
reg_score = select_info.score;
}
}
/* If could not find registered memory access lane, try to use emulation */
if (status != UCS_OK) {
if (!allow_am) {
return status;
}
select_ctx->ucp_ep_init_flags |= UCP_EP_INIT_CREATE_AM_LANE;
}
if (!(ep_init_flags & UCP_EP_INIT_FLAG_MEM_TYPE) &&
(mem_type != UCS_MEMORY_TYPE_HOST)) {
/* Select transports for allocated memory only for host mem, to keep