Skip to content

Commit 6b5c602

Browse files
committed
Add more solvers to GPU testing
1 parent a4c228d commit 6b5c602

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

src/broyden.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::GeneralBroyde
6666
alg.reset_tolerance
6767
reset_check = x -> abs(x) reset_tolerance
6868
return GeneralBroydenCache{iip}(f, alg, u, _mutable_zero(u), fu, zero(fu),
69-
zero(fu), p, J⁻¹, zero(_vec(fu)'), _mutable_zero(u), false, 0, alg.max_resets,
70-
maxiters, internalnorm, ReturnCode.Default, abstol, reset_tolerance,
69+
zero(fu), p, J⁻¹, zero(_reshape(fu, 1, :)), _mutable_zero(u), false, 0,
70+
alg.max_resets, maxiters, internalnorm, ReturnCode.Default, abstol, reset_tolerance,
7171
reset_check, prob, NLStats(1, 0, 0, 0, 0),
7272
init_linesearch_cache(alg.linesearch, f, u, p, fu, Val(iip)))
7373
end

src/gaussnewton.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function SciMLBase.__init(prob::NonlinearLeastSquaresProblem{uType, iip}, alg_::
8282
alg = get_concrete_algorithm(alg_, prob)
8383
@unpack f, u0, p = prob
8484

85-
if !needs_square_A(alg.linsolve) && !(u isa Number) && !(u isa StaticArray)
85+
if !needs_square_A(alg.linsolve) && !(u0 isa Number) && !(u0 isa StaticArray)
8686
linsolve_with_JᵀJ = Val(false)
8787
else
8888
linsolve_with_JᵀJ = Val(true)

src/lbroyden.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ end
249249
return nothing
250250
end
251251
mul!(xᵀVᵀ[:, 1:η], x', Vᵀ)
252-
mul!(y', xᵀVᵀ[:, 1:η], U)
252+
mul!(reshape(y, 1, :), xᵀVᵀ[:, 1:η], U)
253253
return nothing
254254
end
255255

256256
@views function __lbroyden_rmatvec(U::AbstractMatrix, Vᵀ::AbstractMatrix, x::AbstractVector)
257257
# Computes xᵀ × Vᵀ × U
258258
size(U, 1) == 0 && return x
259-
return (x' * Vᵀ) * U
259+
return (reshape(x, 1, :) * Vᵀ) * U
260260
end

src/utils.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ function _try_factorize_and_check_singular!(linsolve, X)
257257
end
258258
_try_factorize_and_check_singular!(::Nothing, x) = _issingular(x), false
259259

260+
_reshape(x, args...) = reshape(x, args...)
261+
_reshape(x::Number, args...) = x
262+
260263
# Needs Square Matrix
261264
"""
262265
needs_square_A(alg)

test/gpu.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using CUDA, NonlinearSolve
22

3+
CUDA.allowscalar(false)
4+
35
A = cu(rand(4, 4))
46
u0 = cu(rand(4))
57
b = cu(rand(4))
@@ -9,4 +11,23 @@ function f(du, u, p)
911
end
1012

1113
prob = NonlinearProblem(f, u0)
12-
sol = solve(prob, NewtonRaphson())
14+
15+
# TrustRegion is broken
16+
# LimitedMemoryBroyden will diverge!
17+
for alg in (NewtonRaphson(), LevenbergMarquardt(; linsolve = QRFactorization()),
18+
PseudoTransient(; alpha_initial = 10.0f0), GeneralKlement(), GeneralBroyden(),
19+
LimitedMemoryBroyden())
20+
@test_nowarn sol = solve(prob, alg; abstol = 1.0f-8, reltol = 1.0f-8)
21+
end
22+
23+
f(u, p) = A * u .+ b
24+
25+
prob = NonlinearProblem{false}(f, u0)
26+
27+
# TrustRegion is broken
28+
# LimitedMemoryBroyden will diverge!
29+
for alg in (NewtonRaphson(), LevenbergMarquardt(; linsolve = QRFactorization()),
30+
PseudoTransient(; alpha_initial = 10.0f0), GeneralKlement(), GeneralBroyden(),
31+
LimitedMemoryBroyden())
32+
@test_nowarn sol = solve(prob, alg; abstol = 1.0f-8, reltol = 1.0f-8)
33+
end

0 commit comments

Comments
 (0)