(feat): Metal.jl (Apple Silicon GPU) backend support#34
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Metal.jl (Apple Silicon GPU) backend support for AdaptiveArrayPools, mirroring the existing CUDA extension. Also extracts shared GPU pooling algorithms into a common layer (gpu_backend_common.jl) used by both CUDA and Metal extensions, and gates both GPU extensions on Julia 1.11+.
Changes:
- New Metal extension (
ext/AdaptiveArrayPoolsMetalExt/) with types, acquire, state management, safety, display, and convenience functions forMtlArraypooling - Extracted shared GPU backend common layer (
src/gpu_backend_common.jl) with_gpu_claim_slot!,_gpu_get_cached_array!,_gpu_cached_reshape!,_gpu_invalidate_released_slots!, refactoring CUDA to use the same shared code - Added Julia 1.11+ version gate to both CUDA and Metal GPU extensions
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Project.toml | Add Metal weak dependency and compat |
| src/AdaptiveArrayPools.jl | Include gpu_backend_common.jl, export Metal stubs |
| src/gpu_backend_common.jl | New shared GPU pooling algorithms (hooks + implementations) |
| src/task_local_pool.jl | Add Metal task-local pool function stubs |
| src/utils.jl | Add _show_wrapper_cache, loop over GPU backends in pool_stats() |
| ext/AdaptiveArrayPoolsMetalExt/*.jl | Full Metal extension (types, acquire, state, debug, macros, convenience, utils, task_local_pool) |
| ext/AdaptiveArrayPoolsCUDAExt/*.jl | Refactored to use shared GPU backend hooks, added Julia 1.11 gate |
| test/metal/*.jl | Comprehensive Metal test suite |
| test/runtests.jl, test/cuda/runtests.jl | Version gates and Metal test inclusion |
| docs/ | Metal documentation and navigation updates |
| README.md | Add Metal to supported backends |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #34 +/- ##
=======================================
Coverage 96.53% 96.53%
=======================================
Files 14 14
Lines 2566 2568 +2
=======================================
+ Hits 2477 2479 +2
Misses 89 89
🚀 New features to boost your workflow:
|
Standalone Metal extension with full parity to CUDA: checkpoint/rewind,
lazy mode, typed-lazy mode, safety (poisoning/escape detection/borrow
tracking), @with_pool :metal, DisabledPool{:metal}, and task-local
multi-device pools. No shared GPU common layer — each backend is
self-contained to preserve type stability and zero-alloc guarantees.
CUDA extension imports modern-path-only functions (_store_arr_wrapper!, _reshape_impl!, _check_pool_growth) that don't exist on Julia 1.10 LTS. Wrap all includes in @static if VERSION >= v"1.11-" to prevent precompilation failure on older Julia.
Replace `return`-based early exit (unreliable inside @static if on 1.10) with if-else branching to properly skip GPU tests on Julia LTS.
974ec5e to
733a41f
Compare
- Add docs/src/features/metal-support.md with full Metal API reference - Fix cuda-support.md: replace incorrect N-way cache description with actual arr_wrappers-based direct-index caching mechanism - Add Metal backend to README supported backends and doc links - Add Metal page to docs/make.jl navigation and path mappings
Summary
Adds Metal.jl backend support for AdaptiveArrayPools, enabling zero-allocation GPU array pooling on Apple Silicon. Same checkpoint/rewind semantics and
@with_poolmacro support as CUDA.What's new
@with_pool :metal— pool GPU arrays on Apple Silicon with the same API as:cudasrc/gpu_backend_common.jl) — extracted common algorithms (_gpu_claim_slot!,_gpu_get_cached_array!,_gpu_cached_reshape!,_gpu_invalidate_released_slots!) used by both CUDA and Metal extensionsVERSION >= v"1.11-"(requiressetfield!-based Array internals)Usage
Known limitations
MtlArrayinternal fields (:data,:maxsize,:offset,:dims,.data.rc), guarded with@staticchecks