Repository navigation
hk: give G17P dependencies memory scope while a writable import lives - #472
Merged
RyanTheTide merged 1 commit intoNov 19, 2026
Conversation
G17P's GPU caches are tagged by virtual address, so a write through one mapping becomes visible to a read through another only after a memory-scope flush (hk_cdm_alias_scope()). G17P takes that flush while sparse or capture/replay resources live, but not for memory imports, and an fd import or a host import gets an address of its own while another import may map the same pages. aurora-silicon#266's bt suite (gist linked from aurora-silicon#266), on the M4 Pro: every word written through one import and read through another after a barrier was stale (two host imports of one allocation, overlapping host imports, a memfd mapped twice, two dma-bufs of the same pages, two overlapping dma-bufs): 3072 of 3072 and 49152 of 49152 words wrong per shape. One dma-buf imported twice is the same BO and address, and was already exact. Count live fd imports and host imports the GPU may write in va_alias_resources, as capture/replay memory already is. All those cases read exact data now. A device that imports nothing is unchanged: bt's per-level barrier cost on a device with capture/replay and both import extensions enabled but no import stays the same (17 kernel, grid and push shapes, best of 7 per level: 0.45-1.79 us on aurora-wip, 0.48-1.84 us with this change, within run-to-run noise). While an import lives, compute and transfer dependencies take the memory-scope flush (up to +1 us per level, the cost M5 pays on every device that enables these features). Still not covered, as documented in hk_cdm_alias_scope(): a capture/replay buffer or import created after a command buffer was recorded and reached through an address the command buffer loads (bt late, pending, simul, event, xsem), which M5's device-wide rule covers at that cost. meson asahi+vulkan 199/199 on aurora-wip, 0 GPU recoveries. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com> Assisted-by: LLM
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.
What
G17P's GPU caches are tagged by virtual address. A write through one mapping becomes visible to a read through another mapping only after a memory-scope flush (
hk_cdm_alias_scope()). G17P takes that flush while sparse or capture/replay resources live, but not for memory imports, and an fd import or a host import gets its own address while another import can map the same pages. On the M4 Pro, every word written through one import and read through another after a barrier is stale.This adds the import half of the visibility problem #266 fixed for M5, for G17P. #266's M5 rule decides once per device (any device that enables sparse, capture/replay or an import extension flushes with memory scope at every dependency). This change keeps G17P's existing record-time counter instead, so a device that imports nothing pays nothing.
How
hk_AllocateMemory()marks fd imports and host imports the GPU may write (anything butAGX_HOST_PTR_READ_ONLY) asalias_import. They count inva_alias_resourceswhile they live, like capture/replay memory already does. The comment abovehk_cdm_alias_scope()now lists imports as covered.Still not covered, and already documented there: a capture/replay buffer or import created after a command buffer was recorded and reached through an address the command buffer loads. M5's device-wide rule covers that, at its cost.
Testing
MacBook Pro 16" M4 Pro (J616s, T6040, G17P), GPU firmware 25G83, Linux 7.3.0-m4.171, on AC. Release builds from one build directory with the same meson options:
aurora-wip57df4db;Guarded runs,
MESA_SHADER_CACHE_DISABLE=true, 0 GPU recoveries.Visibility through a second address (#266's
bt)Sources: Erik's gist from #266 (https://gist.github.com/erikwb/992e9d6d37eaba85b191807d34b1ec44), built as its
build.shdoes.bt <mode> 3 64: chains of 64 levels that alternately write a buffer through one address and read it through another, with an application barrier between levels, over 4 shapes (1024 or 16384 words, 16384 or 262144 threads), 3 runs each. The cells are wrong words over words checked, summed over the shapes. The device enables bufferDeviceAddressCaptureReplay, VK_KHR_external_memory_fd, VK_EXT_external_memory_dma_buf and VK_EXT_external_memory_host.aliasaliashostaliashostaliashostaliashostaliasdmabufdmabufdmabufdmabufxsubxsubxsubxsublatelatelatelatelatelateThe
laterows created after recording are the documented remaining gap: unchanged, and they need capture/replay tooling (GFXReconstruct-style replays).Cost
bt cost 64measures per-level cost, best of 7, on the same device with all those features enabled and nothing imported. Diff is the per-level cost of the barrier in µs:nop 1 thr push 16nop 1 thr push 256nop 1 thr p256 samenop grid push 16nop grid push 256snop 1 thr push 0snop grid push 0sxform 1 thr push 0sxform grid push 0xform 1 thr push 32xform 1 thr push 256xform grid push 32xform grid push 256xform30 1 thr push 256xform30 grid push 256xfpre 1 thr push 40xfpre grid push 40The two builds match within run-to-run noise. While a writable import lives, compute and transfer dependencies take the memory-scope flush. On our downstream stack, forcing that flush costs up to about 1 µs per level in the same benchmark, the price M5 pays on every device that enables these features.
Conformance
On aurora-wip + this commit: meson
--suite asahi --suite vulkan199/199;dEQP-VK.api.external.memory.{dma_buf,host,opaque_fd}.*anddEQP-VK.memory.external_memory_host.*(108 cases): 94 Pass, 14 NotSupported, 0 Fail.Commands
🤖 Generated with Claude Code