Skip to content

Commit e9f36b1

Browse files
committed
ucx: check supported transports for setting priority
1 parent 4b18e1d commit e9f36b1

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

contrib/platform/mellanox/optimized.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
coll = ^ml
6262
hwloc_base_binding_policy = core
6363
btl = self
64+
pml_ucx_priority = 60
6465
# Basic behavior to smooth startup
6566
mca_base_component_show_load_errors = 0
6667
orte_abort_timeout = 10

ompi/mca/pml/ucx/pml_ucx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct mca_pml_ucx_module {
5757
mca_pml_ucx_freelist_t convs;
5858

5959
int priority;
60+
int max_priority;
6061
bool cuda_initialized;
6162
};
6263

ompi/mca/pml/ucx/pml_ucx_component.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ mca_pml_base_component_2_0_0_t mca_pml_ucx_component = {
4949

5050
static int mca_pml_ucx_component_register(void)
5151
{
52-
ompi_pml_ucx.priority = 51;
52+
ompi_pml_ucx.priority = 25;
5353
(void) mca_base_component_var_register(&mca_pml_ucx_component.pmlm_version, "priority",
5454
"Priority of the UCX component",
5555
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
5656
OPAL_INFO_LVL_3,
5757
MCA_BASE_VAR_SCOPE_LOCAL,
5858
&ompi_pml_ucx.priority);
5959

60+
ompi_pml_ucx.max_priority = 51;
61+
(void) mca_base_component_var_register(&mca_pml_ucx_component.pmlm_version, "max_priority",
62+
"Priority of the UCX component if suitable hardware is detected",
63+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
64+
OPAL_INFO_LVL_3,
65+
MCA_BASE_VAR_SCOPE_LOCAL,
66+
&ompi_pml_ucx.max_priority);
67+
6068
ompi_pml_ucx.num_disconnect = 1;
6169
(void) mca_base_component_var_register(&mca_pml_ucx_component.pmlm_version, "num_disconnect",
6270
"How may disconnects go in parallel",
@@ -98,7 +106,9 @@ mca_pml_ucx_component_init(int* priority, bool enable_progress_threads,
98106
return NULL;
99107
}
100108

101-
*priority = ompi_pml_ucx.priority;
109+
*priority = opal_common_ucx_priority(ompi_pml_ucx.ucp_context,
110+
ompi_pml_ucx.priority,
111+
ompi_pml_ucx.max_priority);
102112
return &ompi_pml_ucx.super;
103113
}
104114

opal/mca/common/ucx/common_ucx.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "opal/memoryhooks/memory.h"
2020

2121
#include <ucm/api/ucm.h>
22+
#include <stdio.h>
2223

2324
/***********************************************************************/
2425

@@ -126,6 +127,59 @@ OPAL_DECLSPEC void opal_common_ucx_mca_deregister(void)
126127
opal_output_close(opal_common_ucx.output);
127128
}
128129

130+
OPAL_DECLSPEC int opal_common_ucx_priority(ucp_context_h context, int min, int max)
131+
{
132+
#if HAVE_DECL_OPEN_MEMSTREAM
133+
static const char *transports[] = {
134+
"cuda_ipc", "ud_verbs", "rc_verbs", "dc_mlx5"
135+
};
136+
char *match, *ptr, *buffer;
137+
char needle[32];
138+
FILE *stream;
139+
size_t size;
140+
size_t i;
141+
142+
if (min >= max) {
143+
/* no need to check anything - minimal priority is already high enough */
144+
return min;
145+
}
146+
147+
stream = open_memstream(&buffer, &size);
148+
if (stream == NULL) {
149+
MCA_COMMON_UCX_VERBOSE(1, "failed to open memory stream for ucx info (%s), "
150+
"setting default ucx priority to %d",
151+
strerror(errno), min);
152+
return min;
153+
}
154+
155+
ucp_context_print_info(context, stream);
156+
157+
fclose(stream);
158+
159+
for (i = 0; i < sizeof(transports) / sizeof(transports[0]); ++i) {
160+
/* Match "resource 6 : md 5 dev 4 flags -- rc_verbs/mlx5_0:1" */
161+
snprintf(needle, sizeof(needle), " %s/", transports[i]);
162+
match = strstr(buffer, needle);
163+
if (match != NULL) {
164+
MCA_COMMON_UCX_VERBOSE(2, "found '%s' transport on %s, setting priority to %d",
165+
transports[i], strtok_r(match, " \n", &ptr), max);
166+
free(buffer);
167+
return max;
168+
}
169+
}
170+
171+
free(buffer);
172+
173+
MCA_COMMON_UCX_VERBOSE(2, "didn't find matching transports, setting priority to %d",
174+
min);
175+
#else
176+
MCA_COMMON_UCX_VERBOSE(2, "open_memstream() was not found, setting priority to %d",
177+
min);
178+
#endif
179+
180+
return min;
181+
}
182+
129183
void opal_common_ucx_empty_complete_cb(void *request, ucs_status_t status)
130184
{
131185
}

opal/mca/common/ucx/common_ucx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ extern opal_common_ucx_module_t opal_common_ucx;
107107

108108
OPAL_DECLSPEC void opal_common_ucx_mca_register(void);
109109
OPAL_DECLSPEC void opal_common_ucx_mca_deregister(void);
110+
OPAL_DECLSPEC int opal_common_ucx_priority(ucp_context_h context, int min, int max);
110111
OPAL_DECLSPEC void opal_common_ucx_mca_proc_added(void);
111112
OPAL_DECLSPEC void opal_common_ucx_empty_complete_cb(void *request, ucs_status_t status);
112113
OPAL_DECLSPEC int opal_common_ucx_mca_pmix_fence(ucp_worker_h worker);

opal/mca/common/ucx/configure.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ AC_DEFUN([MCA_opal_common_ucx_CONFIG],[
1818
[common_ucx_happy="yes"],
1919
[common_ucx_happy="no"])
2020

21+
AC_CHECK_DECLS([open_memstream], [], [], [[#include <stdio.h>]])
22+
2123
AS_IF([test "$common_ucx_happy" = "yes"],
2224
[$1],
2325
[$2])

0 commit comments

Comments
 (0)