Skip to content

Build the GPU lu_instance directly instead of calling lu - #502

Merged
ChrisRackauckas merged 1 commit into
JuliaArrays:masterfrom
singhharsh1708:gpu-lu-instance-no-lu
Aug 18, 2026
Merged

Build the GPU lu_instance directly instead of calling lu#502
ChrisRackauckas merged 1 commit into
JuliaArrays:masterfrom
singhharsh1708:gpu-lu-instance-no-lu

Conversation

@singhharsh1708

Copy link
Copy Markdown
Contributor

Fixes #501.

lu_instance for GPU matrices builds the instance by calling lu on an adapted 0x0 array,
which only works for backends that define their own lu. JLArrays does not, so it falls
through to LinearAlgebra's generic path and dies:

using JLArrays, ArrayInterface
ArrayInterface.lu_instance(jl(ones(3, 3)))
# ERROR: Illegal conversion of a JLArray to a Ptr

There is no size that works, lu(jl(ones(0,0))) hits LAPACK getrf! and lu(jl(ones(3,3)))
hits "Scalar indexing is disallowed", so routing through lu is the problem rather than the
0x0.

This builds the LU directly, the same way the Matrix, Symmetric and
Tridiagonal/Diagonal/SymTridiagonal methods already do in ArrayInterface.jl, so no
backend lu is needed. After:

ArrayInterface.lu_instance(jl(ones(3, 3)))
# LU{Float64, JLArray{Float64, 2}, JLArray{Int64, 1}}

which mirrors the CPU result LU{Float64, Matrix{Float64}, Vector{Int64}}.

It matters downstream because JLArrays is what packages use to exercise GPU code paths without
a GPU. OrdinaryDiffEq's GPU autodiff test is failing through this on Julia 1, lts and pre right
now, and #467 reported the same shape for Metal.

Worth checking before merge: I only have JLArrays here, no CUDA/AMDGPU/Metal, so I could not
confirm the ipiv element type matches what those backends' own lu returns. The CPU methods
all use BlasInt and I followed them. If a backend's lu returns Int32 there, this changes
the instance type for it.

@ChrisRackauckas
ChrisRackauckas merged commit 7e7d404 into JuliaArrays:master Aug 18, 2026
15 of 19 checks passed
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.93%. Comparing base (6950d2a) to head (7400d47).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
ext/ArrayInterfaceGPUArraysCoreExt.jl 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #502      +/-   ##
==========================================
- Coverage   61.32%   60.93%   -0.40%     
==========================================
  Files          15       15              
  Lines         618      622       +4     
==========================================
  Hits          379      379              
- Misses        239      243       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lu_instance fails for JLArray

2 participants