Skip to content

[ET-VK] Fix staging buffer allocation to check all memory types for HOST_CACHED#18291

Merged
meta-codesync[bot] merged 2 commits intogh/SS-JIA/491/basefrom
gh/SS-JIA/491/head
Mar 18, 2026
Merged

[ET-VK] Fix staging buffer allocation to check all memory types for HOST_CACHED#18291
meta-codesync[bot] merged 2 commits intogh/SS-JIA/491/basefrom
gh/SS-JIA/491/head

Conversation

@SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Mar 18, 2026

Stack from ghstack (oldest at bottom):

test_host_cached_available() only checked memoryTypes[0] to determine if
HOST_CACHED memory was available. On Pixel devices, memoryTypes[0] is
DEVICE_LOCAL without HOST_CACHED, so the function incorrectly returned
SEQUENTIAL_WRITE_BIT. This caused DEVICE_TO_HOST staging buffers to be
allocated in write-combining (uncached) memory, making CPU reads during
COPY_OUTPUTS ~170x slower than necessary (~40ms vs ~237us on S24).

The fix iterates over all memory types to correctly detect HOST_CACHED support.

On-device profiling of edgetam_first_frame_fp16_vulkan.pte confirms the fix:

  • Pixel 8 Pro COPY_OUTPUTS: 40ms -> 6.3ms (-84%)
  • Pixel 9 Pro XL COPY_OUTPUTS: 40ms -> 2.5ms (-94%)
  • Pixel 8 Pro Method::execute: 492ms -> 464ms (-5.7%)
  • Pixel 9 Pro XL Method::execute: 445ms -> 411ms (-7.6%)

Differential Revision: D97058156

…OST_CACHED

`test_host_cached_available()` only checked `memoryTypes[0]` to determine if
HOST_CACHED memory was available. On Pixel devices, `memoryTypes[0]` is
DEVICE_LOCAL without HOST_CACHED, so the function incorrectly returned
`SEQUENTIAL_WRITE_BIT`. This caused DEVICE_TO_HOST staging buffers to be
allocated in write-combining (uncached) memory, making CPU reads during
COPY_OUTPUTS ~170x slower than necessary (~40ms vs ~237us on S24).

The fix iterates over all memory types to correctly detect HOST_CACHED support.

On-device profiling of edgetam_first_frame_fp16_vulkan.pte confirms the fix:
- Pixel 8 Pro COPY_OUTPUTS: 40ms -> 6.3ms (-84%)
- Pixel 9 Pro XL COPY_OUTPUTS: 40ms -> 2.5ms (-94%)
- Pixel 8 Pro Method::execute: 492ms -> 464ms (-5.7%)
- Pixel 9 Pro XL Method::execute: 445ms -> 411ms (-7.6%)

Differential Revision: [D97058156](https://our.internmc.facebook.com/intern/diff/D97058156/)

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 18, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18291

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit c4106b4 with merge base ed57040 (image):

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

…types for HOST_CACHED"

`test_host_cached_available()` only checked `memoryTypes[0]` to determine if
HOST_CACHED memory was available. On Pixel devices, `memoryTypes[0]` is
DEVICE_LOCAL without HOST_CACHED, so the function incorrectly returned
`SEQUENTIAL_WRITE_BIT`. This caused DEVICE_TO_HOST staging buffers to be
allocated in write-combining (uncached) memory, making CPU reads during
COPY_OUTPUTS ~170x slower than necessary (~40ms vs ~237us on S24).

The fix iterates over all memory types to correctly detect HOST_CACHED support.

On-device profiling of edgetam_first_frame_fp16_vulkan.pte confirms the fix:
- Pixel 8 Pro COPY_OUTPUTS: 40ms -> 6.3ms (-84%)
- Pixel 9 Pro XL COPY_OUTPUTS: 40ms -> 2.5ms (-94%)
- Pixel 8 Pro Method::execute: 492ms -> 464ms (-5.7%)
- Pixel 9 Pro XL Method::execute: 445ms -> 411ms (-7.6%)

Differential Revision: [D97058156](https://our.internmc.facebook.com/intern/diff/D97058156/)

[ghstack-poisoned]
@meta-codesync meta-codesync bot merged commit 2282bbd into gh/SS-JIA/491/base Mar 18, 2026
136 of 139 checks passed
@meta-codesync meta-codesync bot deleted the gh/SS-JIA/491/head branch March 18, 2026 18:42
@meta-codesync meta-codesync bot temporarily deployed to cherry-pick-bot March 18, 2026 18:42 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants