Skip to content

Commit

Permalink
CORE: fix error handling for ctx create epilog
Browse files Browse the repository at this point in the history
  • Loading branch information
samnordmann committed Aug 7, 2023
1 parent 6bdb758 commit 98853d9
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions src/core/ucc_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,21 +417,6 @@ static ucc_status_t ucc_create_tl_contexts(ucc_context_t *ctx,
status = UCC_ERR_NOT_FOUND;
goto err;
}
/* build the list of names of all available tl contexts.
This is a convenience data struct for CLs */
ctx->all_tls.count = ctx->n_tl_ctx;
ctx->all_tls.names = ucc_malloc(sizeof(char*) * ctx->n_tl_ctx, "all_tls");
if (!ctx->all_tls.names) {
ucc_error("failed to allocate %zd bytes for all_tls names",
sizeof(char*) * ctx->n_tl_ctx);
status = UCC_ERR_NO_MEMORY;
goto err;

}
for (i = 0; i < ctx->n_tl_ctx; i++) {
ctx->all_tls.names[i] = (char*)ucc_derived_of(ctx->tl_ctx[i]->super.lib,
ucc_tl_lib_t)->iface->super.name;
}
return UCC_OK;
err:
for (i = 0; i < ctx->n_tl_ctx; i++) {
Expand Down Expand Up @@ -602,7 +587,7 @@ ucc_status_t ucc_context_create_proc_info(ucc_lib_h lib,
ucc_tl_lib_t *tl_lib;
ucc_context_t *ctx;
ucc_status_t status;
uint64_t i, j;
uint64_t i, j, n_tl_ctx, created_ctx_counter = 0;
int num_cls;

num_cls = config->n_cl_cfg;
Expand Down Expand Up @@ -793,20 +778,22 @@ ucc_status_t ucc_context_create_proc_info(ucc_lib_h lib,
}
}

for (i = 0; i < ctx->n_tl_ctx; i++) {
n_tl_ctx = ctx->n_tl_ctx;
for (i = 0; i < n_tl_ctx; i++) {
tl_ctx = ctx->tl_ctx[i];
tl_lib = ucc_derived_of(tl_ctx->super.lib, ucc_tl_lib_t);
if (tl_lib->iface->context.create_epilog) {
status = tl_lib->iface->context.create_epilog(&tl_ctx->super);
if (UCC_OK != status) {
if (UCC_OK == status) {
created_ctx_counter++;
} else {
if (ucc_tl_is_required(lib, tl_lib->iface, 1)) {
ucc_error("ctx create epilog for %s failed: %s",
tl_lib->iface->super.name, ucc_status_string(status));
goto error_ctx_create;
} else {
ucc_debug("ctx create epilog for %s failed: %s",
tl_lib->iface->super.name, ucc_status_string(status));
tl_lib->iface->context.destroy(&tl_ctx->super);
for (j = 0; j < ctx->n_cl_ctx; j++) {
remove_tl_ctx_from_array(ctx->cl_ctx[j]->tl_ctxs,
&ctx->cl_ctx[j]->n_tl_ctxs,
Expand All @@ -816,17 +803,38 @@ ucc_status_t ucc_context_create_proc_info(ucc_lib_h lib,
tl_ctx);
}
}
} else {
created_ctx_counter++;
}
}
if (0 == created_ctx_counter) {
ucc_error("no CL context created in ucc_context_create");
status = UCC_ERR_NO_MESSAGE;
goto error_ctx_create;
}

ctx->all_tls.count = ctx->n_tl_ctx;
ctx->all_tls.names = ucc_malloc(sizeof(char *) * ctx->n_tl_ctx, "all_tls");
if (!ctx->all_tls.names) {
ucc_error("failed to allocate %zd bytes for all_tls names",
sizeof(char *) * ctx->n_tl_ctx);
status = UCC_ERR_NO_MEMORY;
goto error_ctx_create;
}
for (i = 0; i < ctx->n_tl_ctx; i++) {
ctx->all_tls.names[i] =
(char *)ucc_derived_of(ctx->tl_ctx[i]->super.lib, ucc_tl_lib_t)
->iface->super.name;
}

ucc_debug("created ucc context %p for lib %s", ctx, lib->full_prefix);
*context = ctx;
return UCC_OK;

error_ctx_create:
for (i = 0; i < ctx->n_cl_ctx; i++) {
config->cl_cfgs[i]->cl_lib->iface->context.destroy(
&ctx->cl_ctx[i]->super);
for (j = 0; j < created_ctx_counter; j++) {
config->cl_cfgs[j]->cl_lib->iface->context.destroy(
&ctx->cl_ctx[j]->super);
}
ucc_free(ctx->cl_ctx);
error_ctx:
Expand Down

0 comments on commit 98853d9

Please sign in to comment.