Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public algorithm interface renaming using snake_case #942

Merged
merged 22 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 12 additions & 32 deletions include/dlaf/auxiliary/norm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,17 @@

namespace dlaf::auxiliary {

/// Compute the norm @p norm_type of the distributed Matrix @p A (ge/sy/he)
/// Compute the max norm of the distributed Matrix @p A (ge/sy/he)
albestro marked this conversation as resolved.
Show resolved Hide resolved
///
/// - With @p norm_type == lapack::Norm::Max:
/// - With @p uplo == blas::uplo::Lower
/// @pre @p A must be square matrix, A.size().rows() == A.size().cols()
/// - With @p uplo == blas::uplo::Upper
/// @note not yet implemented
/// - With @p uplo == blas::uplo::General
/// @note not yet implemented
/// - With @p norm_type = lapack::Norm::{One, Two, Inf, Fro}
/// @note not yet implemented
/// @note @p uplo == blas::uplo::Upper not yet implemented
///
/// @pre `A.blockSize().rows() == A.blockSize().cols()`,
/// @pre @p A is distributed according to @p grid,
/// @pre @p A has equal tile and block sizes,
/// @return the norm @p norm_type of the Matrix @p A or 0 if `A.size().isEmpty()` (see LAPACK doc for
/// additional info).
/// @return the max norm of the Matrix @p A or 0 if `A.size().isEmpty()`
template <Backend backend, Device device, class T>
dlaf::BaseType<T> norm(comm::CommunicatorGrid grid, comm::Index2D rank, lapack::Norm norm_type,
blas::Uplo uplo, Matrix<const T, device>& A) {
dlaf::BaseType<T> max_norm(comm::CommunicatorGrid grid, comm::Index2D rank, blas::Uplo uplo,
Matrix<const T, device>& A) {
using dlaf::matrix::equal_process_grid;
using dlaf::matrix::single_tile_per_block;

Expand All @@ -53,25 +44,14 @@ dlaf::BaseType<T> norm(comm::CommunicatorGrid grid, comm::Index2D rank, lapack::
if (A.size().isEmpty())
return {0};

switch (norm_type) {
case lapack::Norm::One:
case lapack::Norm::Two:
case lapack::Norm::Inf:
case lapack::Norm::Fro:
DLAF_UNIMPLEMENTED(norm_type);
switch (uplo) {
case blas::Uplo::Lower:
return internal::Norm<backend, device, T>::max_L(grid, rank, A);
case blas::Uplo::Upper:
DLAF_UNIMPLEMENTED(uplo);
return {};
case lapack::Norm::Max:
switch (uplo) {
case blas::Uplo::Lower:
return internal::Norm<backend, device, T>::max_L(grid, rank, A);
case blas::Uplo::Upper:
DLAF_UNIMPLEMENTED(norm_type, uplo);
return {};
case blas::Uplo::General:
return internal::Norm<backend, device, T>::max_G(grid, rank, A);
default:
return {};
}
case blas::Uplo::General:
return internal::Norm<backend, device, T>::max_G(grid, rank, A);
default:
return {};
}
Expand Down
18 changes: 8 additions & 10 deletions include/dlaf/eigensolver/band_to_tridiag.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#include <dlaf/types.h>
#include <dlaf/util_matrix.h>

namespace dlaf {
namespace eigensolver {
namespace dlaf::eigensolver::internal {

/// Reduces a Hermitian band matrix A (with the given band_size(*)) to real symmetric tridiagonal
/// form T by a unitary similarity transformation Q**H * A * Q = T.
Expand Down Expand Up @@ -72,8 +71,8 @@ namespace eigensolver {
/// @pre mat_a is not distributed,
/// @pre mat_a has equal tile and block sizes.
template <Backend B, Device D, class T>
TridiagResult<T, Device::CPU> band_to_tridiag(blas::Uplo uplo, SizeType band_size,
Matrix<const T, D>& mat_a) {
TridiagResult<T, Device::CPU> band_to_tridiagonal(blas::Uplo uplo, SizeType band_size,
Matrix<const T, D>& mat_a) {
DLAF_ASSERT(matrix::square_size(mat_a), mat_a);
DLAF_ASSERT(matrix::square_blocksize(mat_a), mat_a);
DLAF_ASSERT(mat_a.blockSize().rows() % band_size == 0, mat_a.blockSize().rows(), band_size);
Expand All @@ -83,7 +82,7 @@ TridiagResult<T, Device::CPU> band_to_tridiag(blas::Uplo uplo, SizeType band_siz

switch (uplo) {
case blas::Uplo::Lower:
return internal::BandToTridiag<B, D, T>::call_L(band_size, mat_a);
return BandToTridiag<B, D, T>::call_L(band_size, mat_a);
break;
case blas::Uplo::Upper:
DLAF_UNIMPLEMENTED(uplo);
Expand Down Expand Up @@ -145,8 +144,8 @@ TridiagResult<T, Device::CPU> band_to_tridiag(blas::Uplo uplo, SizeType band_siz
/// @pre mat_a is distributed according to grid,
/// @pre mat_a has equal tile and block sizes.
template <Backend backend, Device device, class T>
TridiagResult<T, Device::CPU> band_to_tridiag(comm::CommunicatorGrid grid, blas::Uplo uplo,
SizeType band_size, Matrix<const T, device>& mat_a) {
TridiagResult<T, Device::CPU> band_to_tridiagonal(comm::CommunicatorGrid grid, blas::Uplo uplo,
SizeType band_size, Matrix<const T, device>& mat_a) {
DLAF_ASSERT(matrix::square_size(mat_a), mat_a);
DLAF_ASSERT(matrix::square_blocksize(mat_a), mat_a);
DLAF_ASSERT(matrix::equal_process_grid(mat_a, grid), mat_a, grid);
Expand All @@ -155,11 +154,11 @@ TridiagResult<T, Device::CPU> band_to_tridiag(comm::CommunicatorGrid grid, blas:

// If the grid contains only one rank force local implementation.
if (grid.size() == comm::Size2D(1, 1))
return band_to_tridiag<backend, device, T>(uplo, band_size, mat_a);
return band_to_tridiagonal<backend, device, T>(uplo, band_size, mat_a);

switch (uplo) {
case blas::Uplo::Lower:
return internal::BandToTridiag<backend, device, T>::call_L(grid, band_size, mat_a);
return BandToTridiag<backend, device, T>::call_L(grid, band_size, mat_a);
break;
case blas::Uplo::Upper:
DLAF_UNIMPLEMENTED(uplo);
Expand All @@ -173,4 +172,3 @@ TridiagResult<T, Device::CPU> band_to_tridiag(comm::CommunicatorGrid grid, blas:
}

}
}
5 changes: 1 addition & 4 deletions include/dlaf/eigensolver/band_to_tridiag/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
#include <dlaf/matrix/matrix.h>
#include <dlaf/types.h>

namespace dlaf::eigensolver {
namespace dlaf::eigensolver::internal {

template <class T, Device D>
struct TridiagResult {
Matrix<BaseType<T>, D> tridiagonal;
Matrix<T, D> hh_reflectors;
};

namespace internal {

template <class T>
SizeType nrSweeps(SizeType size) noexcept {
// Complex needs an extra sweep to have a real tridiagonal matrix.
Expand Down Expand Up @@ -63,4 +61,3 @@ DLAF_EIGENSOLVER_B2T_ETI(extern, Backend::MC, Device::GPU, std::complex<float>)
DLAF_EIGENSOLVER_B2T_ETI(extern, Backend::MC, Device::GPU, std::complex<double>)
#endif
}
}
15 changes: 7 additions & 8 deletions include/dlaf/eigensolver/bt_band_to_tridiag.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <dlaf/types.h>
#include <dlaf/util_matrix.h>

namespace dlaf::eigensolver {
namespace dlaf::eigensolver::internal {

// Eigenvalue back-transformation implementation on local memory, which applies the inverse of the
// transformation used to get a tridiagonal matrix from a band one.
Expand Down Expand Up @@ -54,8 +54,8 @@ namespace dlaf::eigensolver {
// @pre mat_e has equal tile and block sizes
// @pre mat_hh has equal tile and block sizes
template <Backend B, Device D, class T>
void backTransformationBandToTridiag(const SizeType band_size, matrix::Matrix<T, D>& mat_e,
matrix::Matrix<const T, Device::CPU>& mat_hh) {
void bt_band_to_tridiagonal(const SizeType band_size, matrix::Matrix<T, D>& mat_e,
matrix::Matrix<const T, Device::CPU>& mat_hh) {
DLAF_ASSERT(matrix::local_matrix(mat_e), mat_e);
DLAF_ASSERT(matrix::local_matrix(mat_hh), mat_hh);

Expand All @@ -71,13 +71,12 @@ void backTransformationBandToTridiag(const SizeType band_size, matrix::Matrix<T,
DLAF_ASSERT(band_size >= 2, band_size);
DLAF_ASSERT(mat_hh.blockSize().rows() % band_size == 0, mat_hh.blockSize(), band_size);

internal::BackTransformationT2B<B, D, T>::call(band_size, mat_e, mat_hh);
BackTransformationT2B<B, D, T>::call(band_size, mat_e, mat_hh);
}

template <Backend B, Device D, class T>
void backTransformationBandToTridiag(comm::CommunicatorGrid grid, const SizeType band_size,
matrix::Matrix<T, D>& mat_e,
matrix::Matrix<const T, Device::CPU>& mat_hh) {
void bt_band_to_tridiagonal(comm::CommunicatorGrid grid, const SizeType band_size,
matrix::Matrix<T, D>& mat_e, matrix::Matrix<const T, Device::CPU>& mat_hh) {
DLAF_ASSERT(matrix::equal_process_grid(mat_e, grid), mat_e, grid);
DLAF_ASSERT(matrix::equal_process_grid(mat_hh, grid), mat_hh, grid);

Expand All @@ -90,6 +89,6 @@ void backTransformationBandToTridiag(comm::CommunicatorGrid grid, const SizeType
DLAF_ASSERT(band_size >= 2, band_size);
DLAF_ASSERT(mat_hh.blockSize().rows() % band_size == 0, mat_hh.blockSize(), band_size);

internal::BackTransformationT2B<B, D, T>::call(grid, band_size, mat_e, mat_hh);
BackTransformationT2B<B, D, T>::call(grid, band_size, mat_e, mat_hh);
msimberg marked this conversation as resolved.
Show resolved Hide resolved
}
}
18 changes: 7 additions & 11 deletions include/dlaf/eigensolver/bt_reduction_to_band.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include <dlaf/types.h>
#include <dlaf/util_matrix.h>

namespace dlaf {
namespace eigensolver {
namespace dlaf::eigensolver::internal {

/// Eigenvalue back-transformation implementation on local memory.
///
Expand All @@ -38,9 +37,8 @@ namespace eigensolver {
/// @pre mat_c has equal tile and block sizes,
/// @pre mat_v has equal tile and block sizes.
template <Backend backend, Device device, class T>
void backTransformationReductionToBand(const SizeType b, Matrix<T, device>& mat_c,
Matrix<const T, device>& mat_v,
Matrix<const T, Device::CPU>& mat_taus) {
void bt_reduction_to_band(const SizeType b, Matrix<T, device>& mat_c, Matrix<const T, device>& mat_v,
Matrix<const T, Device::CPU>& mat_taus) {
DLAF_ASSERT(matrix::local_matrix(mat_c), mat_c);
DLAF_ASSERT(matrix::local_matrix(mat_v), mat_v);
DLAF_ASSERT(square_size(mat_v), mat_v);
Expand All @@ -57,7 +55,7 @@ void backTransformationReductionToBand(const SizeType b, Matrix<T, device>& mat_
};
DLAF_ASSERT(mat_taus.nrTiles().rows() == nr_reflectors_blocks(), mat_taus.size().rows(), mat_v, b);

internal::BackTransformationReductionToBand<backend, device, T>::call(b, mat_c, mat_v, mat_taus);
BackTransformationReductionToBand<backend, device, T>::call(b, mat_c, mat_v, mat_taus);
}

/// Eigenvalue back-transformation implementation on distributed memory.
Expand All @@ -76,9 +74,8 @@ void backTransformationReductionToBand(const SizeType b, Matrix<T, device>& mat_
/// @pre mat_c has equal tile and block sizes,
/// @pre mat_v has equal tile and block sizes.
template <Backend backend, Device device, class T>
void backTransformationReductionToBand(comm::CommunicatorGrid grid, const SizeType b,
Matrix<T, device>& mat_c, Matrix<const T, device>& mat_v,
Matrix<const T, Device::CPU>& mat_taus) {
void bt_reduction_to_band(comm::CommunicatorGrid grid, const SizeType b, Matrix<T, device>& mat_c,
Matrix<const T, device>& mat_v, Matrix<const T, Device::CPU>& mat_taus) {
DLAF_ASSERT(matrix::equal_process_grid(mat_c, grid), mat_c, grid);
DLAF_ASSERT(matrix::equal_process_grid(mat_v, grid), mat_v, grid);
DLAF_ASSERT(square_size(mat_v), mat_v);
Expand All @@ -97,7 +94,6 @@ void backTransformationReductionToBand(comm::CommunicatorGrid grid, const SizeTy
DLAF_ASSERT(mat_taus.distribution().localNrTiles().rows() == nr_reflectors_blocks(), mat_taus, mat_v,
b);

internal::BackTransformationReductionToBand<backend, device, T>::call(grid, b, mat_c, mat_v, mat_taus);
}
BackTransformationReductionToBand<backend, device, T>::call(grid, b, mat_c, mat_v, mat_taus);
}
}
23 changes: 12 additions & 11 deletions include/dlaf/eigensolver/eigensolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <dlaf/types.h>
#include <dlaf/util_matrix.h>

namespace dlaf::eigensolver {
namespace dlaf {

/// Standard Eigensolver.
///
Expand All @@ -36,8 +36,8 @@ namespace dlaf::eigensolver {
/// @param eigenvalues is a N x 1 matrix which on output contains the eigenvalues
/// @param eigenvectors is a N x N matrix which on output contains the eigenvectors
template <Backend B, Device D, class T>
void eigensolver(blas::Uplo uplo, Matrix<T, D>& mat, Matrix<BaseType<T>, D>& eigenvalues,
Matrix<T, D>& eigenvectors) {
void hermitian_eigensolver(blas::Uplo uplo, Matrix<T, D>& mat, Matrix<BaseType<T>, D>& eigenvalues,
Matrix<T, D>& eigenvectors) {
DLAF_ASSERT(matrix::local_matrix(mat), mat);
DLAF_ASSERT(square_size(mat), mat);
DLAF_ASSERT(square_blocksize(mat), mat);
Expand All @@ -54,7 +54,7 @@ void eigensolver(blas::Uplo uplo, Matrix<T, D>& mat, Matrix<BaseType<T>, D>& eig
DLAF_ASSERT(single_tile_per_block(eigenvalues), eigenvalues);
DLAF_ASSERT(single_tile_per_block(eigenvectors), eigenvectors);

internal::Eigensolver<B, D, T>::call(uplo, mat, eigenvalues, eigenvectors);
eigensolver::internal::Eigensolver<B, D, T>::call(uplo, mat, eigenvalues, eigenvectors);
}

/// Standard Eigensolver.
Expand All @@ -70,13 +70,13 @@ void eigensolver(blas::Uplo uplo, Matrix<T, D>& mat, Matrix<BaseType<T>, D>& eig
/// @param uplo specifies if upper or lower triangular part of @p mat will be referenced
/// @param mat contains the Hermitian matrix A
template <Backend B, Device D, class T>
EigensolverResult<T, D> eigensolver(blas::Uplo uplo, Matrix<T, D>& mat) {
EigensolverResult<T, D> hermitian_eigensolver(blas::Uplo uplo, Matrix<T, D>& mat) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to check, is the name EigensolverResult still accurate?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this out for now, but @rasolca we probably need your input on what you'd like to do here leter.

const SizeType size = mat.size().rows();
matrix::Matrix<BaseType<T>, D> eigenvalues(LocalElementSize(size, 1),
TileElementSize(mat.blockSize().rows(), 1));
matrix::Matrix<T, D> eigenvectors(LocalElementSize(size, size), mat.blockSize());

eigensolver<B, D, T>(uplo, mat, eigenvalues, eigenvectors);
hermitian_eigensolver<B, D, T>(uplo, mat, eigenvalues, eigenvectors);
return {std::move(eigenvalues), std::move(eigenvectors)};
}

Expand All @@ -96,8 +96,8 @@ EigensolverResult<T, D> eigensolver(blas::Uplo uplo, Matrix<T, D>& mat) {
/// @param eigenvalues is a N x 1 matrix which on output contains the eigenvalues
/// @param eigenvectors is a N x N matrix which on output contains the eigenvectors
template <Backend B, Device D, class T>
void eigensolver(comm::CommunicatorGrid grid, blas::Uplo uplo, Matrix<T, D>& mat,
Matrix<BaseType<T>, D>& eigenvalues, Matrix<T, D>& eigenvectors) {
void hermitian_eigensolver(comm::CommunicatorGrid grid, blas::Uplo uplo, Matrix<T, D>& mat,
Matrix<BaseType<T>, D>& eigenvalues, Matrix<T, D>& eigenvectors) {
DLAF_ASSERT(matrix::equal_process_grid(mat, grid), mat);
DLAF_ASSERT(square_size(mat), mat);
DLAF_ASSERT(square_blocksize(mat), mat);
Expand All @@ -114,7 +114,7 @@ void eigensolver(comm::CommunicatorGrid grid, blas::Uplo uplo, Matrix<T, D>& mat
DLAF_ASSERT(single_tile_per_block(eigenvalues), eigenvalues);
DLAF_ASSERT(single_tile_per_block(eigenvectors), eigenvectors);

internal::Eigensolver<B, D, T>::call(grid, uplo, mat, eigenvalues, eigenvectors);
eigensolver::internal::Eigensolver<B, D, T>::call(grid, uplo, mat, eigenvalues, eigenvectors);
}

/// Standard Eigensolver.
Expand All @@ -131,13 +131,14 @@ void eigensolver(comm::CommunicatorGrid grid, blas::Uplo uplo, Matrix<T, D>& mat
/// @param uplo specifies if upper or lower triangular part of @p mat will be referenced
/// @param mat contains the Hermitian matrix A
template <Backend B, Device D, class T>
EigensolverResult<T, D> eigensolver(comm::CommunicatorGrid grid, blas::Uplo uplo, Matrix<T, D>& mat) {
EigensolverResult<T, D> hermitian_eigensolver(comm::CommunicatorGrid grid, blas::Uplo uplo,
Matrix<T, D>& mat) {
const SizeType size = mat.size().rows();
matrix::Matrix<BaseType<T>, D> eigenvalues(LocalElementSize(size, 1),
TileElementSize(mat.blockSize().rows(), 1));
matrix::Matrix<T, D> eigenvectors(GlobalElementSize(size, size), mat.blockSize(), grid);

eigensolver<B, D, T>(grid, uplo, mat, eigenvalues, eigenvectors);
hermitian_eigensolver<B, D, T>(grid, uplo, mat, eigenvalues, eigenvectors);
return {std::move(eigenvalues), std::move(eigenvectors)};
}
}
4 changes: 2 additions & 2 deletions include/dlaf/eigensolver/eigensolver/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#include <dlaf/matrix/matrix.h>
#include <dlaf/types.h>

namespace dlaf::eigensolver {
namespace dlaf {

template <class T, Device D>
struct EigensolverResult {
Matrix<BaseType<T>, D> eigenvalues;
Matrix<T, D> eigenvectors;
};

namespace internal {
namespace eigensolver::internal {

template <Backend B, Device D, class T>
struct Eigensolver {
Expand Down
20 changes: 10 additions & 10 deletions include/dlaf/eigensolver/eigensolver/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ void Eigensolver<B, D, T>::call(blas::Uplo uplo, Matrix<T, D>& mat_a, Matrix<Bas
if (uplo != blas::Uplo::Lower)
DLAF_UNIMPLEMENTED(uplo);

auto mat_taus = reductionToBand<B>(mat_a, band_size);
auto ret = band_to_tridiag<Backend::MC>(uplo, band_size, mat_a);
auto mat_taus = reduction_to_band<B>(mat_a, band_size);
auto ret = band_to_tridiagonal<Backend::MC>(uplo, band_size, mat_a);

eigensolver::tridiagSolver<B>(ret.tridiagonal, evals, mat_e);
tridiagonal_eigensolver<B>(ret.tridiagonal, evals, mat_e);

backTransformationBandToTridiag<B>(band_size, mat_e, ret.hh_reflectors);
backTransformationReductionToBand<B>(band_size, mat_e, mat_a, mat_taus);
bt_band_to_tridiagonal<B>(band_size, mat_e, ret.hh_reflectors);
bt_reduction_to_band<B>(band_size, mat_e, mat_a, mat_taus);
}

template <Backend B, Device D, class T>
Expand All @@ -60,8 +60,8 @@ void Eigensolver<B, D, T>::call(comm::CommunicatorGrid grid, blas::Uplo uplo, Ma
if (uplo != blas::Uplo::Lower)
DLAF_UNIMPLEMENTED(uplo);

auto mat_taus = reductionToBand<B>(grid, mat_a, band_size);
auto ret = band_to_tridiag<Backend::MC>(grid, uplo, band_size, mat_a);
auto mat_taus = reduction_to_band<B>(grid, mat_a, band_size);
auto ret = band_to_tridiagonal<Backend::MC>(grid, uplo, band_size, mat_a);

#ifdef DLAF_WITH_HDF5
std::optional<matrix::internal::FileHDF5> file;
Expand All @@ -72,7 +72,7 @@ void Eigensolver<B, D, T>::call(comm::CommunicatorGrid grid, blas::Uplo uplo, Ma
}
#endif

eigensolver::tridiagSolver<B>(grid, ret.tridiagonal, evals, mat_e);
tridiagonal_eigensolver<B>(grid, ret.tridiagonal, evals, mat_e);

#ifdef DLAF_WITH_HDF5
if (getTuneParameters().debug_dump_trisolver_data) {
Expand All @@ -81,7 +81,7 @@ void Eigensolver<B, D, T>::call(comm::CommunicatorGrid grid, blas::Uplo uplo, Ma
}
#endif

backTransformationBandToTridiag<B>(grid, band_size, mat_e, ret.hh_reflectors);
backTransformationReductionToBand<B>(grid, band_size, mat_e, mat_a, mat_taus);
bt_band_to_tridiagonal<B>(grid, band_size, mat_e, ret.hh_reflectors);
bt_reduction_to_band<B>(grid, band_size, mat_e, mat_a, mat_taus);
}
}
Loading
Loading