Skip to content

Commit bbe8ce7

Browse files
committed
UCP: Fallback to block reg when nonblock is not supported
Fallback to blocking registrations if none of MDs support nonblocking registration for the given mem type. Improves perf on GH|B systems when ODP is not available (e.g. because of DDP)
1 parent 1084d5f commit bbe8ce7

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

src/ucp/core/ucp_context.c

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
16101634
static ucs_status_t
16111635
ucp_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;

src/ucp/core/ucp_context.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ typedef struct ucp_context {
390390

391391
uint64_t mem_type_mask; /* Supported mem type mask */
392392

393+
/* Bitmask of memory types for which at least one MD supports
394+
* non-blocking registration. Each bit corresponds to a value from
395+
* ucs_memory_type_t. */
396+
uint64_t reg_nb_supported_mem_types;
397+
393398
ucp_tl_resource_desc_t *tl_rscs; /* Array of communication resources */
394399
ucp_tl_bitmap_t tl_bitmap; /* Cached map of tl resources used by workers.
395400
* Not all resources may be used if unified

0 commit comments

Comments
 (0)