Skip to content

[WebGPU] Move copy implementation into data transfer - #33410

Open
Xiaofei Han (xiaofeihan1) wants to merge 1 commit into
microsoft:mainfrom
xiaofeihan1:codex/webgpu-copy-extraction
Open

Xiaofei Han (xiaofeihan1) wants to merge 1 commit into
microsoft:mainfrom
xiaofeihan1:codex/webgpu-copy-extraction

Conversation

@xiaofeihan1

Copy link
Copy Markdown
Contributor

Description

Move Upload, MemCpy, and Download from BufferManager into the existing DataTransferImpl, and route the existing native, plugin, and test callers through that implementation.

This is a copy-only extraction from #33286:

  • DataTransferImpl still receives the caller-selected BufferManager, together with its context and recording.
  • Upload and download still call context.Flush(buffer_manager, recording). Submission order, staging-buffer behavior, validation, and copy-size alignment are preserved.
  • BufferManager retains allocation, caching, and release responsibilities.
  • No changes to Flush implementation/signatures, recording-to-pool association, Run/replay lifecycle, or initializer-pool retirement.

Validation: Windows Release, WebGPU/D3D12. Existing tests were migrated to exercise the relocated copy implementation.

Native configuration and build, both passed:

cmake -S W:\cmake -B W:\b -Donnxruntime_USE_EP_API_ADAPTERS=OFF
cmake --build W:\b --config Release --target onnxruntime_provider_test --parallel 12

From W:\b\Release, native regressions passed: 76 passed, 1 capability-related skip (WebGpuContextTest.AdapterIndexRejectsUnsupportedBuild).

.\onnxruntime_provider_test.exe --gtest_filter="WebGpuDataTransferTest.*:WebGpuContextTest.*:WebGpuConcurrentContextTest.*:WebGpuConcurrentContextTestStandalone.*:WebGpuDispatchNormalizationTest.*:WebGpuDispatchExecutionTest.*:MoETest.QMoETest_WebGPU_SingleTokenGateIndices" --gtest_output=xml:W:\build\WebGpuRebase\copy-only-native-results.xml

Plugin configuration and build, both passed:

cmake -S W:\cmake -B W:\b -Donnxruntime_USE_EP_API_ADAPTERS=ON
cmake --build W:\b --config Release --target onnxruntime_provider_test --parallel 12

From W:\b\Release, modern plugin regressions passed: 57 passed; 2 pre-existing disabled tests were not run.

.\onnxruntime_provider_test.exe --gtest_filter="WebGpuPluginRecordingModeTest.*:WebGpuPluginSharedAllocatorRegistrationTest.*:WebGpuPluginSharedAllocatorTest.*:WebGpuSessionAllocatorDeathTest.*:PluginEpWebGpuConcurrency.*" --gtest_output=xml:W:\build\WebGpuRebase\copy-only-plugin-results.xml

The supported legacy-mode suite also passed: 41 passed (CTest: 1/1 passed).

ctest --test-dir W:\b -C Release -R "^onnxruntime_webgpu_legacy_test$" --output-on-failure

WASM was not built locally.

Motivation and Context

Separate data-copy implementation from buffer allocation/cache management without coupling that cleanup to a buffer-retirement redesign. Keeping the explicit BufferManager dependency preserves the existing flush behavior and makes this refactor independently reviewable.

Keep the explicit BufferManager dependency and existing flush/retirement behavior while separating upload, GPU copy, and download implementation from buffer allocation and caching.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 49a8cb48-b647-4474-996c-4819f8171941
Copilot AI balanced review requested due to automatic review settings October 16, 2026 03:21

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.

🟢 Approval recommended

The focused extraction preserves existing behavior, consistently migrates callers and regression tests, and has no identified actionable findings.

0 open findings

What changed in this PR

Separates WebGPU data transfers from buffer management while preserving existing copy, submission, and buffer-lifetime behavior.

Changes:

  • Moves upload, GPU copy, and download implementations into DataTransferImpl.
  • Updates native and plugin callers while retaining caller-selected buffer managers.
  • Migrates existing regression tests to the relocated implementation.
File Description
onnxruntime/​test/​providers/​webgpu/​webgpu_stream_regression_test.cc Migrates buffer-clear test transfers.
onnxruntime/​test/​providers/​webgpu/​webgpu_context_test.cc Migrates ordering, allocation, and replay tests.
onnxruntime/​test/​providers/​webgpu/​plugin/​test_webgpu_allocators.cc Updates a comment naming the copy implementation.
onnxruntime/​test/​providers/​webgpu/​dispatch_normalization_test.cc Migrates test uploads and readbacks.
onnxruntime/​test/​providers/​webgpu/​contrib_ops/​moe_test.cc Migrates gate-index test transfers.
onnxruntime/​test/​providers/​webgpu/​concurrent_context_test.cc Updates concurrent transfer construction.
onnxruntime/​core/​providers/​webgpu/​webgpu_provider_factory.cc Updates plugin transfer construction and explanatory comment.
onnxruntime/​core/​providers/​webgpu/​webgpu_execution_provider.cc Passes context to native transfers.
onnxruntime/​core/​providers/​webgpu/​webgpu_context.h Grants transfer implementation access.
onnxruntime/​core/​providers/​webgpu/​ep/​sync_stream.cc Passes context to stream transfers.
onnxruntime/​core/​providers/​webgpu/​data_transfer.h Declares copy methods and context dependency.
onnxruntime/​core/​providers/​webgpu/​data_transfer.cc Houses the relocated copy implementations.
onnxruntime/​core/​providers/​webgpu/​buffer_manager.h Removes copy declarations and clarifies responsibilities.
onnxruntime/​core/​providers/​webgpu/​buffer_manager.cc Removes relocated copy implementations.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants