Skip to content

Commit ea17b0b

Browse files
UCP/CORE: Refactor to not reference mlx in UCP
1 parent 838ec0f commit ea17b0b

File tree

2 files changed

+23
-80
lines changed

2 files changed

+23
-80
lines changed

src/ucp/core/ucp_context.c

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
/* Factor to multiply with in order to get infinite latency */
7373
#define UCP_CONTEXT_INFINITE_LAT_FACTOR 100
7474

75-
#define UCP_MLX_PREFIX "mlx"
76-
#define UCP_MLX_DEFAULT_PORT "1"
77-
7875
typedef enum ucp_transports_list_search_result {
7976
UCP_TRANSPORTS_LIST_SEARCH_RESULT_PRIMARY = UCS_BIT(0),
8077
UCP_TRANSPORTS_LIST_SEARCH_RESULT_AUX_IN_MAIN = UCS_BIT(1),
@@ -1080,56 +1077,51 @@ ucp_config_is_tl_name_present(const ucs_config_names_array_t *tl_array,
10801077
tl_cfg_mask));
10811078
}
10821079

1083-
/* Return a pointer to the suffix of the device name,
1084-
* or the end of the string if no suffix is found. */
1085-
static const char *ucp_get_dev_name_suffix(const char *dev_name)
1080+
static UCS_F_ALWAYS_INLINE void
1081+
ucp_get_dev_basename(const char *dev_name, char *dev_basename_p)
10861082
{
10871083
const char *colon = strchr(dev_name, ':');
1088-
if (colon == NULL) {
1089-
return dev_name + strlen(dev_name);
1090-
}
1091-
return colon + 1;
1092-
}
1084+
size_t basename_len;
10931085

1094-
static inline int
1095-
ucp_is_dev_mlx_default_port(const char *dev_name, const char *dev_name_suffix)
1096-
{
1097-
return (!strncmp(dev_name, UCP_MLX_PREFIX, strlen(UCP_MLX_PREFIX))) &&
1098-
(!strcmp(dev_name_suffix, UCP_MLX_DEFAULT_PORT));
1086+
if (colon != NULL) {
1087+
basename_len = colon - dev_name;
1088+
memcpy(dev_basename_p, dev_name, basename_len);
1089+
dev_basename_p[basename_len] = '\0';
1090+
} else {
1091+
dev_basename_p[0] = '\0';
1092+
}
10991093
}
11001094

1095+
/* go over the device list from the user and check (against the available resources)
1096+
* which can be satisfied */
11011097
static int ucp_is_resource_in_device_list(const uct_tl_resource_desc_t *resource,
11021098
const ucs_config_names_array_t *devices,
11031099
uint64_t *dev_cfg_mask,
11041100
uct_device_type_t dev_type)
11051101
{
1106-
char dev_name_base[UCT_DEVICE_NAME_MAX];
1102+
char dev_basename[UCT_DEVICE_NAME_MAX];
11071103
uint64_t mask, exclusive_mask;
1108-
const char *dev_name_suffix;
11091104

1110-
/* go over the device list from the user and check (against the available resources)
1111-
* which can be satisfied */
11121105
ucs_assert_always(devices[dev_type].count <= 64); /* Using uint64_t bitmap */
1106+
1107+
/* search for the full device name */
11131108
mask = ucp_str_array_search((const char**)devices[dev_type].names,
11141109
devices[dev_type].count, resource->dev_name,
11151110
NULL);
1111+
mask |= ucp_str_array_search_in_ranges((const char**)devices[dev_type].names,
1112+
devices[dev_type].count,
1113+
resource->dev_name);
11161114

1115+
/* for network devices, also search for the base name (before the colon) */
11171116
if (dev_type == UCT_DEVICE_TYPE_NET) {
1118-
dev_name_suffix = ucp_get_dev_name_suffix(resource->dev_name);
1119-
1120-
if (ucp_is_dev_mlx_default_port(resource->dev_name, dev_name_suffix)) {
1121-
ucs_strncpy_zero(dev_name_base, resource->dev_name,
1122-
(size_t)(dev_name_suffix - resource->dev_name));
1123-
1124-
/* search for the base name (ex: mlx5_0) */
1117+
ucp_get_dev_basename(resource->dev_name, dev_basename);
1118+
if (*dev_basename != '\0') {
11251119
mask |= ucp_str_array_search((const char**)devices[dev_type].names,
1126-
devices[dev_type].count, dev_name_base,
1120+
devices[dev_type].count, dev_basename,
11271121
NULL);
1128-
1129-
/* search in ranges (ex: mlx5_[0-2]) */
11301122
mask |= ucp_str_array_search_in_ranges(
11311123
(const char**)devices[dev_type].names,
1132-
devices[dev_type].count, dev_name_base);
1124+
devices[dev_type].count, dev_basename);
11331125
}
11341126
}
11351127

test/gtest/ucp/test_ucp_context.cc

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -377,53 +377,4 @@ UCS_TEST_P(test_ucp_net_devices_config, partial_range_selection)
377377
EXPECT_EQ(selected_base_names, expected_base_names);
378378
}
379379

380-
/*
381-
* Test that non-mlx devices are not affected by the mlx default port logic.
382-
*/
383-
UCS_TEST_P(test_ucp_net_devices_config, non_mlx_device_unaffected)
384-
{
385-
std::string devices_list;
386-
std::set<std::string> non_mlx_devices;
387-
388-
entity *e = create_entity();
389-
390-
std::set<std::string> mlx5_devices = get_mlx5_device_names(*e);
391-
392-
/* Find all non-mlx network devices */
393-
for_each_net_device(*e, [&](const uct_tl_resource_desc_t *rsc) {
394-
if (!has_device(mlx5_devices, rsc->dev_name)) {
395-
non_mlx_devices.insert(rsc->dev_name);
396-
}
397-
});
398-
399-
if (non_mlx_devices.empty()) {
400-
GTEST_SKIP() << "No non-mlx network devices available";
401-
}
402-
403-
/* Build comma-separated list of all non-mlx devices */
404-
for (const std::string &dev : non_mlx_devices) {
405-
if (!devices_list.empty()) {
406-
devices_list += ",";
407-
}
408-
devices_list += dev;
409-
}
410-
411-
m_entities.clear();
412-
413-
/* Create context with all non-mlx devices */
414-
modify_config("NET_DEVICES", devices_list.c_str());
415-
e = create_entity();
416-
417-
/* Verify all devices were selected */
418-
std::set<std::string> selected_devices;
419-
for_each_net_device(*e, [&](const uct_tl_resource_desc_t *rsc) {
420-
selected_devices.insert(rsc->dev_name);
421-
});
422-
423-
for (const std::string &dev : non_mlx_devices) {
424-
EXPECT_TRUE(has_device(selected_devices, dev))
425-
<< "Non-mlx device '" << dev << "' should be selected";
426-
}
427-
}
428-
429380
UCP_INSTANTIATE_TEST_CASE_TLS(test_ucp_net_devices_config, all, "all")

0 commit comments

Comments
 (0)