Rate This Document
Findability
Accuracy
Completeness
Readability

gemm_?8?8s32

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.

A_offset is a scalar of fixed type int8_t. A_offset is added to all elements in op(A).

B_offset is a scalar of fixed type int8_t. B_offset is added to all elements in op(B).

C_offset has three definitions (the element type is int32_t):

  • A scalar. C_offset is added to each element in matrix C.
  • A row vector. C_offset is added to each row in matrix C.
  • A column vector. C_offset is added to each column in matrix C.

Interface Definition

C interface:

void cblas_gemm_s8s8s32(

const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const CBLAS_OFFSET offsetc,

const BLASINT m, const BLASINT n, const BLASINT k, const float alpha,

const BLASINT8 *a, const BLASINT lda, const BLASINT8 oa,

const BLASINT8 *b, const BLASINT ldb, const BLASINT8 ob,

const float beta, int32_t *c, const BLASINT ldc, const int32_t *oc);

void cblas_gemm_u8u8s32(

const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const CBLAS_OFFSET offsetc,

const BLASINT m, const BLASINT n, const BLASINT k, const float alpha,

const BLASUINT8 *a, const BLASINT lda, const BLASINT8 oa,

const BLASUINT8 *b, const BLASINT ldb, const BLASINT8 ob,

const float beta, int32_t *c, const BLASINT ldc, const int32_t *oc);

void cblas_gemm_s8u8s32(

const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const CBLAS_OFFSET offsetc,

const BLASINT m, const BLASINT n, const BLASINT k, const float alpha,

const BLASINT8 *a, const BLASINT lda, const BLASINT8 oa,

const BLASUINT8 *b, const BLASINT ldb, const BLASINT8 ob,

const float beta, int32_t *c, const BLASINT ldc, const int32_t *oc);

void cblas_gemm_u8s8s32(

const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE transa, const CBLAS_TRANSPOSE transb, const CBLAS_OFFSET offsetc,

const BLASINT m, const BLASINT n, const BLASINT k, const float alpha,

const BLASUINT8 *a, const BLASINT lda, const BLASINT8 oa,

const BLASINT8 *b, const BLASINT ldb, const BLASINT8 ob,

const float beta, int32_t *c, const BLASINT ldc, const int32_t *oc);

Fortran interface:

int8 gemm has no Fortran interface.

Parameters

Parameter

Type

Description

Input/Output

layout

Enumeration type CBLAS_LAYOUT

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

  • If layout = CblasRowMajor, it indicates the row-major order.
  • If layout = CblasColMajor, it indicates the column-major order.

Input

transa

Enumeration type CBLAS_TRANSPOSE

Whether matrix A is non-transposed or transposed.

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

Input

transb

Enumeration type CBLAS_TRANSPOSE

Whether matrix B is non-transposed or transposed.

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

Input

offsetc

Enumeration type CBLAS_OFFSET

Whether the oc parameter (C_offset defined in GEMM) is a row vector, column vector, or scalar.

  • If offsetc = CblasRowOffset, C_offset is a row vector.
  • If offsetc = CblasColOffset, C_offset is a column vector.
  • If offsetc = CblasFixOffset, C_offset is a scalar.

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

Single-precision floating-point type

Multiplication coefficient.

Input

A

  • int8_t for gemm_s8s8s32
  • uint8_t for gemm_u8u8s32
  • int8_t for gemm_s8u8s32
  • uint8_t for gemm_u8s8s32

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

oa

int8_t

Value of A_offset defined in GEMM.

Input

B

  • int8_t for gemm_s8s8s32
  • uint8_t for gemm_u8u8s32
  • uint8_t for gemm_s8u8s32
  • int8_t for gemm_u8s8s32

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

ob

int8_t

Value of B_offset defined in GEMM.

Input

beta

Single-precision floating-point type

Multiplication coefficient.

Input

C

int32_t

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

oc

int32_t

Value of C_offset defined in GEMM.

  • When the value of offsetc is CblasRowOffset, this input represents a row vector.
  • When the value of offsetc is CblasColOffset, this input represents a column vector.
  • When the value of offsetc is CblasFixOffset, this input represents a scalar.

Input

Dependencies

#include "kblas.h"

Examples

C interface:
    int m = 4, k = 3, n = 4, lda = 4, ldb = 3, ldc = 4; 
    float alpha = 1.0, beta = 2.0;
 
    int8_t oa=3, ob=5;
    CBLAS_OFFSET offsetc = CblasRowOffset;
    int32_t oc[] = {1, 2, 3, 4};

     /* 
     * A: 
     *     35,      39,     27, 
     *     38,      55,     40, 
     *     46,      35,     41, 
     *     54,      55,     24, 
     * B: 
     *     35,       54,       35,       40, 
     *     38,       39,       55,       41, 
     *     46,       55,       27,       24, 
     * C: 
     *     7,      7,      7,      7, 
     *     7,      7,      7,      7, 
     *     7,      7,      7,      7, 
     *     7,      7,      7,      7, 
     */ 
    int8_t a[12] = {35, 38, 46, 54,
                    39, 55, 35, 55,
                    27, 40, 41, 24};
    int8_t b[12] = {35, 38, 46,
                    54, 39, 55,
                    35, 55, 27,
                    40, 41, 24};
    int32_t c[16] = {7, 7, 7, 7, 
                    7, 7, 7, 7, 
                    7, 7, 7, 7, 
                    7, 7, 7, 7}; 

    cblas_gemm_s8s8s32(CblasColMajor, CblasNoTrans, CblasNoTrans, offsetc,
        m, n, k, alpha, 
        a, lda, oa,
        b, ldb, ob,
        beta, c, ldc, oc);
    /* 
     * Output C: 
     *     4871 5906 5017 4530
     *     6342 7567 6513 5778
     *     5853 7219 5665 5247
     *     6166 7551 6641 6034
     * 
     */