20
20
#include "osc_ucx.h"
21
21
#include "osc_ucx_request.h"
22
22
23
+ #define memcpy_off (_dst , _src , _len , _off ) \
24
+ memcpy(((char*)(_dst)) + (_off), _src, _len); \
25
+ (_off) += (_len);
26
+
23
27
static int component_open (void );
24
28
static int component_register (void );
25
29
static 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
278
282
int disps [comm_size ];
279
283
int rkey_sizes [comm_size ];
280
284
uint64_t zero = 0 ;
285
+ size_t info_offset ;
286
+ uint64_t size_u64 ;
281
287
282
288
/* the osc/sm component is the exclusive provider for support for
283
289
* shared memory windows */
@@ -521,22 +527,27 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
521
527
goto error ;
522
528
}
523
529
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 ;
525
532
my_info = malloc (my_info_len );
526
533
if (my_info == NULL ) {
527
534
ret = OMPI_ERR_TEMP_OUT_OF_RESOURCE ;
528
535
goto error ;
529
536
}
530
537
538
+ info_offset = 0 ;
539
+
531
540
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 );
533
542
} else {
534
- memcpy (my_info , & zero , sizeof (uint64_t ));
543
+ memcpy_off (my_info , & zero , sizeof (uint64_t ), info_offset );
535
544
}
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 );
540
551
541
552
ret = allgather_len_and_info (my_info , (int )my_info_len , & recv_buf , disps , module -> comm );
542
553
if (ret != OMPI_SUCCESS ) {
@@ -552,25 +563,32 @@ static int component_select(struct ompi_win_t *win, void **base, size_t size, in
552
563
553
564
for (i = 0 ; i < comm_size ; i ++ ) {
554
565
ucp_ep_h ep = OSC_UCX_GET_EP (module -> comm , i );
566
+ uint64_t dest_size ;
555
567
assert (ep != NULL );
556
568
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 );
560
577
561
578
(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 ] ,
564
581
& ((module -> win_info_array [i ]).rkey ));
565
582
if (status != UCS_OK ) {
566
583
OSC_UCX_VERBOSE (1 , "ucp_ep_rkey_unpack failed: %d" , status );
567
584
ret = OMPI_ERROR ;
568
585
goto error ;
569
586
}
587
+ info_offset += rkey_sizes [i ];
570
588
(module -> win_info_array [i ]).rkey_init = true;
571
589
}
572
590
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 ] ,
574
592
& ((module -> state_info_array [i ]).rkey ));
575
593
if (status != UCS_OK ) {
576
594
OSC_UCX_VERBOSE (1 , "ucp_ep_rkey_unpack failed: %d" , status );
0 commit comments