This example illustrates the functionality to perform Cholesky decomposition, potrf
, and to solve a linear system using the resulting Cholesky factor, potrs
. The potrf
functions decompose a Hermitian positive-definite matrix potrs
functions solve a linear system
- Declare several constants for the sizes of the matrices.
- Allocate the input- and output-matrices on the host and device, initialize the input data. Matrix
$A_0$ is not Hermitian positive semi-definite, matrix$A_1$ is Hermitian positive semi-definite. - Create a hipSOLVER handle.
- Query the size of the working space of the
potrf
andpotrs
functions and allocate the required amount of device memory. - Call the
potrf
function to decompose$A_0$ and assert that it failed since$A_0$ does not meet the requirements. - Call the
potrf
function to decompose$A_1$ and assert that it succeeds. - Call the
potrs
function to solve the system$A_1\times X=B$ . - Copy the device result back to the host.
- Free device resources and the hipSOLVER handle.
- Validate that the result found is correct by calculating
$A_1\times X$ , and print the result.
- hipSOLVER is initialized by calling
hipsolverCreate(hipsolverHandle_t*)
and it is terminated by callinghipsolverDestroy(hipsolverHandle_t)
. -
hipsolver[SDCZ]potrf
performs Cholesky decomposition on Hermitian positive semi-definite matrix$A$ . The correct function signature should be chosen based on the datatype of the input matrix:-
S
(single-precision:float
). -
D
(double-precision:double
). -
C
(single-precision complex:hipFloatComplex
). -
Z
(double-precision complex:hipDoubleComplex
).
-
-
hipsolver[SDCZ]potrf_bufferSize
obtains the size needed for the working space for thehipsolver[SDCZ]potrf
function. -
hipsolver[SDCZ]potrs
solves the system of linear equations defined by$A\times X=B$ , where$A$ is a Cholesky-decomposed Hermitian positive semi-definiten
-by-n
matrix,$X$ is ann
-by-nrhs
matrix, and$B$ is ann
-by-nrhs
matrix. - The
potrf
andpotrs
functions require the specification of ahipsolverFillMode_t
, which indicates which triangular part of the matrix is processed and replaced by the functions. The legal values areHIPSOLVER_FILL_MODE_LOWER
andHIPSOLVER_FILL_MODE_UPPER
. - The
potrf
andpotrs
functions also require the specification of the leading dimension of all matrices. The leading dimension specifies the number of elements between the beginnings of successive matrix vectors. In other fields, this may be referred to as the stride. This concept allows the matrix used in thepotrf
andpotrs
functions to be a sub-matrix of a larger one. Since hipSOLVER matrices are stored in column-major order, the leading dimension must be greater than or equal to the number of rows of the matrix.
HIPSOLVER_FILL_MODE_LOWER
hipsolverCreate
hipsolverDestroy
hipsolverDpotrf
hipsolverDpotrf_bufferSize
hipsolverDpotrs
hipsolverFillMode_t
hipsolverHandle_t
hipFree
hipMalloc
hipMemcpy
hipMemcpyHostToDevice
hipMemcpyDeviceToHost