Skip to content

TOPO/CUDA: cuda topo provider. - #12244

Draft
ofirfarjun7 wants to merge 2 commits into
openucx:masterfrom
ofirfarjun7:topic/cuda-topo-provider
Draft

ofirfarjun7 wants to merge 2 commits into
openucx:masterfrom
ofirfarjun7:topic/cuda-topo-provider

Conversation

@ofirfarjun7

@ofirfarjun7 ofirfarjun7 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What?

Add a CUDA topology provider owned by the GDA module and make topology providers composable.

The provider exposes the GPU-to-NIC assignment through the existing topology distance API. Assigned GPU/NIC pairs retain their sysfs distance, while unassigned pairs report maximum distance. Both UCP and UCT can therefore consume the same assignment without exposing the GDA matrix outside its module.

Why?

#11422 added topology-based HCA selection for GPU memory registration. #12125 addresses the mismatch between that UCP selection and GDA assignment by publishing additional GDA-specific resource metadata to UCP.

This PR unifies both selection paths in the topology layer. GDA publishes its assignment as topology distance, so the existing UCP policy from #11422 and GDA resource discovery consume the same result. This supersedes the separate metadata and UCP selection mechanism proposed by #12125.

How?

  • Register topology providers by name and maintain them in TOPO_PRIO execution order. Providers are applied from low to high priority so each provider can refine the accumulated result.
  • Use cuda,sysfs,default as the default chain: default initializes the result, sysfs supplies physical distance, and CUDA applies GPU/NIC assignment.
  • Initialize the CUDA provider from the GDA module. It enumerates GPUs with NVML, enumerates active IB devices, detects direct NICs, and ranks reachable NICs using sysfs topology.
  • Control the number of assigned NICs per GPU with UCX_CUDA_TOPO_MAX_NICS_PER_GPU.
  • Return maximum distance for unassigned GPU/NIC pairs and preserve sysfs latency/bandwidth for assigned pairs.
  • Query the common topology API when exposing rc_gda resources and remove the private GDA device-matrix implementation and its UCP workaround.

@ofirfarjun7
ofirfarjun7 requested a review from a team as a code owner November 4, 2026 13:18
@ofirfarjun7
ofirfarjun7 marked this pull request as draft November 4, 2026 13:19
@ofirfarjun7 ofirfarjun7 added the WIP-DNM Work in progress / Do not review label Nov 4, 2026
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Co-authored-by: Artemy Kovalyov <artemyko@nvidia.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@ofirfarjun7
ofirfarjun7 force-pushed the topic/cuda-topo-provider branch from 85420b1 to 0ab24ee Compare November 4, 2026 13:31
if ((uct_gdaki_topo_get_assignment(device1, device2, &is_assigned) ||
uct_gdaki_topo_get_assignment(device2, device1, &is_assigned)) &&
!is_assigned) {
*distance = ucs_topo_max_distance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blocker: ucs_topo_max_distance is latency=INFINITY/bandwidth=0, and this value now flows out of ucs_topo_get_distance() to all callers. ucp_proto_common_update_lane_perf_by_distance() then sets perf->bandwidth = 0 and sys_latency = inf, which trips ucs_assert(tl_perf->bandwidth > 1.0) in ucp_proto_common_get_lane_perf() for any CUDA zcopy lane on a non-assigned NIC (the lane is not filtered, ucp_proto_common_filter_min_frag() only checks ucs_topo_is_reachable()). pls use a large but finite penalty.

ucs_offsetof(ucs_global_opts_t, plugin_path), UCS_CONFIG_TYPE_PATH_ARRAY},

{"TOPO_PRIO", "sysfs,default",
{"TOPO_PRIO", "cuda,sysfs,default",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enabling the cuda provider by default makes the GDA GPU-NIC assignment apply to every ucs_topo_get_distance() caller, not just rc_gda device listing. With MAX_NICS_PER_GPU=auto (num_nics/num_gpus, i.e. 1 on an 8:8 node) all rc_mlx5 lanes for GPU memory except one become infinitely far. Is this intended, and how is it meant to interact with UCX_GPU_NIC_ASSIGNMENT_MODE and UCX_MAX_HCA_PER_GPU?

{
ucs_topo_restore_state(m_topo_state);
ucs::test::cleanup();
ucs_sys_topo_reset_provider();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blocker: priorities are now latched at reset time instead of resolved lazily, and pop_config() runs in the test destructor, after cleanup(). So this reset still sees TOPO_PRIO="test_high,missing2,missing1,test_low" and leaves sysfs/default at priority -1, making ucs_topo_get_distance() return the default distance for every later test in the process. pls restore TOPO_PRIO before resetting.

Comment thread src/uct/ib/mlx5/gdaki/topo.c Outdated
ucs_status_t status;
char name[16];

status = uct_gdaki_topo_nvml_status(nvmlDeviceGetCount_v2(&count),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls use UCT_CUDA_NVML_WRAP_CALL() from uct/cuda/base/cuda_nvml.h instead of calling nvml directly. It dlopen's libnvidia-ml.so.1 (so the module keeps loading on hosts without it), already owns the nvmlInit_v2/nvmlShutdown lifecycle, and UCT_CUDA_NVML_CALL_DEBUG already does what uct_gdaki_topo_nvml_status() does.

return UCS_ERR_IO_ERROR;
}

static ucs_status_t uct_gdaki_topo_enum_gpus(void)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this duplicates uct_cuda_init_devices() (CUDA+NVML enumeration, set_class ACC, enable_aux_path, "GPU%u" naming). It also looks up by bus id only, so for CUDA-visible GPUs it registers a second sys_dev next to the (bus_id, cuda_device) record from uct_cuda_get_sys_dev_and_bus_id() and names it "GPU<nvml_idx>" at priority 30, overriding the cuda base names. can we reuse the cuda base enumeration?

Comment thread src/uct/ib/mlx5/gdaki/topo.c Outdated
return status;
}

if (cuInit(0) != CUDA_SUCCESS) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no CUDA driver API is used in this file - can we drop cuInit() and the <cuda.h> include? It also initializes the CUDA driver at module load for processes that never touch CUDA.

{NULL}
};

static ucs_config_global_list_entry_t uct_gdaki_topo_config_entry = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the entry is never added to ucs_config_global_list, so UCX_CUDA_TOPO_MAX_NICS_PER_GPU is not listed by ucx_info -c, is rejected by ucp_config_modify(), and is reported as an unused env var when the gda module is not loaded. pls add UCS_CONFIG_REGISTER_TABLE_ENTRY(&uct_gdaki_topo_config_entry, &ucs_config_global_list).

Comment thread src/uct/ib/base/ib_md.c
@@ -121,11 +121,6 @@ ucs_config_field_t uct_ib_md_config_table[] = {
"Use GPU Direct RDMA for HCA to access GPU pages directly\n",
ucs_offsetof(uct_ib_md_config_t, enable_gpudirect_rdma), UCS_CONFIG_TYPE_TERNARY},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

dropping the field silently ignores existing UCX_IB_GDA_MAX_HCA_PER_GPU settings. pls keep the entry with UCS_CONFIG_TYPE_DEPRECATED so users get a warning pointing at the new variable.

uct_rc_gdaki_iface_config_t);

UCT_TL_INIT(&uct_ib_component, rc_gda, ctor, , )
UCS_MODULE_INIT()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this moves full IB enumeration (ibv_open_device + uct_ib_device_query per device) and NVML init from the lazy UCS_INIT_ONCE in uct_gdaki_fill_cuda_tl_devices() to module load, so every process loading the ib mlx5 gda module pays it even when rc_gda is not in UCX_TLS. can we keep it lazy?

Comment thread src/uct/ib/mlx5/gdaki/topo.c Outdated
const uct_gdaki_topo_candidate_t *b = pb;
int cmp;

(void)arg;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: pls use void *UCS_V_UNUSED arg in the signature, like the other ucs_qsort_r comparators; (void)arg; is not used anywhere in src/.

@svc-nvidia-pr-review

Copy link
Copy Markdown

This is ~700 added lines and mixes two separable changes: the UCS topology provider chaining refactor (topo.c/topo.h/global_opts.c + tests) and the new gdaki cuda provider that replaces the GDA device matrix. pls split it per REVIEW.md (>500 added lines, and refactoring should not ride along with a feature).

Notes on coverage gaps: test_topo.provider_registration covers chaining, duplicate and invalid-ops registration, but there is no test for the priority < 0 skip path or for ucs_sys_topo_reset_provider() reordering after a TOPO_PRIO change.

Notes on coverage gaps: The new uct_gdaki_topo_* assignment logic (max_nics_per_gpu auto/inf/N, direct-NIC preference, unreachable GPU → empty map) has no test; it replaces previously-tested-by-hardware gdaki behavior and only runs on GDA-capable nodes, so a regression here will be invisible in CI.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

goto err;
}

if (ucs_topo_distance_cmp(&distance, &ucs_topo_max_distance) == 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this inverts the old filter: a NIC that the provider did not enumerate (no active port, ibv_open_device() failure) or a provider that failed to register (no NVML, cuInit() failure, TOPO_PRIO without "cuda") leaves the distance at the sysfs value, so we now report rc_gda devices for every CUDA device x NIC pair instead of UCS_ERR_NO_DEVICE. In particular the "skipping GDA device, port is not active" check is lost. pls query the assignment explicitly instead of using max_distance as a sentinel.

{NULL}
};

static ucs_config_global_list_entry_t uct_gdaki_topo_config_entry = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the entry is never added to ucs_config_global_list, so UCX_CUDA_TOPO_MAX_NICS_PER_GPU is not printed by ucx_info -c and is rejected by ucp_config_modify()/uct_config_modify() (gtest modify_config too).

Suggested change
static ucs_config_global_list_entry_t uct_gdaki_topo_config_entry = {
static ucs_config_global_list_entry_t uct_gdaki_topo_config_entry = {
.name = "CUDA topology",
.prefix = "CUDA_TOPO_",
.table = uct_gdaki_topo_config_table,
.size = sizeof(uct_gdaki_topo_config_t)
};
UCS_CONFIG_REGISTER_TABLE_ENTRY(&uct_gdaki_topo_config_entry,
&ucs_config_global_list);

continue;
}

status = ucs_topo_find_device_by_bus_id(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this duplicates uct_cuda_init_devices() (NVML enumeration, ACC class, aux path, name) and, because it looks up by BDF only while uct_cuda_get_sys_dev_and_bus_id() looks up by BDF+CUdevice, it registers a second sys_dev record for every CUDA-visible GPU and renames it at priority 30. can we reuse the existing enumeration instead?

Comment thread src/uct/ib/mlx5/gdaki/topo.c Outdated
goto out_release_config;
}

status = uct_gdaki_topo_nvml_status(nvmlInit_v2(), "nvmlInit_v2");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: pls use UCT_CUDA_NVML_WRAP_CALL()/uct/cuda/base/cuda_nvml.h instead of calling nvml directly, so the module keeps lazy dlopen of libnvidia-ml and one place owns nvmlInit/nvmlShutdown.

uct_rc_gdaki_iface_config_t);

UCT_TL_INIT(&uct_ib_component, rc_gda, ctor, , )
UCS_MODULE_INIT()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this moves cuInit(), nvmlInit() and ibv_open_device() of every IB device to module load time (UCS_MODULE_FRAMEWORK_LOAD(uct_ib_mlx5)), so they run on any mlx5 system even when rc_gda is not in UCX_TLS. why not keep it lazy, as the device matrix was?

@svc-nvidia-pr-review

Copy link
Copy Markdown

src/uct/ib/mlx5/gdaki/topo.c

the "cuda" provider is global, so this now reports bandwidth=0/latency=inf between a GPU and every NIC that is not in the GDA assignment for all consumers of ucs_topo_get_distance() (ucp_proto_common_get_lane_distance(), ucp_context_select_reg_mds(), ucp_rkey/proto_rndv), not only for rc_gda. With MAX_NICS_PER_GPU=auto (num_nics/num_gpus, i.e. 1 on a typical DGX) UCP would see a single usable NIC per GPU for rndv/rma lanes. Is that intended? If the constraint is meant for rc_gda only, it shouldn't go through the topo distance API.

Residual coverage gaps: beyond the gaps already noted, there is no test that a NIC absent from the provider's NIC list (inactive port) is excluded from rc_gda devices — the behavior in finding 2 is only observable on GDA hardware.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

}
}

if (flags & UCP_PROTO_COMMON_INIT_FLAG_REMOTE_ACCESS) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blocker: rkey_cfg_index is UCP_WORKER_CFG_INDEX_NULL whenever rkey_config_key == NULL — e.g. rndv/get/zcopy is probed for UCP_OP_ID_RNDV_RECV when the RTS carried no rkey (ucp_proto_rndv_send_reply() sets rkey_cfg_index = UCP_WORKER_CFG_INDEX_NULL). This filter runs before the rkey_config_key == NULL check in ucp_proto_common_find_lanes(), so ucp_worker_rkey_config() asserts in debug and reads past worker->rkey_config in release.

Suggested change:

    if ((flags & UCP_PROTO_COMMON_INIT_FLAG_REMOTE_ACCESS) &&
        (params->rkey_config_key != NULL)) {
        rkey_config = ucp_worker_rkey_config(
                params->worker, common_params->super.rkey_cfg_index);
        distance    = rkey_config->lanes_distance[lane];
        if (ucs_topo_distance_cmp(&distance, &ucs_topo_max_distance) == 0) {

UCT_GDAKI_TOPO_NAME_PRIO);
}

static ucs_status_t uct_gdaki_topo_enum_gpus(void)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this duplicates the GPU enumeration already done by uct_cuda_init_devices() (CUDA + NVML by BDF, class ACC, aux path, device names, mark_incomplete on NVML failure). can we reuse it instead of keeping a second enumeration in sync?

return status;
}

ucs_snprintf_safe(name, sizeof(name), "GPU%u", index);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: UCT_GDAKI_TOPO_NAME_PRIO=30 overrides the GPU%d name set by cuda_base (priority 10), but index here is the enumeration/NVML index, not the CUDA device index. So device names in the proto/topo tables change when CUDA_VISIBLE_DEVICES hides GPUs, and NVML-only GPUs get renamed from UNKN%u to GPU%u.

return b->reachable - a->reachable;
}

if (a->is_direct != b->is_direct) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is_direct is compared before the distance, so a GPU with no direct NIC of its own can get another GPU's direct NIC as candidate 0 and then break at line 390, ending up with a single wrong NIC. ucs_topo_is_reachable() returns 1 for a GPU that was never matched with a sibling, so this is reachable. why not keep the distance as the first key?

goto err;
}

if (ucs_topo_distance_cmp(&distance, &ucs_topo_max_distance) == 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

with a UCX_TOPO_PRIO that does not list cuda (e.g. the previous default sysfs,default), the provider gets priority -1 and is skipped, so no pair ever reports max distance and rc_gda exposes every GPU x NIC pair instead of the limited set GDA_MAX_HCA_PER_GPU used to produce. pls at least log a diag when the assignment is not active.

@svc-nvidia-pr-review

Copy link
Copy Markdown

Residual coverage gaps (not posted as inline comments): nothing exercises the deprecated GDA_MAX_HCA_PER_GPU -> CUDA_TOPO_MAX_NICS_PER_GPU transition, and the rkey_config_key == NULL + REMOTE_ACCESS path in finding 1 is only hit by rndv receive without an rkey (non-contig sender datatype), which the mock proto tests do not cover.

#ifndef UCT_GDAKI_TOPO_H
#define UCT_GDAKI_TOPO_H

void uct_gdaki_topo_init(void);

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.

Concern: scope is too wide

#12125 kept the HCA preference scoped to GDA (only with UCP_FEATURE_DEVICE and MAX_HCA_PER_GPU set). This PR exposes the GDA assignment through the global ucs_topo_get_distance(), enabled by default on CUDA+mlx5 builds, so it affects code unrelated to GDA:

  • Memory registration (ucp_context_select_reg_mds): GPU memory is registered only on the NICs assigned to that GPU, for all ucp_mem_map users.
  • Protocol lanes and performance estimates (proto_common.c): lanes on unassigned NICs are dropped or estimated with zero bandwidth, for host-initiated RMA/AM/rendezvous on GPU buffers.
  • Remote key and rendezvous distances (ucp_rkey.c, proto_rndv.c): the max distance is packed into remote keys, so the peer also skips those lanes.
  • Connection setup scoring (ucp_worker.c): with the default UCX_SELECT_DISTANCE_MD=cuda_cpy, NICs not assigned to the GPU current at ucp_init get zero bandwidth.
  • ucx_info output and GPU naming (GPU<n>).

None of these check UCP_FEATURE_DEVICE, UCX_TLS or UCX_NET_DEVICES, so a plain host-side CUDA application gets its NICs restricted.

Other issues:

  • ucs_topo_get_distance() returns max distance as a policy marker ("not assigned") instead of a physical distance.
  • It overlaps with UCX_GPU_NIC_ASSIGNMENT_MODE: both filters apply, so the result is their intersection, which can be empty (e.g. 2 GPUs and 4 NICs, flip and the GDA split leave one NIC per GPU).
  • MAX_HCA_PER_GPU is removed without deprecation, and registration and GDA can no longer be tuned separately.
  • The provider mechanism is generic, but the assignment still lives in gdaki and only exists when the gda module is built and loaded.
  • The ranking uses sysfs distance, which does not see PCIe switch depth: NICs under the same top switch tie, and the tie-break may pick a NIC on another lower switch.

Proposal: one GPU-NIC assignment in a common place

  • Grouping: UCS topology groups, by NUMA node or by deepest shared PCIe switch (UCP/CONTEXT: Add PCIe switch grouping for GPU-NIC assignment #12202). The switch grouping matches the rail-local intent of the GDA ranking and handles the tie case.
  • Move the assignment builder (ucp_gpu_nic_assignment_build/lookup, modes flip/round_robin/shared) from UCP to UCS, and add:
    • pinning a direct NIC to its own GPU;
    • an optional limit on NICs per GPU (replacing MAX_HCA_PER_GPU/MAX_NICS_PER_GPU).
  • Consumers look up the assignment explicitly:
    • UCP protocol lanes, as today;
    • UCP registration (ucp_context_select_reg_mds);
    • rc_gda: UCT lists GPU×NIC pairs, each tagged with its GPU (similar to ctl_device in UCP/DEVICE: Align GPU memory registration with GDA assignments #12125), and UCP drops unassigned pairs in ucp_context_gpu_nic_assignment_init() before any interface is opened. GDA then honors the same UCX_NET_DEVICES, mode and grouping as host traffic.
  • Keep ucs_topo_get_distance() physical: no new topology provider and no TOPO_PRIO change.

@rakhmets rakhmets Nov 20, 2026 •

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'm not sure if this a right place for this logic. Maybe it would be better to try to align with existing approach. I would try to implement it in the following way. UCT provides devices and their characteristics. UCS provides topology information, distance between devices. UCP orchestrates the information.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP-DNM Work in progress / Do not review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants