Skip to content

Commit

Permalink
Add cudss_set and cudss_get for CudssSolver
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Dec 3, 2023
1 parent bdd7c95 commit 98a8c12
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
27 changes: 18 additions & 9 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ end
cudss_set(matrix::CudssMatrix, A::CuVector)
cudss_set(matrix::CudssMatrix, A::CuMatrix)
cudss_set(matrix::CudssMatrix, A::CuSparseMatrixCSR)
cudss_set(data::CudssSolver, param::String, value)
cudss_set(config::CudssConfig, param::String, value)
cudss_set(data::CudssData, param::String, value)
The available config parameters are:
"reordering_alg"
Expand All @@ -37,8 +38,6 @@ The available config parameters are:
"pivot_epsilon"
"max_lu_nnz"
cudss_set(data::CudssData, param::String, value)
The available data parameters are:
"info"
"lu_nnz"
Expand All @@ -64,22 +63,29 @@ function cudss_set(matrix::CudssMatrix, A::CuSparseMatrixCSR)
cudssMatrixSetCsrPointers(matrix, A.rowPtr, CU_NULL, A.colVal, A.nzVal)
end

function cudss_set(data::CudssSolver, param::String, value)
(param cudss_config_parameters) && cudss_set(solver.config, param, value)
(param cudss_data_parameters) && cudss_set(solver.data, param, value)
end

function cudss_set(data::CudssData, param::String, value)
type = cudss_types[param]
type = CUDSS_TYPES[param]
val = Ref{type}(value)
nbytes = sizeof(val)
cudssDataSet(handle(), data, param, val, nbytes)
end

function cudss_set(config::CudssConfig, param::String, value)
type = cudss_types[param]
type = CUDSS_TYPES[param]
val = Ref{type}(value)
nbytes = sizeof(val)
cudssConfigSet(config, param, val, nbytes)
end

"""
value = cudss_get(data::CudssSolver, param::String)
value = cudss_get(config::CudssConfig, param::String)
value = cudss_get(data::CudssData, param::String)
The available config parameters are:
"reordering_alg"
Expand All @@ -94,8 +100,6 @@ The available config parameters are:
"pivot_epsilon"
"max_lu_nnz"
value = cudss_get(data::CudssData, param::String)
The available data parameters are:
"info"
"lu_nnz"
Expand All @@ -109,8 +113,13 @@ The available data parameters are:
"""
function cudss_get end

function cudss_get(solver::CudssSolver, param::String)
(param cudss_config_parameters) && cudss_get(solver.config, param)
(param cudss_data_parameters) && cudss_get(solver.data, param)
end

function cudss_get(data::CudssData, param::String)
type = cudss_types[param]
type = CUDSS_TYPES[param]
val = Ref{type}()
nbytes = sizeof(val)
nbytes_written = Ref{Cint}()
Expand All @@ -119,7 +128,7 @@ function cudss_get(data::CudssData, param::String)
end

function cudss_get(config::CudssConfig, param::String)
type = cudss_types[param]
type = CUDSS_TYPES[param]
val = Ref{type}()
nbytes = sizeof(val)
nbytes_written = Ref{Cint}()
Expand Down
11 changes: 9 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# cuDSS types

const cudss_types = Dict{String, DataType}(
const CUDSS_DATA_PARAMETERS = ("info", "lu_nnz", "npivots", "inertia", "perm_reorder",
"perm_row", "perm_col", "diag", "user_perm")

const CUDSS_CONFIG_PARAMETERS = ("reordering_alg", "factorization_alg", "solve_alg", "matching_type",
"solve_mode", "ir_n_steps", "ir_tol", "pivot_type", "pivot_threshold",
"pivot_epsilon", "max_lu_nnz")

const CUDSS_TYPES = Dict{String, DataType}(
# data type
"info" => Cint,
"lu_nnz" => Int64,
"npivots" => Int64,
"inertia" => Cint,
"inertia" => (Cint, Cint),
"perm_reorder" => Vector{Cint},
"perm_row" => Vector{Cint},
"perm_col" => Vector{Cint},
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ using CUDSS
using SparseArrays
using LinearAlgebra

import CUDSS: CUDSS_DATA_PARAMETERS, CUDSS_CONFIG_PARAMETERS
import CUDSS: CUDSS_ALG_DEFAULT, CUDSS_ALG_1, CUDSS_ALG_2, CUDSS_ALG_3

include("test_cudss.jl")

@testset "CUDSS" begin
Expand Down
35 changes: 25 additions & 10 deletions test/test_cudss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ function cudss_dense()
end
end


function cudss_sparse()
n = 20
@testset "precision = $T" for T in (Float32, Float64, ComplexF32, ComplexF64)
A_cpu = sprand(T, n, n, 1.0)
A_cpu = A_cpu + A_cpu'
A_gpu = CuSparseMatrixCSR(A_cpu)
@testset "structure = $structure" for structure in ("G", "S", "H", "SPD", "HPD")
@testset "view = $view" for view in ('L', 'U', 'F')
@testset "view = $view" for view in ('L', 'U', 'F')
@testset "structure = $structure" for structure in ('G', "G", 'S', "S", 'H', "H", "SPD", "HPD")
matrix = CudssMatrix(A_gpu, structure, view)
format = Ref{CUDSS.cudssMatrixFormat_t}()
CUDSS.cudssMatrixGetFormat(matrix, format)
Expand All @@ -59,19 +58,16 @@ end

function cudss_data()
data = CudssData()
@testset "parameter = $parameter" for parameter in ("info", "lu_nnz", "npivots", "inertia", "perm_reorder",
"perm_row", "perm_col", "diag", "user_perm")
@testset "parameter = $parameter" for parameter in CUDSS_DATA_PARAMETERS
val = cudss_get(data, parameter)
end
end

function cudss_config()
config = CudssConfig()
@testset "parameter = $parameter" for parameter in ("reordering_alg", "factorization_alg", "solve_alg",
"matching_type", "solve_mode", "ir_n_steps", "ir_tol",
"pivot_type", "pivot_threshold", "pivot_epsilon", "max_lu_nnz")
@testset "parameter = $parameter" for parameter in CUDSS_CONFIG_PARAMETERS
val = cudss_get(config, parameter)
for val in (CUDSS.CUDSS_ALG_DEFAULT, CUDSS.CUDSS_ALG_1, CUDSS.CUDSS_ALG_2, CUDSS.CUDSS_ALG_3)
for val in (CUDSS_ALG_DEFAULT, CUDSS_ALG_1, CUDSS_ALG_2, CUDSS_ALG_3)
(parameter == "reordering_alg") && cudss_set(config, parameter, val)
(parameter == "factorization_alg") && cudss_set(config, parameter, val)
(parameter == "solve_alg") && cudss_set(config, parameter, val)
Expand All @@ -95,7 +91,7 @@ function cudss_solver()
A_cpu = sprand(T, n, n, 1.0)
A_cpu = A_cpu + A_cpu'
A_gpu = CuSparseMatrixCSR(A_cpu)
@testset "structure = $structure" for structure in ("G", "S", "H", "SPD", "HPD")
@testset "structure = $structure" for structure in ('G', "G", 'S', "S", 'H', "H", "SPD", "HPD")
@testset "view = $view" for view in ('L', 'U', 'F')
solver = CudssSolver(A_gpu, structure, view)

Expand All @@ -104,6 +100,25 @@ function cudss_solver()
b_cpu = rand(T, n)
b_gpu = CuVector(b_cpu)
cudss("analysis", solver, x_gpu, b_gpu)

@testset "parameter = $parameter" for parameter in CUDSS_CONFIG_PARAMETERS CUDSS_DATA_PARAMETERS
val = cudss_get(config, parameter)
for val in (CUDSS_ALG_DEFAULT, CUDSS_ALG_1, CUDSS_ALG_2, CUDSS_ALG_3)
(parameter == "reordering_alg") && cudss_set(solver, parameter, val)
(parameter == "factorization_alg") && cudss_set(solver, parameter, val)
(parameter == "solve_alg") && cudss_set(solver, parameter, val)
end
(parameter == "matching_type") && cudss_set(solver, parameter, 0)
(parameter == "solve_mode") && cudss_set(solver, parameter, 0)
(parameter == "ir_n_steps") && cudss_set(solver, parameter, 1)
(parameter == "ir_tol") && cudss_set(solver, parameter, 1e-8)
for val in ('C', 'R', 'N')
(parameter == "pivot_type") && cudss_set(solver, parameter, val)
end
(parameter == "pivot_threshold") && cudss_set(solver, parameter, 2.0)
(parameter == "pivot_epsilon") && cudss_set(solver, parameter, 1e-12)
(parameter == "max_lu_nnz") && cudss_set(solver, parameter, 10)
end
end
end
end
Expand Down

0 comments on commit 98a8c12

Please sign in to comment.