Skip to content

Commit

Permalink
Blas GEMM: fix early exit logic, see issue #1088
Browse files Browse the repository at this point in the history
The GEMM algorithm should perform a quick return
if C is empty, otherwise if A and/or B are empty
a simple scaling of C by beta can be performed
before exiting.
  • Loading branch information
lucbv committed Sep 1, 2021
1 parent dc6d57e commit fe451e9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/blas/KokkosBlas3_gemm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <KokkosKernels_Macros.hpp>
#include <KokkosBlas3_gemm_spec.hpp>
#include <KokkosBlas2_gemv.hpp>
#include <KokkosBlas1_scal.hpp>
#include <KokkosKernels_helpers.hpp>
#include <sstream>
#include <type_traits>
Expand Down Expand Up @@ -199,15 +200,22 @@ gemm (const char transA[],
}
#endif // KOKKOSKERNELS_DEBUG_LEVEL > 0

// Return if degenerated matrices are provided
if((A.extent(0) == 0) || (A.extent(1) == 0) || (C.extent(1) == 0))
// Return if C matrix is degenerated
if((C.extent(0) == 0) || (C.extent(1) == 0)) {
return;
}

// Simply scale C if A matrix is degenerated
if(A.extent(1) == 0) {
scal(C, beta, C);
return;
}

// Check if gemv code path is allowed and profitable, and if so run it.
if(Impl::gemv_based_gemm(transA, transB, alpha, A, B, beta, C))
return;

// Minimize the number of Impl::GEMV instantiations, by
// Minimize the number of Impl::GEMM instantiations, by
// standardizing on particular View specializations for its template
// parameters.
typedef Kokkos::View<typename AViewType::const_value_type**,
Expand Down

0 comments on commit fe451e9

Please sign in to comment.