@@ -1607,6 +1607,30 @@ static ucs_status_t ucp_check_resources(ucp_context_h context,
16071607 return ucp_check_tl_names (context );
16081608}
16091609
1610+ static void
1611+ ucp_context_update_md_maps (ucp_context_h context , ucs_memory_type_t mem_type ,
1612+ unsigned md_index )
1613+ {
1614+ const uct_md_attr_v2_t * md_attr = & context -> tl_mds [md_index ].attr ;
1615+
1616+ if (!(md_attr -> flags & UCT_MD_FLAG_REG )) {
1617+ return ;
1618+ }
1619+
1620+ if (md_attr -> reg_mem_types & UCS_BIT (mem_type )) {
1621+ context -> reg_md_map [mem_type ] |= UCS_BIT (md_index );
1622+ }
1623+
1624+ if (md_attr -> cache_mem_types & UCS_BIT (mem_type )) {
1625+ context -> cache_md_map [mem_type ] |= UCS_BIT (md_index );
1626+ }
1627+
1628+ if ((context -> config .ext .gva_enable != UCS_CONFIG_OFF ) &&
1629+ (md_attr -> gva_mem_types & UCS_BIT (mem_type ))) {
1630+ context -> gva_md_map [mem_type ] |= UCS_BIT (md_index );
1631+ }
1632+ }
1633+
16101634static ucs_status_t
16111635ucp_add_component_resources (ucp_context_h context , ucp_rsc_index_t cmpt_index ,
16121636 ucs_string_set_t avail_devices [],
@@ -1626,6 +1650,7 @@ ucp_add_component_resources(ucp_context_h context, ucp_rsc_index_t cmpt_index,
16261650 uint64_t mem_type_bitmap ;
16271651 ucs_memory_type_t mem_type ;
16281652 const uct_md_attr_v2_t * md_attr ;
1653+ int md_supports_nonblock_reg ;
16291654
16301655 /* List memory domain resources */
16311656 uct_component_attr .field_mask = UCT_COMPONENT_ATTR_FIELD_MD_RESOURCES |
@@ -1687,10 +1712,17 @@ ucp_add_component_resources(ucp_context_h context, ucp_rsc_index_t cmpt_index,
16871712 mem_type_mask |= mem_type_bitmap ;
16881713 }
16891714
1690- ucs_memory_type_for_each (mem_type ) {
1691- if (md_attr -> flags & UCT_MD_FLAG_REG ) {
1715+ if (md_attr -> flags & UCT_MD_FLAG_REG ) {
1716+ ucs_memory_type_for_each (mem_type ) {
1717+ /* Record availability of non-blocking registration support */
1718+ md_supports_nonblock_reg = md_attr -> reg_nonblock_mem_types &
1719+ UCS_BIT (mem_type );
1720+ if (md_supports_nonblock_reg ) {
1721+ context -> reg_nb_supported_mem_types |= UCS_BIT (mem_type );
1722+ }
1723+
16921724 if ((context -> config .ext .reg_nb_mem_types & UCS_BIT (mem_type )) &&
1693- !( md_attr -> reg_nonblock_mem_types & UCS_BIT ( mem_type )) ) {
1725+ !md_supports_nonblock_reg ) {
16941726 if (md_attr -> reg_mem_types & UCS_BIT (mem_type )) {
16951727 /* Keep map of MDs supporting blocking registration
16961728 * if non-blocking registration is requested for the
@@ -1702,18 +1734,7 @@ ucp_add_component_resources(ucp_context_h context, ucp_rsc_index_t cmpt_index,
17021734 continue ;
17031735 }
17041736
1705- if (md_attr -> reg_mem_types & UCS_BIT (mem_type )) {
1706- context -> reg_md_map [mem_type ] |= UCS_BIT (md_index );
1707- }
1708-
1709- if (md_attr -> cache_mem_types & UCS_BIT (mem_type )) {
1710- context -> cache_md_map [mem_type ] |= UCS_BIT (md_index );
1711- }
1712-
1713- if ((context -> config .ext .gva_enable != UCS_CONFIG_OFF ) &&
1714- (md_attr -> gva_mem_types & UCS_BIT (mem_type ))) {
1715- context -> gva_md_map [mem_type ] |= UCS_BIT (md_index );
1716- }
1737+ ucp_context_update_md_maps (context , mem_type , md_index );
17171738 }
17181739 }
17191740
@@ -1774,9 +1795,23 @@ static void ucp_fill_resources_reg_md_map_update(ucp_context_h context)
17741795 ucs_memory_type_t mem_type ;
17751796 ucp_md_index_t md_index ;
17761797
1777- /* If we have a dmabuf provider for a memory type, it means we can register
1778- * memory of this type with any md that supports dmabuf registration. */
17791798 ucs_memory_type_for_each (mem_type ) {
1799+ /* Fallback: If non-blocking registration was requested for this memory
1800+ * type but no MD actually supports it, treat it as if the request was
1801+ * not set (i.e., allow blocking-capable MDs as well). */
1802+ if (context -> config .ext .reg_nb_mem_types & UCS_BIT (mem_type )) {
1803+ if (!(context -> reg_nb_supported_mem_types & UCS_BIT (mem_type ))) {
1804+ ucs_assert (context -> reg_md_map [mem_type ] == 0 );
1805+
1806+ for (md_index = 0 ; md_index < context -> num_mds ; ++ md_index ) {
1807+ ucp_context_update_md_maps (context , mem_type , md_index );
1808+ }
1809+ }
1810+ }
1811+
1812+ /* If we have a dmabuf provider for a memory type, it means we can
1813+ * register memory of this type with any md that supports dmabuf
1814+ * registration. */
17801815 if (context -> dmabuf_mds [mem_type ] != UCP_NULL_RESOURCE ) {
17811816 context -> reg_md_map [mem_type ] |= context -> dmabuf_reg_md_map ;
17821817 }
@@ -1823,6 +1858,7 @@ static ucs_status_t ucp_fill_resources(ucp_context_h context,
18231858 context -> mem_type_mask = 0 ;
18241859 context -> num_mem_type_detect_mds = 0 ;
18251860 context -> export_md_map = 0 ;
1861+ context -> reg_nb_supported_mem_types = 0 ;
18261862
18271863 ucs_memory_type_for_each (mem_type ) {
18281864 context -> reg_md_map [mem_type ] = 0 ;
0 commit comments