diff --git a/ext/ArrayInterfaceGPUArraysCoreExt.jl b/ext/ArrayInterfaceGPUArraysCoreExt.jl index 79bbf606..09990f05 100644 --- a/ext/ArrayInterfaceGPUArraysCoreExt.jl +++ b/ext/ArrayInterfaceGPUArraysCoreExt.jl @@ -2,7 +2,7 @@ module ArrayInterfaceGPUArraysCoreExt using Adapt using ArrayInterface -using LinearAlgebra: lu +import LinearAlgebra import GPUArraysCore ArrayInterface.fast_scalar_indexing(::Type{<:GPUArraysCore.AbstractGPUArray}) = false @@ -19,8 +19,16 @@ function ArrayInterface.restructure(x::GPUArraysCore.AbstractGPUArray, y) reshape(Adapt.adapt(ArrayInterface.parameterless_type(x), y), Base.size(x)...) end +# Build the `LU` directly rather than calling `lu` on an adapted array, matching the CPU +# methods in ArrayInterface.jl. Going through `lu` only works for backends that define their +# own, so it breaks on JLArrays (which downstream packages use to test GPU paths without a +# GPU) and on Metal, see #501 and #467. function ArrayInterface.lu_instance(A::GPUArraysCore.AbstractGPUMatrix{T}) where {T} - lu(Adapt.adapt(ArrayInterface.parameterless_type(A), ones(T, 0, 0))) + noUnitT = typeof(zero(T)) + luT = LinearAlgebra.lutype(noUnitT) + ipiv = similar(A, LinearAlgebra.BlasInt, 0) + info = zero(LinearAlgebra.BlasInt) + return LinearAlgebra.LU{luT}(similar(A, 0, 0), ipiv, info) end # Doesn't do much, but makes a gigantic change to the dependency chain.