Krylov operators
KrylovPreconditioners.KrylovOperator
— FunctionKrylovOperator(A; nrhs::Int=1, transa::Char='N')
Create a Krylov operator to accelerate sparse matrix-vector or matrix-matrix products on GPU architectures. The operator is compatible with sparse matrices stored on NVIDIA, AMD, and Intel GPUs.
Input arguments
A
: The sparse matrix on the GPU that serves as the operator for matrix-vector or matrix-matrix products;nrhs
: Specifies the number of columns for the right-hand sides. Defaults to1
for standard matrix-vector products;transa
: Determines how the matrixA
is applied during the products;'N'
for no transposition,'T'
for transpose, and'C'
for conjugate transpose.
Output argument
op
: An instance ofAbstractKrylovOperator
representing the Krylov operator for the specified sparse matrix and parameters.
KrylovPreconditioners.update!
— Methodupdate!(op::AbstractKrylovOperator, A)
Update the sparse matrix A
associated with the given AbstractKrylovOperator
without the need to reallocate buffers or repeat the structural analysis phase for detecting parallelism for sparse matrix-vector or matrix-matrix products. A
and the operator op
must have the same sparsity pattern, enabling efficient reuse of existing resources.
Input arguments
op
: The Krylov operator to update;A
: The new sparse matrix to associate with the operator.
Nvidia GPUs
Sparse matrices have a specific storage on Nvidia GPUs (CuSparseMatrixCSC
, CuSparseMatrixCSR
or CuSparseMatrixCOO
):
using CUDA, CUDA.CUSPARSE
using SparseArrays
using KrylovPreconditioners
if CUDA.functional()
# CPU Arrays
A_cpu = sprand(200, 100, 0.3)
# GPU Arrays
A_csc_gpu = CuSparseMatrixCSC(A_cpu)
A_csr_gpu = CuSparseMatrixCSR(A_cpu)
A_coo_gpu = CuSparseMatrixCOO(A_cpu)
# Krylov operators
op_csc = KrylovOperator(A_csc_gpu; nrhs=1, transa='N')
op_csr = KrylovOperator(A_csr_gpu; nrhs=1, transa='T')
op_coo = KrylovOperator(A_coo_gpu; nrhs=5, transa='N')
end
AMD GPUs
Sparse matrices have a specific storage on AMD GPUs (ROCSparseMatrixCSC
, ROCSparseMatrixCSR
or ROCSparseMatrixCOO
):
using AMDGPU, AMDGPU.rocSPARSE
using SparseArrays
using KrylovPreconditioners
if AMDGPU.functional()
# CPU Arrays
A_cpu = sprand(200, 100, 0.3)
# GPU Arrays
A_csc_gpu = ROCSparseMatrixCSC(A_cpu)
A_csr_gpu = ROCSparseMatrixCSR(A_cpu)
A_coo_gpu = ROCSparseMatrixCOO(A_cpu)
# Krylov operators
op_csc = KrylovOperator(A_csc_gpu; nrhs=1, transa='N')
op_csr = KrylovOperator(A_csr_gpu; nrhs=1, transa='T')
op_coo = KrylovOperator(A_coo_gpu; nrhs=5, transa='N')
end
Intel GPUs
Sparse matrices have a specific storage on Intel GPUs (oneSparseMatrixCSR
):
using oneAPI, oneAPI.oneMKL
using SparseArrays
using KrylovPreconditioners
if oneAPI.functional()
# CPU Arrays
A_cpu = sprand(Float32, 20, 10, 0.3)
# GPU Arrays
A_csr_gpu = oneSparseMatrixCSR(A_cpu)
# Krylov operator
op_csr = KrylovOperator(A_csr_gpu; nrhs=1, transa='N')
end