This example showcases the usage of the hipBLAS Level2 Hermitian rank-2 update functionality. The hipBLAS HER2 function performs a Hermitian rank-2 update operation, which is defined as follows:
where
- Read in command-line parameters.
- Allocate and initialize the host vectors and matrix.
- Compute CPU reference result.
- Create a hipBLAS handle.
- Allocate and initialize the device vectors and matrix.
- Copy input vectors and matrix from host to device.
- Invoke the hipBLAS HER2 function.
- Copy the result from device to host.
- Destroy the hipBLAS handle and release device memory.
- Validate the output by comparing it to the CPU reference result.
The application provides the following optional command line arguments:
-
-a
or--alpha
. The scalar value$\alpha$ used in the HER2 operation. Its default value is 1. -
-x
or--incx
. The stride between consecutive values in the data array that makes up vector$x$ , which must be greater than 0. Its default value is 1. -
-y
or--incy
. The stride between consecutive values in the data array that makes up vector$y$ , which must be greater than 0. Its default value is 1. -
-n
or--n
. The dimension of matrix$A$ and vectors$x$ and$y$ , which must be greater than 0. Its default value is 5.
-
hipBLAS is initialized by calling
hipblasCreate(hipblasHandle_t*)
and it is terminated by callinghipblasDestroy(hipblasHandle_t)
. -
The pointer mode controls whether scalar parameters must be allocated on the host (
HIPBLAS_POINTER_MODE_HOST
) or on the device (HIPBLAS_POINTER_MODE_DEVICE
). It is controlled byhipblasSetPointerMode
. -
hipblasSetVector
andhipblasSetMatrix
are helper functions provided by the hipBLAS API for writing data to the GPU, whereashipblasGetVector
andhipblasGetMatrix
are intended for retrieving data from the GPU. Note thathipMemcpy
can also be used to copy/get data to/from the GPU in the usual way. -
hipblas[CZ]her2(handle, uplo, n, *alpha, *x, incx, *y, incy, *AP, lda)
computes a Hermitian rank-2 update. The character matched in[CZ]
denotes the data type of the operation, and can be eitherC
(complex float:hipblasComplex
), orZ
(complex double:hipblasDoubleComplex
). The required arguments come as the following:-
handle
, the hipBLAS API handle. -
uplo
. Because a Hermitian matrix is symmetric over the diagonal, except that the values in the upper triangle are the complex conjugate of the values in the lower triangle, the required work can be reduced by only updating a single half of the matrix. The part of the matrix to update is given byuplo
:HIPBLAS_FILL_MODE_UPPER
(used in this example) indicates that the upper triangle of$A$ should be updated,HIPBLAS_FILL_MODE_LOWER
indicates that the lower triangle of$A$ should be updated andHIPBLAS_FILL_MODE_FULL
indicates that the full matrix will be updated. -
n
gives the dimensions of the vector and matrix inputs. -
alpha
is the complex scalar. -
x
andy
are the input vectors, andincx
andincy
are the increments in elements between items of$x$ and$y$ , respectively. -
AP
is the device pointer to matrix$A$ in device memory. -
lda
is the leading dimension of$A$ , that is, the number of elements between the starts of the columns of$A$ . Note that hipBLAS matrices are laid out in column major ordering.
-
-
If
ROCM_MATHLIBS_API_USE_HIP_COMPLEX
is defined (adding#define ROCM_MATHLIBS_API_USE_HIP_COMPLEX
before#include <hipblas/hipblas.h>
), the hipBLAS API is exposed as using the hip defined complex types. That is,hipblasComplex
is a typedef ofhipFloatComplex
(also namedhipComplex
) and they can be used equivalently. -
hipFloatComplex
andstd::complex<float>
have compatible memory layout, and performing a memory copy between values of these types will correctly perform the expected copy. -
hipCaddf(a, b)
addshipFloatComplex
valuesa
andb
element-wise together. This function is from a family of host/device HIP functions which operate on complex values.
HIPBLAS_FILL_MODE_UPPER
HIPBLAS_POINTER_MODE_HOST
hipblasCher2
hipblasComplex
hipblasCreate
hipblasDestroy
hipblasFillMode_t
hipblasHandle_t
hipblasSetMatrix
hipblasSetPointerMode
hipblasSetVector
ROCM_MATHLIBS_API_USE_HIP_COMPLEX
hipCaddf
hipFloatComplex
hipFree
hipMalloc