gemm_bias

Computes a matrix-matrix product with general matrices.

Syntax

Buffer API

void gemm_bias(queue &exec_queue, transpose transa, transpose transb, offset offset_type, std::int64_t m, std::int64_t n, std::int64_t k, Ts alpha, buffer<Ta, 1> &a, std::int64_t lda, Ta ao, buffer<Tb, 1> &b, std::int64_t ldb, Tb bo, Ts beta, buffer<Tc, 1> &c, std::int64_t ldc, buffer<Tc, 1> &co)

USM API

event gemm_bias(queue &exec_queue, transpose transa, transpose transb, offset offset_type, std::int64_t m, std::int64_t n, std::int64_t k, Ts alpha, Ta *a, std::int64_t lda, Ta ao, Tb *b, std::int64_t ldb, Tb bo, Ts beta, Tc *c, std::int64_t ldc, Tc *co, const vector_class<event> &dependencies = {})

gemm_bias supports the following precisions and devices.

Ts

Ta

Tb

Tc

Devices Supported

float

int8_t

uint8_t

int32_t

Host, CPU, and GPU

float

int8_t

int8_t

int32_t

Host, CPU, and GPU

float

uint8_t

int8_t

int32_t

Host, CPU, and GPU

Description

The gemm_bias routines compute a scalar-matrix-matrix product and add the result to a scalar-matrix product, with general matrices. The operation is defined as:

C ← alpha*(op(A) - A_offset)*(op(B) - B_offset) + beta*C + C_offset

for the offset API where:

  • op(X) is one of op(X) = X, or op(X) = XT, or op(X) = XH

  • alpha and beta are scalars

  • A_offset is an m-by-k matrix with every element equal to the value ao

  • B_offset is a k-by-n matrix with every element equal to the value bo

  • C_offset is an m-by-n matrix defined by the co buffer as described in Data Types

  • A, B, and C are matrices

Here, op(A) is m x k, op(B) is k x n, and C is m x n.

Input Parameters

exec_queue

The queue where the routine should be executed.

transa

Specifies op(A), the transposition operation applied to A. See Data Types for more details.

transb

Specifies op(B), the transposition operation applied to B. See Data Types for more details.

offset_type

Specifies the form of C_offset used in the matrix multiplication. See Data Types for more details.

m

Number of rows of op(A) and C. Must be at least zero.

n

Number of columns of op(B) and C. Must be at least zero.

k

Number of columns of op(A) and rows of op(B). Must be at least zero.

alpha

Scaling factor for the matrix-matrix product.

a

Buffer holding the input matrix A.

If A is not transposed, A is an m-by-k matrix so the array a must have size at least lda*k (respectively, lda*m) if column (respectively, row) major layout is used to store matrices. If A is transposed, A is an k-by-m matrix so the array a must have size at least lda*m (respectively lda*k) if column (respectively, row) major is used to store matrices. See Matrix Storage for more details.

lda

Leading dimension of A. If matrices are stored using column major layout, lda must be at least m if A is not transposed, and at least k if A is transposed. If matrices are stored using row major layout, lda must be at least k if A is not transposed, and at least m if A is transposed. It must be positive.

ao

Specifies the scalar offset value for matrix A.

b

Buffer holding the input matrix B.

If B is not transposed, B is a k-by-n matrix so the array b must have size at least ldb*n (respectively, ldb*k) if column (respectively, row) major layout is used to store matrices. If B is transposed, B is an n-by-k matrix so the array b must have size at least ldb*k (respectively, ldb*n) if column (respectively, row) major is used to store matrices. See Matrix Storage for more details.

ldb

Leading dimension of B. If matrices are stored using column major layout, ldb must be at least k if B is not transposed, and m if B is transposed. If matrices are stored using row major layout, ldb must be at least n if B is not transposed, and at least k if B is transposed. It must be positive.

bo

Specifies the scalar offset value for matrix B.

beta

Scaling factor for matrix C.

c

Buffer holding the input matrix C. Must have size at least ldc * n. See Matrix Storage for more details.

ldc

Leading dimension of C. Must be positive and at least m.

co

Buffer holding the offset values for matrix C.

If offset_type = offset::fix, the co array must have size at least 1.

If offset_type = offset::col, the co array must have size at least max(1,m).

If offset_type = offset::row, the co array must have size at least max(1,n).

See Data Types for more details.

dependencies

List of events to wait for before starting computation, if any. If omitted, defaults to no dependencies.

Output Parameters

Buffer API

c

Output buffer, overwritten by alpha*op(A)*op(B) + beta*C for the standard API and alpha*(op(A) - A_offset)*(op(B) - B_offset) + beta*C + C_offset.

USM API

c

Output array, overwritten by alpha*op(A)*op(B) + beta*C for the standard API and alpha*(op(A) - A_offset)*(op(B) - B_offset) + beta*C + C_offset.

Notes

If beta = 0, matrix C does not need to be initialized before calling gemm_bias.