11/**
22 * Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2025-2026. ALL RIGHTS RESERVED.
3+ * Copyright (C) Advanced Micro Devices, Inc. 2026. ALL RIGHTS RESERVED.
34 *
45 * See file LICENSE for terms.
56 */
@@ -106,8 +107,8 @@ static uct_allocated_memory_t ucp_device_mem_handle_hash_remove(void *handle)
106107}
107108
108109static ucs_status_t
109- ucp_device_detect_local_sys_dev (ucp_context_h context ,
110- ucs_memory_type_t mem_type ,
110+ ucp_device_detect_local_sys_dev (const ucp_context_h context ,
111+ const ucs_memory_type_t mem_type ,
111112 ucs_sys_device_t * local_sys_dev )
112113{
113114 ucs_memory_info_t mem_info ;
@@ -310,7 +311,7 @@ static ucs_status_t ucp_device_local_mem_list_create_handle(
310311
311312static ucs_status_t ucp_device_local_mem_list_params_check (
312313 const ucp_device_mem_list_params_t * params , ucs_memory_type_t mem_type ,
313- ucs_sys_device_t * local_sys_dev )
314+ ucs_sys_device_t local_sys_dev )
314315{
315316 const ucp_device_mem_list_elem_t * local_elements = UCS_PARAM_VALUE (
316317 UCP_DEVICE_MEM_LIST_PARAMS_FIELD , params , elements , ELEMENTS , NULL );
@@ -325,7 +326,6 @@ static ucs_status_t ucp_device_local_mem_list_params_check(
325326 const ucp_device_mem_list_elem_t * element ;
326327 ucp_mem_h memh ;
327328 size_t i ;
328- ucs_status_t status ;
329329
330330 if ((local_elements == NULL ) || (element_size == 0 ) ||
331331 (num_elements == 0 ) || (worker == NULL )) {
@@ -335,12 +335,6 @@ static ucs_status_t ucp_device_local_mem_list_params_check(
335335 return UCS_ERR_INVALID_PARAM ;
336336 }
337337
338- status = ucp_device_detect_local_sys_dev (worker -> context , mem_type ,
339- local_sys_dev );
340- if (status != UCS_OK ) {
341- return status ;
342- }
343-
344338 for (i = 0 ; i < num_elements ; i ++ ) {
345339 element = (const ucp_device_mem_list_elem_t * )
346340 UCS_PTR_BYTE_OFFSET (local_elements , i * element_size );
@@ -351,26 +345,59 @@ static ucs_status_t ucp_device_local_mem_list_params_check(
351345 return UCS_ERR_INVALID_PARAM ;
352346 }
353347
354- if (memh -> sys_dev != * local_sys_dev ) {
348+ if (memh -> sys_dev != local_sys_dev ) {
355349 ucs_error ("mismatched local sys_dev for element=%zu" , i );
356350 return UCS_ERR_UNSUPPORTED ;
357351 }
358352 }
359353
354+ return UCS_OK ;
355+ }
356+
357+ static ucs_status_t
358+ ucp_device_detect_export_mem_type (const ucp_context_h context ,
359+ ucs_memory_type_t * export_mem_type_p ,
360+ ucs_sys_device_t * sys_dev_p )
361+ {
362+ ucs_status_t status = UCS_ERR_UNSUPPORTED ;
363+ ucs_memory_type_t mem_type ;
364+
365+ ucs_for_each_bit (mem_type , UCP_DEVICE_MEM_TYPES ) {
366+ status = ucp_device_detect_local_sys_dev (context , mem_type , sys_dev_p );
367+ if (status == UCS_OK ) {
368+ * export_mem_type_p = mem_type ;
369+ break ;
370+ }
371+ }
372+
360373 return status ;
361374}
362375
363376ucs_status_t
364377ucp_device_local_mem_list_create (const ucp_device_mem_list_params_t * params ,
365378 ucp_device_local_mem_list_h * mem_list_h )
366379{
367- const ucs_memory_type_t export_mem_type = UCS_MEMORY_TYPE_CUDA ;
368- ucs_status_t status ;
369- uct_allocated_memory_t mem ;
380+ const ucp_worker_h worker = UCS_PARAM_VALUE ( UCP_DEVICE_MEM_LIST_PARAMS_FIELD ,
381+ params , worker , WORKER , NULL ) ;
382+ ucs_memory_type_t export_mem_type ;
370383 ucs_sys_device_t local_sys_dev ;
384+ uct_allocated_memory_t mem ;
385+ ucs_status_t status ;
386+
387+ if (worker == NULL ) {
388+ ucs_error ("missing worker in local mem list params" );
389+ return UCS_ERR_INVALID_PARAM ;
390+ }
391+
392+ status = ucp_device_detect_export_mem_type (worker -> context ,
393+ & export_mem_type ,
394+ & local_sys_dev );
395+ if (status != UCS_OK ) {
396+ return status ;
397+ }
371398
372399 status = ucp_device_local_mem_list_params_check (params , export_mem_type ,
373- & local_sys_dev );
400+ local_sys_dev );
374401 if (status != UCS_OK ) {
375402 ucs_error ("failed to check local mem list params: %s" ,
376403 ucs_status_string (status ));
@@ -534,32 +561,20 @@ ucp_device_remote_mem_list_fill(const ucp_device_mem_list_elem_t *ucp_element,
534561}
535562
536563static ucs_status_t ucp_device_remote_mem_list_create_handle (
537- const ucp_device_mem_list_params_t * params , ucs_memory_type_t mem_type ,
538- uct_allocated_memory_t * mem )
564+ const ucp_device_mem_list_params_t * params , const ucp_ep_h ep ,
565+ const ucs_memory_type_t mem_type , uct_allocated_memory_t * mem ,
566+ const ucs_sys_device_t local_sys_dev )
539567{
540- const ucp_ep_h ep = ucp_device_remote_mem_list_get_first_ep (params );
541568 size_t uct_elem_size ;
542569 size_t handle_size = 0 ;
543570 ucp_tl_bitmap_t tl_bitmap [UCP_DEVICE_TL_TYPE_LAST ] = {};
544571 const ucp_device_mem_list_elem_t * ucp_element ;
545572 ucp_device_remote_mem_list_t * handle ;
546573 uct_device_remote_mem_elem_t * uct_element ;
547- ucs_sys_device_t local_sys_dev ;
548574 size_t i , num_lanes ;
549575 ucs_status_t status ;
550576 int tl_type ;
551577
552- if (ep == NULL ) {
553- ucs_error ("no ep found in remote mem list" );
554- return UCS_ERR_INVALID_PARAM ;
555- }
556-
557- status = ucp_device_detect_local_sys_dev (ep -> worker -> context , mem_type ,
558- & local_sys_dev );
559- if (status != UCS_OK ) {
560- return status ;
561- }
562-
563578 ucp_device_get_tl_bitmap (ep -> worker , tl_bitmap , local_sys_dev );
564579
565580 /* handle->num_lanes is the least common multiple of both lane types, so:
@@ -582,7 +597,7 @@ static ucs_status_t ucp_device_remote_mem_list_create_handle(
582597 uct_elem_size = sizeof (uct_device_remote_mem_elem_t ) +
583598 (sizeof (uct_device_remote_tl_elem_t ) * num_lanes );
584599 handle_size = sizeof (* handle ) + (params -> num_elements * uct_elem_size );
585- handle = ucs_calloc (1 , handle_size , "ucp_device_remote_mem_list_t" );
600+ handle = ucs_calloc (1 , handle_size , "ucp_device_remote_mem_list_t" );
586601 if (handle == NULL ) {
587602 ucs_error ("failed to allocate ucp_device_remote_mem_list_t" );
588603 return UCS_ERR_NO_MEMORY ;
@@ -601,7 +616,7 @@ static ucs_status_t ucp_device_remote_mem_list_create_handle(
601616
602617 if (tl_type == UCP_DEVICE_TL_TYPE_LAST ) {
603618 ucs_error ("lane not found for element %zd" , i );
604- status = UCS_ERR_INVALID_PARAM ;
619+ status = UCS_ERR_INVALID_PARAM ;
605620 goto out ;
606621 }
607622
@@ -616,10 +631,10 @@ static ucs_status_t ucp_device_remote_mem_list_create_handle(
616631 ucp_element = UCS_PTR_BYTE_OFFSET (ucp_element , params -> element_size );
617632 }
618633
619- handle -> version = UCP_DEVICE_MEM_LIST_VERSION_V1 ;
620- handle -> length = params -> num_elements ;
634+ handle -> version = UCP_DEVICE_MEM_LIST_VERSION_V1 ;
635+ handle -> length = params -> num_elements ;
621636 handle -> num_lanes = num_lanes ;
622- status = ucp_device_mem_list_export_handle (
637+ status = ucp_device_mem_list_export_handle (
623638 ep -> worker , handle , handle_size , mem_type , local_sys_dev , mem ,
624639 "ucp_device_remote_mem_list_handle_t" );
625640
@@ -683,17 +698,31 @@ ucs_status_t
683698ucp_device_remote_mem_list_create (const ucp_device_mem_list_params_t * params ,
684699 ucp_device_remote_mem_list_h * mem_list_h )
685700{
686- const ucs_memory_type_t export_mem_type = UCS_MEMORY_TYPE_CUDA ;
687- ucs_status_t status ;
701+ const ucp_ep_h ep = ucp_device_remote_mem_list_get_first_ep (params );
702+ ucs_memory_type_t export_mem_type ;
703+ ucs_sys_device_t sys_dev ;
688704 uct_allocated_memory_t mem ;
705+ ucs_status_t status ;
706+
707+ if (ep == NULL ) {
708+ ucs_error ("no ep found in remote mem list params" );
709+ return UCS_ERR_INVALID_PARAM ;
710+ }
711+
712+ status = ucp_device_detect_export_mem_type (ep -> worker -> context ,
713+ & export_mem_type , & sys_dev );
714+ if (status != UCS_OK ) {
715+ return status ;
716+ }
689717
690718 status = ucp_device_remote_mem_list_params_check (params );
691719 if (status != UCS_OK ) {
692720 return status ;
693721 }
694722
695- status = ucp_device_remote_mem_list_create_handle (params , export_mem_type ,
696- & mem );
723+ status = ucp_device_remote_mem_list_create_handle (params , ep ,
724+ export_mem_type ,
725+ & mem , sys_dev );
697726 if (status != UCS_OK ) {
698727 /*
699728 * Do not log error for UCS_ERR_NOT_CONNECTED because it is expected
0 commit comments