[gpu] Add acquire/release context accessors to all GPU backends - #9431
Open
derek-gerstmann wants to merge 1 commit into
Open
[gpu] Add acquire/release context accessors to all GPU backends#9431derek-gerstmann wants to merge 1 commit into
derek-gerstmann wants to merge 1 commit into
Conversation
The acquire_context()/release_context() functions in each GPU runtime cannot be overridden on Windows: the runtime-library symbols are strong and are only referenced internally within the runtime libs, so the weak-symbol replacement used on other platforms does not work there. The CUDA backend already worked around this with halide_set_cuda_acquire_context()/halide_set_cuda_release_context() accessors that swap a function pointer at runtime. Apply the same pattern to the OpenCL, Metal, D3D12Compute, Vulkan, and WebGPU backends so they are consistent with CUDA: - Split each backend's acquire/release context function into a halide_default_* implementation plus a dispatcher that calls through a settable function pointer, and add halide_set_*_acquire_context / halide_set_*_release_context accessors with matching typedefs in the public runtime headers. - Wire the handlers into the JIT: add JITHandlers fields, merge_handlers entries, per-context handler shims, and make_module() hookup, mirroring the CUDA handling. - Register the new setters (and the previously-missing CUDA ones) in halide_runtime_api_functions[]. - Add per-backend correctness tests modeled on custom_cuda_context.cpp. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9431 +/- ##
==========================================
- Coverage 70.12% 70.11% -0.02%
==========================================
Files 261 261
Lines 79405 79539 +134
Branches 19362 19397 +35
==========================================
+ Hits 55684 55765 +81
- Misses 17896 17958 +62
+ Partials 5825 5816 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mcourteaux
approved these changes
Sep 6, 2026
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.
Summary
The per-backend
halide_*_acquire_context()/halide_*_release_context()functions can't be overridden on Windows: the runtime-library symbols are strong and are only referenced internally to the runtime libs, so the weak-symbol replacement that works on Linux/macOS doesn't apply there. The CUDA backend already provides runtime accessors (halide_set_cuda_acquire_context()/halide_set_cuda_release_context()) that swap a function pointer instead, which works on all platforms.This PR brings the OpenCL, Metal, D3D12Compute, Vulkan, and WebGPU backends in line with CUDA.
Changes
halide_default_*implementation plus a dispatcher that calls through a settable pointer, with newhalide_set_*_acquire_context/halide_set_*_release_contextaccessors and matching typedefs in the public runtime headers.JITHandlersfields,merge_handlersentries, per-context handler shims, andmake_module()hookup, mirroring the CUDA path.runtime_api.cpp: register the new accessors — and the CUDA ones, which had been missing — inhalide_runtime_api_functions[].test/correctness/custom_{opencl,metal,d3d12compute,vulkan,webgpu}_context.cpp, modeled oncustom_cuda_context.cpp.Testing
Full build passes. The Metal test passes end-to-end on an Apple GPU (
HL_JIT_TARGET=host-metal); the other backends' tests[SKIP]unless their target is enabled.🤖 Generated with Claude Code