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+
1923static int component_open (void );
2024static int component_register (void );
2125static 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