onnxruntime
49481a71 - [WebGPU] Use Queue.WriteBuffer for small CPU-to-GPU uploads (#33551)

Commit
2 days ago
[WebGPU] Use Queue.WriteBuffer for small CPU-to-GPU uploads (#33551) ### Description <!-- Describe your changes. --> Automatically use `Queue.WriteBuffer` for eligible CPU-to-GPU uploads up to and including 1 MiB. - Flush deferred readers before queue writes to preserve read-before-overwrite ordering. - Preserve mapped-buffer handling and staging for larger, unaligned, and capture/replay uploads. - Retain existing completion, validation, device-loss, and failure handling. - Add focused upload tests and document ordering, source-lifetime guarantees, and the size threshold. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Profiling Qwen/DFlash2 on A100 identified substantial host overhead from allocating, mapping, copying, and submitting a fresh staging buffer for each upload. Queue writes let Dawn reuse staging allocations and batch pending transfers with subsequent queue work, without adding CPU completion waits. The conservative 1 MiB cap is the largest consistently beneficial size measured on A100/Vulkan. Larger transfers can regress, so they retain the existing staging path rather than extrapolating the small-upload improvement. **Validation:** On Linux/A100/Vulkan, 80 native tests passed with one unrelated build-mode skip, and 100 GenAI tests passed. Both 512-token baseline and DFlash2 generation runs preserved exact tokens and speculative counters. Formatting and lint checks passed. ### Update: Rebased onto latest main, including merged PR #33491, and reran A100/Vulkan benchmarks to measure the incremental benefit of `Queue.WriteBuffer`. **Results**: - Baseline: **3.3% faster** (short), **6.8% faster** (long) - DFlash2 width 3: **2.5% faster** (short), **3.1% faster** (long) All generated tokens and speculative counters matched. Native and plugin tests passed. Existing batched uploads remain unaffected, and larger transfers retain the staging path. This confirms that the optimization provides additional performance benefits beyond #33491. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
Parents
Loading