Skip to content

[feat] support GDR in mooncake backend#131

Open
xupinjie wants to merge 1 commit into
Ascend:mainfrom
xupinjie:pinjie/GDR_v2
Open

[feat] support GDR in mooncake backend#131
xupinjie wants to merge 1 commit into
Ascend:mainfrom
xupinjie:pinjie/GDR_v2

Conversation

@xupinjie

Copy link
Copy Markdown
Contributor

Add GDR support for mooncake backend

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[c572550 [feat] support GDR in mooncake ...](c572550) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@xupinjie

Copy link
Copy Markdown
Contributor Author
backend_compare_chart

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[901d4b8 [feat] support GDR in mooncake ...](901d4b8) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[8297b8f [feat] support GDR in mooncake ...](8297b8f) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[8c7637a [feat] support GDR in mooncake ...](8c7637a) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[e861d15 [feat] support GDR in mooncake ...](e861d15) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

Comment thread transfer_queue/utils/mooncake_utils.py Outdated
@0oshowero0

Copy link
Copy Markdown
Collaborator

What will happen if user use TCP transport and GDR on?

Copilot AI left a comment

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.

Pull request overview

Adds GPUDirect RDMA (GDR) support to the MooncakeStore backend by introducing a persistent, pre-registered CUDA staging buffer and integrating a GDR-aware PUT/GET/CLEAR data path for tensors (including chunking for oversized tensors).

Changes:

  • Introduce transfer_queue.utils.mooncake_utils with staging-buffer management (GdrStaging) and helper utilities for aligned packing, grouping, and chunked sub-keys.
  • Add a GDR-enabled tensor transfer path to MooncakeStoreClient (PUT/GET), including oversized tensor chunking via :c{i} sub-keys and CLEAR expansion to remove sub-keys.
  • Extend unit/e2e/perf tooling and config to exercise and benchmark the new GDR mode, and add cuda-python to the Mooncake optional dependency set.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
transfer_queue/utils/mooncake_utils.py New GDR utilities: aligned layout, chunked sub-keys, grouping, and persistent CUDA staging buffer implementation.
transfer_queue/storage/clients/mooncake_client.py Integrates GDR staging into MooncakeStoreClient PUT/GET/CLEAR, including chunked oversized tensor handling and staging lifecycle management.
tests/test_mooncake_utils.py New unit tests for the mooncake GDR utilities and MooncakeStoreClient.clear() chunk-subkey expansion behavior.
tests/e2e/test_e2e_lifecycle_consistency.py Adds a GDR-enabled Mooncake backend config and a CUDA-only E2E roundtrip scenario for GPU tensors.
scripts/performance_test/perftest.py Adds GDR awareness to perf test harness (device setup + GET timing semantics).
scripts/performance_test/perftest_config.yaml Documents/configures MooncakeStore use_gdr flag in perf test config.
pyproject.toml Adds cuda-python to the mooncake optional dependency group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +80 to +83
# GdrStaging instance created eagerly but cudaMalloc is deferred to first use.
# Skip GDR if CUDA context is not initialized in this process (e.g. CPU-only workers)
gdr_eligible = self.use_gdr and buffer_bytes > 0 and torch.cuda.is_initialized()
self._gdr_staging: GdrStaging | None = GdrStaging(buffer_bytes) if gdr_eligible else None
Comment thread transfer_queue/storage/clients/mooncake_client.py Outdated
Comment thread transfer_queue/storage/clients/mooncake_client.py Outdated
Comment on lines +449 to +453
for i, sub_key in enumerate(sub_keys):
chunk_size = min(buffer_size, total - i * buffer_size)
self._batch_get_into_with_retry([sub_key], [staging.ptr], [chunk_size])
staging.memcpy_d2d_async(final_tensor.data_ptr() + i * buffer_size, staging.ptr, chunk_size)
staging.synchronize()
Comment thread transfer_queue/storage/clients/mooncake_client.py Outdated
Comment thread tests/test_mooncake_utils.py
staging = self._gdr_staging
buffer_size = staging.size

# Caller guarantees all tensors are CUDA; make contiguous outside the lock.
Comment thread scripts/performance_test/perftest_config.yaml Outdated
@xupinjie

xupinjie commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

What will happen if user use TCP transport and GDR on?

Valid. GDR requires RDMA transport. We'll add a validation in init that raises a clear ValueError (or at minimum a warning + auto-disable) when use_gdr=True and protocol != "rdma", so users get a clear error message immediately rather than a cryptic failure at transfer time.

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[94cf818 [feat] support GDR in mooncake ...](94cf818) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[20cd384 [feat] support GDR in mooncake ...](20cd384) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

Comment thread tests/e2e/test_e2e_lifecycle_consistency.py Outdated
Comment thread transfer_queue/storage/clients/mooncake_client.py
Comment thread transfer_queue/utils/mooncake_utils.py
Comment thread transfer_queue/utils/mooncake_utils.py
Comment thread tests/e2e/test_e2e_lifecycle_consistency.py Outdated
@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[517592b [feat] support GDR in mooncake ...](517592b) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.

Comment thread transfer_queue/utils/mooncake_utils.py Outdated
Comment thread transfer_queue/utils/mooncake_utils.py
Comment on lines +227 to +228
# Ensure all pending GPU work in this process is done before the staging stream reads.
torch.cuda.synchronize()

@xupinjie xupinjie Jul 12, 2026

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.

The current_stream event approach is only safe when all tensors in the batch were produced on the caller's current stream at call time — a guarantee we cannot enforce or verify, since PyTorch provides no API to query which stream produced a given tensor.
torch.cuda.synchronize() is the only correct option here; in RL workloads this sync lands at a natural computation boundary where the device is already nearly idle, so the practical overhead is negligible.

Comment thread transfer_queue/storage/clients/mooncake_client.py Outdated
Comment on lines +350 to +355
if (gpu_tensor_indices and use_gdr_path) or non_tensor_indices:
if custom_backend_meta is None or len(custom_backend_meta) != len(keys):
raise ValueError(
"custom_backend_meta is required when GDR is enabled (for n_chunks) "
"or when any dtype is None (for packed_size)."
)

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.

At get() time there is no way to determine which keys were stored as oversized chunks without reading n_chunks from custom_backend_meta — the information simply does not exist elsewhere.
Making custom_backend_meta optional would silently treat a missing entry as "no chunking", producing corrupted results if the key was actually split; a strict validation that fails loudly is safer than a relaxed contract that corrupts data.

Comment thread tests/test_mooncake_utils.py
Comment thread docs/storage_backends/mooncake_gdr.md Outdated
Comment thread docs/storage_backends/mooncake_gdr.md Outdated
Comment thread scripts/performance_test/perftest.py
Comment thread scripts/performance_test/perftest.py Outdated
Signed-off-by: xupinjie <xupinjie321@outlook.com>
@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@xupinjie , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[fe893c8 [feat] support GDR in mooncake ...](fe893c8) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants