Skip to content

Commit

Permalink
Added some comments & doc
Browse files Browse the repository at this point in the history
  • Loading branch information
OuadiElfarouki authored and s-Nick committed Jun 14, 2023
1 parent ba200e1 commit d2587d7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
31 changes: 26 additions & 5 deletions include/interface/extension_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,37 @@ typename sb_handle_t::event_t _omatcopy2(sb_handle_t& sb_handle, char trans,
ld_in, inc_in, out_memory, ld_out, inc_out);
}

/**
* \brief Computes scaled addition of two matrices A & B with or without
* transpose and copying results back to an output matrix C.
*
* @tparam sb_handle_t SB_Handle type
* @tparam element_t Undelying element data type of the matrix container
* @tparam index_t Index type
* @tparam container_t Inputs/Output Container Type
* @param trans_a Apply or not matrix transpose to A.
* @param trans_b Apply or not matrix transpose to B.
* @param m Number of rows in output matrix C
* @param n Number of columns in output matrix C
* @param alpha Scaling factor of matrix A
* @param A Container Input matrix A
* @param lda Matrix A leading dimension
* @param beta scaling factor of matrix B
* @param B Container Input matrix B
* @param ldb Matrix B leading dimension
* @param C Container Output matrix C
* @param ldc Matrix C leading dimension
*/
template <typename sb_handle_t, typename element_t, typename index_t,
typename container_t>
typename sb_handle_t::event_t _omatadd(sb_handle_t& sb_handle, char trans_a,
char trans_b, index_t m, index_t n,
element_t alpha, container_t a,
element_t alpha, container_t A,
index_t lda, element_t beta,
container_t b, index_t ldb,
container_t c, index_t ldc) {
return internal::_omatadd(sb_handle, trans_a, trans_b, m, n, alpha, a, lda,
beta, b, ldb, c, ldc);
container_t B, index_t ldb,
container_t C, index_t ldc) {
return internal::_omatadd(sb_handle, trans_a, trans_b, m, n, alpha, A, lda,
beta, B, ldb, C, ldc);
}

/**
Expand Down
57 changes: 37 additions & 20 deletions test/unittest/extension/omatadd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@
using index_t = int;
namespace reference_blas {

// blas-like extension omatAdd used as wrapper around omatcopy
/**
* @brief Reference omat-add implementation using reference omatcopy.
*
* @param trans_a (char) 'n' or 't' corresponding to non-transposed or
* transposed matrix A respectively.
* @param trans_b (char) 'n' or 't' corresponding to non-transposed or
* transposed matrix B respectively.
* @param m Number of rows in output matrix C
* @param n Number of columns in output matrix C
* @param alpha Scaling factor of matrix A
* @param A (vector) Input matrix A
* @param lda_m Matrix A leading dimension multiplier. (lda = lda_m * A_rows)
* @param beta scaling factor of matrix B
* @param B (vector) Input matrix B
* @param ldb_m Matrix B leading dimension multiplier. (ldb = ldb_m * B_rows)
* @param C (vector) Output matrix C
* @param ldc_m Matrix C leading dimension multiplier. (ldc = ldc_m * C_rows)
*/
template <typename scalar_t>
void omatadd(const char trans_a, const char trans_b, const index_t m,
const index_t n, const scalar_t alpha, std::vector<scalar_t> &a,
const index_t lda_m, const scalar_t beta, std::vector<scalar_t> &b,
const index_t ldb_m, std::vector<scalar_t> &c,
const index_t n, const scalar_t alpha, std::vector<scalar_t> &A,
const index_t lda_m, const scalar_t beta, std::vector<scalar_t> &B,
const index_t ldb_m, std::vector<scalar_t> &C,
const index_t ldc_m) {
const index_t a_rows = trans_a == 't' ? n : m;
const index_t a_cols = trans_a == 't' ? m : n;
Expand All @@ -42,27 +59,26 @@ void omatadd(const char trans_a, const char trans_b, const index_t m,

index_t ldc = ldc_m * m;

// Temp Matrix 1 for computing a -> alpha * op(A)
// Temp Matrix 1 for computing A -> alpha * op(A)
std::vector<scalar_t> TempMatrix1(ldc * n, 0);
omatcopy(trans_a, a_rows, a_cols, alpha, a.data(), lda_m * a_rows,
omatcopy(trans_a, a_rows, a_cols, alpha, A.data(), lda_m * a_rows,
TempMatrix1.data(), ldc);
// Temp Matrix 2 for computing b -> beta * op(B)
// Temp Matrix 2 for computing B -> beta * op(B)
std::vector<scalar_t> TempMatrix2(ldc * n, 0);
omatcopy(trans_b, b_rows, b_cols, beta, b.data(), ldb_m * b_rows,
omatcopy(trans_b, b_rows, b_cols, beta, B.data(), ldb_m * b_rows,
TempMatrix2.data(), ldc);

// Compute Sum of Temp matrices -> c
// Compute Sum of Temp matrices -> C
for (index_t j = 0; j < n; j++) {
for (index_t i = 0; i < m; i++) {
c.at(i + j * ldc) =
C.at(i + j * ldc) =
TempMatrix1.at(i + j * ldc) + TempMatrix2.at(i + j * ldc);
}
}
}

} // namespace reference_blas

// Parameters : trans_a, trans_b, m, n, alpha, beta, lda_m, ldb_m, ldc_m
template <typename scalar_t>
using combination_t =
std::tuple<char, char, int, int, scalar_t, scalar_t, int, int, int>;
Expand Down Expand Up @@ -118,15 +134,16 @@ void run_test(const combination_t<scalar_t> combi) {
}

template <typename scalar_t>
const auto combi = ::testing::Combine(::testing::Values<char>('n', 't'),
::testing::Values<char>('n', 't'),
::testing::Values<index_t>(16, 33, 63),
::testing::Values<index_t>(16, 33, 63),
::testing::Values<scalar_t>(0, 1, 2),
::testing::Values<scalar_t>(0, 1, 2),
::testing::Values<index_t>(1, 2),
::testing::Values<index_t>(1, 2),
::testing::Values<index_t>(1, 2, 3));
const auto combi =
::testing::Combine(::testing::Values<char>('n', 't'), // trans_a
::testing::Values<char>('n', 't'), // trans_b
::testing::Values<index_t>(64, 129, 255), // m
::testing::Values<index_t>(64, 129, 255), // n
::testing::Values<scalar_t>(0, 1, 2), // alpha
::testing::Values<scalar_t>(0, 1, 2), // beta
::testing::Values<index_t>(1, 2), // lda_mul
::testing::Values<index_t>(1, 2), // ldb_mul
::testing::Values<index_t>(1, 2, 3)); // ldc_mul

template <class T>
static std::string generate_name(
Expand Down

0 comments on commit d2587d7

Please sign in to comment.