Skip to content

Commit 1704063

Browse files
authored
Merge pull request #5911 from hoopoepg/topic/fixed-zero-size-window-v3.1
OSC/UCX: fixed zero size window - v3.1
2 parents 9bb1edd + d5a60e4 commit 1704063

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

ompi/mca/osc/ucx/osc_ucx_comm.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
#include "osc_ucx.h"
1717
#include "osc_ucx_request.h"
1818

19+
20+
#define CHECK_VALID_RKEY(_module, _target, _count) \
21+
if (!((_module)->win_info_array[_target]).rkey_init && ((_count) > 0)) { \
22+
opal_output_verbose(1, ompi_osc_base_framework.framework_output, \
23+
"%s:%d: window with non-zero length does not have an rkey\n", \
24+
__FILE__, __LINE__); \
25+
return OMPI_ERROR; \
26+
}
27+
1928
typedef struct ucx_iovec {
2029
void *addr;
2130
size_t len;
@@ -337,7 +346,7 @@ static inline int get_dynamic_win_info(uint64_t remote_addr, ompi_osc_ucx_module
337346

338347
if ((module->win_info_array[target]).rkey_init == true) {
339348
ucp_rkey_destroy((module->win_info_array[target]).rkey);
340-
(module->win_info_array[target]).rkey_init == false;
349+
(module->win_info_array[target]).rkey_init = false;
341350
}
342351

343352
status = ucp_get_nbi(ep, (void *)temp_buf, len, remote_state_addr, state_rkey);
@@ -404,6 +413,12 @@ int ompi_osc_ucx_put(const void *origin_addr, int origin_count, struct ompi_data
404413
}
405414
}
406415

416+
CHECK_VALID_RKEY(module, target, target_count);
417+
418+
if (!target_count) {
419+
return OMPI_SUCCESS;
420+
}
421+
407422
rkey = (module->win_info_array[target]).rkey;
408423

409424
ompi_datatype_get_true_extent(origin_dt, &origin_lb, &origin_extent);
@@ -460,6 +475,12 @@ int ompi_osc_ucx_get(void *origin_addr, int origin_count,
460475
}
461476
}
462477

478+
CHECK_VALID_RKEY(module, target, target_count);
479+
480+
if (!target_count) {
481+
return OMPI_SUCCESS;
482+
}
483+
463484
rkey = (module->win_info_array[target]).rkey;
464485

465486
ompi_datatype_get_true_extent(origin_dt, &origin_lb, &origin_extent);
@@ -900,6 +921,8 @@ int ompi_osc_ucx_rput(const void *origin_addr, int origin_count,
900921
}
901922
}
902923

924+
CHECK_VALID_RKEY(module, target, target_count);
925+
903926
rkey = (module->win_info_array[target]).rkey;
904927

905928
OMPI_OSC_UCX_REQUEST_ALLOC(win, ucx_req);
@@ -963,6 +986,8 @@ int ompi_osc_ucx_rget(void *origin_addr, int origin_count,
963986
}
964987
}
965988

989+
CHECK_VALID_RKEY(module, target, target_count);
990+
966991
rkey = (module->win_info_array[target]).rkey;
967992

968993
OMPI_OSC_UCX_REQUEST_ALLOC(win, ucx_req);

ompi/mca/osc/ucx/osc_ucx_component.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include "osc_ucx.h"
1717
#include "osc_ucx_request.h"
1818

19+
#define memcpy_off(_dst, _src, _len, _off) \
20+
memcpy(((char*)(_dst)) + (_off), _src, _len); \
21+
(_off) += (_len);
22+
1923
static int component_open(void);
2024
static int component_register(void);
2125
static int component_init(bool enable_progress_threads, bool enable_mpi_threads);
@@ -325,6 +329,8 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
325329
int disps[comm_size];
326330
int rkey_sizes[comm_size];
327331
uint64_t zero = 0;
332+
size_t info_offset;
333+
uint64_t size_u64;
328334

329335
/* the osc/sm component is the exclusive provider for support for
330336
* shared memory windows */
@@ -538,22 +544,27 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
538544
goto error;
539545
}
540546

541-
my_info_len = 2 * sizeof(uint64_t) + rkey_buffer_size + state_rkey_buffer_size;
547+
size_u64 = (uint64_t)size;
548+
my_info_len = 3 * sizeof(uint64_t) + rkey_buffer_size + state_rkey_buffer_size;
542549
my_info = malloc(my_info_len);
543550
if (my_info == NULL) {
544551
ret = OMPI_ERR_TEMP_OUT_OF_RESOURCE;
545552
goto error;
546553
}
547554

555+
info_offset = 0;
556+
548557
if (flavor == MPI_WIN_FLAVOR_ALLOCATE || flavor == MPI_WIN_FLAVOR_CREATE) {
549-
memcpy(my_info, base, sizeof(uint64_t));
558+
memcpy_off(my_info, base, sizeof(uint64_t), info_offset);
550559
} else {
551-
memcpy(my_info, &zero, sizeof(uint64_t));
560+
memcpy_off(my_info, &zero, sizeof(uint64_t), info_offset);
552561
}
553-
memcpy((void *)((char *)my_info + sizeof(uint64_t)), &state_base, sizeof(uint64_t));
554-
memcpy((void *)((char *)my_info + 2 * sizeof(uint64_t)), rkey_buffer, rkey_buffer_size);
555-
memcpy((void *)((char *)my_info + 2 * sizeof(uint64_t) + rkey_buffer_size),
556-
state_rkey_buffer, state_rkey_buffer_size);
562+
memcpy_off(my_info, &state_base, sizeof(uint64_t), info_offset);
563+
memcpy_off(my_info, &size_u64, sizeof(uint64_t), info_offset);
564+
memcpy_off(my_info, rkey_buffer, rkey_buffer_size, info_offset);
565+
memcpy_off(my_info, state_rkey_buffer, state_rkey_buffer_size, info_offset);
566+
567+
assert(my_info_len == info_offset);
557568

558569
ret = allgather_len_and_info(my_info, (int)my_info_len, &recv_buf, disps, module->comm);
559570
if (ret != OMPI_SUCCESS) {
@@ -569,15 +580,21 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
569580

570581
for (i = 0; i < comm_size; i++) {
571582
ucp_ep_h ep = OSC_UCX_GET_EP(module->comm, i);
583+
uint64_t dest_size;
572584
assert(ep != NULL);
573585

574-
memcpy(&(module->win_info_array[i]).addr, &recv_buf[disps[i]], sizeof(uint64_t));
575-
memcpy(&(module->state_info_array[i]).addr, &recv_buf[disps[i] + sizeof(uint64_t)],
576-
sizeof(uint64_t));
586+
info_offset = disps[i];
587+
588+
memcpy(&(module->win_info_array[i]).addr, &recv_buf[info_offset], sizeof(uint64_t));
589+
info_offset += sizeof(uint64_t);
590+
memcpy(&(module->state_info_array[i]).addr, &recv_buf[info_offset], sizeof(uint64_t));
591+
info_offset += sizeof(uint64_t);
592+
memcpy(&dest_size, &recv_buf[info_offset], sizeof(uint64_t));
593+
info_offset += sizeof(uint64_t);
577594

578595
(module->win_info_array[i]).rkey_init = false;
579-
if (size > 0 && (flavor == MPI_WIN_FLAVOR_ALLOCATE || flavor == MPI_WIN_FLAVOR_CREATE)) {
580-
status = ucp_ep_rkey_unpack(ep, &(recv_buf[disps[i] + 2 * sizeof(uint64_t)]),
596+
if (dest_size > 0 && (flavor == MPI_WIN_FLAVOR_ALLOCATE || flavor == MPI_WIN_FLAVOR_CREATE)) {
597+
status = ucp_ep_rkey_unpack(ep, &recv_buf[info_offset],
581598
&((module->win_info_array[i]).rkey));
582599
if (status != UCS_OK) {
583600
opal_output_verbose(1, ompi_osc_base_framework.framework_output,
@@ -586,10 +603,11 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
586603
ret = OMPI_ERROR;
587604
goto error;
588605
}
606+
info_offset += rkey_sizes[i];
589607
(module->win_info_array[i]).rkey_init = true;
590608
}
591609

592-
status = ucp_ep_rkey_unpack(ep, &(recv_buf[disps[i] + 2 * sizeof(uint64_t) + rkey_sizes[i]]),
610+
status = ucp_ep_rkey_unpack(ep, &recv_buf[info_offset],
593611
&((module->state_info_array[i]).rkey));
594612
if (status != UCS_OK) {
595613
opal_output_verbose(1, ompi_osc_base_framework.framework_output,

0 commit comments

Comments
 (0)