Skip to content

Commit

Permalink
c api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli committed Jun 17, 2024
1 parent 09ae24c commit 3141ef3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 21 deletions.
1 change: 1 addition & 0 deletions test/unit/c_api/eigensolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DLAF_addTest(
DLAF_addTest(
test_gen_eigensolver_c_api
SOURCES test_gen_eigensolver_c_api.cpp test_gen_eigensolver_c_api_wrapper.c
../factorization/test_cholesky_c_api_wrapper.c
LIBRARIES dlaf.c_api
USE_MAIN CAPI
MPIRANKS 6
Expand Down
97 changes: 76 additions & 21 deletions test/unit/c_api/eigensolver/test_gen_eigensolver_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <dlaf/matrix/matrix.h>
#include <dlaf_c_test/c_api_helpers.h>

#include "../factorization/test_cholesky_c_api_wrapper.h"
#include "test_gen_eigensolver_c_api_config.h"
#include "test_gen_eigensolver_c_api_wrapper.h"

Expand Down Expand Up @@ -55,6 +56,8 @@ using GenEigensolverTestGPU = GenEigensolverTest<T>;
TYPED_TEST_SUITE(GenEigensolverTestGPU, MatrixElementTypes);
#endif

using dlaf::eigensolver::internal::Factorization;

const std::vector<blas::Uplo> blas_uplos({blas::Uplo::Lower});

const std::vector<std::tuple<SizeType, SizeType, SizeType>> sizes = {
Expand All @@ -65,7 +68,7 @@ const std::vector<std::tuple<SizeType, SizeType, SizeType>> sizes = {
{34, 8, 3}, {32, 6, 3} // m > mb, sub-band
};

template <class T, Backend B, Device D, API api>
template <class T, Backend B, Device D, API api, Factorization factorization>
void testGenEigensolver(const blas::Uplo uplo, const SizeType m, const SizeType mb,
CommunicatorGrid& grid) {
auto dlaf_context = c_api_test_inititialize<api>(pika_argc, pika_argv, dlaf_argc, dlaf_argv, grid);
Expand Down Expand Up @@ -131,28 +134,68 @@ void testGenEigensolver(const blas::Uplo uplo, const SizeType m, const SizeType

int err = -1;
if constexpr (std::is_same_v<T, double>) {
err =
C_dlaf_symmetric_generalized_eigensolver_d(dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a,
local_b_ptr, dlaf_desc_b, eigenvalues_ptr,
local_eigenvectors_ptr, dlaf_desc_eigenvectors);
if (factorization == Factorization::do_factorization) {
err = C_dlaf_symmetric_generalized_eigensolver_d(dlaf_context, dlaf_uplo, local_a_ptr,
dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr,
dlaf_desc_eigenvectors);
}
else {
err = C_dlaf_cholesky_factorization_d(dlaf_context, dlaf_uplo, local_b_ptr, dlaf_desc_b);
DLAF_ASSERT(err == 0, err);

err = C_dlaf_symmetric_generalized_eigensolver_factorized_d(
dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr, dlaf_desc_eigenvectors);
}
}
else if constexpr (std::is_same_v<T, float>) {
err =
C_dlaf_symmetric_generalized_eigensolver_s(dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a,
local_b_ptr, dlaf_desc_b, eigenvalues_ptr,
local_eigenvectors_ptr, dlaf_desc_eigenvectors);
if (factorization == Factorization::do_factorization) {
err = C_dlaf_symmetric_generalized_eigensolver_s(dlaf_context, dlaf_uplo, local_a_ptr,
dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr,
dlaf_desc_eigenvectors);
}
else {
err = C_dlaf_cholesky_factorization_s(dlaf_context, dlaf_uplo, local_b_ptr, dlaf_desc_b);
DLAF_ASSERT(err == 0, err);

err = C_dlaf_symmetric_generalized_eigensolver_factorized_s(
dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr, dlaf_desc_eigenvectors);
}
}
else if constexpr (std::is_same_v<T, std::complex<double>>) {
err =
C_dlaf_hermitian_generalized_eigensolver_z(dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a,
local_b_ptr, dlaf_desc_b, eigenvalues_ptr,
local_eigenvectors_ptr, dlaf_desc_eigenvectors);
if (factorization == Factorization::do_factorization) {
err = C_dlaf_hermitian_generalized_eigensolver_z(dlaf_context, dlaf_uplo, local_a_ptr,
dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr,
dlaf_desc_eigenvectors);
}
else {
err = C_dlaf_cholesky_factorization_z(dlaf_context, dlaf_uplo, local_b_ptr, dlaf_desc_b);
DLAF_ASSERT(err == 0, err);

err = C_dlaf_hermitian_generalized_eigensolver_factorized_z(
dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr, dlaf_desc_eigenvectors);
}
}
else if constexpr (std::is_same_v<T, std::complex<float>>) {
err =
C_dlaf_hermitian_generalized_eigensolver_c(dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a,
local_b_ptr, dlaf_desc_b, eigenvalues_ptr,
local_eigenvectors_ptr, dlaf_desc_eigenvectors);
if (factorization == Factorization::do_factorization) {
err = C_dlaf_hermitian_generalized_eigensolver_c(dlaf_context, dlaf_uplo, local_a_ptr,
dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr,
dlaf_desc_eigenvectors);
}
else {
err = C_dlaf_cholesky_factorization_c(dlaf_context, dlaf_uplo, local_b_ptr, dlaf_desc_b);
DLAF_ASSERT(err == 0, err);

err = C_dlaf_hermitian_generalized_eigensolver_factorized_c(
dlaf_context, dlaf_uplo, local_a_ptr, dlaf_desc_a, local_b_ptr, dlaf_desc_b,
eigenvalues_ptr, local_eigenvectors_ptr, dlaf_desc_eigenvectors);
}
}
else {
DLAF_ASSERT(false, typeid(T).name());
Expand Down Expand Up @@ -209,7 +252,10 @@ TYPED_TEST(GenEigensolverTestMC, CorrectnessDistributedDLAF) {
for (comm::CommunicatorGrid& grid : this->commGrids()) {
for (auto uplo : blas_uplos) {
for (auto [m, mb, b_min] : sizes) {
testGenEigensolver<TypeParam, Backend::MC, Device::CPU, API::dlaf>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::MC, Device::CPU, API::dlaf,
Factorization::do_factorization>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::MC, Device::CPU, API::dlaf,
Factorization::already_factorized>(uplo, m, mb, grid);
}
}
}
Expand All @@ -220,7 +266,10 @@ TYPED_TEST(GenEigensolverTestGPU, CorrectnessDistributedDLAF) {
for (comm::CommunicatorGrid& grid : this->commGrids()) {
for (auto uplo : blas_uplos) {
for (auto [m, mb, b_min] : sizes) {
testGenEigensolver<TypeParam, Backend::GPU, Device::GPU, API::dlaf>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::GPU, Device::GPU, API::dlaf,
Factorization::do_factorization>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::GPU, Device::GPU, API::dlaf,
Factorization::already_factorized>(uplo, m, mb, grid);
}
}
}
Expand All @@ -233,7 +282,10 @@ TYPED_TEST(GenEigensolverTestMC, CorrectnessDistributedScaLAPACK) {
for (comm::CommunicatorGrid& grid : this->commGrids()) {
for (auto uplo : blas_uplos) {
for (auto [m, mb, b_min] : sizes) {
testGenEigensolver<TypeParam, Backend::MC, Device::CPU, API::scalapack>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::MC, Device::CPU, API::scalapack,
Factorization::do_factorization>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::MC, Device::CPU, API::scalapack,
Factorization::already_factorized>(uplo, m, mb, grid);
}
}
}
Expand All @@ -244,7 +296,10 @@ TYPED_TEST(GenEigensolverTestGPU, CorrectnessDistributedScaLAPACK) {
for (comm::CommunicatorGrid& grid : this->commGrids()) {
for (auto uplo : blas_uplos) {
for (auto [m, mb, b_min] : sizes) {
testGenEigensolver<TypeParam, Backend::GPU, Device::GPU, API::scalapack>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::GPU, Device::GPU, API::scalapack,
Factorization::do_factorization>(uplo, m, mb, grid);
testGenEigensolver<TypeParam, Backend::GPU, Device::GPU, API::scalapack,
Factorization::already_factorized>(uplo, m, mb, grid);
}
}
}
Expand Down

0 comments on commit 3141ef3

Please sign in to comment.