1111#include "components/tl/ucc_tl.h"
1212#include "components/topo/ucc_sysinfo.h"
1313#include "utils/ucc_malloc.h"
14+ #include "utils/ucc_math.h"
1415#include "utils/ucc_log.h"
1516#include "utils/ucc_list.h"
1617#include "utils/ucc_string.h"
1718#include "utils/ucc_debug.h"
1819#include "ucc_progress_queue.h"
1920
20- _Static_assert (UCC_MEM_MAP_TL_NAME_LEN == sizeof (size_t ),
21- "UCC_MEM_MAP_TL_NAME_LEN must equal sizeof(size_t) for pack layout" );
22-
2321static uint32_t ucc_context_seq_num = 0 ;
2422static ucc_config_field_t ucc_context_config_table [] = {
2523 {"ESTIMATED_NUM_EPS" , "0" ,
@@ -1246,6 +1244,7 @@ ucc_status_t ucc_mem_map_import(ucc_context_h context,
12461244
12471245 if (ctx -> n_tl_ctx == 0 ) {
12481246 ucc_debug ("No TL contexts available for import" );
1247+ local_memh -> tl_h = NULL ;
12491248 local_memh -> mode = mode ;
12501249 local_memh -> context = ctx ;
12511250 * memh_size = 0 ;
@@ -1328,7 +1327,7 @@ ucc_status_t ucc_mem_map_export(ucc_context_h context,
13281327 int tls ;
13291328 int tlh_index ;
13301329
1331- if (!params ) {
1330+ if (mode != UCC_MEM_MAP_MODE_EXPORT_OFFLOAD && !params ) {
13321331 ucc_error ("params cannot be NULL" );
13331332 return UCC_ERR_INVALID_PARAM ;
13341333 }
@@ -1433,8 +1432,8 @@ ucc_status_t ucc_mem_map_export(ucc_context_h context,
14331432 if (mode == UCC_MEM_MAP_MODE_EXPORT ) {
14341433 ucc_free (local_memh -> tl_h );
14351434 ucc_free (local_memh );
1435+ * memh = NULL ;
14361436 }
1437- * memh = NULL ;
14381437 * memh_size = 0 ;
14391438 return UCC_OK ;
14401439 }
@@ -1478,14 +1477,20 @@ ucc_status_t ucc_mem_map_export(ucc_context_h context,
14781477 }
14791478 }
14801479 } else {
1481- exported_memh -> tl_h = local_memh -> tl_h ;
1480+ exported_memh -> tl_h = (ucc_mem_map_tl_t * )ucc_calloc (
1481+ packed_tls , sizeof (ucc_mem_map_tl_t ), "packed tl memh" );
1482+ if (!exported_memh -> tl_h ) {
1483+ ucc_error ("failed to allocate handle for exported buffers' tl handles" );
1484+ status = UCC_ERR_NO_MEMORY ;
1485+ ucc_free (exported_memh );
1486+ goto failed_pack ;
1487+ }
14821488
1483- for (i = 0 ; i < local_memh -> num_tls ; i ++ ) {
1489+ for (i = 0 , offset = 0 , tls = 0 ; i < ( int ) local_memh -> num_tls ; i ++ ) {
14841490 if (!local_memh -> tl_h [i ].packed_size ) {
14851491 ucc_free (packed_buffers [i ]);
14861492 continue ;
14871493 }
1488- /* these are already packed in order */
14891494 strncpy (PTR_OFFSET (exported_memh -> pack_buffer , offset ),
14901495 local_memh -> tl_h [i ].tl_name , UCC_MEM_MAP_TL_NAME_LEN );
14911496 offset += UCC_MEM_MAP_TL_NAME_LEN ;
@@ -1496,6 +1501,8 @@ ucc_status_t ucc_mem_map_export(ucc_context_h context,
14961501 packed_buffers [i ], local_memh -> tl_h [i ].packed_size );
14971502 ucc_free (packed_buffers [i ]);
14981503 offset += local_memh -> tl_h [i ].packed_size ;
1504+ memcpy (& exported_memh -> tl_h [tls ++ ], & local_memh -> tl_h [i ],
1505+ sizeof (ucc_mem_map_tl_t ));
14991506 }
15001507 }
15011508
@@ -1506,9 +1513,7 @@ ucc_status_t ucc_mem_map_export(ucc_context_h context,
15061513 exported_memh -> num_tls = packed_tls ;
15071514 * memh = exported_memh ;
15081515 * memh_size = sizeof (ucc_mem_map_memh_t ) + offset ;
1509- if (mode == UCC_MEM_MAP_MODE_EXPORT ) {
1510- ucc_free (local_memh -> tl_h );
1511- }
1516+ ucc_free (local_memh -> tl_h );
15121517 ucc_free (local_memh );
15131518 ucc_free (packed_buffers );
15141519 return UCC_OK ;
0 commit comments