forked from openucx/ucx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathucp_context.c
More file actions
2885 lines (2446 loc) · 108 KB
/
ucp_context.c
File metadata and controls
2885 lines (2446 loc) · 108 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) ARM Ltd. 2016. ALL RIGHTS RESERVED.
* Copyright (C) Intel Corporation, 2023. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ucp_context.h"
#include "ucp_request.h"
#include <ucs/config/parser.h>
#include <ucs/algorithm/crc.h>
#include <ucs/arch/atomic.h>
#include <ucs/datastruct/mpool.inl>
#include <ucs/datastruct/queue.h>
#include <ucs/datastruct/string_set.h>
#include <ucs/debug/log.h>
#include <ucs/debug/debug_int.h>
#include <ucs/sys/compiler.h>
#include <ucs/sys/string.h>
#include <ucs/type/init_once.h>
#include <ucs/vfs/base/vfs_cb.h>
#include <ucs/vfs/base/vfs_obj.h>
#include <string.h>
#include <dlfcn.h>
#define UCP_RSC_CONFIG_ALL "all"
#define UCP_AM_HANDLER_FOREACH(_macro) \
_macro(UCP_AM_ID_WIREUP) \
_macro(UCP_AM_ID_EAGER_ONLY) \
_macro(UCP_AM_ID_EAGER_FIRST) \
_macro(UCP_AM_ID_EAGER_MIDDLE) \
_macro(UCP_AM_ID_EAGER_SYNC_ONLY) \
_macro(UCP_AM_ID_EAGER_SYNC_FIRST) \
_macro(UCP_AM_ID_EAGER_SYNC_ACK) \
_macro(UCP_AM_ID_RNDV_RTS) \
_macro(UCP_AM_ID_RNDV_ATS) \
_macro(UCP_AM_ID_RNDV_RTR) \
_macro(UCP_AM_ID_RNDV_DATA) \
_macro(UCP_AM_ID_OFFLOAD_SYNC_ACK) \
_macro(UCP_AM_ID_STREAM_DATA) \
_macro(UCP_AM_ID_RNDV_ATP) \
_macro(UCP_AM_ID_PUT) \
_macro(UCP_AM_ID_GET_REQ) \
_macro(UCP_AM_ID_GET_REP) \
_macro(UCP_AM_ID_ATOMIC_REQ) \
_macro(UCP_AM_ID_ATOMIC_REP) \
_macro(UCP_AM_ID_CMPL) \
_macro(UCP_AM_ID_AM_SINGLE) \
_macro(UCP_AM_ID_AM_FIRST) \
_macro(UCP_AM_ID_AM_MIDDLE) \
_macro(UCP_AM_ID_AM_SINGLE_REPLY) \
_macro(UCP_AM_ID_AM_FIRST_PSN) \
_macro(UCP_AM_ID_AM_MIDDLE_PSN)
#define UCP_AM_HANDLER_DECL(_id) extern ucp_am_handler_t ucp_am_handler_##_id;
#define UCP_AM_HANDLER_ENTRY(_id) [_id] = &ucp_am_handler_##_id,
#define UCP_CPU_EST_BCOPY_BW_DEFAULT (7000 * UCS_MBYTE)
#define UCP_CPU_EST_BCOPY_BW_DEFAULT_PROTOV1 (5800 * UCS_MBYTE)
#define UCP_CPU_EST_BCOPY_BW_AMD_PROTOV1 (5008 * UCS_MBYTE)
#define UCP_TL_AUX_SUFFIX "aux"
#define UCP_TL_AUX(_tl_name) _tl_name ":" UCP_TL_AUX_SUFFIX
/* Factor to multiply with in order to get infinite latency */
#define UCP_CONTEXT_INFINITE_LAT_FACTOR 100
typedef enum ucp_transports_list_search_result {
UCP_TRANSPORTS_LIST_SEARCH_RESULT_PRIMARY = UCS_BIT(0),
UCP_TRANSPORTS_LIST_SEARCH_RESULT_AUX_IN_MAIN = UCS_BIT(1),
UCP_TRANSPORTS_LIST_SEARCH_RESULT_AUX_IN_ALIAS = UCS_BIT(2),
UCP_TRANSPORTS_LIST_SEARCH_RESULT_TL_AND_AUX_IN_ALIAS = UCS_BIT(3)
} ucp_transports_list_search_result_t;
/* Declare all am handlers */
UCP_AM_HANDLER_FOREACH(UCP_AM_HANDLER_DECL)
ucp_am_handler_t *ucp_am_handlers[UCP_AM_ID_LAST] = {
UCP_AM_HANDLER_FOREACH(UCP_AM_HANDLER_ENTRY)
};
static const char *ucp_atomic_modes[] = {
[UCP_ATOMIC_MODE_CPU] = "cpu",
[UCP_ATOMIC_MODE_DEVICE] = "device",
[UCP_ATOMIC_MODE_GUESS] = "guess",
[UCP_ATOMIC_MODE_LAST] = NULL,
};
static const char *ucp_fence_modes[] = {
[UCP_FENCE_MODE_WEAK] = "weak",
[UCP_FENCE_MODE_STRONG] = "strong",
[UCP_FENCE_MODE_AUTO] = "auto",
[UCP_FENCE_MODE_EP_BASED] = "ep_based",
[UCP_FENCE_MODE_LAST] = NULL
};
static const char *ucp_rndv_modes[] = {
[UCP_RNDV_MODE_AUTO] = "auto",
[UCP_RNDV_MODE_GET_ZCOPY] = "get_zcopy",
[UCP_RNDV_MODE_PUT_ZCOPY] = "put_zcopy",
[UCP_RNDV_MODE_GET_PIPELINE] = "get_ppln",
[UCP_RNDV_MODE_PUT_PIPELINE] = "put_ppln",
[UCP_RNDV_MODE_AM] = "am",
[UCP_RNDV_MODE_RKEY_PTR] = "rkey_ptr",
[UCP_RNDV_MODE_LAST] = NULL,
};
static size_t ucp_rndv_frag_default_sizes[] = {
[UCS_MEMORY_TYPE_HOST] = 512 * UCS_KBYTE,
[UCS_MEMORY_TYPE_CUDA] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_CUDA_MANAGED] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_ROCM] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_ROCM_MANAGED] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_RDMA] = 0,
[UCS_MEMORY_TYPE_ZE_HOST] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_ZE_DEVICE] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_ZE_MANAGED] = 4 * UCS_MBYTE,
[UCS_MEMORY_TYPE_LAST] = 0
};
static size_t ucp_rndv_frag_default_num_elems[] = {
[UCS_MEMORY_TYPE_HOST] = 128,
[UCS_MEMORY_TYPE_CUDA] = 128,
[UCS_MEMORY_TYPE_CUDA_MANAGED] = 128,
[UCS_MEMORY_TYPE_ROCM] = 128,
[UCS_MEMORY_TYPE_ROCM_MANAGED] = 128,
[UCS_MEMORY_TYPE_RDMA] = 0,
[UCS_MEMORY_TYPE_ZE_HOST] = 128,
[UCS_MEMORY_TYPE_ZE_DEVICE] = 128,
[UCS_MEMORY_TYPE_ZE_MANAGED] = 128,
[UCS_MEMORY_TYPE_LAST] = 0
};
const char *ucp_object_versions[] = {
[UCP_OBJECT_VERSION_V1] = "v1",
[UCP_OBJECT_VERSION_V2] = "v2",
[UCP_OBJECT_VERSION_LAST] = NULL
};
const char *ucp_extra_op_attr_flags_names[] = {
[UCP_OP_ATTR_INDEX(UCP_OP_ATTR_FLAG_NO_IMM_CMPL)] = "no_imm_cmpl",
[UCP_OP_ATTR_INDEX(UCP_OP_ATTR_FLAG_FAST_CMPL)] = "fast_cmpl",
[UCP_OP_ATTR_INDEX(UCP_OP_ATTR_FLAG_FORCE_IMM_CMPL)] = "force_imm_cmpl",
[UCP_OP_ATTR_INDEX(UCP_OP_ATTR_FLAG_MULTI_SEND)] = "multi_send",
NULL
};
static UCS_CONFIG_DEFINE_ARRAY(memunit_sizes, sizeof(size_t),
UCS_CONFIG_TYPE_MEMUNITS);
static ucs_config_field_t ucp_context_config_table[] = {
{"SELECT_DISTANCE_MD", "cuda_cpy",
"MD whose distance is queried when evaluating transport selection score",
ucs_offsetof(ucp_context_config_t, select_distance_md), UCS_CONFIG_TYPE_STRING},
{"MEMTYPE_REG_WHOLE_ALLOC_TYPES", "cuda",
"Memory types which have whole allocations registered.\n"
"Allowed memory types: cuda, rocm, rocm-managed, ze-host, ze-device, ze-managed",
ucs_offsetof(ucp_context_config_t, reg_whole_alloc_bitmap),
UCS_CONFIG_TYPE_BITMAP(ucs_memory_type_names)},
{"RNDV_MEMTYPE_DIRECT_SIZE", "inf",
"Maximum size for mem type direct in rendezvous protocol\n",
ucs_offsetof(ucp_context_config_t, rndv_memtype_direct_size),
UCS_CONFIG_TYPE_MEMUNITS},
{"BCOPY_THRESH", "auto",
"Threshold for switching from short to bcopy protocol",
ucs_offsetof(ucp_context_config_t, bcopy_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"RNDV_THRESH", UCS_VALUE_AUTO_STR,
"Threshold for switching from eager to rendezvous protocol", 0,
UCS_CONFIG_TYPE_KEY_VALUE(UCS_CONFIG_TYPE_MEMUNITS,
{"intra", "threshold for intra-node communication",
ucs_offsetof(ucp_context_config_t, rndv_intra_thresh)},
{"inter", "threshold for inter-node communication",
ucs_offsetof(ucp_context_config_t, rndv_inter_thresh)},
{NULL}
)},
{"RNDV_SEND_NBR_THRESH", "256k",
"Threshold for switching from eager to rendezvous protocol in ucp_tag_send_nbr().\n"
"Relevant only if UCX_RNDV_THRESH is set to \"auto\".",
ucs_offsetof(ucp_context_config_t, rndv_send_nbr_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"RNDV_THRESH_FALLBACK", "inf",
"Message size to start using the rendezvous protocol in case the calculated threshold\n"
"is zero or negative",
ucs_offsetof(ucp_context_config_t, rndv_thresh_fallback), UCS_CONFIG_TYPE_MEMUNITS},
{"RNDV_PERF_DIFF", "1",
"The percentage allowed for performance difference between rendezvous and "
"the eager_zcopy protocol",
ucs_offsetof(ucp_context_config_t, rndv_perf_diff), UCS_CONFIG_TYPE_DOUBLE},
{"MULTI_LANE_MAX_RATIO", "4",
"Maximal allowed ratio between slowest and fastest lane in a multi-lane\n"
"protocol. Lanes slower than the specified ratio will not be used.",
ucs_offsetof(ucp_context_config_t, multi_lane_max_ratio), UCS_CONFIG_TYPE_DOUBLE},
{"MULTI_PATH_RATIO", "auto",
"Bandwidth efficiency ratio when more than one path per device is used.\n"
"This value represents the fraction of bandwidth taken by each connection\n"
"on the same device. A value of 'auto' means that fraction is calculated\n"
"based on the maximal number of paths supported by the device.",
ucs_offsetof(ucp_context_config_t, multi_path_ratio),
UCS_CONFIG_TYPE_POS_DOUBLE},
{"MAX_EAGER_LANES", NULL, "",
ucs_offsetof(ucp_context_config_t, max_eager_lanes), UCS_CONFIG_TYPE_UINT},
{"MAX_EAGER_RAILS", "1",
"Maximal number of devices on which an eager operation may be executed in parallel",
ucs_offsetof(ucp_context_config_t, max_eager_lanes), UCS_CONFIG_TYPE_UINT},
{"MAX_RNDV_LANES", NULL,"",
ucs_offsetof(ucp_context_config_t, max_rndv_lanes), UCS_CONFIG_TYPE_UINT},
{"MAX_RNDV_RAILS", "2",
"Maximal number of devices on which a rendezvous operation may be executed in parallel",
ucs_offsetof(ucp_context_config_t, max_rndv_lanes), UCS_CONFIG_TYPE_UINT},
{"MAX_RMA_LANES", NULL, "",
ucs_offsetof(ucp_context_config_t, max_rma_lanes), UCS_CONFIG_TYPE_UINT},
{"MAX_RMA_RAILS", "1",
"Maximal number of devices on which a RMA operation may be executed in parallel",
ucs_offsetof(ucp_context_config_t, max_rma_lanes), UCS_CONFIG_TYPE_UINT},
{"MIN_RNDV_CHUNK_SIZE", "16k",
"Minimum chunk size to split the message sent with rendezvous protocol on\n"
"multiple rails. Must be greater than 0.",
ucs_offsetof(ucp_context_config_t, min_rndv_chunk_size), UCS_CONFIG_TYPE_MEMUNITS},
{"MIN_RMA_CHUNK_SIZE", "8k",
"Minimum chunk size to split the message sent with RMA protocol on\n"
"multiple rails. Must be greater than 0.",
ucs_offsetof(ucp_context_config_t, min_rma_chunk_size), UCS_CONFIG_TYPE_MEMUNITS},
{"RMA_ZCOPY_MAX_SEG_SIZE", "auto",
"Max size of a segment for rma/rndv zcopy.",
ucs_offsetof(ucp_context_config_t, rma_zcopy_max_seg_size), UCS_CONFIG_TYPE_MEMUNITS},
{"RNDV_SCHEME", "auto",
"Communication scheme in RNDV protocol.\n"
" get_zcopy - use get_zcopy scheme in RNDV protocol.\n"
" put_zcopy - use put_zcopy scheme in RNDV protocol.\n"
" get_ppln - use pipelined get_zcopy scheme in RNDV protocol.\n"
" put_ppln - use pipelined put_zcopy scheme in RNDV protocol.\n"
" rkey_ptr - use rkey_ptr in RNDV protocol.\n"
" am - use active message scheme in RNDV protocol.\n"
" auto - runtime automatically chooses optimal scheme to use.",
ucs_offsetof(ucp_context_config_t, rndv_mode), UCS_CONFIG_TYPE_ENUM(ucp_rndv_modes)},
{"RKEY_PTR_SEG_SIZE", "512k",
"Segment size that is used to perform data transfer when doing RKEY PTR progress",
ucs_offsetof(ucp_context_config_t, rkey_ptr_seg_size), UCS_CONFIG_TYPE_MEMUNITS},
{"ZCOPY_THRESH", "auto",
"Threshold for switching from buffer copy to zero copy protocol",
ucs_offsetof(ucp_context_config_t, zcopy_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"BCOPY_BW", "auto",
"Estimation of buffer copy bandwidth",
ucs_offsetof(ucp_context_config_t, bcopy_bw), UCS_CONFIG_TYPE_BW},
{"ATOMIC_MODE", "guess",
"Atomic operations synchronization mode.\n"
" cpu - atomic operations are consistent with respect to the CPU.\n"
" device - atomic operations are performed on one of the transport devices,\n"
" and there is guarantee of consistency with respect to the CPU."
" guess - atomic operations mode is configured based on underlying\n"
" transport capabilities. If one of active transports supports\n"
" the DEVICE atomic mode, the DEVICE mode is selected.\n"
" Otherwise the CPU mode is selected.",
ucs_offsetof(ucp_context_config_t, atomic_mode), UCS_CONFIG_TYPE_ENUM(ucp_atomic_modes)},
{"ADDRESS_DEBUG_INFO",
#if ENABLE_DEBUG_DATA
"y",
#else
"n",
#endif
"Add debugging information to worker address.",
ucs_offsetof(ucp_context_config_t, address_debug_info), UCS_CONFIG_TYPE_BOOL},
{"MAX_WORKER_NAME", NULL, "",
ucs_offsetof(ucp_context_config_t, max_worker_address_name),
UCS_CONFIG_TYPE_UINT},
{"MAX_WORKER_ADDRESS_NAME", UCS_PP_MAKE_STRING(UCP_WORKER_ADDRESS_NAME_MAX),
"Maximal length of worker address name. Sent to remote peer as part of\n"
"worker address if UCX_ADDRESS_DEBUG_INFO is set to 'yes'",
ucs_offsetof(ucp_context_config_t, max_worker_address_name),
UCS_CONFIG_TYPE_UINT},
{"USE_MT_MUTEX", "n", "Use mutex for multithreading support in UCP.\n"
"n - Not use mutex for multithreading support in UCP (use spinlock by default).\n"
"y - Use mutex for multithreading support in UCP.",
ucs_offsetof(ucp_context_config_t, use_mt_mutex), UCS_CONFIG_TYPE_BOOL},
{"ADAPTIVE_PROGRESS", "y",
"Enable adaptive progress mechanism, which turns on polling only on active\n"
"transport interfaces.",
ucs_offsetof(ucp_context_config_t, adaptive_progress), UCS_CONFIG_TYPE_BOOL},
{"SEG_SIZE", "8192",
"Size of a segment in the worker preregistered memory pool.",
ucs_offsetof(ucp_context_config_t, seg_size), UCS_CONFIG_TYPE_MEMUNITS},
{"TM_THRESH", "1024", /* TODO: calculate automatically */
"Threshold for using tag matching offload capabilities.\n"
"Smaller buffers will not be posted to the transport.",
ucs_offsetof(ucp_context_config_t, tm_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"TM_MAX_BB_SIZE", "1024", /* TODO: calculate automatically */
"Maximal size for posting \"bounce buffer\" (UCX internal preregistered memory) for\n"
"tag offload receives. When message arrives, it is copied into the user buffer (similar\n"
"to eager protocol). The size values has to be equal or less than segment size.\n"
"Also the value has to be bigger than UCX_TM_THRESH to take an effect." ,
ucs_offsetof(ucp_context_config_t, tm_max_bb_size), UCS_CONFIG_TYPE_MEMUNITS},
{"TM_FORCE_THRESH", "8192", /* TODO: calculate automatically */
"Threshold for forcing tag matching offload mode. Every tag receive operation\n"
"with buffer bigger than this threshold would force offloading of all uncompleted\n"
"non-offloaded receive operations to the transport (e. g. operations with\n"
"buffers below the UCX_TM_THRESH value). Offloading may be unsuccessful in certain\n"
"cases (non-contig buffer, or sender wildcard).",
ucs_offsetof(ucp_context_config_t, tm_force_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"TM_SW_RNDV", "n",
"Use software rendezvous protocol even when tag matching offload is enabled.\n"
"In this case tag matching offload will be used for messages sent with eager\n"
"protocol only. If the value is set to \"try\", the rendezvous protocol is\n"
"selected automatically according to the performance characteristics.",
ucs_offsetof(ucp_context_config_t, tm_sw_rndv), UCS_CONFIG_TYPE_TERNARY},
{"NUM_EPS", "auto",
"An optimization hint of how many endpoints would be created on this context.\n"
"Does not affect semantics, but only transport selection criteria and the\n"
"resulting performance.\n"
" If set to a value different from \"auto\" it will override the value passed\n"
"to ucp_init()",
ucs_offsetof(ucp_context_config_t, estimated_num_eps), UCS_CONFIG_TYPE_ULUNITS},
{"NUM_PPN", "auto",
"An optimization hint for the number of processes expected to be launched\n"
"on a single node. Does not affect semantics, only transport selection criteria\n"
"and the resulting performance.",
ucs_offsetof(ucp_context_config_t, estimated_num_ppn), UCS_CONFIG_TYPE_ULUNITS},
{"RNDV_FRAG_MEM_TYPE", NULL, "",
ucs_offsetof(ucp_context_config_t, rndv_frag_mem_types),
UCS_CONFIG_TYPE_BITMAP(ucs_memory_type_names)},
{"RNDV_FRAG_MEM_TYPES", "host,cuda",
"Memory types of fragments used for RNDV pipeline protocol.\n"
"Allowed memory types are: host, cuda, rocm, ze-host, ze-device",
ucs_offsetof(ucp_context_config_t, rndv_frag_mem_types),
UCS_CONFIG_TYPE_BITMAP(ucs_memory_type_names)},
{"MEMTYPE_COPY_ENABLE", "y",
"Allows memory type copies. This option influences protocol selection.\n",
ucs_offsetof(ucp_context_config_t, memtype_copy_enable), UCS_CONFIG_TYPE_BOOL},
{"RNDV_PIPELINE_SEND_THRESH", "inf",
"RNDV size threshold to enable sender side pipeline for mem type",
ucs_offsetof(ucp_context_config_t, rndv_pipeline_send_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"RNDV_PIPELINE_SHM_ENABLE", "y",
"Use two stage pipeline rendezvous protocol for intra-node GPU to GPU transfers",
ucs_offsetof(ucp_context_config_t, rndv_shm_ppln_enable), UCS_CONFIG_TYPE_BOOL},
{"RNDV_PIPELINE_ERROR_HANDLING", "n",
"Allow using error handling protocol in the rendezvous pipeline protocol\n"
"even if invalidation workflow isn't supported",
ucs_offsetof(ucp_context_config_t, rndv_errh_ppln_enable), UCS_CONFIG_TYPE_BOOL},
{"FLUSH_WORKER_EPS", "y",
"Enable flushing the worker by flushing its endpoints. Allows completing\n"
"the flush operation in a bounded time even if there are new requests on\n"
"another thread, or incoming active messages, but consumes more resources.",
ucs_offsetof(ucp_context_config_t, flush_worker_eps), UCS_CONFIG_TYPE_BOOL},
{"FENCE_MODE", "auto",
"Fence mode used in ucp_worker_fence routine.\n"
" weak - use weak fence mode.\n"
" strong - use strong fence mode.\n"
" auto - automatically detect fence mode.\n"
" ep_based - use endpoint-based fence mode.",
ucs_offsetof(ucp_context_config_t, fence_mode),
UCS_CONFIG_TYPE_ENUM(ucp_fence_modes)},
{"UNIFIED_MODE", "n",
"Enable various optimizations intended for homogeneous environment.\n"
"Enabling this mode implies that the local transport resources/devices\n"
"of all entities which connect to each other are the same.",
ucs_offsetof(ucp_context_config_t, unified_mode), UCS_CONFIG_TYPE_BOOL},
{"CM_USE_ALL_DEVICES", "y",
"When creating client/server endpoints, use all available devices.\n"
"If disabled, use only the one device on which the connection\n"
"establishment is done",
ucs_offsetof(ucp_context_config_t, cm_use_all_devices), UCS_CONFIG_TYPE_BOOL},
{"LISTENER_BACKLOG", "auto",
"'auto' means that each transport would use its maximal allowed value.\n"
"If a value larger than what a transport supports is set, the backlog value\n"
"would be cut to that maximal value.",
ucs_offsetof(ucp_context_config_t, listener_backlog), UCS_CONFIG_TYPE_ULUNITS},
{"PROTO_ENABLE", "y",
"Enable new protocol selection logic",
ucs_offsetof(ucp_context_config_t, proto_enable), UCS_CONFIG_TYPE_BOOL},
{"PROTO_REQUEST_RESET", "n",
"Experimental: forces reset of pending request when an endpoint has been\n"
"connected, useful for testing purposes only",
ucs_offsetof(ucp_context_config_t, proto_request_reset), UCS_CONFIG_TYPE_BOOL},
{"KEEPALIVE_INTERVAL", "20s",
"Time interval between keepalive rounds. Must be non-zero value.",
ucs_offsetof(ucp_context_config_t, keepalive_interval),
UCS_CONFIG_TYPE_TIME_UNITS},
{"KEEPALIVE_NUM_EPS", "128",
"Maximal number of endpoints to check on every keepalive round\n"
"(inf - check all endpoints on every round, must be greater than 0)",
ucs_offsetof(ucp_context_config_t, keepalive_num_eps), UCS_CONFIG_TYPE_UINT},
{"DYNAMIC_TL_SWITCH_INTERVAL", "inf",
"Time interval between dynamic transport switching rounds. Must be\n"
"non-zero value. use 'inf' to disable this feature.",
ucs_offsetof(ucp_context_config_t, dynamic_tl_switch_interval),
UCS_CONFIG_TYPE_TIME_UNITS},
{"DYNAMIC_TL_PROGRESS_FACTOR", "10",
"Number of usage tracker rounds performed for each progress operation. Must be\n"
"non-zero value.",
ucs_offsetof(ucp_context_config_t, dynamic_tl_progress_factor),
UCS_CONFIG_TYPE_TIME_UNITS},
{"RESOLVE_REMOTE_EP_ID", "n",
"Defines whether resolving remote endpoint ID is required or not when\n"
"creating a local endpoint. 'auto' means resolving remote endpoint ID only\n"
"in case of error handling and keepalive enabled.",
ucs_offsetof(ucp_context_config_t, resolve_remote_ep_id),
UCS_CONFIG_TYPE_ON_OFF_AUTO},
{"PROTO_INDIRECT_ID", "auto",
"Enable indirect IDs to object pointers (endpoint, request) in wire protocols.\n"
"A value of 'auto' means to enable only if error handling is enabled on the\n"
"endpoint.",
ucs_offsetof(ucp_context_config_t, proto_indirect_id), UCS_CONFIG_TYPE_ON_OFF_AUTO},
{"RNDV_PUT_FORCE_FLUSH", "n",
"When using rendezvous put protocol, force using a flush operation to ensure\n"
"remote data delivery before sending ATP message.\n"
"If flush mode is not forced, and the underlying transport supports both active\n"
"messages and put operations, the protocol will do {put,fence,ATP} on the same\n"
"lane without waiting for remote completion.",
ucs_offsetof(ucp_context_config_t, rndv_put_force_flush), UCS_CONFIG_TYPE_BOOL},
{"SA_DATA_VERSION", "v2",
"Defines the minimal header version the client will use for establishing\n"
"client/server connection",
ucs_offsetof(ucp_context_config_t, sa_client_min_hdr_version),
UCS_CONFIG_TYPE_ENUM(ucp_object_versions)},
{"RKEY_MPOOL_MAX_MD", "2",
"Maximum number of UCP rkey MDs which can be unpacked into memory pool\n"
"element. UCP rkeys containing larger number of MDs will be unpacked to\n"
"dynamically allocated memory.",
ucs_offsetof(ucp_context_config_t, rkey_mpool_max_md), UCS_CONFIG_TYPE_INT},
{"ADDRESS_VERSION", "v1",
"Defines UCP worker address format obtained with ucp_worker_get_address() or\n"
"ucp_worker_query() routines.",
ucs_offsetof(ucp_context_config_t, worker_addr_version),
UCS_CONFIG_TYPE_ENUM(ucp_object_versions)},
{"PROTO_INFO", "auto",
"Enable printing protocols information. The value is interpreted as follows:\n"
" 'y' : Print information for all protocols\n"
" 'n' : Do not print any protocol information\n"
" 'auto' : Print information when UCX_LOG_LEVEL is 'debug' or higher\n"
" 'used' : Print information for used protocols\n"
" glob_pattern : Print information for operations matching the glob pattern.\n"
" For example: '*tag*gpu*', '*put*fast*host*'",
ucs_offsetof(ucp_context_config_t, proto_info), UCS_CONFIG_TYPE_STRING},
{"RNDV_ALIGN_THRESH", "64kB",
"If the rendezvous payload size is larger than this value, it could be split\n"
"in order to optimize memory alignment",
ucs_offsetof(ucp_context_config_t, rndv_align_thresh), UCS_CONFIG_TYPE_MEMUNITS},
{"PROTO_INFO_DIR", "",
"If non-empty, protocol selection information files will be written to this\n"
"directory.",
ucs_offsetof(ucp_context_config_t, proto_info_dir), UCS_CONFIG_TYPE_STRING},
{"REG_NONBLOCK_MEM_TYPES", "",
"Perform only non-blocking memory registration for these memory types.\n"
"Non-blocking registration means that the page registration may be\n"
"deferred until it is accessed by the CPU or a transport.",
ucs_offsetof(ucp_context_config_t, reg_nb_mem_types),
UCS_CONFIG_TYPE_BITMAP(ucs_memory_type_names)},
{"REG_NONBLOCK_FALLBACK", "y",
"Allow fallback to blocking memory registration if no MDs supporting non-blocking\n"
"registration.",
ucs_offsetof(ucp_context_config_t, reg_nb_fallback), UCS_CONFIG_TYPE_BOOL},
{"PREFER_OFFLOAD", "y",
"Prefer transports capable of remote memory access for RMA and AMO operations.\n"
"The value is interpreted as follows:\n"
" 'y' : Prefer transports with native RMA/AMO support (if available)\n"
" 'n' : Select RMA/AMO lanes according to performance charasteristics",
ucs_offsetof(ucp_context_config_t, prefer_offload), UCS_CONFIG_TYPE_BOOL},
{"PROTO_OVERHEAD", "single:5ns,multi:10ns,rndv_offload:40ns,rndv_rtr:40ns,"
"rndv_rts:275ns,sw:40ns,rkey_ptr:0",
"Protocol overhead", 0,
UCS_CONFIG_TYPE_KEY_VALUE(UCS_CONFIG_TYPE_TIME,
{"single", "overhead of single-lane protocol",
ucs_offsetof(ucp_context_config_t, proto_overhead_single)},
{"multi", "overhead of managing multiple lanes",
ucs_offsetof(ucp_context_config_t, proto_overhead_multi)},
{"rndv_offload", "overhead of rendezvous offload protocol",
ucs_offsetof(ucp_context_config_t, proto_overhead_rndv_offload)},
{"rndv_rtr", "overhead of rendezvous RTR protocol",
ucs_offsetof(ucp_context_config_t, proto_overhead_rndv_rtr)},
{"rndv_rts", "overhead of rendezvous RTS protocol",
ucs_offsetof(ucp_context_config_t, proto_overhead_rndv_rts)},
{"sw", "overhead of software emulation protocol",
ucs_offsetof(ucp_context_config_t, proto_overhead_sw)},
{"rkey_ptr", "overhead of the protocol copying from mapped remote "
"memory",
ucs_offsetof(ucp_context_config_t, proto_overhead_rkey_ptr)},
{NULL}
)},
{"GVA_ENABLE", "off",
"Enable Global VA infrastructure. Setting to 'auto' will try to enable, "
"but if error handling enabled will disable",
ucs_offsetof(ucp_context_config_t, gva_enable), UCS_CONFIG_TYPE_ON_OFF_AUTO},
{"GVA_MLOCK", "y",
"Lock memory with mlock() when using global VA MR",
ucs_offsetof(ucp_context_config_t, gva_mlock), UCS_CONFIG_TYPE_BOOL},
{"GVA_PREFETCH", "y",
"Prefetch memory when using global VA MR",
ucs_offsetof(ucp_context_config_t, gva_prefetch), UCS_CONFIG_TYPE_BOOL},
{"EXTRA_OP_ATTR_FLAGS", "",
"Additional send/receive operation flags that are added for each request"
"in addition to what is set explicitly by the user. \n"
"Possible values are: no_imm_cmpl, fast_cmpl, force_imm_cmpl, multi_send.",
ucs_offsetof(ucp_context_config_t, extra_op_attr_flags),
UCS_CONFIG_TYPE_BITMAP(ucp_extra_op_attr_flags_names)},
{"MAX_PRIORITY_EPS", "20",
"Max number of prioritized endpoints. Does not affect semantics,\n"
"but only transport selection criteria and resulting performance.",
ucs_offsetof(ucp_context_config_t, max_priority_eps),
UCS_CONFIG_TYPE_UINT},
{"WIREUP_VIA_AM_LANE", "n",
"Use AM lane to send wireup messages",
ucs_offsetof(ucp_context_config_t, wireup_via_am_lane),
UCS_CONFIG_TYPE_BOOL},
{"CONNECT_ALL_TO_ALL", "n",
"Establish connections between all pairs of local and remote devices that\n"
"are reachable through the transport layer.",
ucs_offsetof(ucp_context_config_t, connect_all_to_all),
UCS_CONFIG_TYPE_BOOL},
{"SINGLE_NET_DEVICE", "n", "Use only one network device for all protocols.",
ucs_offsetof(ucp_context_config_t, proto_use_single_net_device),
UCS_CONFIG_TYPE_BOOL},
{"NODE_LOCAL_ID", "auto",
"An optimization hint for the local identificator on a single node. Does \n"
"not affect semantics, only transport selection criteria and the \n"
"resulting performance.",
ucs_offsetof(ucp_context_config_t, node_local_id), UCS_CONFIG_TYPE_ULUNITS},
{NULL}
};
static ucs_config_field_t ucp_config_table[] = {
{"NET_DEVICES", UCP_RSC_CONFIG_ALL,
"Specifies which network device(s) to use. The order is not meaningful.\n",
ucs_offsetof(ucp_config_t, devices[UCT_DEVICE_TYPE_NET]), UCS_CONFIG_TYPE_ALLOW_LIST},
{"SHM_DEVICES", UCP_RSC_CONFIG_ALL,
"Specifies which intra-node device(s) to use. The order is not meaningful.\n",
ucs_offsetof(ucp_config_t, devices[UCT_DEVICE_TYPE_SHM]), UCS_CONFIG_TYPE_ALLOW_LIST},
{"ACC_DEVICES", UCP_RSC_CONFIG_ALL,
"Specifies which accelerator device(s) to use. The order is not meaningful.\n",
ucs_offsetof(ucp_config_t, devices[UCT_DEVICE_TYPE_ACC]), UCS_CONFIG_TYPE_ALLOW_LIST},
{"SELF_DEVICES", UCP_RSC_CONFIG_ALL,
"Specifies which loop-back device(s) to use. The order is not meaningful.\n",
ucs_offsetof(ucp_config_t, devices[UCT_DEVICE_TYPE_SELF]), UCS_CONFIG_TYPE_ALLOW_LIST},
{"TLS", UCP_RSC_CONFIG_ALL,
"Comma-separated list of transports to use. The order is not meaningful.\n"
" - all : use all the available transports.\n"
" - sm/shm : all shared memory transports (mm, cma, knem).\n"
" - mm : shared memory transports - only memory mappers.\n"
" - ugni : ugni_smsg and ugni_rdma (uses ugni_udt for bootstrap).\n"
" - ib : all infiniband transports (rc/rc_mlx5, ud/ud_mlx5, dc_mlx5, srd).\n"
" - rc_v : rc verbs (uses ud for bootstrap).\n"
" - rc_x : rc with accelerated verbs (uses ud_mlx5 for bootstrap).\n"
" - rc : rc_v and rc_x (preferably if available).\n"
" - ud_v : ud verbs.\n"
" - ud_x : ud with accelerated verbs.\n"
" - ud : ud_v and ud_x (preferably if available).\n"
" - srd : EFA srd reliable transport.\n"
" - dc/dc_x : dc with accelerated verbs.\n"
" - tcp : sockets over TCP/IP.\n"
" - cuda : CUDA (NVIDIA GPU) memory support.\n"
" - rocm : ROCm (AMD GPU) memory support.\n"
" - ze : ZE (Intel GPU) memory support.\n"
" Using a \\ prefix before a transport name treats it as an explicit transport name\n"
" and disables aliasing.",
ucs_offsetof(ucp_config_t, tls), UCS_CONFIG_TYPE_ALLOW_LIST},
{"PROTOS", UCP_RSC_CONFIG_ALL,
"Comma-separated list of glob patterns specifying protocols to use.\n"
"The order is not meaningful.\n"
"Each expression in the list may contain any of the following wildcard:\n"
" * - matches any number of any characters including none.\n"
" ? - matches any single character.\n"
" [abc] - matches one character given in the bracket.\n"
" [a-z] - matches one character from the range given in the bracket.",
ucs_offsetof(ucp_config_t, protos), UCS_CONFIG_TYPE_ALLOW_LIST},
{"ALLOC_PRIO", "md:sysv,md:posix,thp,md:*,mmap,heap",
"Priority of memory allocation methods. Each item in the list can be either\n"
"an allocation method (huge, thp, mmap, libc) or md:<NAME> which means to use the\n"
"specified memory domain for allocation. NAME can be either a UCT component\n"
"name, or a wildcard - '*' - which is equivalent to all UCT components.",
ucs_offsetof(ucp_config_t, alloc_prio), UCS_CONFIG_TYPE_STRING_ARRAY},
{"RNDV_FRAG_SIZE", "host:512K,cuda:4M",
"Comma-separated list of memory types and associated fragment sizes.\n"
"The memory types in the list is used for rendezvous bounce buffers.",
ucs_offsetof(ucp_config_t, rndv_frag_sizes), UCS_CONFIG_TYPE_STRING_ARRAY},
{"RNDV_FRAG_ALLOC_COUNT", "host:128,cuda:128",
"Comma separated list of memory pool allocation granularity per memory type.",
ucs_offsetof(ucp_config_t, rndv_frag_elems), UCS_CONFIG_TYPE_STRING_ARRAY},
{"SOCKADDR_TLS_PRIORITY", "rdmacm,tcp,sockcm",
"Priority of sockaddr transports for client/server connection establishment.\n"
"The '*' wildcard expands to all the available sockaddr transports.",
ucs_offsetof(ucp_config_t, sockaddr_cm_tls), UCS_CONFIG_TYPE_STRING_ARRAY},
{"SOCKADDR_AUX_TLS", "",
"The configuration parameter is deprecated. UCX_TLS should be used to\n"
"specify the transport for client/server connection establishment.",
UCS_CONFIG_DEPRECATED_FIELD_OFFSET, UCS_CONFIG_TYPE_DEPRECATED},
{"WARN_INVALID_CONFIG", "y",
"Issue a warning in case of invalid device and/or transport configuration.",
ucs_offsetof(ucp_config_t, warn_invalid_config), UCS_CONFIG_TYPE_BOOL},
{"RX_MPOOL_SIZES", "64,1kb",
"List of worker mpool sizes separated by comma. The values must be power of 2\n"
"Values larger than the maximum UCT transport segment size will be ignored.\n"
"These pools are used for UCP AM and unexpected TAG messages. When assigning\n"
"pool sizes, note that the data may be stored with some header.",
ucs_offsetof(ucp_config_t, mpool_sizes), UCS_CONFIG_TYPE_ARRAY(memunit_sizes)},
{"RCACHE_ENABLE", "try", "Use user space memory registration cache.",
ucs_offsetof(ucp_config_t, enable_rcache), UCS_CONFIG_TYPE_TERNARY},
{"", "RCACHE_PURGE_ON_FORK=y;RCACHE_MEM_PRIO=500;", NULL,
ucs_offsetof(ucp_config_t, rcache_config),
UCS_CONFIG_TYPE_TABLE(ucs_config_rcache_table)},
{"", "", NULL,
ucs_offsetof(ucp_config_t, ctx),
UCS_CONFIG_TYPE_TABLE(ucp_context_config_table)},
{"MAX_COMPONENT_MDS", "16",
"Maximum number of memory domains per component to use.",
ucs_offsetof(ucp_config_t, max_component_mds), UCS_CONFIG_TYPE_ULUNITS},
{NULL}
};
UCS_CONFIG_DECLARE_TABLE(ucp_config_table, "UCP context", NULL, ucp_config_t)
static ucp_tl_alias_t ucp_tl_aliases[] = {
{ "mm", { "posix", "sysv", "xpmem", NULL } }, /* for backward compatibility */
{ "sm", { "posix", "sysv", "xpmem", "knem", "cma", NULL } },
{ "shm", { "posix", "sysv", "xpmem", "knem", "cma", NULL } },
{ "ib", { "rc_verbs", "ud_verbs", "rc_mlx5", "ud_mlx5", "dc_mlx5",
"gga_mlx5", UCP_TL_AUX("ud_mlx5"), UCP_TL_AUX("ud_verbs"),
"srd", "rc_gda", NULL } },
{ "ud_v", { "ud_verbs", NULL } },
{ "ud_x", { "ud_mlx5", NULL } },
{ "ud", { "ud_mlx5", "ud_verbs", NULL } },
{ "rc_v", { "rc_verbs", UCP_TL_AUX("ud_verbs"), NULL } },
{ "rc_x", { "rc_mlx5", UCP_TL_AUX("ud_mlx5"), NULL } },
{ "rc", { "rc_mlx5", UCP_TL_AUX("ud_mlx5"), "rc_verbs",
UCP_TL_AUX("ud_verbs"), NULL } },
{ "dc", { "dc_mlx5", UCP_TL_AUX("ud_mlx5"), NULL } },
{ "dc_x", { "dc_mlx5", UCP_TL_AUX("ud_mlx5"), NULL } },
{ "ugni", { "ugni_smsg", UCP_TL_AUX("ugni_udt"), "ugni_rdma", NULL } },
{ "cuda", { "cuda_copy", "cuda_ipc", "gdr_copy", NULL } },
{ "rocm", { "rocm_copy", "rocm_ipc", "rocm_gdr", NULL } },
{ "ze", { "ze_copy", "ze_ipc", "ze_gdr", NULL } },
{ "gaudi", { "gaudi_gdr", NULL } },
{ "gga", { "gga_mlx5", NULL } },
{ NULL }
};
const char *ucp_feature_str[] = {
[ucs_ilog2(UCP_FEATURE_TAG)] = "UCP_FEATURE_TAG",
[ucs_ilog2(UCP_FEATURE_RMA)] = "UCP_FEATURE_RMA",
[ucs_ilog2(UCP_FEATURE_AMO32)] = "UCP_FEATURE_AMO32",
[ucs_ilog2(UCP_FEATURE_AMO64)] = "UCP_FEATURE_AMO64",
[ucs_ilog2(UCP_FEATURE_WAKEUP)] = "UCP_FEATURE_WAKEUP",
[ucs_ilog2(UCP_FEATURE_STREAM)] = "UCP_FEATURE_STREAM",
[ucs_ilog2(UCP_FEATURE_AM)] = "UCP_FEATURE_AM",
[ucs_ilog2(UCP_FEATURE_DEVICE)] = "UCP_FEATURE_DEVICE",
NULL
};
const ucp_tl_bitmap_t ucp_tl_bitmap_max = {{UINT64_MAX, UINT64_MAX}};
const ucp_tl_bitmap_t ucp_tl_bitmap_min = {{0}};
static void ucp_load_uct_components(void)
{
static ucs_init_once_t init_once = UCS_INIT_ONCE_INITIALIZER;
uct_component_h *components;
unsigned num_components;
ucs_status_t status;
UCS_INIT_ONCE(&init_once) {
status = uct_query_components(&components, &num_components);
if (status == UCS_OK) {
uct_release_component_list(components);
} else {
ucs_warn("failed to query UCT components: %s",
ucs_status_string(status));
}
}
}
ucs_status_t ucp_config_read(const char *env_prefix, const char *filename,
ucp_config_t **config_p)
{
unsigned full_prefix_len = sizeof(UCS_DEFAULT_ENV_PREFIX);
unsigned env_prefix_len = 0;
ucp_config_t *config;
ucs_status_t status;
config = ucs_malloc(sizeof(*config), "ucp config");
if (config == NULL) {
status = UCS_ERR_NO_MEMORY;
goto err;
}
if (env_prefix != NULL) {
env_prefix_len = strlen(env_prefix);
/* Extra one byte for underscore _ character */
full_prefix_len += env_prefix_len + 1;
}
config->env_prefix = ucs_malloc(full_prefix_len, "ucp config");
if (config->env_prefix == NULL) {
status = UCS_ERR_NO_MEMORY;
goto err_free_config;
}
if (env_prefix_len != 0) {
ucs_snprintf_zero(config->env_prefix, full_prefix_len, "%s_%s",
env_prefix, UCS_DEFAULT_ENV_PREFIX);
} else {
ucs_snprintf_zero(config->env_prefix, full_prefix_len, "%s",
UCS_DEFAULT_ENV_PREFIX);
}
status = ucs_config_parser_fill_opts(config,
UCS_CONFIG_GET_TABLE(ucp_config_table),
config->env_prefix, 0);
if (status != UCS_OK) {
goto err_free_prefix;
}
ucs_list_head_init(&config->cached_key_list);
/* Load UCT components to populate ucs_config_global_list with UCT
* configuration options */
ucp_load_uct_components();
*config_p = config;
return UCS_OK;
err_free_prefix:
ucs_free(config->env_prefix);
err_free_config:
ucs_free(config);
err:
return status;
}
static void ucp_cached_key_release(ucs_config_cached_key_t *key_val)
{
ucs_assert(key_val != NULL);
ucs_free(key_val->key);
ucs_free(key_val->value);
ucs_free(key_val);
}
static void ucp_cached_key_list_release(ucs_list_link_t *list)
{
ucs_config_cached_key_t *key_val;
while (!ucs_list_is_empty(list)) {
key_val = ucs_list_extract_head(list, typeof(*key_val), list);
ucp_cached_key_release(key_val);
}
}
static ucs_status_t
ucp_config_cached_key_add(ucs_list_link_t *list,
const char *key, const char *value)
{
ucs_config_cached_key_t *cached_key;
cached_key = ucs_malloc(sizeof(*cached_key), "cached config key/value");
if (cached_key == NULL) {
goto err;
}
cached_key->key = ucs_strdup(key, "cached config key");
cached_key->value = ucs_strdup(value, "cached config value");
cached_key->used = 0;
if ((cached_key->key == NULL) || (cached_key->value == NULL)) {
goto err_free_key;
}
ucs_list_add_tail(list, &cached_key->list);
return UCS_OK;
err_free_key:
ucp_cached_key_release(cached_key);
err:
return UCS_ERR_NO_MEMORY;
}
void ucp_config_release(ucp_config_t *config)
{
ucp_cached_key_list_release(&config->cached_key_list);
ucs_config_parser_release_opts(config, ucp_config_table);
ucs_free(config->env_prefix);
ucs_free(config);
}
ucs_status_t ucp_config_modify_internal(ucp_config_t *config, const char *name,
const char *value)
{
return ucs_config_parser_set_value(config, ucp_config_table, NULL, name,
value);
}
ucs_status_t ucp_config_modify(ucp_config_t *config, const char *name,
const char *value)
{
ucs_status_t status;
status = ucp_config_modify_internal(config, name, value);
if (status != UCS_ERR_NO_ELEM) {
return status;
}
if (ucs_global_opts_is_read_only(name)) {
ucs_debug("'%s' global configuration is read-only", name);
return UCS_ERR_INVALID_PARAM;
}
status = ucs_global_opts_set_value(name, value);
if (status != UCS_ERR_NO_ELEM) {
return status;
}
if (!ucs_config_global_list_has_field(name)) {
ucs_debug("'%s' configuration is invalid", name);
return UCS_ERR_INVALID_PARAM;
}
return ucp_config_cached_key_add(&config->cached_key_list, name, value);
}
static
void ucp_config_print_cached_uct(const ucp_config_t *config, FILE *stream,
const char *title,
ucs_config_print_flags_t flags)
{
ucs_config_cached_key_t *key_val;
if (flags & UCS_CONFIG_PRINT_HEADER) {
fprintf(stream, "\n");
fprintf(stream, "#\n");
fprintf(stream, "# Cached UCT %s\n", title);
fprintf(stream, "#\n");
fprintf(stream, "\n");
}
if (flags & UCS_CONFIG_PRINT_CONFIG) {
ucs_list_for_each(key_val, &config->cached_key_list, list) {
fprintf(stream, "%s=%s\n", key_val->key, key_val->value);
}
}
if (flags & UCS_CONFIG_PRINT_HEADER) {
fprintf(stream, "\n");
}
}
void ucp_config_print(const ucp_config_t *config, FILE *stream,
const char *title, ucs_config_print_flags_t print_flags)
{
ucs_config_parser_print_opts(stream, title, config, ucp_config_table, NULL,
UCS_DEFAULT_ENV_PREFIX, print_flags, NULL);
ucp_config_print_cached_uct(config, stream, title, print_flags);
}
void ucp_apply_uct_config_list(ucp_context_h context, void *config)
{
ucs_config_cached_key_t *key_val;
ucs_status_t status;
ucs_list_for_each(key_val, &context->cached_key_list, list) {
status = uct_config_modify(config, key_val->key, key_val->value);
if (status == UCS_OK) {
ucs_debug("apply UCT configuration %s=%s", key_val->key,
key_val->value);
key_val->used = 1;
}
}
}
/* Search str in the array. If str_suffix is specified, search for
* 'str:str_suffix' string.
* @return bitmap of indexes in which the string appears in the array.
*/
static uint64_t ucp_str_array_search(const char **array, unsigned array_len,
const char *str, const char *str_suffix)
{
const size_t len = strlen(str);
uint64_t result;
const char *p;
int i;
result = 0;
for (i = 0; i < array_len; ++i) {
if (str_suffix == NULL) {
if (!strcmp(array[i], str)) {
result |= UCS_BIT(i);
}
} else if (!strncmp(array[i], str, len)) {
p = array[i] + len;
if ((*p == ':') && !strcmp(p + 1, str_suffix)) {
result |= UCS_BIT(i);
}
}
}
return result;
}
static unsigned ucp_tl_alias_count(ucp_tl_alias_t *alias)
{
unsigned count;
for (count = 0; alias->tls[count] != NULL; ++count);
return count;
}