@@ -511,6 +511,11 @@ static ucs_config_field_t ucp_context_config_table[] = {
511511 ucs_offsetof (ucp_context_config_t , reg_nb_mem_types ),
512512 UCS_CONFIG_TYPE_BITMAP (ucs_memory_type_names )},
513513
514+ {"REG_NONBLOCK_FALLBACK" , "y" ,
515+ "Allow fallback to blocking memory registration if no MDs supporting non-blocking\n"
516+ "registration." ,
517+ ucs_offsetof (ucp_context_config_t , reg_nb_fallback ), UCS_CONFIG_TYPE_BOOL },
518+
514519 {"PREFER_OFFLOAD" , "y" ,
515520 "Prefer transports capable of remote memory access for RMA and AMO operations.\n"
516521 "The value is interpreted as follows:\n"
@@ -1632,11 +1637,10 @@ ucp_add_component_resources(ucp_context_h context, ucp_rsc_index_t cmpt_index,
16321637 unsigned num_tl_resources ;
16331638 ucs_status_t status ;
16341639 ucp_rsc_index_t i ;
1640+ const uct_md_attr_v2_t * md_attr ;
16351641 unsigned md_index ;
16361642 uint64_t mem_type_mask ;
16371643 uint64_t mem_type_bitmap ;
1638- ucs_memory_type_t mem_type ;
1639- const uct_md_attr_v2_t * md_attr ;
16401644
16411645 /* List memory domain resources */
16421646 uct_component_attr .field_mask = UCT_COMPONENT_ATTR_FIELD_MD_RESOURCES |
@@ -1698,51 +1702,6 @@ ucp_add_component_resources(ucp_context_h context, ucp_rsc_index_t cmpt_index,
16981702 mem_type_mask |= mem_type_bitmap ;
16991703 }
17001704
1701- ucs_memory_type_for_each (mem_type ) {
1702- if (md_attr -> flags & UCT_MD_FLAG_REG ) {
1703- if ((context -> config .ext .reg_nb_mem_types & UCS_BIT (mem_type )) &&
1704- !(md_attr -> reg_nonblock_mem_types & UCS_BIT (mem_type ))) {
1705- if (md_attr -> reg_mem_types & UCS_BIT (mem_type )) {
1706- /* Keep map of MDs supporting blocking registration
1707- * if non-blocking registration is requested for the
1708- * given memory type. In some cases blocking
1709- * registration maybe required anyway (e.g. internal
1710- * staging buffers for rndv pipeline protocols). */
1711- context -> reg_block_md_map [mem_type ] |= UCS_BIT (md_index );
1712- }
1713- continue ;
1714- }
1715-
1716- if (md_attr -> reg_mem_types & UCS_BIT (mem_type )) {
1717- context -> reg_md_map [mem_type ] |= UCS_BIT (md_index );
1718- }
1719-
1720- if (md_attr -> cache_mem_types & UCS_BIT (mem_type )) {
1721- context -> cache_md_map [mem_type ] |= UCS_BIT (md_index );
1722- }
1723-
1724- if ((context -> config .ext .gva_enable != UCS_CONFIG_OFF ) &&
1725- (md_attr -> gva_mem_types & UCS_BIT (mem_type ))) {
1726- context -> gva_md_map [mem_type ] |= UCS_BIT (md_index );
1727- }
1728- }
1729- }
1730-
1731- if (md_attr -> flags & UCT_MD_FLAG_EXPORTED_MKEY ) {
1732- context -> export_md_map |= UCS_BIT (md_index );
1733- }
1734-
1735- if (md_attr -> flags & UCT_MD_FLAG_REG_DMABUF ) {
1736- context -> dmabuf_reg_md_map |= UCS_BIT (md_index );
1737- }
1738-
1739- ucs_for_each_bit (mem_type , md_attr -> dmabuf_mem_types ) {
1740- /* In case of multiple providers, take the first one */
1741- if (context -> dmabuf_mds [mem_type ] == UCP_NULL_RESOURCE ) {
1742- context -> dmabuf_mds [mem_type ] = md_index ;
1743- }
1744- }
1745-
17461705 ++ context -> num_mds ;
17471706 }
17481707
@@ -1779,15 +1738,86 @@ static ucs_status_t ucp_fill_aux_tls(ucs_string_set_t *aux_tls)
17791738 return UCS_OK ;
17801739}
17811740
1741+ static void
1742+ ucp_update_memtype_md_map (uint64_t mem_types_map , ucs_memory_type_t mem_type ,
1743+ ucp_md_index_t md_index , ucp_md_map_t * md_map_p )
1744+ {
1745+ if (mem_types_map & UCS_BIT (mem_type )) {
1746+ * md_map_p |= UCS_BIT (md_index );
1747+ }
1748+ }
1749+
17821750static void ucp_fill_resources_reg_md_map_update (ucp_context_h context )
17831751{
17841752 UCS_STRING_BUFFER_ONSTACK (strb , 256 );
1753+ ucp_md_map_t reg_block_md_map ;
1754+ ucp_md_map_t reg_nonblock_md_map ;
17851755 ucs_memory_type_t mem_type ;
17861756 ucp_md_index_t md_index ;
1757+ const uct_md_attr_v2_t * md_attr ;
1758+
1759+ for (md_index = 0 ; md_index < context -> num_mds ; ++ md_index ) {
1760+ md_attr = & context -> tl_mds [md_index ].attr ;
1761+ if (md_attr -> flags & UCT_MD_FLAG_EXPORTED_MKEY ) {
1762+ context -> export_md_map |= UCS_BIT (md_index );
1763+ }
1764+
1765+ if (md_attr -> flags & UCT_MD_FLAG_REG_DMABUF ) {
1766+ context -> dmabuf_reg_md_map |= UCS_BIT (md_index );
1767+ }
1768+ }
17871769
1788- /* If we have a dmabuf provider for a memory type, it means we can register
1789- * memory of this type with any md that supports dmabuf registration. */
17901770 ucs_memory_type_for_each (mem_type ) {
1771+ reg_block_md_map = 0 ;
1772+ reg_nonblock_md_map = 0 ;
1773+ for (md_index = 0 ; md_index < context -> num_mds ; ++ md_index ) {
1774+ md_attr = & context -> tl_mds [md_index ].attr ;
1775+ if (md_attr -> dmabuf_mem_types & UCS_BIT (mem_type )) {
1776+ /* In case of multiple providers, take the first one */
1777+ if (context -> dmabuf_mds [mem_type ] == UCP_NULL_RESOURCE ) {
1778+ context -> dmabuf_mds [mem_type ] = md_index ;
1779+ }
1780+ }
1781+
1782+ if (!(md_attr -> flags & UCT_MD_FLAG_REG )) {
1783+ continue ;
1784+ }
1785+
1786+ ucp_update_memtype_md_map (
1787+ md_attr -> reg_nonblock_mem_types , mem_type ,
1788+ md_index , & reg_nonblock_md_map );
1789+ ucp_update_memtype_md_map (
1790+ md_attr -> reg_mem_types , mem_type , md_index ,
1791+ & reg_block_md_map );
1792+ ucp_update_memtype_md_map (
1793+ md_attr -> cache_mem_types , mem_type , md_index ,
1794+ & context -> cache_md_map [mem_type ]);
1795+
1796+ if (context -> config .ext .gva_enable != UCS_CONFIG_OFF ) {
1797+ ucp_update_memtype_md_map (
1798+ md_attr -> gva_mem_types , mem_type , md_index ,
1799+ & context -> gva_md_map [mem_type ]);
1800+ }
1801+ }
1802+
1803+ if ((context -> config .ext .reg_nb_mem_types & UCS_BIT (mem_type )) &&
1804+ ((reg_nonblock_md_map != 0 ) || !context -> config .ext .reg_nb_fallback )) {
1805+ /* Keep map of MDs supporting blocking registration
1806+ * if non-blocking registration is requested for the
1807+ * given memory type. In some cases blocking
1808+ * registration maybe required anyway (e.g. internal
1809+ * staging buffers for rndv pipeline protocols). */
1810+ context -> reg_block_md_map [mem_type ] =
1811+ reg_block_md_map & ~reg_nonblock_md_map ;
1812+ context -> reg_md_map [mem_type ] = reg_nonblock_md_map ;
1813+ } else {
1814+ context -> reg_block_md_map [mem_type ] = reg_block_md_map ;
1815+ context -> reg_md_map [mem_type ] = reg_block_md_map ;
1816+ }
1817+
1818+ /* If we have a dmabuf provider for a memory type, it means we can
1819+ * register memory of this type with any md that supports dmabuf
1820+ * registration. */
17911821 if (context -> dmabuf_mds [mem_type ] != UCP_NULL_RESOURCE ) {
17921822 context -> reg_md_map [mem_type ] |= context -> dmabuf_reg_md_map ;
17931823 }
0 commit comments