Skip to content

Commit cc06e89

Browse files
lkdvosclaude
andcommitted
Drop the cuSOLVER workspace queries
They are no longer used now that the CUSOLVER driver always constructs Q with `ungqr!`. Inline the ungqr!-based Q construction into `_qr_buildQ!`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 0bf732f commit cc06e89

3 files changed

Lines changed: 10 additions & 40 deletions

File tree

‎ext/MatrixAlgebraKitCUDAExt/MatrixAlgebraKitCUDAExt.jl‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ for f in (:geqrf!, :ungqr!, :unmqr!)
3434
end
3535

3636
MatrixAlgebraKit.prefers_ungqr(::CUSOLVER) = true
37-
MatrixAlgebraKit.supports_unmqr(::CUSOLVER, side, trans, A, τ, C) =
38-
YACUSOLVER.unmqr_worksize(side, trans, A, τ, C) > 0
3937

4038
MatrixAlgebraKit.supports_svd_full(::CUSOLVER, f::Symbol) = f in (:qr_iteration, :jacobi, :svd_polar)
4139

‎ext/MatrixAlgebraKitCUDAExt/yacusolver.jl‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ using CUDA.cuSOLVER: geqrf!, ormqr!, orgqr!
1313
const unmqr! = ormqr!
1414
const ungqr! = orgqr!
1515

16-
# report a non-positive size when the 32-bit workspace query fails or overflows
17-
for (bname, elty) in (
18-
(:cusolverDnSormqr_bufferSize, :Float32),
19-
(:cusolverDnDormqr_bufferSize, :Float64),
20-
(:cusolverDnCunmqr_bufferSize, :ComplexF32),
21-
(:cusolverDnZunmqr_bufferSize, :ComplexF64),
22-
)
23-
unchecked = Symbol(:unchecked_, bname)
24-
@eval function unmqr_worksize(
25-
side::Char, trans::Char, A::StridedCuMatrix{$elty},
26-
tau::CuVector{$elty}, C::StridedCuVecOrMat{$elty}
27-
)
28-
m, n = ndims(C) == 2 ? size(C) : (length(C), 1)
29-
out = Ref{Cint}(0)
30-
status = cuSOLVER.$unchecked(
31-
cuSOLVER.dense_handle(), side, trans, m, n, length(tau),
32-
A, max(1, stride(A, 2)), tau, C, max(1, stride(C, 2)), out
33-
)
34-
return status == cuSOLVER.CUSOLVER_STATUS_SUCCESS ? Int(out[]) : -1
35-
end
36-
end
37-
3816
# Wrapper for SVD via QR Iteration
3917
for (bname, fname, elty, relty) in
4018
(

‎src/implementations/qr.jl‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ for f in (:geqrt!, :gemqrt!, :geqp3!, :geqrf!, :ungqr!, :unmqr!)
125125
end
126126
end
127127

128-
# cuSOLVER's 32-bit ormqr workspace query breaks down for large matrices
129-
supports_unmqr(::Driver, side, trans, A, τ, C) = true
130-
131-
# cuSOLVER generates Q faster with ungqr! than by applying the reflectors with unmqr!
128+
# cuSOLVER generates Q faster with ungqr! than by applying the reflectors with unmqr!,
129+
# and avoids the large workspace of ormqr, whose 32-bit size query fails for large matrices
132130
prefers_ungqr(::Driver) = false
133131

134132
# copy R out of the packed factorization, leaving the reflectors in A intact
@@ -140,16 +138,14 @@ function _qr_copyR!(R::AbstractMatrix, A::AbstractMatrix, jpvt = nothing)
140138
end
141139

142140
function _qr_buildQ!(driver::Driver, Q::AbstractMatrix, A::AbstractMatrix, τ, minmn::Int)
143-
(prefers_ungqr(driver) || !supports_unmqr(driver, 'L', 'N', A, τ, Q)) &&
144-
return _qr_buildQ_ungqr!(driver, Q, A, τ, minmn)
145-
return unmqr!(driver, 'L', 'N', A, τ, one!(Q))
146-
end
147-
148-
# build Q in its own space: copy in the reflectors, unit vectors elsewhere
149-
function _qr_buildQ_ungqr!(driver::Driver, Q::AbstractMatrix, A::AbstractMatrix, τ, minmn::Int)
150-
size(Q, 2) > minmn && one!(Q)
151-
copyto!(view(Q, :, 1:minmn), view(A, :, 1:minmn))
152-
ungqr!(driver, Q, τ)
141+
if prefers_ungqr(driver)
142+
# build Q in its own space: copy in the reflectors, unit vectors elsewhere
143+
size(Q, 2) > minmn && one!(Q)
144+
copyto!(view(Q, :, 1:minmn), view(A, :, 1:minmn))
145+
ungqr!(driver, Q, τ)
146+
else
147+
Q = unmqr!(driver, 'L', 'N', A, τ, one!(Q))
148+
end
153149
return Q
154150
end
155151

@@ -291,8 +287,6 @@ function qr_null_householder!(
291287
N = gemqrt!(driver, 'L', 'N', A, T, N)
292288
else
293289
A, τ = geqrf!(driver, A)
294-
supports_unmqr(driver, 'L', 'N', A, τ, N) ||
295-
throw(ArgumentError(lazy"$driver cannot construct the null space for these dimensions"))
296290
N = unmqr!(driver, 'L', 'N', A, τ, N)
297291
end
298292
return N

0 commit comments

Comments
 (0)