Repository navigation
[ET-VK][runtime] Make output staging visible to the host before readback - #24910
Merged
Merged
Conversation
Pull Request resolved: #24865 ## Ulterior Motive Found while preparing zero-copy graph I/O through app-provided GPU resources, added in the next commit. That commit also needs global memory barriers for memory the graph does not track, so this one adds them first. ## Rationale **What**: End each recorded graph execution with a global memory barrier from all GPU writes to host reads. To record it, `vkapi::PipelineBarrier` gains `global_access` masks, recorded as a `VkMemoryBarrier`. **Why**: The host reads output staging buffers once `execute()` returns, after a fence wait. A fence wait alone does not make the GPU's writes visible to the host. The Vulkan spec's note under `vkWaitForFences`: > Signaling a fence and waiting on the host does not guarantee that the results of memory accesses will be visible to the host, as the access scope of a memory dependency defined by a fence only includes device access. A memory barrier or other memory dependency must be used to guarantee this. `StagingBuffer` already calls `vmaInvalidateAllocation` before reading. That covers only device writes already made available to the host memory domain through `VK_ACCESS_HOST_READ_BIT`, which takes the barrier added here. Output staging prefers `HOST_CACHED` memory, which is often non-coherent. ## Details - Graph execution - **Before**: the last command buffer ended with the last node's commands. - **After**: it ends with an `ALL_COMMANDS`/`MEMORY_WRITE` → `HOST`/`HOST_READ` barrier. The barrier is recorded once with the command buffers and replayed on every `execute()`. Its source scope covers the command buffers that large graphs submit earlier without a fence. - `PipelineBarrier` - **Before**: buffer and image barriers only. - **After**: optional `global_access` masks. `CommandBuffer::record_barrier()` records a `VkMemoryBarrier` when either mask is set; existing barriers leave both zero and record as before. No failure was observed without the barrier: in practice, drivers flush GPU caches when a submission completes. The spec does not guarantee it. Inputs need no change: queue submission makes earlier host writes visible to the device, and `StagingBuffer` flushes non-coherent memory after writing. Test utilities that submit work and read staging without `ComputeGraph::execute()` keep the gap. This diff was authored with Claude Code. ghstack-source-id: 470836157 @exported-using-ghexport Differential Revision: [D130959944](https://our.internmc.facebook.com/intern/diff/D130959944/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D130959944/)!
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24910
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 123 PendingAs of commit 1bd43bb with merge base 27adac1 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
SS-JIA
approved these changes
Nov 11, 2026
This branch had an error being deployed
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.
This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #24865 by @SS-JIA
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/712/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/712/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/711/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/712/orig
Differential Revision: D130959944
@diff-train-skip-merge