2020#include "osc_ucx.h"
2121#include "osc_ucx_request.h"
2222
23+ #define memcpy_off (_dst , _src , _len , _off ) \
24+ memcpy(((char*)(_dst)) + (_off), _src, _len); \
25+ (_off) += (_len);
26+
2327static int component_open (void );
2428static int component_register (void );
2529static int component_init (bool enable_progress_threads , bool enable_mpi_threads );
@@ -278,6 +282,8 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
278282 int disps [comm_size ];
279283 int rkey_sizes [comm_size ];
280284 uint64_t zero = 0 ;
285+ size_t info_offset ;
286+ uint64_t size_u64 ;
281287
282288 /* the osc/sm component is the exclusive provider for support for
283289 * shared memory windows */
@@ -521,22 +527,27 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
521527 goto error ;
522528 }
523529
524- my_info_len = 2 * sizeof (uint64_t ) + rkey_buffer_size + state_rkey_buffer_size ;
530+ size_u64 = (uint64_t )size ;
531+ my_info_len = 3 * sizeof (uint64_t ) + rkey_buffer_size + state_rkey_buffer_size ;
525532 my_info = malloc (my_info_len );
526533 if (my_info == NULL ) {
527534 ret = OMPI_ERR_TEMP_OUT_OF_RESOURCE ;
528535 goto error ;
529536 }
530537
538+ info_offset = 0 ;
539+
531540 if (flavor == MPI_WIN_FLAVOR_ALLOCATE || flavor == MPI_WIN_FLAVOR_CREATE ) {
532- memcpy (my_info , base , sizeof (uint64_t ));
541+ memcpy_off (my_info , base , sizeof (uint64_t ), info_offset );
533542 } else {
534- memcpy (my_info , & zero , sizeof (uint64_t ));
543+ memcpy_off (my_info , & zero , sizeof (uint64_t ), info_offset );
535544 }
536- memcpy ((void * )((char * )my_info + sizeof (uint64_t )), & state_base , sizeof (uint64_t ));
537- memcpy ((void * )((char * )my_info + 2 * sizeof (uint64_t )), rkey_buffer , rkey_buffer_size );
538- memcpy ((void * )((char * )my_info + 2 * sizeof (uint64_t ) + rkey_buffer_size ),
539- state_rkey_buffer , state_rkey_buffer_size );
545+ memcpy_off (my_info , & state_base , sizeof (uint64_t ), info_offset );
546+ memcpy_off (my_info , & size_u64 , sizeof (uint64_t ), info_offset );
547+ memcpy_off (my_info , rkey_buffer , rkey_buffer_size , info_offset );
548+ memcpy_off (my_info , state_rkey_buffer , state_rkey_buffer_size , info_offset );
549+
550+ assert (my_info_len == info_offset );
540551
541552 ret = allgather_len_and_info (my_info , (int )my_info_len , & recv_buf , disps , module -> comm );
542553 if (ret != OMPI_SUCCESS ) {
@@ -552,25 +563,32 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
552563
553564 for (i = 0 ; i < comm_size ; i ++ ) {
554565 ucp_ep_h ep = OSC_UCX_GET_EP (module -> comm , i );
566+ uint64_t dest_size ;
555567 assert (ep != NULL );
556568
557- memcpy (& (module -> win_info_array [i ]).addr , & recv_buf [disps [i ]], sizeof (uint64_t ));
558- memcpy (& (module -> state_info_array [i ]).addr , & recv_buf [disps [i ] + sizeof (uint64_t )],
559- sizeof (uint64_t ));
569+ info_offset = disps [i ];
570+
571+ memcpy (& (module -> win_info_array [i ]).addr , & recv_buf [info_offset ], sizeof (uint64_t ));
572+ info_offset += sizeof (uint64_t );
573+ memcpy (& (module -> state_info_array [i ]).addr , & recv_buf [info_offset ], sizeof (uint64_t ));
574+ info_offset += sizeof (uint64_t );
575+ memcpy (& dest_size , & recv_buf [info_offset ], sizeof (uint64_t ));
576+ info_offset += sizeof (uint64_t );
560577
561578 (module -> win_info_array [i ]).rkey_init = false;
562- if (size > 0 && (flavor == MPI_WIN_FLAVOR_ALLOCATE || flavor == MPI_WIN_FLAVOR_CREATE )) {
563- status = ucp_ep_rkey_unpack (ep , & ( recv_buf [disps [ i ] + 2 * sizeof ( uint64_t )]) ,
579+ if (dest_size > 0 && (flavor == MPI_WIN_FLAVOR_ALLOCATE || flavor == MPI_WIN_FLAVOR_CREATE )) {
580+ status = ucp_ep_rkey_unpack (ep , & recv_buf [info_offset ] ,
564581 & ((module -> win_info_array [i ]).rkey ));
565582 if (status != UCS_OK ) {
566583 OSC_UCX_VERBOSE (1 , "ucp_ep_rkey_unpack failed: %d" , status );
567584 ret = OMPI_ERROR ;
568585 goto error ;
569586 }
587+ info_offset += rkey_sizes [i ];
570588 (module -> win_info_array [i ]).rkey_init = true;
571589 }
572590
573- status = ucp_ep_rkey_unpack (ep , & ( recv_buf [disps [ i ] + 2 * sizeof ( uint64_t ) + rkey_sizes [ i ]]) ,
591+ status = ucp_ep_rkey_unpack (ep , & recv_buf [info_offset ] ,
574592 & ((module -> state_info_array [i ]).rkey ));
575593 if (status != UCS_OK ) {
576594 OSC_UCX_VERBOSE (1 , "ucp_ep_rkey_unpack failed: %d" , status );
0 commit comments