Rate This Document
Findability
Accuracy
Completeness
Readability

gemm_?8?8s32_compute

Perform general matrix multiplication on the packed A/B 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_gemm_s8s8s32_compute(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_s8u8s32_compute(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_u8u8s32_compute(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_u8s8s32_compute(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);

Parameters

Parameter

Type

Description

Input/Output

order

Enumeration type CBLAS_ORDER

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

Input

TransA

Enumeration type CBLAS_TRANSPOSE

Whether matrix A is a conventional matrix, a transposed matrix, or a conjugate matrix.

  • If trans = CblasNoTrans, .
  • If trans = CblasTrans, .

Input

TransB

Enumeration type CBLAS_TRANSPOSE

Whether matrix B is a conventional matrix, a transposed matrix, or a conjugate matrix.

  • If trans = CblasNoTrans, .
  • If trans = CblasTrans, .

Input

M

Integer

Number of rows of matrix op(A) and matrix C.

Input

N

Integer

Number of columns of matrix op(B) and matrix C.

Input

K

Integer

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

Input

alpha

  • Single-precision floating-point type.

Multiplication coefficient.

Input

A

  • The type is int8 in gemm_s8?8s32.
  • The type is uint8 in gemm_u8?8s32.

Matrix A.

Input

lda

Integer

  • For column-major matrices, if TransA = CblasNoTrans, lda must be at least max(1, m); otherwise, it must be at least max(1, k).
  • For row-major matrices, if TransA = CblasNoTrans, lda must be at least max(1, k); otherwise, it must be at least max(1, m).

Input

B

  • The type is int8 in gemm_?8s8s32.
  • The type is uint8 in gemm_?8u8s32.

Matrix B.

Input

ldb

Integer

  • For column-major matrices, if TransB = CblasNoTrans, ldb must be at least max(1, k); otherwise, it must be at least max(1, n).
  • For row-major matrices, if TransB = CblasNoTrans, ldb must be at least max(1, n); otherwise, it must be at least max(1, k).

Input

beta

  • Single-precision floating-point type.

Multiplication coefficient.

Input

C

  • int type

Matrix C.

Input/Output

ldc

Integer

For column-major matrices, ldc must be at least max(1, m); otherwise, it must be at least max(1, n).

Input

Dependency

#include "kblas.h"

Examples

void test_igemm_compute(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE transA, const enum CBLAS_TRANSPOSE transB, BLASINT row, BLASINT col)
{
    BLASUINT8 *a = (BLASUINT8 *)malloc(sizeof(BLASUINT8) * row * col);
    BLASINT8 *b = (BLASINT8 *)malloc(sizeof(BLASINT8) * col * row);
    int32_t *c = (int32_t *)malloc(sizeof(int32_t) * row * row);
    for (int i = 0; i < row * col; i++) {
        a[i] = i;
        b[i] = i;
    }
    for (int i = 0; i < row * row; i++) {
        c[i] = i;
    }
    BLASINT m = row;
    BLASINT n = row;
    BLASINT k = col;
    BLASINT lda, ldb, ldc = m;
    size_t size_a = cblas_gemm_s8u8s32_pack_get_size(CblasA, m, n, k);
    size_t size_b = cblas_gemm_s8u8s32_pack_get_size(CblasB, m, n, k);
    BLASUINT8 *sa = (BLASUINT8 *)malloc(size_a);
    BLASINT8 *sb = (BLASINT8 *)malloc(size_b);
    if (order == CblasColMajor) {
        if (transA == CblasNoTrans) {
            lda = m;
        } else {
            lda = k;
        }
        if (transB == CblasNoTrans) {
            ldb = k;
        } else {
            ldb = n;
        }
    } else { // CblasRowMajor
        if (transA == CblasNoTrans) {
            lda = k;
        } else {
            lda = m;
        }
        if (transB == CblasNoTrans) {
            ldb = n;
        } else {
            ldb = k;
        }
    }
    float alpha = 2.0;
    float beta = 3.0;
    cblas_gemm_s8u8s32_pack(order, CblasA, transA, m, n, k, a, lda, sa);
    cblas_gemm_s8u8s32_pack(order, CblasB, transB, m, n, k, b, ldb, sb);
    int oc = 3;
    cblas_gemm_u8s8s32_compute(order, transA, transB, CblasFixOffset, m, n, k, alpha, sa, lda, 0, sb, ldb, 0, beta, c, ldc, &oc);
 
    free(a);
    free(b);
    free(c);
    free(sa);
    free(sb);
}