gemm
Computes a matrix-matrix product with general matrices.
Description
The
gemm
routines compute a scalar-matrix-matrix product and add the result to a scalar-matrix product, with general matrices.
The operation is defined as:
where:
- op(X) is one of op(X) =X, or op(X) =XT, or op(X) =XH
- alphaandbetaare scalars
- A,BandCare matrices
- op(A) ismxkmatrix
- op(B) iskxnmatrix
- Cismxnmatrix
gemm
supports the following precisions:Ts | Ta | Tb | Tc |
---|---|---|---|
sycl::half | sycl::half | sycl::half | sycl::half |
float | sycl::half | sycl::half | float |
float | oneapi::mkl::bfloat16 | oneapi::mkl::bfloat16 | float |
float | float | float | float |
double | double | double | double |
std::complex<float> | std::complex<float> | std::complex<float> | std::complex<float> |
std::complex<double> | std::complex<double> | std::complex<double> | std::complex<double> |
gemm (Buffer Version)
Syntax
namespace oneapi::mkl::blas::column_major {
void gemm(sycl::queue &queue,
oneapi::mkl::transpose transa,
oneapi::mkl::transpose transb,
std::int64_t m,
std::int64_t n,
std::int64_t k,
Ts alpha,
sycl::buffer<Ta,1> &a,
std::int64_t lda,
sycl::buffer<Tb,1> &b,
std::int64_t ldb,
Ts beta,
sycl::buffer<Tc,1> &c,
std::int64_t ldc)
}
namespace oneapi::mkl::blas::row_major {
void gemm(sycl::queue &queue,
oneapi::mkl::transpose transa,
oneapi::mkl::transpose transb,
std::int64_t m,
std::int64_t n,
std::int64_t k,
Ts alpha,
sycl::buffer<Ta,1> &a,
std::int64_t lda,
sycl::buffer<Tb,1> &b,
std::int64_t ldb,
Ts beta,
sycl::buffer<Tc,1> &c,
std::int64_t ldc)
}
Input Parameters
- queue
- The queue where the routine should be executed.
- transa
- transb
- m
- Number of rows of matrix op(A) and matrixC. Must be at least zero.
- n
- Number of columns of matrix op(B) and matrixC. Must be at least zero.
- k
- Number of columns of matrix op(A) and rows of matrix op(B). Must be at least zero.
- alpha
- Scaling factor for matrix-matrix product.
- a
- Buffer holding input matrixA. See Matrix Storage for more details.transa=transpose::nontranstransa=transpose::transortrans=transpose::conjtransColumn majorAismxkmatrix. Size of arrayamust be at leastlda*kAiskxmmatrix. Size of arrayamust be at leastlda*mRow majorAismxkmatrix. Size of arrayamust be at leastlda*mAiskxmmatrix. Size of arrayamust be at leastlda*k
- lda
- Leading dimension of matrixA. Must be positive.transa=transpose::nontranstransa=transpose::transortrans=transpose::conjtransColumn majorMust be at leastmMust be at leastkRow majorMust be at leastkMust be at leastm
- b
- Buffer holding input matrixB. See Matrix Storage for more details.transb=transpose::nontranstransb=transpose::transortrans=transpose::conjtransColumn majorBiskxnmatrix. Size of arraybmust be at leastldb*nBisnxkmatrix. Size of arraybmust be at leastldb*kRow majorBiskxnmatrix. Size of arraybmust be at leastldb*kBisnxkmatrix. Size of arraybmust be at leastldb*n
- ldb
- Leading dimension of matrixB. Must be positive.transb=transpose::nontranstransb=transpose::transortrans=transpose::conjtransColumn majorMust be at leastkMust be at leastnRow majorMust be at leastnMust be at leastk
- beta
- Scaling factor for matrixC.
- c
- Buffer holding input/output matrixC. See Matrix Storage for more details.Column majorCismxnmatrix. Size of arraycmust be at leastldc*nRow majorCismxnmatrix. Size of arraycmust be at leastldc*m
- ldc
- Leading dimension of matrixC. Must be positive.Column majorMust be at leastmRow majorMust be at leastn
Output Parameters
- c
- Output buffer overwritten byalpha* op(A)*op(B) +beta*C.
If
beta
= 0, matrix C
does not need to be initialized before calling gemm
. Examples
An example of how to use buffer version of
gemm
can be found in oneMKL installation directory, under:examples/dpcpp/blas/source/gemm.cpp
gemm (USM Version)
Syntax
namespace oneapi::mkl::blas::column_major {
sycl::event gemm(sycl::queue &queue,
oneapi::mkl::transpose transa,
oneapi::mkl::transpose transb,
std::int64_t m,
std::int64_t n,
std::int64_t k,
Ts alpha,
const Ta *a,
std::int64_t lda,
const Tb *b,
std::int64_t ldb,
Ts beta,
Tc *c,
std::int64_t ldc,
const std::vector<sycl::event> &dependencies = {})
}
namespace oneapi::mkl::blas::row_major {
sycl::event gemm(sycl::queue &queue,
oneapi::mkl::transpose transa,
oneapi::mkl::transpose transb,
std::int64_t m,
std::int64_t n,
std::int64_t k,
Ts alpha,
const Ta *a,
std::int64_t lda,
const Tb *b,
std::int64_t ldb,
Ts beta,
Tc *c,
std::int64_t ldc,
const std::vector<sycl::event> &dependencies = {})
}
Input Parameters
- queue
- The queue where the routine should be executed.
- transa
- transb
- m
- Number of rows of matrix op(A) and matrixC. Must be at least zero.
- n
- Number of columns of matrix op(B) and matrixC. Must be at least zero.
- k
- Number of columns of matrix op(A) and rows of matrix op(B). Must be at least zero.
- alpha
- Scaling factor for matrix-matrix product.
- a
- Pointer to input matrixA. See Matrix Storage for more details.Anot transposedAtransposedColumn majorAismxkmatrix. Size of arrayamust be at leastlda*kAiskxmmatrix. Size of arrayamust be at leastlda*mRow majorAismxkmatrix. Size of arrayamust be at leastlda*mAiskxmmatrix. Size of arrayamust be at leastlda*k
- lda
- Leading dimension of matrixA. Must be positive.Anot transposedAtransposedColumn majorMust be at leastmMust be at leastkRow majorMust be at leastkMust be at leastm
- b
- Pointer to input matrixB. See Matrix Storage for more details.Bnot transposedBtransposedColumn majorBiskxnmatrix. Size of arraybmust be at leastldb*nBisnxkmatrix. Size of arraybmust be at leastldb*kRow majorBiskxnmatrix. Size of arraybmust be at leastldb*kBisnxkmatrix. Size of arraybmust be at leastldb*n
- ldb
- Leading dimension of matrixB. Must be positive.Bnot transposedBtransposedColumn majorMust be at leastkMust be at leastnRow majorMust be at leastnMust be at leastk
- beta
- Scaling factor for matrixC.
- c
- Pointer to input/output matrixC. See Matrix Storage for more details.Column majorCismxnmatrix. Size of arraycmust be at leastldc*nRow majorCismxnmatrix. Size of arraycmust be at leastldc*m
- ldc
- Leading dimension of matrixC. Must be positive.Column majorMust be at leastmRow majorMust be at leastn
- dependencies
- List of events to wait for before starting computation, if any. If omitted, defaults to no dependencies.
Output Parameters
- c
- Pointer to output matrix overwritten byalpha* op(A)*op(B) +beta*C.
If
beta
= 0, matrix C
does not need to be initialized before calling gemm
. Return Values
Output event to wait on to ensure computation is complete.
Examples
An example of how to use USM version of
gemm
can be found in oneMKL installation directory, under:examples/dpcpp/blas/source/gemm_usm.cpp