Matrix multiply (matmul) functions#

hipSPARSELt: Matrix multiply (matmul) functions
Matrix multiply (matmul) functions

Functions

hipsparseStatus_t hipsparseLtMatmulGetWorkspace (const hipsparseLtHandle_t *handle, const hipsparseLtMatmulPlan_t *plan, size_t *workspaceSize)
 Determines the required workspace size. More...
 
hipsparseStatus_t hipsparseLtMatmulPlanInit (const hipsparseLtHandle_t *handle, hipsparseLtMatmulPlan_t *plan, const hipsparseLtMatmulDescriptor_t *matmulDescr, const hipsparseLtMatmulAlgSelection_t *algSelection)
 Initializes the matrix multiplication plan descriptor. More...
 
hipsparseStatus_t hipsparseLtMatmulPlanDestroy (const hipsparseLtMatmulPlan_t *plan)
 Destroy a matrix multiplication plan descriptor. More...
 
hipsparseStatus_t hipsparseLtMatmul (const hipsparseLtHandle_t *handle, const hipsparseLtMatmulPlan_t *plan, const void *alpha, const void *d_A, const void *d_B, const void *beta, const void *d_C, void *d_D, void *workspace, hipStream_t *streams, int32_t numStreams)
 Sparse matrix dense matrix multiplication. More...
 
hipsparseStatus_t hipsparseLtMatmulSearch (const hipsparseLtHandle_t *handle, hipsparseLtMatmulPlan_t *plan, const void *alpha, const void *d_A, const void *d_B, const void *beta, const void *d_C, void *d_D, void *workspace, hipStream_t *streams, int32_t numStreams)
 Sparse matrix dense matrix multiplication. More...
 

Detailed Description

Multiplies sparse matrices

Function Documentation

◆ hipsparseLtMatmul()

hipsparseStatus_t hipsparseLtMatmul ( const hipsparseLtHandle_t handle,
const hipsparseLtMatmulPlan_t plan,
const void *  alpha,
const void *  d_A,
const void *  d_B,
const void *  beta,
const void *  d_C,
void *  d_D,
void *  workspace,
hipStream_t *  streams,
int32_t  numStreams 
)

Sparse matrix dense matrix multiplication.

hipsparseLtMatmul computes the matrix multiplication of matrices A and B to produce the output matrix D, according to the following operation:

\[ D := Activation(\alpha \cdot op(A) \cdot op(B) + \beta \cdot C + bias) * scale \]

Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Currently, only supports the case where D has the same shape of C.
Parameters
[in]handlehipsparselt library handle
[in]planMatrix multiplication plan
[in]alphascalar \(\alpha\). (float)
[in]d_APointer to the structured matrix A
[in]d_BPointer to the dense matrix B
[in]betascalar \(\beta\). (float)
[in]d_CPointer to the dense matrix C
[out]d_DPointer to the dense matrix D
[in]workspacePointor to the worksapce
[in]streamsPointer to HIP stream array for the computation
[in]numStreamsNumber of HIP streams in streams
Return values
HIPSPARSE_STATUS_SUCCESSthe operation completed successfully.
HIPSPARSE_STATUS_NOT_INITIALIZEDhandle or plan is invalid.
HIPSPARSE_STATUS_INVALID_VALUEhandle, plan alpha, d_A, d_B, beta, d_C , d_D , workspace streams or numStreams is invalid.
HIPSPARSE_STATUS_NOT_SUPPORTEDthe problme is not supported.

◆ hipsparseLtMatmulGetWorkspace()

hipsparseStatus_t hipsparseLtMatmulGetWorkspace ( const hipsparseLtHandle_t handle,
const hipsparseLtMatmulPlan_t plan,
size_t *  workspaceSize 
)

Determines the required workspace size.

hipsparseLtMatmulGetWorkspace determines the required workspace size associated to the selected algorithm.

Parameters
[in]handlehipsparselt library handle
[in]planthe matrix multiplication plan descriptor.
[out]workspaceSizeWorkspace size in bytes
Return values
HIPSPARSE_STATUS_SUCCESSthe operation completed successfully.
HIPSPARSE_STATUS_INVALID_VALUEhandle , algSelection or workspaceSize is invalid.

◆ hipsparseLtMatmulPlanDestroy()

hipsparseStatus_t hipsparseLtMatmulPlanDestroy ( const hipsparseLtMatmulPlan_t plan)

Destroy a matrix multiplication plan descriptor.

hipsparseLtMatmulPlanDestroy releases the resources used by an instance of the matrix multiplication plan. This function is the last call with a specific plan instance.

Parameters
[in]planthe matrix multiplication plan descriptor
Return values
HIPSPARSE_STATUS_SUCCESSthe operation completed successfully.
HIPSPARSE_STATUS_INVALID_VALUEplan is invalid.

◆ hipsparseLtMatmulPlanInit()

hipsparseStatus_t hipsparseLtMatmulPlanInit ( const hipsparseLtHandle_t handle,
hipsparseLtMatmulPlan_t plan,
const hipsparseLtMatmulDescriptor_t matmulDescr,
const hipsparseLtMatmulAlgSelection_t algSelection 
)

Initializes the matrix multiplication plan descriptor.

hipsparseLtMatmulPlanInit creates a matrix multiplication plan descriptor. It should be destroyed at the end using hipsparseLtMatmulPlanDestroy.

Parameters
[in]handlehipsparselt library handle
[out]planthe matrix multiplication plan descriptor
[in]matmulDescrthe matrix multiplication descriptor
[in]algSelectionthe algorithm selection descriptor
Return values
HIPSPARSE_STATUS_SUCCESSthe operation completed successfully.
HIPSPARSE_STATUS_INVALID_VALUEhandle , plan , matmulDescr , algSelection or workspaceSize is invalid. HIPSPARSELT_MAT_NUM_BATCHES from matrix A to D are inconisistent

◆ hipsparseLtMatmulSearch()

hipsparseStatus_t hipsparseLtMatmulSearch ( const hipsparseLtHandle_t handle,
hipsparseLtMatmulPlan_t plan,
const void *  alpha,
const void *  d_A,
const void *  d_B,
const void *  beta,
const void *  d_C,
void *  d_D,
void *  workspace,
hipStream_t *  streams,
int32_t  numStreams 
)

Sparse matrix dense matrix multiplication.

hipsparseLtMatmulSearch evaluates all available algorithms for the matrix multiplication and automatically updates the plan by selecting the fastest one. The functionality is intended to be used for auto-tuning purposes when the same operation is repeated multiple times over different inputs.

Note
This function's behavior is the same of hipsparseLtMatmul
d_C and d_D must be two different memory buffers, otherwise the output will be incorrect.
This function is NOT asynchronous with respect to streams[0] (blocking call)
The number of iterations for the evaluation can be set by using hipsparseLtMatmulAlgSetAttribute() with HIPSPARSELT_MATMUL_SEARCH_ITERATIONS.
The selected algorithm id can be retrieved by using
Parameters
[in]handlehipsparselt library handle
[in]planMatrix multiplication plan
[in]alphascalar \(\alpha\). (float)
[in]d_APointer to the structured matrix A
[in]d_BPointer to the dense matrix B
[in]betascalar \(\beta\). (float)
[in]d_CPointer to the dense matrix C
[out]d_DPointer to the dense matrix D
[in]workspacePointor to the worksapce
[in]streamsPointer to HIP stream array for the computation
[in]numStreamsNumber of HIP streams in streams
Return values
HIPSPARSE_STATUS_SUCCESSthe operation completed successfully.
HIPSPARSE_STATUS_NOT_INITIALIZEDhandle or plan is invalid.
HIPSPARSE_STATUS_INVALID_VALUEhandle, plan alpha, d_A, d_B, beta, d_C , d_D , workspace streams or numStreams is invalid.
HIPSPARSE_STATUS_NOT_SUPPORTEDthe problme is not supported.