Add swap_blocks_batch op with batched async memcpy#265
Open
chaojun-zhang wants to merge 1 commit intovllm-project:mainfrom
Open
Add swap_blocks_batch op with batched async memcpy#265chaojun-zhang wants to merge 1 commit intovllm-project:mainfrom
chaojun-zhang wants to merge 1 commit intovllm-project:mainfrom
Conversation
775df35 to
65e047e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new swap_blocks_batch cache op for XPU that performs a batch of independent (src_ptr, dst_ptr, size) async copies in one call, with a staging-buffer snapshot for H2D to avoid post-call host mutation races.
Changes:
- Add
swap_blocks_batchTorch op + C++ wrapper (csrc/cache.cpp,csrc/torch_bindings.cpp,csrc/ops.h). - Add
xpuAsyncMemcpyBatchimplementation to perform batched async copies with optional H2D staging (csrc/utils/mem_cpy.*). - Add Python test coverage for batched swaps and a H2D mutation-race regression test (
tests/test_cache.py) plus a Python wrapper (tests/register_ops.py).
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 |
|---|---|
| tests/test_cache.py | Adds new tests and helpers for swap_blocks_batch, including a mutation-race check. |
| tests/register_ops.py | Adds a Python wrapper for the new Torch op. |
| csrc/utils/mem_cpy.h | Declares xpuAsyncMemcpyBatch API. |
| csrc/utils/mem_cpy.cpp | Implements batched async memcpy with H2D staging. |
| csrc/torch_bindings.cpp | Registers the new swap_blocks_batch op in the cache ops library. |
| csrc/ops.h | Exposes the new op signature in the public header. |
| csrc/cache.cpp | Implements swap_blocks_batch input validation and forwards to the memcpy helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
dd8018c to
66a2859
Compare
mayuyuace
approved these changes
Apr 10, 2026
Signed-off-by: chaojun-zhang <chaojun.zhang@intel.com>
66a2859 to
728eaa9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS ABOVE HAVE BEEN CONSIDERED.
Purpose
Add a batch version of swap_blocks that copies N independent (src_ptr, dst_ptr, size) triples in a single call, modeled after the CUDA swap_blocks_batch (which uses cuMemcpyBatchAsync).
Test Plan
pytest -s -v tests/tests_cache.py::test_swap_blocks_batch_h2d_mutation_race
pytest -s -v tests/tests_cache.py::test_swap_blocks_batch
Test Result
(Optional) Documentation Update
BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)