Add promote_eltype for CuArray / ROCArray / MtlArray#483
Open
ChrisRackauckas-Claude wants to merge 1 commit intoJuliaArrays:masterfrom
Open
Add promote_eltype for CuArray / ROCArray / MtlArray#483ChrisRackauckas-Claude wants to merge 1 commit intoJuliaArrays:masterfrom
ChrisRackauckas-Claude wants to merge 1 commit intoJuliaArrays:masterfrom
Conversation
`ArrayInterface.promote_eltype` only had a method for plain `Array{T, N}`
(with an explicit "no generic fallback is given" note in the docstring).
Downstream packages that pass GPU array types through
`promote_eltype` therefore hit a `MethodError` — for example,
SciML/NonlinearSolve.jl#910 tripped this on
`test/cuda_tests.jl:33 "GeneralizedFirstOrderAlgorithm"` when deriving
a Dual-eltype wrapper-signature array type for `CuArray{Float32}`:
MethodError: no method matching promote_eltype(
::Type{CuArray{Float32, 1, CUDA.DeviceMemory}},
::Type{ForwardDiff.Dual{Tag{NonlinearSolveBase.NonlinearSolveTag, Float32}, Float32, 1}})
Adds the obvious eltype-swapping method in each GPU extension,
preserving the non-eltype type parameters (`M` for `CuArray` memory
kind, `B` for `ROCArray` buffer type, `S` for `MtlArray` storage mode):
ArrayInterface.promote_eltype(
::Type{<:CuArray{T, N, M}}, ::Type{T2}
) where {T, N, M, T2} = CuArray{promote_type(T, T2), N, M}
ArrayInterface.promote_eltype(
::Type{<:ROCArray{T, N, B}}, ::Type{T2}
) where {T, N, B, T2} = ROCArray{promote_type(T, T2), N, B}
ArrayInterface.promote_eltype(
::Type{<:MtlArray{T, N, S}}, ::Type{T2}
) where {T, N, S, T2} = MtlArray{promote_type(T, T2), N, S}
Bumps patch version 7.23.0 → 7.24.0 so downstream packages can
compat-bound the new method.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #483 +/- ##
==========================================
- Coverage 60.82% 60.20% -0.63%
==========================================
Files 14 14
Lines 582 588 +6
==========================================
Hits 354 354
- Misses 228 234 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
ArrayInterface.promote_eltypemethods for the three GPU array types, defined in their respective package extensions (ArrayInterfaceCUDAExt,ArrayInterfaceAMDGPUExt,ArrayInterfaceMetalExt).promote_type(T, T2)while preserving the array's other type parameters (memory kindMforCuArray, buffer typeBforROCArray, storage modeSforMtlArray).7.23.0→7.24.0.Why
ArrayInterface.promote_eltypewas only defined forArray{T, N}(with a "no generic fallback" note in its docstring), so downstream packages that pass GPU array types throughpromote_eltypehit aMethodError. Example from SciML/NonlinearSolve.jl#910 (test/cuda_tests.jl:33 "GeneralizedFirstOrderAlgorithm") when deriving a Dual-eltype wrapper-signature type for aCuArray{Float32}state:Adding the obvious eltype-swapping method in each GPU extension makes
promote_eltypeusable for GPU-array downstream code paths without forcing callers back onto the allocatingtypeof(similar(a, T2))pattern.Test plan
Notes
promote_eltypecontract — the "no generic fallback" docstring note still holds; this PR just adds three more concrete methods.🤖 Generated with Claude Code