Rate This Document
Findability
Accuracy
Completeness
Readability

?gemm_pack

Perform the pack operation on a matrix and store it in the allocated buffer.

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_sgemm_pack(const enum CBLAS_ORDER order, const enum CBLAS_IDENTIFIER identifier, const enum CBLAS_TRANSPOSE trans, const BLASINT m, const BLASINT n, const BLASINT k, const float *src, const BLASINT ld, float *dst);

void cblas_dgemm_pack(const enum CBLAS_ORDER order, const enum CBLAS_IDENTIFIER identifier, const enum CBLAS_TRANSPOSE trans, const BLASINT m, const BLASINT n, const BLASINT k, const double *src, const BLASINT ld, double *dst);

void cblas_cgemm_pack(const enum CBLAS_ORDER order, const enum CBLAS_IDENTIFIER identifier, const enum CBLAS_TRANSPOSE trans, const BLASINT m, const BLASINT n, const BLASINT k, const void *src, const BLASINT ld, void *dst);

void cblas_zgemm_pack(const enum CBLAS_ORDER order, const enum CBLAS_IDENTIFIER identifier, const enum CBLAS_TRANSPOSE trans, const BLASINT m, const BLASINT n, const BLASINT k, const void *src, const BLASINT ld, void *dst);

void cblas_bgemm_pack(const enum CBLAS_ORDER order, const enum CBLAS_IDENTIFIER identifier, const enum CBLAS_TRANSPOSE trans, const BLASINT m, const BLASINT n, const BLASINT k, const __bf16 *src, const BLASINT ld, __bf16 *dst);

void cblas_sbgemm_pack(const enum CBLAS_ORDER order, const enum CBLAS_IDENTIFIER identifier, const enum CBLAS_TRANSPOSE trans, const BLASINT m, const BLASINT n, const BLASINT k, const __bf16 *src, const BLASINT ld, __bf16 *dst);

Parameters

Parameter

Type

Description

Input/Output

order

Enumeration type CBLAS_ORDER

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

Input

identifier

Enumeration type CBLAS_IDENTIFIER

Matrix to be packed.

  • If identifier = CblasA, pack matrix A.
  • If identifier = CblasB, pack matrix B.

Input

trans

Enumeration type CBLAS_TRANSPOSE

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

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

Whether matrix B is a conventional matrix or a transposed 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

src

  • Single-precision floating-point type for sgemm.
  • Double-precision floating-point type for dgemm.
  • Single-precision complex type for cgemm.
  • Double-precision complex type for zgemm.
  • Half-precision floating-point type for bgemm.

Matrix A/B.

Input

ld

Integer

  • For column-major matrices, if identifier = CblasA and trans = CblasNoTrans, ld must be at least max(1, m); otherwise, it must be at least max(1, k).
  • For row-major matrices, if identifier = CblasA and trans = CblasNoTrans, ld must be at least max(1, k); otherwise, it must be at least max(1, m).
  • For column-major matrices, if identifier = CblasB and trans = CblasNoTrans, ld must be at least max(1, k); otherwise, it must be at least max(1, n).
  • For row-major matrices, if identifier = CblasB and trans = CblasNoTrans, ld must be at least max(1, n); otherwise, it must be at least max(1, k).

Input

dst

  • Single-precision floating-point type for sgemm.
  • Double-precision floating-point type for dgemm.
  • Single-precision complex type for cgemm.
  • Double-precision complex type for zgemm.
  • Half-precision floating-point type for bgemm.

Packed matrix A/B.

Input/Output

Dependency

#include "kblas.h"

Examples

C interface:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    int m = 4, k = 3, n = 4, ld = 4; 
     /* 
     * src: 
     *     0.340188,       0.411647,       -0.222225, 
     *     -0.105617,      -0.302449,      0.053970, 
     *     0.283099,       -0.164777,      -0.022603, 
     *     0.298440,       0.268230,       0.128871, 
     */ 
    float src[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}; 
    size_t size = cblas_sgemm_pack_get_size(CblasA, m, n, k);
    float *dst = (float *)malloc(size);
    cblas_sgemm_pack(CblasColMajor, CblasA, CblasTrans, m, n, k, src, ld, dst); 
    free(dst);
    /* 
     * Output dst: 
     *     0.340188       -0.105617        0.283099        0.298440 
     *     0.411647       -0.302449       -0.164777        0.268230 
     *    -0.222225        0.053970       -0.022603        0.128871
     */