Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ucp/core/ucp_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,10 @@ ucp_add_component_resources(ucp_context_h context, ucp_rsc_index_t cmpt_index,
++context->num_mem_type_detect_mds;
}

if (md_attr->detect_mem_types & ~UCS_BIT(UCS_MEMORY_TYPE_HOST)) {
context->has_non_host_detect_md = 1;
}

detect_mem_type_mask |= md_attr->detect_mem_types;
alloc_mem_type_mask |= md_attr->alloc_mem_types;

Expand Down Expand Up @@ -1955,6 +1959,7 @@ static ucs_status_t ucp_fill_resources(ucp_context_h context,
context->num_tls = 0;
context->supported_mem_type_mask = 0;
context->num_mem_type_detect_mds = 0;
context->has_non_host_detect_md = 0;
context->export_md_map = 0;

ucs_memory_type_for_each(mem_type) {
Expand Down
9 changes: 9 additions & 0 deletions src/ucp/core/ucp_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ typedef struct ucp_context {
/* List of MDs that detect non host memory type */
ucp_md_index_t mem_type_detect_mds[UCS_MEMORY_TYPE_LAST];
ucp_md_index_t num_mem_type_detect_mds; /* Number of mem type MDs */
uint8_t has_non_host_detect_md; /* Any detect MD supports non-host memory types */

/* Map of dmabuf providers per memory type. Each entry in the array is
either the index of the provider MD, or UCP_NULL_RESOURCE if no such MD
Expand Down Expand Up @@ -683,6 +684,14 @@ ucp_memory_detect_internal(ucp_context_h context, const void *address,

status = ucs_memtype_cache_lookup(address, length, mem_info);
if (ucs_likely(status == UCS_ERR_NO_ELEM)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know what memory allocator is being used for such unknown memory, and would it make sense to add hook under src/ucm instead? afaiu the slow path was meant to be used when memtype cache was disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know what memory allocator is being used for such unknown memory, and would it make sense to add hook under src/ucm instead? afaiu the slow path was meant to be used when memtype cache was disabled.

Unknown memtype here is not a specific allocator. It can happen even with memtype cache enabled, for example when UCM reports UNKNOWN for existing allocations or paths it cannot classify immediately, or when cache coverage is incomplete for the queried range.

Because of that, the internal slowpath is not only for the cache-disabled case. It is the correctness fallback for unknown or non-covered entries while cache is active.

Adding a hook under src/ucm is useful only if we identify a concrete allocator/runtime path that currently bypasses UCM memtype events. That may reduce slowpath frequency, but it will not remove the need for fallback in cross-context cases such as separate L0 contexts (for example PyTorch or SYCL vs UCX).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for details, also I think that memtype cache only tracks non-host memory, so no element currently means host memory type. if so I think that doing slowpath for those cases could have perf impact? for all the cases you mention maybe the memtype could be passed along with pointer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense. I agree we should avoid per-call warnings in this path, but we can add lightweight observability: I mean to track slowpath hits (miss and unknown cases) in the existing UCP stats tree using UCS_STATS_NODE_DECLARE, and emit a one-time or end-of-run summary hint when the counters are non-zero. That gives actionable feedback to pass explicit memtype hints without adding hot-path log noise.

Also agreed that passing memtype with the pointer is the preferred fix at the application boundary. In our NIXL/Dynamo integration we already do this for PyTorch GPU buffers by setting UCP_MEM_MAP_PARAM_FIELD_MEMORY_TYPE to UCS_MEMORY_TYPE_ZE_DEVICE, and in that path detection is bypassed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is logging aspect but also the implied uct_md_mem_query() that could have perf impact for host memory case (repeatedly calling it as host mem type is never in memtype cache).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is logging aspect but also the implied uct_md_mem_query() that could have perf impact for host memory case (repeatedly calling it as host mem type is never in memtype cache).

I agree we should avoid changing NO_ELEM semantics globally due performance risk on host-heavy paths. I will make this PR into draft for now

if (context->has_non_host_detect_md) {
ucs_trace_req("address %p length %zu: not found in memtype cache, "
"running slowpath for non-host capable context",
address, length);
ucp_memory_detect_slowpath(context, address, length, mem_info);
return;
}

ucs_trace_req("address %p length %zu: not found in memtype cache, "
"assuming host memory",
address, length);
Expand Down
Loading