Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spml/ucx: shuffle EPs creation #12907

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions oshmem/mca/spml/ucx/spml_ucx.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,16 @@ int mca_spml_ucx_clear_put_op_mask(mca_spml_ucx_ctx_t *ctx)
int mca_spml_ucx_add_procs(oshmem_group_t* group, size_t nprocs)
{
int rc = OSHMEM_ERROR;
int my_rank = oshmem_my_proc_id();
size_t ucp_workers = mca_spml_ucx.ucp_workers;
unsigned int *wk_roffs = NULL;
unsigned int *wk_rsizes = NULL;
char *wk_raddrs = NULL;
size_t i, w, n;
size_t i, j, w, n, temp;
ucs_status_t err;
ucp_address_t **wk_local_addr;
unsigned int *wk_addr_len;
ucp_ep_params_t ep_params;
int *indices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned int?


wk_local_addr = calloc(mca_spml_ucx.ucp_workers, sizeof(ucp_address_t *));
wk_addr_len = calloc(mca_spml_ucx.ucp_workers, sizeof(size_t));
Expand Down Expand Up @@ -691,23 +691,40 @@ int mca_spml_ucx_add_procs(oshmem_group_t* group, size_t nprocs)
}
}

indices = malloc(nprocs * sizeof(int));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: sizeof(*indices)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!indices) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the convention is compare to NULL

goto error;
}

for (i = 0; i < nprocs; i++) {
indices[i] = i;
gleon99 marked this conversation as resolved.
Show resolved Hide resolved
}

srand((unsigned int)time(NULL));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO can omit (unsigned int)


/* Get the EP connection requests for all the processes from modex */
for (n = 0; n < nprocs; ++n) {
i = (my_rank + n) % nprocs;
for (i = nprocs - 1; i >= 0; --i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe perform randomization as a separate function/loop

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to iterate over the EPs once, and to save another iteration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok for me, but i guess one extra loop on sequential memory on ep creation would not impact perf

/* Fisher-Yates shuffle algorithm */
if (i > 0) {
j = rand() % (i + 1);
temp = indices[i];
indices[i] = indices[j];
indices[j] = temp;
}

ep_params.field_mask = UCP_EP_PARAM_FIELD_REMOTE_ADDRESS;
ep_params.address = (ucp_address_t *)mca_spml_ucx.remote_addrs_tbl[0][i];
ep_params.address = (ucp_address_t *) mca_spml_ucx.remote_addrs_tbl[0][indices[i]];

err = ucp_ep_create(mca_spml_ucx_ctx_default.ucp_worker[0], &ep_params,
&mca_spml_ucx_ctx_default.ucp_peers[i].ucp_conn);
&mca_spml_ucx_ctx_default.ucp_peers[indices[i]].ucp_conn);
if (UCS_OK != err) {
SPML_UCX_ERROR("ucp_ep_create(proc=%zu/%zu) failed: %s", n, nprocs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also update log line index (i and indices[i])

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice I'm using proc_index instead of i.
I changed n to proc_index, why indices[proc_index]? the loop still iterates until nproc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right, already up-to-date. we could add indices[proc_index] to the log along with iteration since it is randomized.

ucs_status_string(err));
goto error2;
}

/* Initialize mkeys as NULL for all processes */
mca_spml_ucx_peer_mkey_cache_init(&mca_spml_ucx_ctx_default, i);
mca_spml_ucx_peer_mkey_cache_init(&mca_spml_ucx_ctx_default, indices[i]);
}

for (i = 0; i < mca_spml_ucx.ucp_workers; i++) {
Expand All @@ -719,6 +736,7 @@ int mca_spml_ucx_add_procs(oshmem_group_t* group, size_t nprocs)
free(wk_roffs);
free(wk_addr_len);
free(wk_local_addr);
free(indices);

SPML_UCX_VERBOSE(50, "*** ADDED PROCS ***");

Expand Down Expand Up @@ -753,6 +771,7 @@ int mca_spml_ucx_add_procs(oshmem_group_t* group, size_t nprocs)
free(wk_raddrs);
free(wk_rsizes);
free(wk_roffs);
free(indices);
error:
free(wk_addr_len);
free(wk_local_addr);
Expand Down
Loading