Skip to content

Commit e22007d

Browse files
Sergei-Lebedevjanjust
authored andcommitted
CORE: add ucc_modules config
1 parent 7b6a743 commit e22007d

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/core/ucc_global_opts.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ucc_global_config_t ucc_global_config = {
2929
.log_buffer_size = 1024,
3030
.log_data_size = 0,
3131
.log_print_enable = 0,
32-
.log_level_trigger = UCC_LOG_LEVEL_FATAL};
32+
.log_level_trigger = UCC_LOG_LEVEL_FATAL,
33+
.modules = {{NULL, 0}, 0}};
3334

3435
ucc_config_field_t ucc_global_config_table[] = {
3536
{"LOG_LEVEL", "warn",
@@ -108,5 +109,17 @@ ucc_config_field_t ucc_global_config_table[] = {
108109
"Log level to trigger error handling.",
109110
ucc_offsetof(ucc_global_config_t, log_level_trigger), UCC_CONFIG_TYPE_ENUM(ucc_log_level_names)},
110111

112+
{"MODULES", "all",
113+
"Comma-separated list of component modules to load.\n"
114+
"Use <name> to match a component in any framework, or\n"
115+
"<framework>_<name> for a specific framework (e.g. tl_cuda).\n"
116+
"Prefix with '^' to negate.\n"
117+
" - all - load all available modules (default).\n"
118+
" - ^cuda - load all modules except cuda (any framework).\n"
119+
" - ^tl_cuda,ec_cuda - load all modules except tl_cuda and ec_cuda.\n"
120+
" - ucp,nccl - load only ucp and nccl.",
121+
ucc_offsetof(ucc_global_config_t, modules),
122+
UCC_CONFIG_TYPE_ALLOW_LIST},
123+
111124
{NULL}
112125
};

src/core/ucc_global_opts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ typedef struct ucc_global_config {
2727
/* Coll component libraries path */
2828
char *component_path;
2929
char *install_path;
30+
/* Modules filter (allow/negate list) */
31+
ucc_config_allow_list_t modules;
3032
int initialized;
3133
/* Profiling mode */
3234
uint64_t profile_mode;

src/utils/ucc_component.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,47 @@
2222
#define IFACE_NAME_LEN_MAX \
2323
(UCC_MAX_FRAMEWORK_NAME_LEN + UCC_MAX_COMPONENT_NAME_LEN + 32)
2424

25+
/* Check if a module name from the allow list matches the given component.
26+
Entries with a framework prefix are matched as <framework>_<component>
27+
(e.g. "tl_cuda"), entries without a known framework prefix are matched
28+
against the component name only (e.g. "cuda" matches cuda in any
29+
framework). */
30+
static int ucc_modules_list_search(const ucc_config_names_array_t *names,
31+
const char *framework_name,
32+
const char *component_name)
33+
{
34+
char qualified[UCC_MAX_FRAMEWORK_NAME_LEN +
35+
UCC_MAX_COMPONENT_NAME_LEN + 2];
36+
unsigned i;
37+
38+
ucc_snprintf_safe(qualified, sizeof(qualified), "%s_%s",
39+
framework_name, component_name);
40+
41+
for (i = 0; i < names->count; i++) {
42+
if ((strcmp(names->names[i], qualified) == 0) ||
43+
(strcmp(names->names[i], component_name) == 0)) {
44+
return i;
45+
}
46+
}
47+
return -1;
48+
}
49+
50+
static int ucc_component_is_enabled(const char *framework_name,
51+
const char *component_name)
52+
{
53+
ucc_config_allow_list_t *modules = &ucc_global_config.modules;
54+
int found;
55+
56+
if (modules->mode == UCC_CONFIG_ALLOW_LIST_ALLOW_ALL) {
57+
return 1;
58+
}
59+
60+
found = ucc_modules_list_search(&modules->array, framework_name,
61+
component_name) >= 0;
62+
return ((modules->mode == UCC_CONFIG_ALLOW_LIST_ALLOW) && found) ||
63+
((modules->mode == UCC_CONFIG_ALLOW_LIST_NEGATE) && !found);
64+
}
65+
2566
static ucc_status_t ucc_component_load_one(const char *so_path,
2667
const char *framework_name,
2768
ucc_component_iface_t **c_iface)
@@ -50,6 +91,14 @@ static ucc_status_t ucc_component_load_one(const char *so_path,
5091
ucc_strncpy_safe(iface_struct, so_path + basename_start,
5192
iface_struct_name_len + 1);
5293

94+
if (!ucc_component_is_enabled(framework_name,
95+
iface_struct + strlen(framework_pattern))) {
96+
ucc_debug("component '%s_%s' is disabled by UCC_MODULES configuration",
97+
framework_name, iface_struct + strlen(framework_pattern));
98+
*c_iface = NULL;
99+
return UCC_ERR_NO_MESSAGE;
100+
}
101+
53102
handle = dlopen(so_path, RTLD_LAZY);
54103
if (!handle) {
55104
error = dlerror();

0 commit comments

Comments
 (0)