Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
sshin23 committed Aug 18, 2022
2 parents 792c993 + e739a3b commit 4de5b22
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 146 deletions.
2 changes: 1 addition & 1 deletion lib/MadNLPGPU/src/MadNLPGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import MadNLP:
AbstractOptions, AbstractLinearSolver, AbstractNLPModel, set_options!,
SymbolicException,FactorizationException,SolveException,InertiaException,
introduce, factorize!, solve!, improve!, is_inertia, inertia, tril_to_full!,
LapackOptions, input_type, is_supported, symul!
LapackOptions, input_type, is_supported, default_options, symul!

symul!(y, A, x::CuVector{T}, α = 1., β = 0.) where T = CUBLAS.symv!('L', T(α), A, x, T(β), y)

Expand Down
17 changes: 7 additions & 10 deletions lib/MadNLPGPU/src/interface.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@

function CuInteriorPointSolver(nlp::AbstractNLPModel{T};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(), kwargs...
) where T
opt = MadNLP.Options(linear_solver=LapackGPUSolver)
MadNLP.set_options!(opt,option_dict,kwargs)
MadNLP.check_option_sanity(opt)
function CuInteriorPointSolver(nlp::AbstractNLPModel{T}; kwargs...) where T
opt_ipm, opt_linear_solver, logger = MadNLP.load_options(; linear_solver=LapackGPUSolver, kwargs...)

KKTSystem = if (opt.kkt_system == MadNLP.SPARSE_KKT_SYSTEM) || (opt.kkt_system == MadNLP.SPARSE_UNREDUCED_KKT_SYSTEM)
@assert is_supported(opt_ipm.linear_solver, T)
KKTSystem = if (opt_ipm.kkt_system == MadNLP.SPARSE_KKT_SYSTEM) || (opt_ipm.kkt_system == MadNLP.SPARSE_UNREDUCED_KKT_SYSTEM)
error("Sparse KKT system are currently not supported on CUDA GPU.\n" *
"Please use `DENSE_KKT_SYSTEM` or `DENSE_CONDENSED_KKT_SYSTEM` instead.")
elseif opt.kkt_system == MadNLP.DENSE_KKT_SYSTEM
elseif opt_ipm.kkt_system == MadNLP.DENSE_KKT_SYSTEM
MT = CuMatrix{T}
VT = CuVector{T}
MadNLP.DenseKKTSystem{T, VT, MT}
elseif opt.kkt_system == MadNLP.DENSE_CONDENSED_KKT_SYSTEM
elseif opt_ipm.kkt_system == MadNLP.DENSE_CONDENSED_KKT_SYSTEM
MT = CuMatrix{T}
VT = CuVector{T}
MadNLP.DenseCondensedKKTSystem{T, VT, MT}
end
return MadNLP.InteriorPointSolver{T,KKTSystem}(nlp, opt; option_linear_solver=option_dict)
return MadNLP.InteriorPointSolver{T,KKTSystem}(nlp, opt_ipm, opt_linear_solver; logger=logger)
end
1 change: 1 addition & 0 deletions lib/MadNLPGPU/src/lapackgpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function inertia(M::LapackGPUSolver)
end

input_type(::Type{LapackGPUSolver}) = :dense
MadNLP.default_options(::Type{LapackGPUSolver}) = LapackOptions()
is_supported(::Type{LapackGPUSolver},::Type{Float32}) = true
is_supported(::Type{LapackGPUSolver},::Type{Float64}) = true

6 changes: 3 additions & 3 deletions lib/MadNLPGPU/test/densekkt_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function _compare_gpu_with_cpu(KKTSystem, n, m, ind_fixed)
)

nlp = MadNLPTests.DenseDummyQP{T}(; n=n, m=m, fixed_variables=ind_fixed)

# Solve on CPU
h_ips = MadNLP.InteriorPointSolver(nlp; option_dict=copy(madnlp_options))
h_ips = MadNLP.InteriorPointSolver(nlp; madnlp_options...)
MadNLP.optimize!(h_ips)

# Solve on GPU
d_ips = MadNLPGPU.CuInteriorPointSolver(nlp; option_dict=copy(madnlp_options))
d_ips = MadNLPGPU.CuInteriorPointSolver(nlp; madnlp_options...)
MadNLP.optimize!(d_ips)

@test isa(d_ips.kkt, KKTSystem{T, CuVector{T}, CuMatrix{T}})
Expand Down
2 changes: 1 addition & 1 deletion lib/MadNLPHSL/src/MadNLPHSL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MadNLP: @kwdef, Logger, @debug, @warn, @error,
SymbolicException,FactorizationException,SolveException,InertiaException,
introduce, factorize!, solve!, improve!, is_inertia, inertia, findIJ, nnz,
get_tril_to_full, transfer!, input_type, _madnlp_unsafe_wrap,
is_supported
is_supported, default_options

include(joinpath("..","deps","deps.jl"))

Expand Down
8 changes: 3 additions & 5 deletions lib/MadNLPHSL/src/ma27.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ for (fa, fb, fc, typ) in [
end

function Ma27Solver(csc::SparseMatrixCSC{T};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
opt=Ma27Options(),logger=Logger(),kwargs...) where T

set_options!(opt,option_dict,kwargs)

opt=Ma27Options(),logger=Logger(),
) where T
I,J = findIJ(csc)
nz=Int32(nnz(csc))

Expand Down Expand Up @@ -175,5 +172,6 @@ end

introduce(::Ma27Solver)="ma27"
input_type(::Type{Ma27Solver}) = :csc
default_options(::Type{Ma27Solver}) = Ma27Options()
is_supported(::Type{Ma27Solver},::Type{Float32}) = true
is_supported(::Type{Ma27Solver},::Type{Float64}) = true
10 changes: 4 additions & 6 deletions lib/MadNLPHSL/src/ma57.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ for (fa,fb,fc,typ) in (
(:ma57a_, :ma57b_, :ma57c_, Float32)
)
@eval begin

ma57ad!(n::Cint,nz::Cint,I::Vector{Cint},J::Vector{Cint},lkeep::Cint,
keep::Vector{Cint},iwork::Vector{Cint},icntl::Vector{Cint},
info::Vector{Cint},rinfo::Vector{$typ}) = ccall(
Expand Down Expand Up @@ -85,11 +85,8 @@ for (fa,fb,fc,typ) in (
end

function Ma57Solver(csc::SparseMatrixCSC{T};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
opt=Ma57Options(),logger=Logger(),kwargs...) where T

set_options!(opt,option_dict,kwargs)

opt=Ma57Options(),logger=Logger()
) where T
I,J=findIJ(csc)

icntl= ma57_default_icntl()
Expand Down Expand Up @@ -174,5 +171,6 @@ end

introduce(::Ma57Solver)="ma57"
input_type(::Type{Ma57Solver}) = :csc
default_options(::Type{Ma57Solver}) = Ma57Options()
is_supported(::Type{Ma57Solver},::Type{Float32}) = true
is_supported(::Type{Ma57Solver},::Type{Float64}) = true
15 changes: 6 additions & 9 deletions lib/MadNLPHSL/src/ma77.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ mutable struct Ma77Solver{T} <: AbstractLinearSolver{T}
end

for (fdefault, fanalyse, ffactor, fsolve, ffinalise, fopen, finputv, finputr, typ) in [
(:ma77_default_control_d, :ma77_analyse_d,
(:ma77_default_control_d, :ma77_analyse_d,
:ma77_factor_d, :ma77_solve_d, :ma77_finalise_d,
:ma77_open_d, :ma77_input_vars_d, :ma77_input_reals_d, Float64),
(:ma77_default_control_s, :ma77_analyse_s,
:ma77_open_d, :ma77_input_vars_d, :ma77_input_reals_d, Float64),
(:ma77_default_control_s, :ma77_analyse_s,
:ma77_factor_s, :ma77_solve_s, :ma77_finalise_s,
:ma77_open_s, :ma77_input_vars_s, :ma77_input_reals_s, Float32),
:ma77_open_s, :ma77_input_vars_s, :ma77_input_reals_s, Float32),
]
@eval begin
ma77_default_control(control::Ma77Control{$typ}) = ccall(
Expand Down Expand Up @@ -245,12 +245,8 @@ end

function Ma77Solver(
csc::SparseMatrixCSC{T,Int32};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
opt=Ma77Options(),logger=Logger(),
kwargs...) where T

set_options!(opt,option_dict,kwargs)

) where T
full,tril_to_full_view = get_tril_to_full(csc)
order = Vector{Int32}(undef,csc.n)

Expand Down Expand Up @@ -356,5 +352,6 @@ end

introduce(::Ma77Solver)="ma77"
input_type(::Type{Ma77Solver}) = :csc
default_options(::Type{Ma77Solver}) = Ma77Options()
is_supported(::Type{Ma77Solver},::Type{Float32}) = true
is_supported(::Type{Ma77Solver},::Type{Float64}) = true
13 changes: 5 additions & 8 deletions lib/MadNLPHSL/src/ma86.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ end


for (fdefault, fanalyse, ffactor, fsolve, ffinalise, typ) in [
(:ma86_default_control_d, :ma86_analyse_d,
:ma86_factor_d, :ma86_solve_d, :ma86_finalise_d, Float64),
(:ma86_default_control_s, :ma86_analyse_s,
(:ma86_default_control_d, :ma86_analyse_d,
:ma86_factor_d, :ma86_solve_d, :ma86_finalise_d, Float64),
(:ma86_default_control_s, :ma86_analyse_s,
:ma86_factor_s, :ma86_solve_s, :ma86_finalise_s, Float32)
]
@eval begin
Expand Down Expand Up @@ -130,12 +130,8 @@ ma86_set_num_threads(n) = ccall((:omp_set_num_threads_,libma86),

function Ma86Solver(
csc::SparseMatrixCSC{T,Int32};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
opt=Ma86Options(),logger=Logger(),
kwargs...) where T

set_options!(opt,option_dict,kwargs)

) where T
ma86_set_num_threads(opt.ma86_num_threads)

order = Vector{Int32}(undef,csc.n)
Expand Down Expand Up @@ -195,6 +191,7 @@ function improve!(M::Ma86Solver)
end
introduce(::Ma86Solver)="ma86"
input_type(::Type{Ma86Solver}) = :csc
default_options(::Type{Ma86Solver}) = Ma86Options()
is_supported(::Type{Ma86Solver},::Type{Float32}) = true
is_supported(::Type{Ma86Solver},::Type{Float64}) = true

12 changes: 5 additions & 7 deletions lib/MadNLPHSL/src/ma97.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ mutable struct Ma97Solver{T} <:AbstractLinearSolver{T}
end

for (fdefault, fanalyse, ffactor, fsolve, ffinalise, typ) in [
(:ma97_default_control_d, :ma97_analyse_d,
:ma97_factor_d, :ma97_solve_d, :ma97_finalise_d, Float64),
(:ma97_default_control_s, :ma97_analyse_s,
(:ma97_default_control_d, :ma97_analyse_d,
:ma97_factor_d, :ma97_solve_d, :ma97_finalise_d, Float64),
(:ma97_default_control_s, :ma97_analyse_s,
:ma97_factor_s, :ma97_solve_s, :ma97_finalise_s, Float32)
]
@eval begin
Expand Down Expand Up @@ -135,11 +135,8 @@ ma97_set_num_threads(n) = ccall((:omp_set_num_threads_,libma97),

function Ma97Solver(
csc::SparseMatrixCSC{T,Int32};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
opt=Ma97Options(),logger=Logger(),
kwargs...) where T

set_options!(opt,option_dict,kwargs)
) where T

ma97_set_num_threads(opt.ma97_num_threads)

Expand Down Expand Up @@ -193,5 +190,6 @@ function improve!(M::Ma97Solver)
end
introduce(::Ma97Solver)="ma97"
input_type(::Type{Ma97Solver}) = :csc
default_options(::Type{Ma97Solver}) = Ma97Options()
is_supported(::Type{Ma97Solver},::Type{Float32}) = true
is_supported(::Type{Ma97Solver},::Type{Float64}) = true
2 changes: 1 addition & 1 deletion lib/MadNLPHSL/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ testset = [

@testset "MadNLPHSL test" begin
for hsl_solver in [Ma27Solver, Ma57Solver, Ma77Solver, Ma86Solver, Ma97Solver]
MadNLPTests.test_linear_solver(hsl_solver,Float32)
# MadNLPTests.test_linear_solver(hsl_solver,Float32)
MadNLPTests.test_linear_solver(hsl_solver,Float64)
end
for (name,optimizer_constructor,exclude) in testset
Expand Down
9 changes: 5 additions & 4 deletions lib/MadNLPKrylov/src/MadNLPKrylov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module MadNLPKrylov
import MadNLP:
@kwdef, Logger, @debug, @warn, @error,
AbstractOptions, AbstractIterator, set_options!, @sprintf,
solve_refine!, mul!, ldiv!, size
solve_refine!, mul!, ldiv!, size, default_options
import IterativeSolvers:
FastHessenberg, ArnoldiDecomp, Residual, init!, init_residual!, expand!, Identity,
orthogonalize_and_normalize!, update_residual!, gmres_iterable!, GMRESIterable, converged,
Expand Down Expand Up @@ -38,10 +38,9 @@ mutable struct KrylovIterator{T} <: AbstractIterator{T}
end

function KrylovIterator(res::Vector{T},_mul!,_ldiv!;
opt=KrylovOptions(),logger=Logger(),
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),kwargs...) where T
opt=KrylovOptions(),logger=Logger(),
) where T
!isempty(kwargs) && (for (key,val) in kwargs; option_dict[key]=val; end)
set_options!(opt,option_dict)

g = GMRESIterable(VirtualPreconditioner(_ldiv!),
Identity(),T[],T[],res,
Expand Down Expand Up @@ -96,4 +95,6 @@ function gmres_iterable_update!(g,x,b)
g.β=g.residual.current
end

default_options(::Type{KrylovIterator}) = KrylovOptions()

end # module
14 changes: 6 additions & 8 deletions lib/MadNLPMumps/src/MadNLPMumps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MadNLP:
@kwdef, Logger, @debug, @warn, @error,
SparseMatrixCSC, SubVector,
SymbolicException,FactorizationException,SolveException,InertiaException,
AbstractOptions, AbstractLinearSolver, set_options!, input_type,
AbstractOptions, AbstractLinearSolver, set_options!, input_type, default_options,
introduce, factorize!, solve!, improve!, is_inertia, is_supported, inertia, findIJ, nnz

const version = parsefile(joinpath(dirname(pathof(MUMPS_seq_jll)),"..","Project.toml"))["version"]
Expand Down Expand Up @@ -112,7 +112,7 @@ if version == "5.3.5+0"
schur::Ptr{T} = C_NULL ##

instance_number::Cint = 0
wk_user::Ptr{T} = C_NULL
wk_user::Ptr{T} = C_NULL

version_number::SVector{32,Cchar} = zeros(32)

Expand Down Expand Up @@ -213,7 +213,7 @@ elseif version == "5.2.1+4"
schur::Ptr{T} = C_NULL ##

instance_number::Cint = 0
wk_user::Ptr{T} = C_NULL
wk_user::Ptr{T} = C_NULL

version_number::SVector{32,Cchar} = zeros(32)

Expand Down Expand Up @@ -265,11 +265,8 @@ end
# ---------------------------------------------------------------------------------------

function MumpsSolver(csc::SparseMatrixCSC{T,Int32};
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
opt=MumpsOptions(),logger=Logger(),
kwargs...) where T

set_options!(opt,option_dict,kwargs)
opt=MumpsOptions(), logger=Logger(),
) where T

I,J = findIJ(csc)
sym_perm = zeros(Int32,csc.n)
Expand Down Expand Up @@ -376,6 +373,7 @@ end

introduce(::MumpsSolver)="mumps"
input_type(::Type{MumpsSolver}) = :csc
default_options(::Type{MumpsSolver}) = MumpsOptions()
is_supported(::Type{MumpsSolver},::Type{Float32}) = true
is_supported(::Type{MumpsSolver},::Type{Float64}) = true

Expand Down
4 changes: 2 additions & 2 deletions lib/MadNLPPardiso/src/MadNLPPardiso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ include(joinpath("..","deps","deps.jl"))
import Libdl: dlopen, RTLD_DEEPBIND
import MadNLP:
MadNLP, @kwdef, Logger, @debug, @warn, @error,
SubVector, SparseMatrixCSC,
SubVector, SparseMatrixCSC,
SymbolicException,FactorizationException,SolveException,InertiaException,
AbstractOptions, AbstractLinearSolver, set_options!,
introduce, factorize!, solve!, improve!, is_inertia, inertia, input_type,
blas_num_threads, is_supported
blas_num_threads, is_supported, default_options
import MKL_jll: libmkl_rt

@isdefined(libpardiso) && include("pardiso.jl")
Expand Down
1 change: 1 addition & 0 deletions lib/MadNLPPardiso/src/pardiso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ end

introduce(::PardisoSolver)="pardiso"
input_type(::Type{PardisoSolver}) = :csc
default_options(::Type{PardisoSolver}) = PardisoOptions()
is_supported(::Type{PardisoSolver},::Type{Float32}) = true
is_supported(::Type{PardisoSolver},::Type{Float64}) = true
8 changes: 3 additions & 5 deletions lib/MadNLPPardiso/src/pardisomkl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ end


function PardisoMKLSolver(csc::SparseMatrixCSC{T};
opt=PardisoMKLOptions(),logger=Logger(),
option_dict::Dict{Symbol,Any}=Dict{Symbol,Any}(),
kwargs...) where T
!isempty(kwargs) && (for (key,val) in kwargs; option_dict[key]=val; end)
set_options!(opt,option_dict)
opt=PardisoMKLOptions(),logger=Logger(),
) where T

w = Vector{T}(undef,csc.n)

Expand Down Expand Up @@ -144,5 +141,6 @@ end
introduce(::PardisoMKLSolver)="pardiso-mkl"

input_type(::Type{PardisoMKLSolver}) = :csc
default_options(::Type{PardisoMKLSolver}) = PardisoMKLOptions()
is_supported(::Type{PardisoMKLSolver},::Type{Float32}) = true
is_supported(::Type{PardisoMKLSolver},::Type{Float64}) = true
8 changes: 5 additions & 3 deletions lib/MadNLPTests/src/MadNLPTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ function test_linear_solver(solver,T; kwargs...)
x = similar(b)

@testset "Linear solver $solver" begin

csc = sparse(row,col,val,m,n)
sol= [0.8542713567839195, 1.4572864321608041]
if MadNLP.input_type(solver) == :csc
M = solver(csc;kwargs...)
opt = MadNLP.default_options(solver)
M = solver(csc; opt=opt)
elseif MadNLP.input_type(solver) == :dense
dense = Array(csc)
M = solver(dense;kwargs...)
opt = MadNLP.default_options(solver)
M = solver(dense; opt=opt)
end
MadNLP.introduce(M)
MadNLP.improve!(M)
Expand Down
Loading

0 comments on commit 4de5b22

Please sign in to comment.