Skip to content

Commit

Permalink
refactor test_scal.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Guglielmo Gagliardi committed Dec 13, 2023
1 parent 399d9da commit 0cd2bd7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 44 deletions.
9 changes: 4 additions & 5 deletions test/include/dlaf_test/matrix/util_generic_blas_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,22 @@ auto opValFunc(ElementGetter&& val, const blas::Op op) {
}

template <class ElementIndex, class T>
auto getMatrixScal(const blas::Op opA, const T beta) {
auto getMatrixScal(const T beta) {
using dlaf::test::TypeUtilities;

auto el_op_a = [](const ElementIndex& index) {
auto el_a = [](const ElementIndex& index) {
const double i = index.row();
const double k = index.col();
return TypeUtilities<T>::polar(.9 * (i + 1) / (k + .5), 2 * i - k);
};

auto res_a = [beta, el_op_a, alpha](const ElementIndex& index) {
auto res_a = [beta, el_a](const ElementIndex& index) {
const double i = index.row();
const double j = index.col();
return beta * el_op_a(index);
};

using internal::opValFunc;
return std::make_tuple(opValFunc(el_op_a, opA), el_op_a, res_a);

return std::make_tuple(el_a, res_a);
}
}
7 changes: 7 additions & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ DLAF_addTest(
USE_MAIN PIKA
)

DLAF_addTest(
test_blas_tile_extensions
SOURCES test_blas_tile_extensions.cpp
LIBRARIES dlaf.core
USE_MAIN PIKA
)

DLAF_addTest(
test_lapack_tile
SOURCES test_lapack_tile.cpp
Expand Down
12 changes: 5 additions & 7 deletions test/unit/test_blas_tile/test_scal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,23 @@ using namespace dlaf::matrix::test;
using namespace testing;

template <Device D, class T, class CT = const T>
void testScal(const blas::Op op_a, const SizeType m,
void testScal(const SizeType m,
const SizeType n, const SizeType extra_lda) {
const TileElementSize size_a =
(op_a == blas::Op::NoTrans) ? TileElementSize(m, n) : TileElementSize(n, m);

const TileElementSize size_a(m, n);

const SizeType lda = std::max<SizeType>(1, size_a.rows()) + extra_lda;

const T beta = TypeUtilities<T>::element(1.1, .4);

auto [el_a, res_a] =
getMatrixScal<TileElementIndex, T>(op_a, beta);
getMatrixScal<TileElementIndex, T>(beta);

auto a = createTile<CT, D>(el_a, size_a, lda);

invokeBlas<D>(tile::internal::scal_o, beta, a);
invokeBlas<D>(tile::internal::scal, beta, a);

std::stringstream s;
s << "Scal: " << op_a;
s << "Scal: ";
s << ", m = " << m << ", n = " << n;
s << ", lda = " << lda;
SCOPED_TRACE(s.str());
Expand Down
49 changes: 17 additions & 32 deletions test/unit/test_blas_tile_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,27 @@

#include <dlaf/blas/tile.h>

#include "test_scal/test_scal.h"
#include "test_add/test_scal.h"
#include "test_blas_tile/test_scal.h"
//#include "test_blas_tile/test_add.h"

#include <gtest/gtest.h>

using namespace dlaf;
using namespace dlaf::test;
using namespace testing;

const std::vector<blas::Diag> blas_diags({blas::Diag::Unit, blas::Diag::NonUnit});
const std::vector<blas::Op> blas_ops({blas::Op::NoTrans, blas::Op::Trans, blas::Op::ConjTrans});
const std::vector<blas::Side> blas_sides({blas::Side::Left, blas::Side::Right});
const std::vector<blas::Uplo> blas_uplos({blas::Uplo::Lower, blas::Uplo::Upper});

template <class T, Device D>
class TileOperationsTest : public ::testing::Test {};

template <class T>
using TileOperationsTestMC = TileOperationsTest<T, Device::CPU>;
using TileOperationsExtensionsTestMC = TileOperationsTest<T, Device::CPU>;

TYPED_TEST_SUITE(TileOperationsTestMC, MatrixElementTypes);
TYPED_TEST_SUITE(TileOperationsExtensionsTestMC, MatrixElementTypes);

#ifdef DLAF_WITH_GPU
template <class T>
using TileOperationsTestGPU = TileOperationsTest<T, Device::GPU>;
using TileOperationsExtensionsTestGPU = TileOperationsTest<T, Device::GPU>;

TYPED_TEST_SUITE(TileOperationsTestGPU, MatrixElementTypes);
TYPED_TEST_SUITE(TileOperationsExtensionsTestGPU, MatrixElementTypes);
#endif

// Tuple elements: m, n, k, extra_lda, extra_ldb, extra_ldc
Expand All @@ -47,37 +41,28 @@ std::vector<std::tuple<SizeType, SizeType, SizeType, SizeType, SizeType, SizeTyp
{1, 1, 1, 0, 3, 0}, {1, 12, 1, 1, 0, 7}, {17, 12, 16, 1, 3, 0}, {11, 23, 8, 0, 3, 4},
{6, 9, 12, 1, 1, 1}, {32, 32, 32, 0, 0, 0}, {32, 32, 32, 4, 5, 7}, {128, 128, 128, 0, 0, 0},
};
//Cosa metto al posto di Gemm riga 51
TYPED_TEST(TileOperationsTestMC, Gemm) {
using Type = TypeParam;
//i cicli for non penso siano corretti, es. riga 56
for (const auto op_a : blas_ops) {
for (const auto op_b : blas_ops) {
for (const auto& [m, n, k, extra_lda, extra_ldb, extra_ldc] : gemm_sizes) {
// Test a and b const Tiles.
dlaf::test::testScal<Device::CPU, Type>(op_a, m, n, extra_lda);

// Test a and b non const Tiles.
dlaf::test::testScal<Device::CPU, Type>(op_a, m, n, extra_lda);
}
}
TYPED_TEST(TileOperationsExtensionsTestMC, Scal) {
using Type = TypeParam;
for (const auto& [m, n, k, extra_lda, extra_ldb, extra_ldc] : gemm_sizes) {
// Test a and b const Tiles.
dlaf::test::testScal<Device::CPU, Type>(m, n, extra_lda);
// Test a and b non const Tiles.
dlaf::test::testScal<Device::CPU, Type>(m, n, extra_lda);
}

}

#ifdef DLAF_WITH_GPU
TYPED_TEST(TileOperationsTestGPU, Gemm) {
TYPED_TEST(TileOperationsExtensionsTestGPU, Scal) {
using Type = TypeParam;

for (const auto op_a : blas_ops) {
for (const auto op_b : blas_ops) {
for (const auto& [m, n, k, extra_lda, extra_ldb, extra_ldc] : gemm_sizes) {
// Test a and b const Tiles.
dlaf::test::testScal<Device::GPU, Type>(op_a, m, n, extra_lda);
dlaf::test::testScal<Device::GPU, Type>(m, n, extra_lda);

// Test a and b non const Tiles.
dlaf::test::testScal<Device::CPU, Type, Type>(op_a, m, n, extra_lda);
dlaf::test::testScal<Device::CPU, Type, Type>(m, n, extra_lda);
}
}
}
}
#endif

0 comments on commit 0cd2bd7

Please sign in to comment.