From 9440a6894c328d65d2f3638bf5e2fb4378c198fc Mon Sep 17 00:00:00 2001 From: Sergey Lebedev Date: Mon, 31 Oct 2022 17:26:40 +0000 Subject: [PATCH] CORE: fix ucc parser build --- config/m4/ucx.m4 | 5 ++++ src/components/base/ucc_base_iface.c | 9 +++++-- src/components/ec/ucc_ec.c | 4 ++-- src/components/mc/ucc_mc.c | 6 ++--- src/components/tl/ucp/tl_ucp_lib.c | 5 ++-- src/core/ucc_constructor.c | 9 +++++-- src/core/ucc_context.c | 6 +++-- src/core/ucc_global_opts.c | 6 ++--- src/core/ucc_lib.c | 8 ++++--- src/utils/ucc_parser.c | 36 +++++++++++++++------------- src/utils/ucc_parser.h | 33 +++++++++++++++++++++---- test/gtest/utils/test_cfg_file.cc | 10 ++++++-- 12 files changed, 93 insertions(+), 44 deletions(-) diff --git a/config/m4/ucx.m4 b/config/m4/ucx.m4 index 968be37bf2..8abdf57f6e 100644 --- a/config/m4/ucx.m4 +++ b/config/m4/ucx.m4 @@ -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 ]) + + 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 ]) ], [ AS_IF([test "x$with_ucx" != "xguess"], diff --git a/src/components/base/ucc_base_iface.c b/src/components/base/ucc_base_iface.c index 93dfd68b1d..0fca2f787e 100644 --- a/src/components/base/ucc_base_iface.c +++ b/src/components/base/ucc_base_iface.c @@ -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" @@ -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; diff --git a/src/components/ec/ucc_ec.c b/src/components/ec/ucc_ec.c index f00dc71f50..093ba381dd 100644 --- a/src/components/ec/ucc_ec.c +++ b/src/components/ec/ucc_ec.c @@ -1,5 +1,6 @@ /** * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * * See file LICENSE for terms. */ @@ -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); diff --git a/src/components/mc/ucc_mc.c b/src/components/mc/ucc_mc.c index 6615f1310e..756fb96444 100644 --- a/src/components/mc/ucc_mc.c +++ b/src/components/mc/ucc_mc.c @@ -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. */ @@ -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); diff --git a/src/components/tl/ucp/tl_ucp_lib.c b/src/components/tl/ucp/tl_ucp_lib.c index c439f0aae6..1722858b92 100644 --- a/src/components/tl/ucp/tl_ucp_lib.c +++ b/src/components/tl/ucp/tl_ucp_lib.c @@ -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; diff --git a/src/core/ucc_constructor.c b/src/core/ucc_constructor.c index c2952a47cb..ddd4333ba0 100644 --- a/src/core/ucc_constructor.c +++ b/src/core/ucc_constructor.c @@ -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. */ @@ -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; @@ -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; diff --git a/src/core/ucc_context.c b/src/core/ucc_context.c index ddc972c06a..7f14e83167 100644 --- a/src/core/ucc_context.c +++ b/src/core/ucc_context.c @@ -1,5 +1,6 @@ /** * Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * * See file LICENSE for terms. */ @@ -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; diff --git a/src/core/ucc_global_opts.c b/src/core/ucc_global_opts.c index dec99d9b2d..b1b3af4060 100644 --- a/src/core/ucc_global_opts.c +++ b/src/core/ucc_global_opts.c @@ -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. */ @@ -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) diff --git a/src/core/ucc_lib.c b/src/core/ucc_lib.c index 7afa841f16..0414f334cf 100644 --- a/src/core/ucc_lib.c +++ b/src/core/ucc_lib.c @@ -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. */ @@ -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; diff --git a/src/utils/ucc_parser.c b/src/utils/ucc_parser.c index 551dfba953..d9433c71d8 100644 --- a/src/utils/ucc_parser.c +++ b/src/utils/ucc_parser.c @@ -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. */ @@ -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; @@ -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) @@ -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; diff --git a/src/utils/ucc_parser.h b/src/utils/ucc_parser.h index 82c86a87ba..82866dcde5 100644 --- a/src/utils/ucc_parser.h +++ b/src/utils/ucc_parser.h @@ -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. */ @@ -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 @@ -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) diff --git a/test/gtest/utils/test_cfg_file.cc b/test/gtest/utils/test_cfg_file.cc index 315a5a9361..9f86fd803e 100644 --- a/test/gtest/utils/test_cfg_file.cc +++ b/test/gtest/utils/test_cfg_file.cc @@ -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" @@ -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; @@ -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); };