Rate This Document
Findability
Accuracy
Completeness
Readability

?hgemm

Compute the product of a general matrix and a matrix.

That is, .

The value of op(X) may be . alpha and beta are multiplication coefficients; op(A) is an m*k matrix; op(B) is a k*n matrix, and C is an m*n matrix.

Interface Definition

C interface:

void cblas_hgemm(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const BLASINT M, const BLASINT N, const BLASINT K, const __fp16 alpha, const __fp16 *A, const BLASINT lda, const __fp16 *B, const BLASINT ldb, const __fp16 beta, __fp16 *C, const BLASINT ldc);

void cblas_shgemm(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const BLASINT M, const BLASINT N, const BLASINT K, const float alpha, const __fp16 *A, const BLASINT lda, const __fp16 *B, const BLASINT ldb, const float beta, float *C, const BLASINT ldc);

void cblas_chgemm(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const BLASINT M, const BLASINT N, const BLASINT K, const void *alpha, const void *A, const BLASINT lda, const void *B, const BLASINT ldb, const void *beta, void *C, const BLASINT ldc);

void cblas_cshgemm(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, const BLASINT M, const BLASINT N, const BLASINT K, const void *alpha, const void *A, const BLASINT lda, const void *B, const BLASINT ldb, const void *beta, void *C, const BLASINT ldc);

Fortran interface:

CALL HGEMM(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)

CALL SHGEMM(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)

CALL CHGEMM(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)

CALL CSHGEMM(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)

Parameters

Parameter

Type

Description

Input/Output

order

Enumeration type CBLAS_ORDER

Whether the matrix is in row- or column-major order.

Input

TransA

Enumeration type CBLAS_TRANSPOSE

Whether matrix A is non-transposed, transposed, or conjugated.

  • If TransA = CblasNoTrans, .
  • If TransA = CblasTrans, .
  • If TransA = CblasConjTrans, .
  • If TransA = CblasConjTrans, .

Input

TransB

Enumeration type CBLAS_TRANSPOSE

Whether matrix B is non-transposed, transposed, or conjugated.

  • If TransB = CblasNoTrans, .
  • If TransB = CblasTrans, .
  • If TransB = CblasConjTrans, .
  • If TransB = CblasConjTrans, .

Input

M

Integer

Number of rows in matrices op(A) and C.

Input

N

Integer

Number of columns in matrices op(B) and C.

Input

K

Integer

Number of columns in matrix op(A) and number of rows in matrix op(B).

Input

alpha

  • Half-precision floating-point type for hgemm
  • Single-precision floating-point type for shgemm
  • Half-precision complex type for chgemm
  • Single-precision complex type for cshgemm

Multiplication coefficient.

Input

A

  • Half-precision floating-point type for hgemm
  • Half-precision floating-point type for shgemm
  • Half-precision complex type for chgemm
  • Half-precision complex type for cshgemm

Matrix A.

Input

lda

Integer

  • For a column-store matrix with TransA = CblasNoTrans, lda must be at least max(1, m); otherwise, lda must be at least max(1, k).
  • For a row-store matrix with TransA = CblasNoTrans, lda must be at least max(1, k); otherwise, lda must be at least max(1, m).

Input

B

  • Half-precision floating-point type for hgemm
  • Half-precision floating-point type for shgemm
  • Half-precision complex type for chgemm
  • Half-precision complex type for cshgemm

Matrix B.

Input

ldb

Integer

  • For a column-store matrix with TransB = CblasNoTrans, ldb must be at least max(1, k); otherwise, ldb must be at least max(1, n).
  • For a row-store matrix with TransB = CblasNoTrans, ldb must be at least max(1, n); otherwise, ldb must be at least max(1, k).

Input

beta

  • Half-precision floating-point type for hgemm
  • Single-precision floating-point type for shgemm
  • Half-precision complex type for chgemm
  • Single-precision complex type for cshgemm

Multiplication coefficient.

Input

C

  • Half-precision floating-point type for hgemm
  • Single-precision floating-point type for shgemm
  • Half-precision complex type for chgemm
  • Single-precision complex type for cshgemm

Matrix C.

Input/Output

ldc

Integer

For a column-store matrix, ldc must be at least max(1, m); otherwise, ldc must be at least max(1, n).

Input

Dependencies

#include "kblas.h"

Examples

C interface:

    int m = 4, k = 3, n = 4, lda = 4, ldb = 3, ldc = 4;  
    __fp16 alpha = 1.0, beta = 2.0;  
     /*  
     * A:  
     *     0.340188,       0.411647,       -0.222225,  
     *     -0.105617,      -0.302449,      0.053970,  
     *     0.283099,       -0.164777,      -0.022603,  
     *     0.298440,       0.268230,       0.128871,  
     * B:  
     *     -0.135216,      0.416195,       -0.358397,      -0.257113,  
     *     0.013401,       0.135712,       0.106969,       -0.362768,  
     *     0.452230,       0.217297,       -0.483699,      0.304177,  
     * C:  
     *     -0.343321,      0.498924,       0.112640,       -0.006417,  
     *     -0.099056,      -0.281743,      -0.203968,      0.472775,  
     *     -0.370210,      0.012932,       0.137552,       -0.207483,  
     *     -0.391191,      0.339112,       0.024287,       0.271358,  
     */  
    __fp16 a[12] = {0.340188, -0.105617, 0.283099,  
                    0.298440, 0.411647, -0.302449,  
                    -0.164777, 0.268230, -0.222225,  
                    0.053970, -0.022603, 0.128871};  
    __fp16 b[12] = {-0.135216, 0.013401, 0.452230, 0.416195,  
                    0.135712, 0.217297, -0.358397, 0.106969,  
                    -0.483699, -0.257113, -0.362768, 0.304177};  
    __fp16 c[16] = {-0.343321, -0.099056, -0.370210, -0.391191,  
                    0.498924, -0.281743, 0.012932, 0.339112,  
                    0.112640, -0.203968, 0.137552, 0.024287,  
                    -0.006417, 0.472775, -0.207483, 0.271358};  
  
    cblas_hgemm(CblasColMajor,CblasNoTrans,CblasNoTrans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);  
    /*  
     * Output C:  
     *     -0.827621       1.147010        0.254881        -0.317229  
     *     -0.163476       -0.636762       -0.428542       1.098841  
     *     -0.791128       0.116416        0.166949        -0.434854  
     *     -0.760862       0.866839        -0.092028       0.407877  
     *  
     */

Fortran interface:

      INTEGER :: M=4, K=3, N=4  
      INTEGER :: LDA=4, LDB=3, LDC=4  
      REAL(4) :: ALPHA=1.0, BETA=2.0  
      REAL(4) :: A(12), B(12), C(16)  
      DATA A/0.340188, -0.105617, 0.283099,  
     $       0.298440, 0.411647, -0.302449,  
     $       -0.164777, 0.268230, -0.222225,  
     $       0.053970, -0.022603, 0.128871/  
      DATA B/-0.135216, 0.013401, 0.452230, 0.416195,  
     $       0.135712, 0.217297, -0.358397, 0.106969,  
     $       -0.483699, -0.257113, -0.362768, 0.304177/  
      DATA C/-0.343321, -0.099056, -0.370210, -0.391191,  
     $       0.498924, -0.281743, 0.012932, 0.339112,  
     $       0.112640, -0.203968, 0.137552, 0.024287,  
     $       -0.006417, 0.472775, -0.207483, 0.271358/  
      EXTERNAL HGEMM  
      CALL HGEMM('N', 'N', M, N, K, ALPHA, A, LDA, B, LDB, BETA, C,  
     $          LDC)  
*     Output C:  
*         -0.827621       1.147010        0.254881        -0.317229  
*         -0.163476       -0.636762       -0.428542       1.098841  
*         -0.791128       0.116416        0.166949        -0.434854  
*         -0.760862       0.866839        -0.092028       0.407877