-
Notifications
You must be signed in to change notification settings - Fork 14
/
ompi_coll_xccl.patch
1264 lines (1260 loc) · 46.1 KB
/
ompi_coll_xccl.patch
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
From 4647ad8e7d5c03f98aa05a2f928458f94a9e77c3 Mon Sep 17 00:00:00 2001
From: Valentin Petrov <[email protected]>
Date: Mon, 2 Mar 2020 13:26:33 +0200
Subject: [PATCH] ompi/coll/xccl
eXperimental openucx collective communication library (XCCL)
integration layer
Signed-off-by: Valentin Petrov <[email protected]>
---
config/ompi_check_xccl.m4 | 75 ++++++
ompi/mca/coll/base/coll_tags.h | 4 +-
ompi/mca/coll/xccl/Makefile.am | 45 ++++
ompi/mca/coll/xccl/coll_xccl.h | 116 +++++++++
ompi/mca/coll/xccl/coll_xccl_component.c | 172 ++++++++++++++
ompi/mca/coll/xccl/coll_xccl_debug.h | 30 +++
ompi/mca/coll/xccl/coll_xccl_dtypes.h | 86 +++++++
ompi/mca/coll/xccl/coll_xccl_module.c | 393 +++++++++++++++++++++++++++++++
ompi/mca/coll/xccl/coll_xccl_ops.c | 207 ++++++++++++++++
ompi/mca/coll/xccl/configure.m4 | 37 +++
10 files changed, 1164 insertions(+), 1 deletion(-)
create mode 100644 config/ompi_check_xccl.m4
create mode 100644 ompi/mca/coll/xccl/Makefile.am
create mode 100644 ompi/mca/coll/xccl/coll_xccl.h
create mode 100644 ompi/mca/coll/xccl/coll_xccl_component.c
create mode 100644 ompi/mca/coll/xccl/coll_xccl_debug.h
create mode 100644 ompi/mca/coll/xccl/coll_xccl_dtypes.h
create mode 100644 ompi/mca/coll/xccl/coll_xccl_module.c
create mode 100644 ompi/mca/coll/xccl/coll_xccl_ops.c
create mode 100644 ompi/mca/coll/xccl/configure.m4
diff --git a/config/ompi_check_xccl.m4 b/config/ompi_check_xccl.m4
new file mode 100644
index 0000000..d7d5548
--- /dev/null
+++ b/config/ompi_check_xccl.m4
@@ -0,0 +1,75 @@
+dnl -*- shell-script -*-
+dnl
+dnl Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+dnl Copyright (c) 2013 Cisco Systems, Inc. All rights reserved.
+dnl Copyright (c) 2015 Research Organization for Information Science
+dnl and Technology (RIST). All rights reserved.
+dnl $COPYRIGHT$
+dnl
+dnl Additional copyrights may follow
+dnl
+dnl $HEADER$
+dnl
+
+# OMPI_CHECK_XCCL(prefix, [action-if-found], [action-if-not-found])
+# --------------------------------------------------------
+# check if xccl support can be found. sets prefix_{CPPFLAGS,
+# LDFLAGS, LIBS} as needed and runs action-if-found if there is
+# support, otherwise executes action-if-not-found
+AC_DEFUN([OMPI_CHECK_XCCL],[
+ OPAL_VAR_SCOPE_PUSH([ompi_check_xccl_dir ompi_check_xccl_libs ompi_check_xccl_happy CPPFLAGS_save LDFLAGS_save LIBS_save])
+
+ AC_ARG_WITH([xccl],
+ [AC_HELP_STRING([--with-xccl(=DIR)],
+ [Build xccl (Mellanox Collective Communication library) support, optionally adding
+ DIR/include and DIR/lib or DIR/lib64 to the search path for headers and libraries])])
+
+ AS_IF([test "$with_xccl" != "no"],
+ [ompi_check_xccl_libs=xccl
+ AS_IF([test ! -z "$with_xccl" && test "$with_xccl" != "yes"],
+ [ompi_check_xccl_dir=$with_xccl])
+
+ CPPFLAGS_save=$CPPFLAGS
+ LDFLAGS_save=$LDFLAGS
+ LIBS_save=$LIBS
+
+ OPAL_LOG_MSG([$1_CPPFLAGS : $$1_CPPFLAGS], 1)
+ OPAL_LOG_MSG([$1_LDFLAGS : $$1_LDFLAGS], 1)
+ OPAL_LOG_MSG([$1_LIBS : $$1_LIBS], 1)
+
+ OPAL_CHECK_PACKAGE([$1],
+ [api/xccl.h],
+ [$ompi_check_xccl_libs],
+ [xccl_lib_init],
+ [],
+ [$ompi_check_xccl_dir],
+ [],
+ [ompi_check_xccl_happy="yes"],
+ [ompi_check_xccl_happy="no"])
+
+ AS_IF([test "$ompi_check_xccl_happy" = "yes"],
+ [
+ CPPFLAGS=$coll_xccl_CPPFLAGS
+ LDFLAGS=$coll_xccl_LDFLAGS
+ LIBS=$coll_xccl_LIBS
+ AC_CHECK_FUNCS(xccl_comm_free, [], [])
+ ],
+ [])
+
+ CPPFLAGS=$CPPFLAGS_save
+ LDFLAGS=$LDFLAGS_save
+ LIBS=$LIBS_save],
+ [ompi_check_xccl_happy=no])
+
+ AS_IF([test "$ompi_check_xccl_happy" = "yes" && test "$enable_progress_threads" = "yes"],
+ [AC_MSG_WARN([xccl driver does not currently support progress threads. Disabling XCCL.])
+ ompi_check_xccl_happy="no"])
+
+ AS_IF([test "$ompi_check_xccl_happy" = "yes"],
+ [$2],
+ [AS_IF([test ! -z "$with_xccl" && test "$with_xccl" != "no"],
+ [AC_MSG_ERROR([XCCL support requested but not found. Aborting])])
+ $3])
+
+ OPAL_VAR_SCOPE_POP
+])
diff --git a/ompi/mca/coll/base/coll_tags.h b/ompi/mca/coll/base/coll_tags.h
index 2bcf2a6..3d22f01 100644
--- a/ompi/mca/coll/base/coll_tags.h
+++ b/ompi/mca/coll/base/coll_tags.h
@@ -41,7 +41,9 @@
#define MCA_COLL_BASE_TAG_SCAN -24
#define MCA_COLL_BASE_TAG_SCATTER -25
#define MCA_COLL_BASE_TAG_SCATTERV -26
-#define MCA_COLL_BASE_TAG_NONBLOCKING_BASE -27
+#define MCA_COLL_BASE_TAG_XCCL -27
+
+#define MCA_COLL_BASE_TAG_NONBLOCKING_BASE -28
#define MCA_COLL_BASE_TAG_NONBLOCKING_END ((-1 * INT_MAX/2) + 1)
#define MCA_COLL_BASE_TAG_NEIGHBOR_BASE (MCA_COLL_BASE_TAG_NONBLOCKING_END - 1)
#define MCA_COLL_BASE_TAG_NEIGHBOR_END (MCA_COLL_BASE_TAG_NEIGHBOR_BASE - 1024)
diff --git a/ompi/mca/coll/xccl/Makefile.am b/ompi/mca/coll/xccl/Makefile.am
new file mode 100644
index 0000000..9db768e
--- /dev/null
+++ b/ompi/mca/coll/xccl/Makefile.am
@@ -0,0 +1,45 @@
+# -*- shell-script -*-
+#
+#
+# Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+# $COPYRIGHT$
+#
+# Additional copyrights may follow
+#
+# $HEADER$
+#
+#
+
+AM_CPPFLAGS = $(coll_xccl_CPPFLAGS)
+
+coll_xccl_sources = \
+ coll_xccl.h \
+ coll_xccl_debug.h \
+ coll_xccl_dtypes.h \
+ coll_xccl_module.c \
+ coll_xccl_component.c \
+ coll_xccl_ops.c
+
+# Make the output library in this directory, and name it either
+# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
+# (for static builds).
+
+if MCA_BUILD_ompi_coll_xccl_DSO
+component_noinst =
+component_install = mca_coll_xccl.la
+else
+component_noinst = libmca_coll_xccl.la
+component_install =
+endif
+
+mcacomponentdir = $(ompilibdir)
+mcacomponent_LTLIBRARIES = $(component_install)
+mca_coll_xccl_la_SOURCES = $(coll_xccl_sources)
+mca_coll_xccl_la_LIBADD = $(top_builddir)/ompi/lib@[email protected] \
+ $(coll_xccl_LIBS)
+mca_coll_xccl_la_LDFLAGS = -module -avoid-version $(coll_xccl_LDFLAGS)
+
+noinst_LTLIBRARIES = $(component_noinst)
+libmca_coll_xccl_la_SOURCES = $(coll_xccl_sources)
+libmca_coll_xccl_la_LIBADD = $(coll_xccl_LIBS)
+libmca_coll_xccl_la_LDFLAGS = -module -avoid-version $(coll_xccl_LDFLAGS)
diff --git a/ompi/mca/coll/xccl/coll_xccl.h b/ompi/mca/coll/xccl/coll_xccl.h
new file mode 100644
index 0000000..9eac860
--- /dev/null
+++ b/ompi/mca/coll/xccl/coll_xccl.h
@@ -0,0 +1,116 @@
+/**
+ Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+ $COPYRIGHT$
+
+ Additional copyrights may follow
+
+ $HEADER$
+ */
+
+#ifndef MCA_COLL_XCCL_H
+#define MCA_COLL_XCCL_H
+
+#include "ompi_config.h"
+
+#include "mpi.h"
+#include "ompi/mca/mca.h"
+#include "opal/memoryhooks/memory.h"
+#include "opal/mca/memory/base/base.h"
+#include "ompi/mca/coll/coll.h"
+#include "ompi/request/request.h"
+#include "ompi/mca/pml/pml.h"
+#include "ompi/mca/coll/base/coll_tags.h"
+#include "ompi/communicator/communicator.h"
+#include "ompi/attribute/attribute.h"
+#include "ompi/op/op.h"
+#include "api/xccl.h"
+#include "coll_xccl_debug.h"
+#ifndef XCCL_VERSION
+#define XCCL_VERSION(major, minor) (((major)<<XCCL_MAJOR_BIT)|((minor)<<XCCL_MINOR_BIT))
+#endif
+BEGIN_C_DECLS
+
+struct mca_coll_xccl_component_t {
+ /** Base coll component */
+ mca_coll_base_component_2_0_0_t super;
+
+ /** MCA parameter: Priority of this component */
+ int xccl_priority;
+
+ /** MCA parameter: Verbose level of this component */
+ int xccl_verbose;
+
+ /** MCA parameter: Enable XCCL */
+ int xccl_enable;
+
+ /** r/o MCA parameter: libxccl compiletime version */
+ char* compiletime_version;
+
+ /** r/o MCA parameter: libxccl runtime version */
+ const char* runtime_version;
+
+ /** MCA parameter: Minimal number of processes in the communicator
+ for the corresponding xccl context to be created */
+ int xccl_np;
+
+ /** Whether or not xccl_init was ever called */
+ bool libxccl_initialized;
+ xccl_lib_h xccl_lib;
+ xccl_context_h xccl_context;
+ xccl_ctx_attr_t xccl_ctx_attr;
+ opal_free_list_t requests;
+ char *tls;
+};
+typedef struct mca_coll_xccl_component_t mca_coll_xccl_component_t;
+
+OMPI_MODULE_DECLSPEC extern mca_coll_xccl_component_t mca_coll_xccl_component;
+
+/**
+ * XCCL enabled communicator
+ */
+struct mca_coll_xccl_module_t {
+ mca_coll_base_module_t super;
+ ompi_communicator_t* comm;
+ int rank;
+ xccl_team_h xccl_team;
+ mca_coll_base_module_allreduce_fn_t previous_allreduce;
+ mca_coll_base_module_t* previous_allreduce_module;
+ mca_coll_base_module_reduce_fn_t previous_reduce;
+ mca_coll_base_module_t* previous_reduce_module;
+ mca_coll_base_module_barrier_fn_t previous_barrier;
+ mca_coll_base_module_t* previous_barrier_module;
+ mca_coll_base_module_bcast_fn_t previous_bcast;
+ mca_coll_base_module_t* previous_bcast_module;
+ mca_coll_base_module_alltoall_fn_t previous_alltoall;
+ mca_coll_base_module_t* previous_alltoall_module;
+};
+typedef struct mca_coll_xccl_module_t mca_coll_xccl_module_t;
+OBJ_CLASS_DECLARATION(mca_coll_xccl_module_t);
+
+int mca_coll_xccl_init_query(bool enable_progress_threads, bool enable_mpi_threads);
+mca_coll_base_module_t *mca_coll_xccl_comm_query(struct ompi_communicator_t *comm, int *priority);
+
+int mca_coll_xccl_allreduce(const void *sbuf, void *rbuf, int count,
+ struct ompi_datatype_t *dtype, struct ompi_op_t *op,
+ struct ompi_communicator_t *comm,
+ mca_coll_base_module_t *module);
+
+int mca_coll_xccl_reduce(const void *sbuf, void *rbuf, int count,
+ struct ompi_datatype_t *dtype, struct ompi_op_t *op,
+ int root, struct ompi_communicator_t *comm,
+ mca_coll_base_module_t *module);
+
+int mca_coll_xccl_barrier(struct ompi_communicator_t *comm,
+ mca_coll_base_module_t *module);
+
+int mca_coll_xccl_bcast(void *buf, int count, struct ompi_datatype_t *dtype,
+ int root, struct ompi_communicator_t *comm,
+ mca_coll_base_module_t *module);
+
+int mca_coll_xccl_alltoall(const void *sbuf, int scount, struct ompi_datatype_t *sdtype,
+ void* rbuf, int rcount, struct ompi_datatype_t *rdtype,
+ struct ompi_communicator_t *comm,
+ mca_coll_base_module_t *module);
+
+END_C_DECLS
+#endif
diff --git a/ompi/mca/coll/xccl/coll_xccl_component.c b/ompi/mca/coll/xccl/coll_xccl_component.c
new file mode 100644
index 0000000..4cc2910
--- /dev/null
+++ b/ompi/mca/coll/xccl/coll_xccl_component.c
@@ -0,0 +1,172 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+ * $COPYRIGHT$
+ *
+ * Additional copyrights may follow
+ *
+ * $HEADER$
+ */
+#include "ompi_config.h"
+#include <stdio.h>
+
+#include <dlfcn.h>
+#include <libgen.h>
+
+#include "coll_xccl.h"
+#include "opal/mca/installdirs/installdirs.h"
+#include "coll_xccl_dtypes.h"
+
+/*
+ * Public string showing the coll ompi_xccl component version number
+ */
+const char *mca_coll_xccl_component_version_string =
+ "Open MPI XCCL collective MCA component version " OMPI_VERSION;
+
+
+static int xccl_open(void);
+static int xccl_close(void);
+static int xccl_register(void);
+int mca_coll_xccl_output = -1;
+mca_coll_xccl_component_t mca_coll_xccl_component = {
+ /* First, the mca_component_t struct containing meta information
+ about the component */
+ {
+ .collm_version = {
+ MCA_COLL_BASE_VERSION_2_0_0,
+
+ /* Component name and version */
+ .mca_component_name = "xccl",
+ MCA_BASE_MAKE_VERSION(component, OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION,
+ OMPI_RELEASE_VERSION),
+
+ /* Component open and close functions */
+ .mca_open_component = xccl_open,
+ .mca_close_component = xccl_close,
+ .mca_register_component_params = xccl_register,
+ },
+ .collm_data = {
+ /* The component is not checkpoint ready */
+ MCA_BASE_METADATA_PARAM_NONE
+ },
+
+ /* Initialization / querying functions */
+ .collm_init_query = mca_coll_xccl_init_query,
+ .collm_comm_query = mca_coll_xccl_comm_query,
+ },
+ 120, /* priority */
+ 0, /* verbose level */
+ 0, /* xccl_enable */
+ NULL /*xccl version */
+};
+
+enum {
+ REGINT_NEG_ONE_OK = 0x01,
+ REGINT_GE_ZERO = 0x02,
+ REGINT_GE_ONE = 0x04,
+ REGINT_NONZERO = 0x08,
+ REGINT_MAX = 0x88
+};
+
+enum {
+ REGSTR_EMPTY_OK = 0x01,
+ REGSTR_MAX = 0x88
+};
+
+
+/*
+ * Utility routine for integer parameter registration
+ */
+static int reg_int(const char* param_name, const char* deprecated_param_name,
+ const char* param_desc, int default_value, int *storage, int flags)
+{
+ int index;
+ *storage = default_value;
+ index = mca_base_component_var_register(&mca_coll_xccl_component.super.collm_version,
+ param_name, param_desc, MCA_BASE_VAR_TYPE_INT,
+ NULL, 0, 0,OPAL_INFO_LVL_9,
+ MCA_BASE_VAR_SCOPE_READONLY, storage);
+ if (NULL != deprecated_param_name) {
+ (void) mca_base_var_register_synonym(index, "ompi", "coll", "xccl", deprecated_param_name,
+ MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
+ }
+
+ if (0 != (flags & REGINT_NEG_ONE_OK) && -1 == *storage) {
+ return OMPI_SUCCESS;
+ }
+
+ if ((0 != (flags & REGINT_GE_ZERO) && *storage < 0) ||
+ (0 != (flags & REGINT_GE_ONE) && *storage < 1) ||
+ (0 != (flags & REGINT_NONZERO) && 0 == *storage)) {
+ opal_output(0, "Bad parameter value for parameter \"%s\"", param_name);
+ return OMPI_ERR_BAD_PARAM;
+ }
+ return OMPI_SUCCESS;
+}
+
+
+static int xccl_register(void)
+{
+ int ret, tmp;
+ ret = OMPI_SUCCESS;
+
+#define CHECK(expr) do { \
+ tmp = (expr); \
+ if (OMPI_SUCCESS != tmp) ret = tmp; \
+ } while (0)
+
+
+ CHECK(reg_int("priority", NULL, "Priority of the xccl coll component",
+ 120, &mca_coll_xccl_component.xccl_priority, 0));
+
+ CHECK(reg_int("verbose", NULL, "Verbose level of the xccl coll component",
+ 0, &mca_coll_xccl_component.xccl_verbose, 0));
+
+ CHECK(reg_int("enable", NULL, "[1|0|] Enable/Disable XCCL",
+ 1, &mca_coll_xccl_component.xccl_enable, 0));
+
+ CHECK(reg_int("np", NULL, "Minimal number of processes in the communicator"
+ " for the corresponding xccl context to be created (default: 32)",
+ 2, &mca_coll_xccl_component.xccl_np, 0));
+
+ /* mca_coll_xccl_component.compiletime_version = XCCL_VERNO_STRING; */
+
+ mca_base_component_var_register(&mca_coll_xccl_component.super.collm_version,
+ MCA_COMPILETIME_VER,
+ "Version of the libxccl library with which Open MPI was compiled",
+ MCA_BASE_VAR_TYPE_VERSION_STRING, NULL, 0, 0,
+ OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY,
+ &mca_coll_xccl_component.compiletime_version);
+ /* mca_coll_xccl_component.runtime_version = xccl_get_version(); */
+ mca_base_component_var_register(&mca_coll_xccl_component.super.collm_version,
+ MCA_RUNTIME_VER,
+ "Version of the libxccl library with which Open MPI is running",
+ MCA_BASE_VAR_TYPE_VERSION_STRING, NULL, 0, 0,
+ OPAL_INFO_LVL_3, MCA_BASE_VAR_SCOPE_READONLY,
+ &mca_coll_xccl_component.runtime_version);
+
+ mca_coll_xccl_component.tls = "hier";
+ mca_base_component_var_register(&mca_coll_xccl_component.super.collm_version,
+ "tls",
+ "Comma separated list of XCCL TLS to be used for team creation",
+ MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
+ OPAL_INFO_LVL_6,
+ MCA_BASE_VAR_SCOPE_READONLY,
+ &mca_coll_xccl_component.tls);
+ return ret;
+}
+
+static int xccl_open(void)
+{
+ mca_coll_xccl_component_t *cm;
+ cm = &mca_coll_xccl_component;
+ mca_coll_xccl_output = opal_output_open(NULL);
+ opal_output_set_verbosity(mca_coll_xccl_output, cm->xccl_verbose);
+ cm->libxccl_initialized = false;
+ return OMPI_SUCCESS;
+}
+
+static int xccl_close(void)
+{
+ return OMPI_SUCCESS;
+}
diff --git a/ompi/mca/coll/xccl/coll_xccl_debug.h b/ompi/mca/coll/xccl/coll_xccl_debug.h
new file mode 100644
index 0000000..ee9bdab
--- /dev/null
+++ b/ompi/mca/coll/xccl/coll_xccl_debug.h
@@ -0,0 +1,30 @@
+/**
+ Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+ $COPYRIGHT$
+
+ Additional copyrights may follow
+
+ $HEADER$
+ */
+
+#ifndef COLL_XCCL_DEBUG_H
+#define COLL_XCCL_DEBUG_H
+#include "ompi_config.h"
+#pragma GCC system_header
+
+#ifdef __BASE_FILE__
+#define __XCCL_FILE__ __BASE_FILE__
+#else
+#define __XCCL_FILE__ __FILE__
+#endif
+
+#define XCCL_VERBOSE(level, format, ...) \
+ opal_output_verbose(level, mca_coll_xccl_output, "%s:%d - %s() " format, \
+ __XCCL_FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__)
+
+#define XCCL_ERROR(format, ... ) \
+ opal_output_verbose(0, mca_coll_xccl_output, "Error: %s:%d - %s() " format, \
+ __XCCL_FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__)
+
+extern int mca_coll_xccl_output;
+#endif
diff --git a/ompi/mca/coll/xccl/coll_xccl_dtypes.h b/ompi/mca/coll/xccl/coll_xccl_dtypes.h
new file mode 100644
index 0000000..52ce6c6
--- /dev/null
+++ b/ompi/mca/coll/xccl/coll_xccl_dtypes.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+ * $COPYRIGHT$
+ *
+ * Additional copyrights may follow
+ *
+ * $HEADER$
+ */
+#ifndef COLL_XCCL_DTYPES_H
+#define COLL_XCCL_DTYPES_H
+#include "ompi/datatype/ompi_datatype.h"
+#include "ompi/datatype/ompi_datatype_internal.h"
+#include "ompi/mca/op/op.h"
+#include "api/xccl.h"
+
+
+static xccl_dt_t ompi_datatype_2_xccl_dt[OMPI_DATATYPE_MAX_PREDEFINED] = {
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_LOOP 0 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_END_LOOP 1 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_LB 2 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_UB 3 */
+ XCCL_DT_INT8, /*OPAL_DATATYPE_INT1 4 */
+ XCCL_DT_INT16, /*OPAL_DATATYPE_INT2 5 */
+ XCCL_DT_INT32, /*OPAL_DATATYPE_INT4 6 */
+ XCCL_DT_INT64, /*OPAL_DATATYPE_INT8 7 */
+ XCCL_DT_INT128, /*OPAL_DATATYPE_INT16 8 */
+ XCCL_DT_UINT8, /*OPAL_DATATYPE_UINT1 9 */
+ XCCL_DT_UINT16, /*OPAL_DATATYPE_UINT2 10 */
+ XCCL_DT_UINT32, /*OPAL_DATATYPE_UINT4 11 */
+ XCCL_DT_UINT64, /*OPAL_DATATYPE_UINT8 12 */
+ XCCL_DT_UINT128, /*OPAL_DATATYPE_UINT16 13 */
+ XCCL_DT_FLOAT16, /*OPAL_DATATYPE_FLOAT2 14 */
+ XCCL_DT_FLOAT32, /*OPAL_DATATYPE_FLOAT4 15 */
+ XCCL_DT_FLOAT64, /*OPAL_DATATYPE_FLOAT8 16 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_FLOAT12 17 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_FLOAT16 18 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_SHORT_FLOAT_COMPLEX 19 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_FLOAT_COMPLEX 20 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_DOUBLE_COMPLEX 21 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_LONG_DOUBLE_COMPLEX 22 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_BOOL 23 */
+ XCCL_DT_UNSUPPORTED, /*OPAL_DATATYPE_WCHAR 24 */
+ XCCL_DT_UNSUPPORTED /*OPAL_DATATYPE_UNAVAILABLE 25 */
+};
+
+static inline xccl_dt_t ompi_dtype_to_xccl_dtype(ompi_datatype_t *dtype)
+{
+ int ompi_type_id = dtype->id;
+ int opal_type_id = dtype->super.id;
+
+ if (ompi_type_id < OMPI_DATATYPE_MPI_MAX_PREDEFINED &&
+ dtype->super.flags & OMPI_DATATYPE_FLAG_PREDEFINED) {
+ if (opal_type_id > 0 && opal_type_id < OPAL_DATATYPE_MAX_PREDEFINED) {
+ return ompi_datatype_2_xccl_dt[opal_type_id];
+ }
+ }
+ return XCCL_DT_UNSUPPORTED;
+}
+
+static xccl_op_t ompi_op_to_xccl_op_map[OMPI_OP_BASE_FORTRAN_OP_MAX + 1] = {
+ XCCL_OP_UNSUPPORTED, /* OMPI_OP_BASE_FORTRAN_NULL = 0 */
+ XCCL_OP_MAX, /* OMPI_OP_BASE_FORTRAN_MAX */
+ XCCL_OP_MIN, /* OMPI_OP_BASE_FORTRAN_MIN */
+ XCCL_OP_SUM, /* OMPI_OP_BASE_FORTRAN_SUM */
+ XCCL_OP_PROD, /* OMPI_OP_BASE_FORTRAN_PROD */
+ XCCL_OP_LAND, /* OMPI_OP_BASE_FORTRAN_LAND */
+ XCCL_OP_BAND, /* OMPI_OP_BASE_FORTRAN_BAND */
+ XCCL_OP_LOR, /* OMPI_OP_BASE_FORTRAN_LOR */
+ XCCL_OP_BOR, /* OMPI_OP_BASE_FORTRAN_BOR */
+ XCCL_OP_LXOR, /* OMPI_OP_BASE_FORTRAN_LXOR */
+ XCCL_OP_BXOR, /* OMPI_OP_BASE_FORTRAN_BXOR */
+ XCCL_OP_UNSUPPORTED, /* OMPI_OP_BASE_FORTRAN_MAXLOC */
+ XCCL_OP_UNSUPPORTED, /* OMPI_OP_BASE_FORTRAN_MINLOC */
+ XCCL_OP_UNSUPPORTED, /* OMPI_OP_BASE_FORTRAN_REPLACE */
+ XCCL_OP_UNSUPPORTED, /* OMPI_OP_BASE_FORTRAN_NO_OP */
+ XCCL_OP_UNSUPPORTED /* OMPI_OP_BASE_FORTRAN_OP_MAX */
+};
+
+static inline xccl_op_t ompi_op_to_xccl_op(ompi_op_t *op) {
+ if (op->o_f_to_c_index > OMPI_OP_BASE_FORTRAN_OP_MAX) {
+ return XCCL_OP_UNSUPPORTED;
+ }
+ return ompi_op_to_xccl_op_map[op->o_f_to_c_index];
+}
+
+#endif /* COLL_XCCL_DTYPES_H */
diff --git a/ompi/mca/coll/xccl/coll_xccl_module.c b/ompi/mca/coll/xccl/coll_xccl_module.c
new file mode 100644
index 0000000..b198ac1
--- /dev/null
+++ b/ompi/mca/coll/xccl/coll_xccl_module.c
@@ -0,0 +1,393 @@
+/**
+ * Copyright (c) 2020 Mellanox Technologies. All rights reserved.
+ * $COPYRIGHT$
+ *
+ * Additional copyrights may follow
+ *
+ * $HEADER$
+ */
+
+#include "ompi_config.h"
+#include "coll_xccl.h"
+#include "coll_xccl_dtypes.h"
+
+#define OBJ_RELEASE_IF_NOT_NULL( obj ) if( NULL != (obj) ) OBJ_RELEASE( obj );
+
+static int xccl_comm_attr_keyval;
+/*
+ * Initial query function that is invoked during MPI_INIT, allowing
+ * this module to indicate what level of thread support it provides.
+ */
+int mca_coll_xccl_init_query(bool enable_progress_threads, bool enable_mpi_threads)
+{
+ return OMPI_SUCCESS;
+}
+
+static void mca_coll_xccl_module_clear(mca_coll_xccl_module_t *xccl_module)
+{
+ xccl_module->xccl_team = NULL;
+ xccl_module->previous_allreduce = NULL;
+ xccl_module->previous_reduce = NULL;
+ xccl_module->previous_barrier = NULL;
+ xccl_module->previous_bcast = NULL;
+ xccl_module->previous_alltoall = NULL;
+}
+
+static void mca_coll_xccl_module_construct(mca_coll_xccl_module_t *xccl_module)
+{
+ mca_coll_xccl_module_clear(xccl_module);
+}
+
+int mca_coll_xccl_progress(void)
+{
+ xccl_context_progress(mca_coll_xccl_component.xccl_context);
+ return OPAL_SUCCESS;
+}
+
+static void mca_coll_xccl_module_destruct(mca_coll_xccl_module_t *xccl_module)
+{
+ int context_destroyed;
+ if (xccl_module->comm == &ompi_mpi_comm_world.comm){
+ if (OMPI_SUCCESS != ompi_attr_free_keyval(COMM_ATTR, &xccl_comm_attr_keyval, 0)) {
+ XCCL_VERBOSE(1,"xccl ompi_attr_free_keyval failed");
+ }
+ }
+
+ /* If the xccl_context is null then we are destroying the xccl_module
+ that didn't initialized fallback colls/modules.
+ Then just clear and return. Otherwise release module pointers and
+ destroy xccl context*/
+
+ if (xccl_module->xccl_team != NULL){
+ OBJ_RELEASE_IF_NOT_NULL(xccl_module->previous_allreduce_module);
+ OBJ_RELEASE_IF_NOT_NULL(xccl_module->previous_reduce_module);
+ OBJ_RELEASE_IF_NOT_NULL(xccl_module->previous_barrier_module);
+ OBJ_RELEASE_IF_NOT_NULL(xccl_module->previous_bcast_module);
+ OBJ_RELEASE_IF_NOT_NULL(xccl_module->previous_alltoall_module);
+ }
+ mca_coll_xccl_module_clear(xccl_module);
+}
+
+#define SAVE_PREV_COLL_API(__api) do { \
+ xccl_module->previous_ ## __api = comm->c_coll->coll_ ## __api; \
+ xccl_module->previous_ ## __api ## _module = comm->c_coll->coll_ ## __api ## _module; \
+ if (!comm->c_coll->coll_ ## __api || !comm->c_coll->coll_ ## __api ## _module) { \
+ return OMPI_ERROR; \
+ } \
+ OBJ_RETAIN(xccl_module->previous_ ## __api ## _module); \
+ } while(0)
+
+static int mca_coll_xccl_save_coll_handlers(mca_coll_xccl_module_t *xccl_module)
+{
+ ompi_communicator_t *comm;
+ comm = xccl_module->comm;
+ SAVE_PREV_COLL_API(allreduce);
+ SAVE_PREV_COLL_API(reduce);
+ SAVE_PREV_COLL_API(barrier);
+ SAVE_PREV_COLL_API(bcast);
+ SAVE_PREV_COLL_API(alltoall);
+ return OMPI_SUCCESS;
+}
+
+/*
+** Communicator free callback
+*/
+static int xccl_comm_attr_del_fn(MPI_Comm comm, int keyval, void *attr_val, void *extra)
+{
+
+ mca_coll_xccl_module_t *xccl_module;
+ xccl_module = (mca_coll_xccl_module_t*) attr_val;
+ xccl_team_destroy(xccl_module->xccl_team);
+ if (xccl_module->comm == &ompi_mpi_comm_world.comm) {
+ if (mca_coll_xccl_component.libxccl_initialized) {
+ XCCL_VERBOSE(5,"XCCL FINALIZE");
+ opal_progress_unregister(mca_coll_xccl_progress);
+ xccl_context_destroy(mca_coll_xccl_component.xccl_context);
+ xccl_lib_cleanup(mca_coll_xccl_component.xccl_lib);
+ }
+ }
+ return OMPI_SUCCESS;
+}
+
+typedef struct oob_allgather_req{
+ xccl_ep_range_t range;
+ void *sbuf;
+ void *rbuf;
+ void *oob_coll_ctx;
+ int my_rank;
+ size_t msglen;
+ int iter;
+ ompi_request_t *reqs[2];
+} oob_allgather_req_t;
+
+static xccl_status_t oob_allgather_test(void *req)
+{
+ oob_allgather_req_t *oob_req = (oob_allgather_req_t*)req;
+ ompi_communicator_t *comm = (ompi_communicator_t *)oob_req->oob_coll_ctx;
+ char *tmpsend = NULL, *tmprecv = NULL;
+ size_t msglen = oob_req->msglen;
+ const int probe_count = 1;
+ int rank, size, sendto, recvfrom, recvdatafrom, senddatafrom, completed, probe;
+
+ if (!comm) comm = &ompi_mpi_comm_world.comm;
+ if (oob_req->range.type == XCCL_EP_RANGE_UNDEFINED) {
+ size = ompi_comm_size(comm);
+ rank = ompi_comm_rank(comm);
+ } else {
+ size = oob_req->range.ep_num;
+ rank = oob_req->my_rank;
+ }
+ if (oob_req->iter == 0) {
+ tmprecv = (char*) oob_req->rbuf + (ptrdiff_t)rank * (ptrdiff_t)msglen;
+ memcpy(tmprecv, oob_req->sbuf, msglen);
+ }
+ sendto = (rank + 1) % size;
+ recvfrom = (rank - 1 + size) % size;
+ if (oob_req->range.type != XCCL_EP_RANGE_UNDEFINED) {
+ sendto = xccl_range_to_rank(oob_req->range, sendto);
+ recvfrom = xccl_range_to_rank(oob_req->range, recvfrom);
+ }
+ for (; oob_req->iter < size - 1; oob_req->iter++) {
+ if (oob_req->iter > 0) {
+ probe = 0;
+ do {
+ ompi_request_test_all(2, oob_req->reqs, &completed, MPI_STATUS_IGNORE);
+ probe++;
+ } while (!completed && probe < probe_count);
+ if (!completed) {
+ return XCCL_INPROGRESS;
+ }
+ }
+ recvdatafrom = (rank - oob_req->iter - 1 + size) % size;
+ senddatafrom = (rank - oob_req->iter + size) % size;
+ tmprecv = (char*)oob_req->rbuf + (ptrdiff_t)recvdatafrom * (ptrdiff_t)msglen;
+ tmpsend = (char*)oob_req->rbuf + (ptrdiff_t)senddatafrom * (ptrdiff_t)msglen;
+
+ MCA_PML_CALL(isend(tmpsend, msglen, MPI_BYTE, sendto, MCA_COLL_BASE_TAG_XCCL,
+ MCA_PML_BASE_SEND_STANDARD, comm, &oob_req->reqs[0]));
+ MCA_PML_CALL(irecv(tmprecv, msglen, MPI_BYTE, recvfrom,
+ MCA_COLL_BASE_TAG_XCCL, comm, &oob_req->reqs[1]));
+ }
+ probe = 0;
+ do {
+ ompi_request_test_all(2, oob_req->reqs, &completed, MPI_STATUS_IGNORE);
+ probe++;
+ } while (!completed && probe < probe_count);
+ if (!completed) {
+ return XCCL_INPROGRESS;
+ }
+ return XCCL_OK;
+}
+
+static xccl_status_t oob_allgather_free(void *req)
+{
+ free(req);
+ return XCCL_OK;
+}
+
+static xccl_status_t oob_allgather(void *sbuf, void *rbuf, size_t msglen,
+ int my_rank, xccl_ep_range_t range,
+ void *oob_coll_ctx, void **req)
+{
+ oob_allgather_req_t *oob_req = malloc(sizeof(*oob_req));
+ oob_req->sbuf = sbuf;
+ oob_req->rbuf = rbuf;
+ oob_req->msglen = msglen;
+ oob_req->range = range;
+ oob_req->oob_coll_ctx = oob_coll_ctx;
+ oob_req->my_rank = my_rank;
+ oob_req->iter = 0;
+ *req = oob_req;
+ return oob_allgather_test(*req);
+}
+
+static int mca_coll_xccl_init_ctx() {
+ mca_coll_xccl_component_t *cm = &mca_coll_xccl_component;
+ ompi_attribute_fn_ptr_union_t del_fn;
+ ompi_attribute_fn_ptr_union_t copy_fn;
+ xccl_lib_config_t *cfg;
+ xccl_context_config_t *ctx_config;
+
+ xccl_lib_params_t lib_params = {
+ .field_mask = XCCL_LIB_PARAM_FIELD_TEAM_USAGE,
+ .team_usage = XCCL_LIB_PARAMS_TEAM_USAGE_SW_COLLECTIVES |
+ XCCL_LIB_PARAMS_TEAM_USAGE_HW_COLLECTIVES,
+ };
+ xccl_context_params_t ctx_params = {
+ .field_mask = XCCL_CONTEXT_PARAM_FIELD_THREAD_MODE |
+ XCCL_CONTEXT_PARAM_FIELD_OOB |
+ XCCL_CONTEXT_PARAM_FIELD_TEAM_COMPLETION_TYPE |
+ XCCL_CONTEXT_PARAM_FIELD_TLS,
+ .thread_mode = XCCL_THREAD_MODE_SINGLE,
+ .completion_type = XCCL_TEAM_COMPLETION_TYPE_BLOCKING,
+ .oob = {
+ .allgather = oob_allgather,
+ .req_test = oob_allgather_test,
+ .req_free = oob_allgather_free,
+ .coll_context = (void*)MPI_COMM_WORLD,
+ .rank = ompi_comm_rank(&ompi_mpi_comm_world.comm),
+ .size = ompi_comm_size(&ompi_mpi_comm_world.comm)
+ },
+ .tls = xccl_tls_str_to_bitmap(cm->tls),
+ };
+
+ XCCL_VERBOSE(10,"Calling xccl_init");
+ if (XCCL_OK != xccl_lib_init(&lib_params, cfg, &cm->xccl_lib)) {
+ XCCL_ERROR("XCCL lib init failed");
+ cm->xccl_enable = 0;
+ return OMPI_ERROR;
+ }
+ if (XCCL_OK != xccl_context_config_read(cm->xccl_lib, NULL, NULL, &ctx_config)) {
+ XCCL_ERROR("XCCL context config read failed");
+ goto cleanup_lib;
+ }
+ if (XCCL_OK != xccl_context_create(cm->xccl_lib, &ctx_params,
+ ctx_config, &cm->xccl_context)) {
+ XCCL_ERROR("XCCL context create failed");
+ xccl_context_config_release(ctx_config);
+ goto cleanup_lib;
+ }
+ xccl_context_config_release(ctx_config);
+
+ copy_fn.attr_communicator_copy_fn = (MPI_Comm_internal_copy_attr_function*) MPI_COMM_NULL_COPY_FN;
+ del_fn.attr_communicator_delete_fn = xccl_comm_attr_del_fn;
+ if (OMPI_SUCCESS != ompi_attr_create_keyval(COMM_ATTR, copy_fn, del_fn,
+ &xccl_comm_attr_keyval, NULL ,0, NULL)) {
+ XCCL_ERROR("XCCL comm keyval create failed");
+ goto cleanup_ctx;
+ }
+ opal_progress_register(mca_coll_xccl_progress);
+ cm->xccl_ctx_attr.field_mask = XCCL_CTX_ATTR_FIELD_SUPPORTED_COLLS;
+ if (XCCL_OK!= xccl_ctx_query(cm->xccl_context, &cm->xccl_ctx_attr)) {
+ XCCL_ERROR("XCCL failed to query context attributes");
+ goto cleanup_ctx;
+ }
+
+ cm->libxccl_initialized = true;
+ return OMPI_SUCCESS;
+cleanup_ctx:
+ xccl_context_destroy(cm->xccl_context);
+
+cleanup_lib:
+ xccl_lib_cleanup(cm->xccl_lib);
+ cm->xccl_enable = 0;
+ cm->libxccl_initialized = false;
+ return OMPI_ERROR;
+}
+/*
+ * Initialize module on the communicator
+ */
+static int mca_coll_xccl_module_enable(mca_coll_base_module_t *module,
+ struct ompi_communicator_t *comm)
+{
+ mca_coll_xccl_component_t *cm = &mca_coll_xccl_component;
+ mca_coll_xccl_module_t *xccl_module;
+ int rc;
+
+ xccl_module = (mca_coll_xccl_module_t *)module;
+ XCCL_VERBOSE(10,"Creating xccl_context for comm %p, comm_id %d, comm_size %d",
+ (void*)comm,comm->c_contextid,ompi_comm_size(comm));
+ xccl_team_params_t team_params = {
+ .field_mask = XCCL_TEAM_PARAM_FIELD_EP_RANGE |
+ XCCL_TEAM_PARAM_FIELD_OOB,
+ .range = {
+ .type = XCCL_EP_RANGE_STRIDED,
+ .strided.start = 0,
+ .strided.stride = 1
+ },
+
+ .oob = {
+ .allgather = oob_allgather,
+ .req_test = oob_allgather_test,
+ .req_free = oob_allgather_free,
+ .coll_context = (void*)comm,
+ .rank = ompi_comm_rank(comm),
+ .size = ompi_comm_size(comm)
+ }
+ };
+ if (XCCL_OK != xccl_team_create_post(cm->xccl_context,
+ &team_params, &xccl_module->xccl_team)) {
+ XCCL_VERBOSE(1,"xccl_team_create_post failed");
+ OBJ_RELEASE(xccl_module);
+ goto err;
+ }
+ while (XCCL_INPROGRESS == xccl_team_create_test(xccl_module->xccl_team)) {;}
+
+ if (OMPI_SUCCESS != mca_coll_xccl_save_coll_handlers((mca_coll_xccl_module_t *)module)){
+ XCCL_ERROR("coll_xccl: mca_coll_xccl_save_coll_handlers failed");
+ goto err;
+ }
+
+ rc = ompi_attr_set_c(COMM_ATTR, comm, &comm->c_keyhash, xccl_comm_attr_keyval, (void *)module, false);
+ if (OMPI_SUCCESS != rc) {
+ XCCL_VERBOSE(1,"xccl ompi_attr_set_c failed");
+ goto err;
+ }
+ return OMPI_SUCCESS;
+
+err:
+ cm->xccl_enable = 0;
+ opal_progress_unregister(mca_coll_xccl_progress);
+ return OMPI_ERROR;
+}
+
+
+/*
+ * Invoked when there's a new communicator that has been created.
+ * Look at the communicator and decide which set of functions and
+ * priority we want to return.
+ */
+mca_coll_base_module_t *
+mca_coll_xccl_comm_query(struct ompi_communicator_t *comm, int *priority)
+{
+ mca_coll_xccl_component_t *cm = &mca_coll_xccl_component;
+ mca_coll_xccl_module_t *xccl_module;
+ *priority = 0;
+
+ if (!cm->xccl_enable){
+ return NULL;
+ }
+
+ if (OMPI_COMM_IS_INTER(comm) || ompi_comm_size(comm) < cm->xccl_np
+ || ompi_comm_size(comm) < 2){
+ return NULL;
+ }
+
+ if (!cm->libxccl_initialized) {
+ if (OMPI_SUCCESS != mca_coll_xccl_init_ctx()) {
+ cm->xccl_enable = 0;
+ return NULL;
+ }
+ }
+
+ xccl_module = OBJ_NEW(mca_coll_xccl_module_t);
+ if (!xccl_module) {
+ cm->xccl_enable = 0;
+ return NULL;
+ }
+ xccl_module->comm = comm;
+ xccl_module->super.coll_module_enable = mca_coll_xccl_module_enable;
+ xccl_module->super.coll_allreduce =
+ cm->xccl_ctx_attr.supported_colls & XCCL_COLL_CAP_ALLREDUCE ?
+ mca_coll_xccl_allreduce : NULL;
+ xccl_module->super.coll_reduce =
+ cm->xccl_ctx_attr.supported_colls & XCCL_COLL_CAP_REDUCE ?
+ mca_coll_xccl_reduce : NULL;
+ xccl_module->super.coll_barrier =
+ cm->xccl_ctx_attr.supported_colls & XCCL_COLL_CAP_BARRIER ?
+ mca_coll_xccl_barrier : NULL;
+ xccl_module->super.coll_bcast =
+ cm->xccl_ctx_attr.supported_colls & XCCL_COLL_CAP_BCAST ?
+ mca_coll_xccl_bcast : NULL;
+ xccl_module->super.coll_alltoall =
+ cm->xccl_ctx_attr.supported_colls & XCCL_COLL_CAP_ALLTOALL ?
+ mca_coll_xccl_alltoall : NULL;
+ *priority = cm->xccl_priority;
+ return &xccl_module->super;
+}
+