KokkosBlas::gemm¶
Defined in header: KokkosBlas3_gemm.hpp
template <class execution_space, class AViewType, class BViewType, class CViewType>
void gemm(const execution_space& space, const char transA[], const char transB[],
typename AViewType::const_value_type& alpha, const AViewType& A, const BViewType& B,
typename CViewType::const_value_type& beta, const CViewType& C);
template <class AViewType, class BViewType, class CViewType>
void gemm(const char transA[], const char transB[], typename AViewType::const_value_type& alpha, const AViewType& A,
const BViewType& B, typename CViewType::const_value_type& beta, const CViewType& C);
Perform a dense matrix-matrix multiplication
Iterate over the entries of
C, scale them withbeta, compute the corresponding dot product of a row ofAwith a column ofB, scale the result withalphaand accumulate back intoCusing the resources from thespaceinstance, orIterate over the entries of
C, scale them withbeta, compute the corresponding dot product of a row ofAwith a column ofB, scale the result withalphaand accumulate back intoCusing resources from the default instance oftypename CViewType::execution_space.
The function will throw a runtime exception if any of the following conditions are not met:
transAstores a valid control value, see below.transBstores a valid control value, see below.A.extent(1) == B.extent(0) && A.extent(0) == C.extent(0) && B.extent(1) == C.extent(1)
Parameters¶
- space:
execution space instance.
- transA, transB:
control parameters to apply transformations to
AandBrespectively, the accepted values are “N” for no transpose, “T” for transpose and “C” for conjugate transpose, all characters after the first one are ignored.- alpha, beta:
scaling parameters for
A*BandC, respectively.- A, B, C:
the two matrices to multiply and the matrix where the scaled multiplication values will be accumulated.
Type Requirements¶
execution_space must be a Kokkos execution space
AViewType must be a Kokkos View of rank 2 that satisfies
Kokkos::SpaceAccessibility<execution_space, typename AViewType::memory_space>::accessible
BViewType must be a Kokkos View of rank 2 that satisfies
Kokkos::SpaceAccessibility<execution_space, typename BViewType::memory_space>::accessible
CViewType must be a Kokkos View of rank 2 that satisfies
Kokkos::SpaceAccessibility<execution_space, typename CViewType::memory_space>::accessible
Example¶
#include<Kokkos_Core.hpp>
#include<KokkosBlas3_gemm.hpp>
int main(int argc, char* argv[]) {
Kokkos::initialize();
{
int M = atoi(argv[1]);
int N = atoi(argv[2]);
Kokkos::View<double**> A("A",M,N);
Kokkos::View<double**> B("B",N,M);
Kokkos::View<double**> C("C",M,M);
Kokkos::deep_copy(A,1.0);
Kokkos::deep_copy(B,2.0);
const double alpha = double(1.0);
const double beta = double(0.0);
KokkosBlas::gemm("N","N",alpha,A,B,beta,C);
}
Kokkos::finalize();
}