Skip to content

Commit

Permalink
Add GPU tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Apr 30, 2024
1 parent a9fa774 commit 460cf12
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ NLPModels = "0.19, 0.20, 0.21"
julia = "^1.6.0"

[extras]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
NLPModelsTest = "7998695d-6960-4d3a-85c4-e1bceb8cd856"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["NLPModelsTest", "Test"]
test = ["CUDA", "NLPModelsTest", "Test"]
6 changes: 3 additions & 3 deletions src/slack-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The slack variables are implicitly ordered as linear and then nonlinear, and
``c_L ≤ c(x) < ∞``, ``-∞ < c(x) ≤ c_U`` and
``c_L ≤ c(x) ≤ c_U``, respectively.
"""
mutable struct SlackModel{T, S, M <: AbstractNLPModel{T, S}} <: AbstractNLPModel{T, S}
mutable struct SlackModel{T, S, M <: AbstractNLPModel{T}} <: AbstractNLPModel{T, S}
meta::NLPModelMeta{T, S}
model::M

Expand All @@ -90,7 +90,7 @@ end

"""Like `SlackModel`, this model converts inequalities into equalities and bounds.
"""
mutable struct SlackNLSModel{T, S, M <: AbstractNLPModel{T, S}} <: AbstractNLSModel{T, S}
mutable struct SlackNLSModel{T, S, M <: AbstractNLPModel{T}} <: AbstractNLSModel{T, S}
meta::NLPModelMeta{T, S}
nls_meta::NLSMeta{T, S}
model::M
Expand Down Expand Up @@ -177,7 +177,7 @@ function SlackNLSModel(
x0 = similar(model.meta.x0, model.meta.nvar + ns)
x0[(model.meta.nvar + 1):end] .= zero(T)
x0[1:(model.meta.nvar)] .= model.meta.x0
nls_meta = NLSMeta{T, S}(
nls_meta = NLSMeta{T, typeof(meta.x0)}( # might differ from S
model.nls_meta.nequ,
model.meta.nvar + ns,
x0 = x0,
Expand Down
42 changes: 42 additions & 0 deletions test/gpu_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function nlp_gpu_tests(p, Model; exclude = [])
@testset "NLP tests of problem $p" begin
nlp_from_T = T -> Model(eval(Symbol(p))(T))
@testset "GPU multiple precision support of problem $p" begin
CUDA.allowscalar() do
multiple_precision_nlp_array(nlp_from_T, CuArray, linear_api = true, exclude = exclude)
end
end
end
end

function nls_gpu_tests(p, Model; exclude = [])
@testset "NLP tests of problem $p" begin
nls_from_T = T -> Model(eval(Symbol(p))(T))
exclude = p == "LLS" ? union(exclude, [hess_coord, hess, hess_residual]) : exclude
@testset "GPU multiple precision support of problem $p" begin
CUDA.allowscalar() do
multiple_precision_nls_array(nls_from_T, CuArray, linear_api = true, exclude = exclude)
end
end
end
end

@testset "Check GPU multiprecision for quasi-Newton model modifiers $M of NLP" for M in [LBFGSModel, LSR1Model, DiagonalPSBModel, DiagonalAndreiModel, SpectralGradientModel]
map(p -> nlp_gpu_tests(p, M, exclude = [hess, hess_coord, ghjvprod, jth_hess, jth_hess_coord, jth_hprod]), union(NLPModelsTest.nlp_problems, NLPModelsTest.nls_problems))
end

@testset "Check GPU multiprecision for model modifiers $M of NLP" for M in [FeasibilityResidual]
map(p -> nlp_gpu_tests(p, M, exclude = [hess, hess_coord, ghjvprod, jth_hess, jth_hess_coord, jth_hprod]), setdiff(NLPModelsTest.nlp_problems, ["BROWNDEN", "HS5"]))
end

@testset "Check GPU multiprecision for model modifiers $M of NLP" for M in [SlackModel]
map(p -> nlp_gpu_tests(p, M, exclude = []), NLPModelsTest.nlp_problems)
end

@testset "Check GPU multiprecision for model modifiers $M of NLP" for M in [FeasibilityResidual]
map(p -> nls_gpu_tests(p, M, exclude = [hess, hess_coord, ghjvprod, jth_hess, jth_hess_coord, jth_hprod]), setdiff(NLPModelsTest.nls_problems, ["MGH01", "BNDROSENBROCK"]))
end

@testset "Check GPU multiprecision for model modifiers $M of NLP" for M in [SlackNLSModel, FeasibilityFormNLS]
map(p -> nls_gpu_tests(p, M, exclude = []), NLPModelsTest.nls_problems)
end
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ include("nls/feasibility-form-nls.jl")
include("nls/feasibility-residual.jl")
include("nls/slack-model.jl")

using NLPModelsTest
using CUDA, NLPModelsTest

if CUDA.functional()
include("gpu_test.jl")
end

if (v"1.7" <= VERSION)
include("allocs_test.jl")
Expand Down

0 comments on commit 460cf12

Please sign in to comment.