Repository navigation
Description
Describe the bug
Since #11553, tagged GPU-to-GPU rendezvous transfers are much slower when the send/receive buffers are allocations that UCX has not seen before.
- On GB200, an 8 MiB message from a CUDA stream-ordered pool allocation (
cudaMallocFromPoolAsync) costs 86 µs instead of 17 µs (about 5x). - A message from a fresh
cudaMallocallocation costs 150-175 µs instead of 77 µs (about 2x). - Messages that reuse the same buffer are unaffected, which is why
ucx_perftestdoes not show it. - The parent commit (221e743) is fine. v1.22.x, v1.23.x (incl. v1.23.2) and master are affected.
UCX_CUDA_COPY_DMABUF=nofully removes the slowdown.
This hits RAPIDS distributed workloads (cudf-polars / rapidsmpf over UCXX), where every shuffle message is a new sub-allocation of an RMM async pool. A PDS-H query (Q9, SF30K) on 4 GB200 nodes goes from ~41 s with v1.20.1 to ~200 s with v1.22.x/v1.23.x. We bisected the application-level regression to this commit on master first-parent history between the v1.21 and v1.22 branch points.
Likely cause (from reading the code):
uct_cuda_copy_md_mem_query()now always callsuct_cuda_copy_md_detect_mem_flags()for an address with a known device. When DMA-BUF is supported, that exports a DMA-BUF fd for the whole allocation (uct_cuda_copy_md_get_dmabuf()->uct_cuda_copy_md_get_dmabuf_fd()->cuMemGetHandleForAddressRange) and closes it again, only to decideUCS_MEM_FLAG_REGISTRABLE.uct_cuda_copy_md_get_dmabuf_fd()also resolvescuMemGetHandleForAddressRangewithcuGetProcAddress()on every call.- This happens even when the caller asked only for the memory type (
uct_cuda_copy_md_detect_memory_type()) and did not requestUCT_MD_MEM_ATTR_V2_FIELD_MEM_FLAGS. - It also happens when no MD that requires
REGISTRABLEis in use. In the reproducer the transports aresm,self,cuda_copy,cuda_ipc, so no IB MD is involved. - In addition,
ucp_memh_get_slow()now callsucp_memory_detect_internal()unconditionally, not only forreg_whole_allocmemory types. So every registration-cache miss pays for an export/close.
Possible directions:
- Probe only when
MEM_FLAGSis requested and some MD in the context has non-zerorequired_mem_flags. - Or cache the result per allocation (base address/length) so it is not repeated for every sub-allocation of the same pool.
Steps to Reproduce
-
Command line: a self-contained reproducer is below. It needs only UCX and the CUDA runtime: two processes on one node (fork), GPU0 sends to GPU1 with
ucp_tag_send_nbx/ucp_tag_recv_nbx, 8 in flight, and every message uses a different buffer.gcc -O2 -o ucp_pool_send_bench ucp_pool_send_bench.c -I$UCX/include -L$UCX/lib -lucp -lucs \ -I$CUDA/include -L$CUDA/lib64 -lcudart export UCX_TLS=sm,self,cuda_copy,cuda_ipc ./ucp_pool_send_bench -m reuse -s 8M -n 1900 -w 8 -g 0,1 # one buffer for all messages ./ucp_pool_send_bench -m pool -s 8M -n 1900 -k 2000 -w 8 -g 0,1 # new pool sub-allocation per message ./ucp_pool_send_bench -m malloc -s 8M -n 1900 -k 2000 -w 8 -g 0,1 # new cudaMalloc buffer per message -
Results: µs per 8 MiB message, average of 2 runs, 1 GB200 node,
UCX_TLS=sm,self,cuda_copy,cuda_ipc:UCX reuse pool malloc v1.20.1 14.8 17.2 78.5 221e743 (master, parent of UCP/UCT/UCS: Add memory registration flags #11553) 15.0 17.2 76.9 b6b8531 (UCP/UCT/UCS: Add memory registration flags #11553) 15.0 86.2 148.5 v1.23.2 15.0 84.6 175.3 b6b8531, UCX_CUDA_COPY_DMABUF=no– 17.2 79.8 v1.23.2, UCX_CUDA_COPY_DMABUF=no– 17.2 71.4 -
UCX version: releases v1.20.1, v1.23.2, and master commits 221e743, b6b8531 and 13ad917, all built from GitHub sources. Configure flags (
ucx_info -v):
--disable-logging --disable-debug --disable-assertions --disable-params-check --enable-cma --enable-mt --enable-numa --with-gnu-ld --with-verbs=<conda> --with-rdmacm=<conda> --with-cuda=<conda> -
UCX environment variables:
UCX_TLS=sm,self,cuda_copy,cuda_ipc;UCX_CUDA_COPY_DMABUF=noonly where noted. The application runs usedUCX_TLS=^ib,ud:aux(cuda_ipc over multi-node NVLink).
Setup and versions
- OS: host Ubuntu 26.04.1 LTS, kernel
7.0.0-2024-nvidia-bos-64k, aarch64
(Linux 7.0.0-2024-nvidia-bos-64k #25-Ubuntu SMP PREEMPT_DYNAMIC aarch64 GNU/Linux);
runs inside an Ubuntu 24.04.3 container. - RDMA/IB: not involved (IB transports excluded).
- GPU: 4x NVIDIA GB200 per node (GB200 NVL72).
- Driver 615.74, CUDA 13.2 (cudart 13.2.86).
CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED=1.gdrdrvis loaded;nv_peer_mem/nvidia_peermemare not loaded.
- On a DGX-1 (V100, kernel 5.4, driver 535), where DMA-BUF is not supported, 221e743 and b6b8531 perform the same. This is consistent with the DMA-BUF probe being the cost.
Additional information (depending on the issue)
- OpenMPI: not used.
ucx_info -d(master), CUDA memory domains:# Memory domain: cuda_cpy # memory types: host (access,reg), cuda (access,alloc,reg,detect,dmabuf), cuda-managed (access,alloc,reg,cache,detect) # Transport: cuda_copy # Memory domain: cuda_ipc # memory types: cuda (access,reg,cache) # Transport: cuda_ipc- Log file: these were release builds (
--disable-logging). We can provideUCX_LOG_LEVEL=datalogs from a logging build if useful. - With
UCX_TLSunset (IB MDs present), IB registration of GPU memory dominates the pool/malloc cases and the numbers are not comparable. That is why the reproducer restricts the transports. - Note: in our application, setting
UCX_CUDA_COPY_DMABUF=nowith v1.23.x leads to GPU out-of-memory errors (not investigated yet). So for us it is not a usable workaround, and a fix in UCX would be needed.
ucp_pool_send_bench.c
/*
* Self-contained reproducer: UCP tagged GPU-to-GPU transfers where every message
* uses a different sub-allocation of a CUDA stream-ordered memory pool, as an
* RMM cuda_async_memory_resource does (RAPIDS / rapidsmpf shuffles).
*
* Two processes on one node (fork), one GPU each. They exchange worker
* addresses over a socketpair and need no MPI or other launcher. The child receives
* and the parent sends N messages of S bytes, -w at a time. The parent prints
* time per message and bandwidth for the timed messages, excluding the warmup.
*
* Buffer modes (-m):
* pool : K distinct buffers allocated up front from one cudaMemPoolCreate pool
* (same as rmm::mr::cuda_async_memory_resource{}); message i uses
* buffer i % K, so most messages hit a buffer UCX has not seen yet
* when K > N
* malloc : same, but each buffer is a separate cudaMalloc allocation
* reuse : one buffer for every message (what ucx_perftest does)
*
* Build: cc -O2 -o ucp_pool_send_bench ucp_pool_send_bench.c \
* -I$UCX/include -L$UCX/lib -lucp -lucs -I$CUDA/include -L$CUDA/lib64 -lcudart
* Run: export UCX_TLS=sm,self,cuda_copy,cuda_ipc
* ./ucp_pool_send_bench -m reuse -s 8M -n 1900 -w 8 -g 0,1
* ./ucp_pool_send_bench -m pool -s 8M -n 1900 -k 2000 -w 8 -g 0,1
* ./ucp_pool_send_bench -m malloc -s 8M -n 1900 -k 2000 -w 8 -g 0,1
* Keep -k >= -n + -W (warmup, default 100) so that every message uses a new buffer.
*/
#define _GNU_SOURCE
#include <cuda_runtime.h>
#include <ucp/api/ucp.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#define CHECK_CUDA(_call) \
do { \
cudaError_t _e = (_call); \
if (_e != cudaSuccess) { \
fprintf(stderr, "%s:%d %s: %s\n", __FILE__, __LINE__, #_call, \
cudaGetErrorString(_e)); \
exit(1); \
} \
} while (0)
#define CHECK_UCS(_call) \
do { \
ucs_status_t _s = (_call); \
if (_s != UCS_OK) { \
fprintf(stderr, "%s:%d %s: %s\n", __FILE__, __LINE__, #_call, \
ucs_status_string(_s)); \
exit(1); \
} \
} while (0)
static const char *mode = "pool";
static size_t msg_size = 8ul << 20;
static long n_msgs = 2000;
static long n_bufs = 2000;
static int window = 8;
static int warmup = 100;
static int gpus[2] = {0, 1};
static size_t parse_size(const char *s)
{
char *end;
double v = strtod(s, &end);
switch (*end) {
case 'G': case 'g': v *= 1024; /* fallthrough */
case 'M': case 'm': v *= 1024; /* fallthrough */
case 'K': case 'k': v *= 1024; break;
}
return (size_t)v;
}
static double now(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec + ts.tv_nsec * 1e-9;
}
static void write_all(int fd, const void *p, size_t n)
{
for (const char *c = p; n > 0;) {
ssize_t r = write(fd, c, n);
if (r <= 0 && errno != EINTR) { perror("write"); exit(1); }
if (r > 0) { c += r; n -= r; }
}
}
static void read_all(int fd, void *p, size_t n)
{
for (char *c = p; n > 0;) {
ssize_t r = read(fd, c, n);
if (r <= 0 && errno != EINTR) { perror("read"); exit(1); }
if (r > 0) { c += r; n -= r; }
}
}
/* Allocate the message buffers on the current device according to mode. */
static void **alloc_buffers(long count)
{
void **bufs = calloc(count, sizeof(*bufs));
if (!strcmp(mode, "reuse")) {
CHECK_CUDA(cudaMalloc(&bufs[0], msg_size));
for (long i = 1; i < count; ++i) bufs[i] = bufs[0];
} else if (!strcmp(mode, "malloc")) {
for (long i = 0; i < count; ++i) CHECK_CUDA(cudaMalloc(&bufs[i], msg_size));
} else {
/* Like rmm::mr::cuda_async_memory_resource{}: own pool, no export handle. */
int dev;
cudaMemPool_t pool;
struct cudaMemPoolProps props;
memset(&props, 0, sizeof(props));
uint64_t threshold = UINT64_MAX;
cudaStream_t stream;
CHECK_CUDA(cudaGetDevice(&dev));
props.allocType = cudaMemAllocationTypePinned;
props.handleTypes = cudaMemHandleTypeNone;
props.location.type = cudaMemLocationTypeDevice;
props.location.id = dev;
CHECK_CUDA(cudaMemPoolCreate(&pool, &props));
CHECK_CUDA(cudaMemPoolSetAttribute(pool, cudaMemPoolAttrReleaseThreshold,
&threshold));
CHECK_CUDA(cudaStreamCreate(&stream));
for (long i = 0; i < count; ++i) {
CHECK_CUDA(cudaMallocFromPoolAsync(&bufs[i], msg_size, pool, stream));
}
CHECK_CUDA(cudaStreamSynchronize(stream));
}
return bufs;
}
static void wait_req(ucp_worker_h worker, void *req)
{
if (req == NULL) return;
if (UCS_PTR_IS_ERR(req)) {
fprintf(stderr, "request failed: %s\n", ucs_status_string(UCS_PTR_STATUS(req)));
exit(1);
}
while (ucp_request_check_status(req) == UCS_INPROGRESS) ucp_worker_progress(worker);
CHECK_UCS(ucp_request_check_status(req));
ucp_request_free(req);
}
static void run(int is_sender, int addr_fd)
{
long total = warmup + n_msgs;
int dev = gpus[is_sender ? 0 : 1];
CHECK_CUDA(cudaSetDevice(dev));
CHECK_CUDA(cudaFree(0));
/* With too few buffers for the message count, wrap around (later messages reuse buffers). */
long count = (!strcmp(mode, "reuse")) ? 1 : (n_bufs < total ? n_bufs : total);
void **bufs = alloc_buffers(count);
ucp_params_t params = {
.field_mask = UCP_PARAM_FIELD_FEATURES,
.features = UCP_FEATURE_TAG
};
ucp_worker_params_t wparams = {
.field_mask = UCP_WORKER_PARAM_FIELD_THREAD_MODE,
.thread_mode = UCS_THREAD_MODE_SINGLE
};
ucp_context_h context;
ucp_worker_h worker;
CHECK_UCS(ucp_init(¶ms, NULL, &context));
CHECK_UCS(ucp_worker_create(context, &wparams, &worker));
/* No memory type hint: UCX detects it, as UCXX does. */
ucp_request_param_t rparam = {.op_attr_mask = 0};
void **reqs = calloc(window, sizeof(*reqs));
double t0 = 0;
if (!is_sender) {
ucp_address_t *addr;
size_t len;
CHECK_UCS(ucp_worker_get_address(worker, &addr, &len));
write_all(addr_fd, &len, sizeof(len));
write_all(addr_fd, addr, len);
ucp_worker_release_address(worker, addr);
for (long i = 0; i < total; ++i) {
int slot = i % window;
wait_req(worker, reqs[slot]);
reqs[slot] = ucp_tag_recv_nbx(worker, bufs[i % count], msg_size, i,
(ucp_tag_t)-1, &rparam);
}
for (int s = 0; s < window; ++s) wait_req(worker, reqs[s]);
/* Tell the sender we are done before tearing down. */
char c = 1;
write_all(addr_fd, &c, 1);
} else {
size_t len;
read_all(addr_fd, &len, sizeof(len));
ucp_address_t *addr = malloc(len);
read_all(addr_fd, addr, len);
ucp_ep_params_t eparams = {
.field_mask = UCP_EP_PARAM_FIELD_REMOTE_ADDRESS,
.address = addr
};
ucp_ep_h ep;
CHECK_UCS(ucp_ep_create(worker, &eparams, &ep));
for (long i = 0; i < total; ++i) {
int slot = i % window;
if (i == warmup) {
for (int s = 0; s < window; ++s) { wait_req(worker, reqs[s]); reqs[s] = NULL; }
t0 = now();
}
wait_req(worker, reqs[slot]);
reqs[slot] = ucp_tag_send_nbx(ep, bufs[i % count], msg_size, i, &rparam);
}
for (int s = 0; s < window; ++s) wait_req(worker, reqs[s]);
double dt = now() - t0;
char c;
read_all(addr_fd, &c, 1);
printf("ucx %s mode %-6s size %zu msgs %ld bufs %ld window %d: "
"%.1f us/msg, %.2f GB/s\n",
ucp_get_version_string(), mode, msg_size, n_msgs, count, window,
dt / n_msgs * 1e6, (double)msg_size * n_msgs / dt / 1e9);
void *creq = ucp_ep_close_nb(ep, UCP_EP_CLOSE_MODE_FORCE);
if (UCS_PTR_IS_PTR(creq)) {
while (ucp_request_check_status(creq) == UCS_INPROGRESS) ucp_worker_progress(worker);
ucp_request_free(creq);
}
free(addr);
}
free(reqs);
ucp_worker_destroy(worker);
ucp_cleanup(context);
}
int main(int argc, char **argv)
{
int opt;
while ((opt = getopt(argc, argv, "m:s:n:k:w:W:g:h")) != -1) {
switch (opt) {
case 'm': mode = optarg; break;
case 's': msg_size = parse_size(optarg); break;
case 'n': n_msgs = atol(optarg); break;
case 'k': n_bufs = atol(optarg); break;
case 'w': window = atoi(optarg); break;
case 'W': warmup = atoi(optarg); break;
case 'g': sscanf(optarg, "%d,%d", &gpus[0], &gpus[1]); break;
default:
fprintf(stderr, "usage: %s [-m pool|malloc|reuse] [-s size] [-n msgs] "
"[-k bufs] [-w window] [-W warmup] [-g sendgpu,recvgpu]\n",
argv[0]);
return opt == 'h' ? 0 : 1;
}
}
if (strcmp(mode, "pool") && strcmp(mode, "malloc") && strcmp(mode, "reuse")) {
fprintf(stderr, "unknown mode %s\n", mode);
return 1;
}
/* Bidirectional: child writes its address and later a done byte; parent reads both. */
int fds[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) { perror("socketpair"); return 1; }
pid_t pid = fork();
if (pid == 0) {
close(fds[0]);
run(0, fds[1]);
return 0;
}
close(fds[1]);
run(1, fds[0]);
int st;
waitpid(pid, &st, 0);
return WIFEXITED(st) ? WEXITSTATUS(st) : 1;
}
Activity
tvegas1 commentedon Nov 13, 2026
The memtype cache can't help this pattern as allocation is done before ucp_init() which prevents hooks from tracking memory range properties. Passing a
memhonly moves that cost intoucp_mem_map(). The fix has to avoid, defer or fix the probe.Can you test if allocating after ucp_init() helps? Is that feasible?
tvegas1 commentedon Nov 13, 2026
@pentschev, can you please test #12333?
pentschev commentedon Nov 16, 2026
Thanks @tvegas1! I tested #12333 (9b87f1b) against its base (5f8ac4c) on GB200 with DMA-BUF supported (driver 615.74, CUDA 13.2). It fixes the issue for us:
UCX_TLS=sm,self,cuda_copy,cuda_ipc):UCX_CUDA_COPY_DMABUF=nocudaMallocbuffers: 179 → 92 µs/msg (DMABUF=no: 87.5)Note: these numbers were measured with a local fix for a cuda_ipc regression from #11979 applied to both builds, because on current master that regression otherwise also slows down pool memory.