Skip to content

Commit

Permalink
CORE: fix ucc parser build
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei-Lebedev committed Nov 1, 2022
1 parent eb73797 commit 9440a68
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 44 deletions.
5 changes: 5 additions & 0 deletions config/m4/ucx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ AS_IF([test "x$ucx_checked" != "xyes"],[
[AC_DEFINE([UCS_HAVE_MPOOL_PARAMS], [1], [params interface for ucs_mpool_init])],
[],
[#include <ucs/datastruct/mpool.h>])
AC_CHECK_MEMBER(ucs_config_global_list_entry_t.flags,
[AC_DEFINE([UCS_HAVE_CONFIG_GLOBAL_LIST_ENTRY_FLAGS], [1], [flags for config table])],
[],
[#include <ucs/config/parser.h>])
],
[
AS_IF([test "x$with_ucx" != "xguess"],
Expand Down
9 changes: 7 additions & 2 deletions src/components/base/ucc_base_iface.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

#include "ucc_base_iface.h"
#include "utils/ucc_malloc.h"
#include "utils/ucc_log.h"
Expand Down Expand Up @@ -50,8 +56,7 @@ ucc_status_t ucc_base_config_read(const char *full_prefix,
return UCC_ERR_NO_MEMORY;
}
cfg->cfg_entry = cfg_entry;
status = ucc_config_parser_fill_opts(cfg, cfg_entry->table, full_prefix,
cfg_entry->prefix, 0);
status = ucc_config_parser_fill_opts(cfg, cfg_entry, full_prefix, 0);
if (UCC_OK != status) {
ucc_free(cfg);
*config = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ec/ucc_ec.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -40,8 +41,7 @@ ucc_status_t ucc_ec_init(const ucc_ec_params_t *ec_params)
continue;
}
status = ucc_config_parser_fill_opts(
ec->config, ec->config_table.table, "UCC_",
ec->config_table.prefix, 1);
ec->config, &ec->config_table, "UCC_", 1);
if (UCC_OK != status) {
ucc_info("failed to parse config for EC component: %s (%d)",
ec->super.name, status);
Expand Down
6 changes: 3 additions & 3 deletions src/components/mc/ucc_mc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -47,8 +48,7 @@ ucc_status_t ucc_mc_init(const ucc_mc_params_t *mc_params)
continue;
}
status = ucc_config_parser_fill_opts(
mc->config, mc->config_table.table, "UCC_",
mc->config_table.prefix, 1);
mc->config, &mc->config_table, "UCC_", 1);
if (UCC_OK != status) {
ucc_info("failed to parse config for mc: %s (%d)",
mc->super.name, status);
Expand Down
5 changes: 2 additions & 3 deletions src/components/tl/ucp/tl_ucp_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ UCC_CLASS_INIT_FUNC(ucc_tl_ucp_lib_t, const ucc_base_lib_params_t *params,
goto err_cfg;
}
status = ucc_config_parser_fill_opts(self->tlcp_configs[i],
tlcp->config.table,
params->full_prefix,
ucc_tl_ucp.super.tl_lib_config.prefix, 0);
&tlcp->config,
params->full_prefix, 0);
if (status != UCC_OK) {
tl_error(&self->super, "failed to read tlcp config");
goto err_cfg;
Expand Down
9 changes: 7 additions & 2 deletions src/core/ucc_constructor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -87,6 +88,9 @@ static ucc_status_t init_lib_paths(void)
return status;
}

UCC_CONFIG_REGISTER_TABLE(ucc_global_config_table, "UCC global", NULL,
ucc_global_config, &ucc_config_global_list)

ucc_status_t ucc_constructor(void)
{
ucc_global_config_t *cfg = &ucc_global_config;
Expand All @@ -95,7 +99,8 @@ ucc_status_t ucc_constructor(void)
if (!cfg->initialized) {
cfg->initialized = 1;
status = ucc_config_parser_fill_opts(
&ucc_global_config, ucc_global_config_table, "UCC_", NULL, 1);
&ucc_global_config, UCC_CONFIG_GET_TABLE(ucc_global_config_table),
"UCC_", 1);
if (UCC_OK != status) {
ucc_error("failed to parse global options");
return status;
Expand Down
6 changes: 4 additions & 2 deletions src/core/ucc_context.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -69,8 +70,9 @@ ucc_status_t ucc_context_config_read(ucc_lib_info_t *lib, const char *filename,
return UCC_ERR_NO_MEMORY;
}

status = ucc_config_parser_fill_opts(config, ucc_context_config_table,
lib->full_prefix, NULL, 0);
status = ucc_config_parser_fill_opts(config,
UCC_CONFIG_GET_TABLE(ucc_context_config_table),
lib->full_prefix, 0);
if (status != UCC_OK) {
ucc_error("failed to read UCC core context config");
goto err_config;
Expand Down
6 changes: 2 additions & 4 deletions src/core/ucc_global_opts.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -55,6 +56,3 @@ ucc_config_field_t ucc_global_config_table[] = {
ucc_offsetof(ucc_global_config_t, cfg_filename), UCC_CONFIG_TYPE_STRING},

{NULL}};

UCC_CONFIG_REGISTER_TABLE(ucc_global_config_table, "UCC global", NULL,
ucc_global_config, &ucc_config_global_list)
8 changes: 5 additions & 3 deletions src/core/ucc_lib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -402,8 +403,9 @@ ucc_status_t ucc_lib_config_read(const char *env_prefix, const char *filename,
strlen(base_prefix) + 1);
}

status = ucc_config_parser_fill_opts(config, ucc_lib_config_table,
config->full_prefix, NULL, 0);
status = ucc_config_parser_fill_opts(config,
UCC_CONFIG_GET_TABLE(ucc_lib_config_table),
config->full_prefix, 0);
if (status != UCC_OK) {
ucc_error("failed to read UCC lib config");
goto err_free_prefix;
Expand Down
36 changes: 20 additions & 16 deletions src/utils/ucc_parser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -316,20 +317,24 @@ static ucc_status_t ucc_apply_file_cfg(void *opts, ucc_config_field_t *fields,
return UCC_OK;
}

ucc_status_t ucc_config_parser_fill_opts(void *opts, ucc_config_field_t *fields,
const char *env_prefix,
const char *table_prefix,
int ignore_errors)
ucc_status_t ucc_config_parser_fill_opts(void *opts, ucs_config_global_list_entry_t *entry,
const char *env_prefix, int ignore_errors)
{
ucs_status_t ucs_status;
ucc_status_t status;

ucs_status = ucs_config_parser_fill_opts(opts, fields, env_prefix,
table_prefix, ignore_errors);
status = ucs_status_to_ucc_status(ucs_status);
#if UCS_HAVE_CONFIG_GLOBAL_LIST_ENTRY_FLAGS
ucs_status = ucs_config_parser_fill_opts(opts, entry, env_prefix,
ignore_errors);
#else
ucs_status = ucs_config_parser_fill_opts(opts, entry->table, env_prefix,
entry->prefix, 0);
#endif

status = ucs_status_to_ucc_status(ucs_status);
if (UCC_OK == status && ucc_global_config.file_cfg) {
status = ucc_apply_file_cfg(opts, fields, env_prefix, table_prefix);
status = ucc_apply_file_cfg(opts, entry->table, env_prefix,
entry->prefix);
}

return status;
Expand All @@ -339,11 +344,11 @@ void ucc_config_parser_print_all_opts(FILE *stream, const char *prefix,
ucc_config_print_flags_t flags,
ucc_list_link_t * config_list)
{
const ucc_config_global_list_entry_t *entry;
ucs_config_print_flags_t ucs_flags;
ucc_status_t status;
char title[64];
void * opts;
ucc_config_global_list_entry_t *entry;
ucs_config_print_flags_t ucs_flags;
ucc_status_t status;
char title[64];
void * opts;

ucs_flags = ucc_print_flags_to_ucs_print_flags(flags);
ucc_list_for_each(entry, config_list, list)
Expand All @@ -360,8 +365,7 @@ void ucc_config_parser_print_all_opts(FILE *stream, const char *prefix,
continue;
}

status = ucc_config_parser_fill_opts(opts, entry->table, prefix,
entry->prefix, 0);
status = ucc_config_parser_fill_opts(opts, entry, prefix, 0);
if (status != UCC_OK) {
ucc_free(opts);
continue;
Expand Down
33 changes: 28 additions & 5 deletions src/utils/ucc_parser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

Expand Down Expand Up @@ -27,9 +28,31 @@ typedef ucs_config_allow_list_t ucc_config_allow_list_t;

typedef struct ucc_file_config ucc_file_config_t;

#define UCC_CONFIG_TYPE_LOG_COMP UCS_CONFIG_TYPE_LOG_COMP
#if UCS_HAVE_CONFIG_GLOBAL_LIST_ENTRY_FLAGS
#define UCC_CONFIG_DECLARE_TABLE(_table, _name, _prefix, _type) \
static ucc_config_global_list_entry_t _table##_config_entry = { \
.name = _name, \
.prefix = _prefix, \
.table = _table, \
.size = sizeof(_type), \
.list = {NULL, NULL}, \
.flags = 0 \
};
#else
#define UCC_CONFIG_DECLARE_TABLE(_table, _name, _prefix, _type) \
static ucc_config_global_list_entry_t _table##_config_entry = { \
.name = _name, \
.prefix = _prefix, \
.table = _table, \
.size = sizeof(_type), \
.list = {NULL, NULL}, \
};
#endif

#define UCC_CONFIG_GET_TABLE(_table) &_table##_config_entry
#define UCC_CONFIG_REGISTER_TABLE UCS_CONFIG_REGISTER_TABLE
#define UCC_CONFIG_REGISTER_TABLE_ENTRY UCS_CONFIG_REGISTER_TABLE_ENTRY
#define UCC_CONFIG_TYPE_LOG_COMP UCS_CONFIG_TYPE_LOG_COMP
#define UCC_CONFIG_TYPE_STRING UCS_CONFIG_TYPE_STRING
#define UCC_CONFIG_TYPE_INT UCS_CONFIG_TYPE_INT
#define UCC_CONFIG_TYPE_UINT UCS_CONFIG_TYPE_UINT
Expand Down Expand Up @@ -65,10 +88,10 @@ typedef struct ucc_config_names_list {
};
} ucc_config_names_list_t;

ucc_status_t ucc_config_parser_fill_opts(void *opts, ucc_config_field_t *fields,
ucc_status_t ucc_config_parser_fill_opts(void *opts,
ucs_config_global_list_entry_t *entry,
const char *env_prefix,
const char *table_prefix,
int ignore_errors);
int ignore_errors);

static inline void
ucc_config_parser_release_opts(void *opts, ucc_config_field_t *fields)
Expand Down
10 changes: 8 additions & 2 deletions test/gtest/utils/test_cfg_file.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/

extern "C" {
#include "utils/ucc_parser.h"
#include "core/ucc_global_opts.h"
Expand Down Expand Up @@ -42,6 +44,9 @@ static ucc_config_field_t ucc_gtest_config_table[] = {
{NULL}
};

UCC_CONFIG_DECLARE_TABLE(ucc_gtest_config_table, "GTEST TABLE", "CFG_",
ucc_gtest_config_t);

class test_cfg_file : public ucc::test {
public:
ucc_file_config_t *file_cfg;
Expand All @@ -61,8 +66,9 @@ class test_cfg_file : public ucc::test {
void init_cfg() {
ucc_status_t status;
std::swap(ucc_global_config.file_cfg, file_cfg);
status = ucc_config_parser_fill_opts(&cfg, ucc_gtest_config_table,
"GTEST_UCC_", "CFG_", 1);
status = ucc_config_parser_fill_opts(
&cfg, UCC_CONFIG_GET_TABLE(ucc_gtest_config_table),
"GTEST_UCC_", 1);
std::swap(ucc_global_config.file_cfg, file_cfg);
EXPECT_EQ(UCC_OK, status);
};
Expand Down

0 comments on commit 9440a68

Please sign in to comment.