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

Adding Additional Internal Timers for SLATE Routines #136

Merged
merged 7 commits into from
Nov 15, 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
8 changes: 8 additions & 0 deletions src/gbsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,24 @@ int64_t gbsv(
Matrix<scalar_t>& B,
Options const& opts)
{
Timer t_gbsv;

slate_assert( A.mt() == A.nt() ); // square
slate_assert( B.mt() == A.mt() );

// factorization
Timer t_gbtrf;
int64_t info = gbtrf( A, pivots, opts );
timers[ "gbsv::gbtrf" ] = t_gbtrf.stop();

// solve
Timer t_gbtrs;
if (info == 0) {
gbtrs( A, pivots, B, opts );
}
timers[ "gbsv::gbtrs" ] = t_gbtrs.stop();

timers[ "gbsv" ] = t_gbsv.stop();

return info;
}
Expand Down
13 changes: 13 additions & 0 deletions src/gels_cholqr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ void gels_cholqr(
Matrix<scalar_t>& BX,
Options const& opts)
{
Timer t_gels_cholqr;

// m, n of op(A) as in docs above.
int64_t m = A.m();
int64_t n = A.n();
Expand Down Expand Up @@ -127,7 +129,9 @@ void gels_cholqr(
R = R.slice( 0, A0_N-1, 0, A0_N-1 );
R.insertLocalTiles();

Timer t_cholqr;
cholqr( A0, R, opts );
timers[ "gels_cholqr::cholqr" ] = t_cholqr.stop();

auto R_U = TriangularMatrix( Uplo::Upper, Diag::NonUnit, R );

Expand All @@ -145,13 +149,17 @@ void gels_cholqr(
Y.insertLocalTiles();

// Y = Q^H B
Timer t_gemm;
gemm( one, QH, BX, zero, Y );
timers[ "gels_cholqr::gemm" ] = t_gemm.stop();

// Copy back the result
copy( Y, X );

// X = R^{-1} Y
Timer t_trsm;
trsm( Side::Left, one, R_U, X, opts );
timers[ "gels_cholqr::trsm" ] = t_trsm.stop();
}
else {
// Solve A X = A0^H X = (QR)^H X = B.
Expand All @@ -167,16 +175,21 @@ void gels_cholqr(

// Y = R^{-H} B
auto RH = conj_transpose( R_U );
Timer t_trsm;
trsm( Side::Left, one, RH, Y, opts );
timers[ "gels_cholqr::trsm" ] = t_trsm.stop();

// X = Q Y, with Q stored in A0.
Timer t_gemm;
gemm( one, A0, Y, zero, BX );
timers[ "gels_cholqr::gemm" ] = t_gemm.stop();
}
}
else {
// todo: LQ factorization
slate_not_implemented( "least squares using LQ" );
}
timers[ "gels_cholqr" ] = t_gels_cholqr.stop();
// todo: return value for errors?
// R or L is singular => A is not full rank
}
Expand Down
21 changes: 21 additions & 0 deletions src/gesv_mixed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ int64_t gesv_mixed(
int& iter,
Options const& opts)
{
Timer t_gesv_mixed;

Target target = get_option( opts, Option::Target, Target::HostTask );

// Assumes column major
Expand Down Expand Up @@ -177,23 +179,29 @@ int64_t gesv_mixed(
copy( A, A_lo, opts );

// Compute the LU factorization of A_lo.
Timer t_getrf_lo;
int64_t info = getrf( A_lo, pivots, opts );
timers[ "gesv_mixed::getrf_lo" ] = t_getrf_lo.stop();
if (info != 0) {
iter = -3;
}
else {
// Solve the system A_lo * X_lo = B_lo.
Timer t_getrs_lo;
getrs( A_lo, pivots, X_lo, opts );
timers[ "gesv_mixed::getrs_lo" ] = t_getrs_lo.stop();

// Convert X_lo to high precision.
copy( X_lo, X, opts );

// Compute R = B - A * X.
slate::copy( B, R, opts );
Timer t_gemm_hi;
gemm<scalar_hi>(
-one_hi, A,
X,
one_hi, R, opts );
timers[ "gesv_mixed::gemm_hi" ] = t_gemm_hi.stop();

// Check whether the nrhs normwise backward error satisfies the
// stopping criterion. If yes, set iter=0 and return.
Expand All @@ -205,26 +213,33 @@ int64_t gesv_mixed(
converged = true;
}

timers[ "gesv_mixed::add_hi" ] = 0;
// iterative refinement
for (int iiter = 0; iiter < itermax && ! converged; ++iiter) {
// Convert R from high to low precision, store result in X_lo.
copy( R, X_lo, opts );

// Solve the system A_lo * X_lo = R_lo.
t_getrs_lo.start();
getrs( A_lo, pivots, X_lo, opts );
timers[ "gesv_mixed::getrs_lo" ] += t_getrs_lo.stop();

// Convert X_lo back to double precision and update the current iterate.
copy( X_lo, R, opts );
Timer t_add_hi;
add<scalar_hi>(
one_hi, R,
one_hi, X, opts );
timers[ "gesv_mixed::add_hi" ] += t_add_hi.stop();

// Compute R = B - A * X.
slate::copy( B, R, opts );
t_gemm_hi.start();
gemm<scalar_hi>(
-one_hi, A,
X,
one_hi, R, opts );
timers[ "gesv_mixed::gemm_hi" ] += t_gemm_hi.stop();

// Check whether nrhs normwise backward error satisfies the
// stopping criterion. If yes, set iter = iiter > 0 and return.
Expand All @@ -248,13 +263,17 @@ int64_t gesv_mixed(
if (use_fallback) {
// Fall back to double precision factor and solve.
// Compute the LU factorization of A.
Timer t_getrf_hi;
info = getrf( A, pivots, opts );
timers[ "gesv_mixed::getrf_hi" ] = t_getrf_hi.stop();

// Solve the system A * X = B.
Timer t_getrs_hi;
if (info == 0) {
slate::copy( B, X, opts );
getrs( A, pivots, X, opts );
}
timers[ "gesv_mixed::getrs_hi" ] = t_getrs_hi.stop();
}
}

Expand All @@ -264,6 +283,8 @@ int64_t gesv_mixed(
B.clearWorkspace();
X.clearWorkspace();
}
timers[ "gesv_mixed" ] = t_gesv_mixed.stop();

return info;
}

Expand Down
31 changes: 31 additions & 0 deletions src/gesv_mixed_gmres.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ int64_t gesv_mixed_gmres(
int& iter,
Options const& opts)
{
Timer t_gesv_mixed_gmres;

using real_hi = blas::real_type<scalar_hi>;

// Constants
Expand Down Expand Up @@ -203,27 +205,35 @@ int64_t gesv_mixed_gmres(

// Compute the LU factorization of A in single-precision.
slate::copy( A, A_lo, opts );
Timer t_getrf_lo;
int64_t info = getrf( A_lo, pivots, opts );
timers[ "gesv_mixed_gmres::getrf_lo" ] = t_getrf_lo.stop();
if (info != 0) {
iter = -3;
}
else {
// Solve the system A * X = B in low precision.
slate::copy( B, X_lo, opts );
Timer t_getrs_lo;
getrs( A_lo, pivots, X_lo, opts );
timers[ "gesv_mixed_gmres::getrs_lo" ] = t_getrs_lo.stop();
slate::copy( X_lo, X, opts );

// IR
timers[ "gesv_mixed_gmres::gemm_hi" ] = 0;
timers[ "gesv_mixed_gmres::add_hi" ] = 0;
int iiter = 0;
while (iiter < itermax) {

// Check for convergence
slate::copy( B, R, opts );
Timer t_gemm_hi;
gemm<scalar_hi>(
-one, A,
X,
one, R,
opts);
timers[ "gesv_mixed_gmres::gemm_hi" ] += t_gemm_hi.stop();
colNorms( Norm::Max, X, colnorms_X.data(), opts );
colNorms( Norm::Max, R, colnorms_R.data(), opts );
if (internal::iterRefConverged<real_hi>( colnorms_R, colnorms_X, cte ))
Expand Down Expand Up @@ -272,19 +282,24 @@ int64_t gesv_mixed_gmres(

// Wj1 = M^-1 A Vj
slate::copy( Vj, X_lo, opts );
t_getrs_lo.start();
getrs( A_lo, pivots, X_lo, opts );
timers[ "gesv_mixed_gmres::getrs_lo" ] += t_getrs_lo.stop();
slate::copy( X_lo, Wj1, opts );

t_gemm_hi.start();
gemm<scalar_hi>(
one, A,
Wj1,
zero, Vj1,
opts );
timers[ "gesv_mixed_gmres::gemm_hi" ] += t_gemm_hi.stop();

// orthogonalize w/ CGS2
auto V0j = V.slice( 0, V.m()-1, 0, j );
auto V0jT = conj_transpose( V0j );
auto Hj = H.slice( 0, j, j, j );
t_gemm_hi.start();
gemm<scalar_hi>(
one, V0jT,
Vj1,
Expand All @@ -295,7 +310,9 @@ int64_t gesv_mixed_gmres(
Hj,
one, Vj1,
opts );
timers[ "gesv_mixed_gmres::gemm_hi" ] += t_gemm_hi.stop();
auto zj = z.slice( 0, j, 0, 0 );
t_gemm_hi.start();
gemm<scalar_hi>(
one, V0jT,
Vj1,
Expand All @@ -306,7 +323,10 @@ int64_t gesv_mixed_gmres(
zj,
one, Vj1,
opts );
timers[ "gesv_mixed_gmres::gemm_hi" ] += t_gemm_hi.stop();
Timer t_add_hi;
add( one, zj, one, Hj, opts );
timers[ "gesv_mixed_gmres::add_hi" ] += t_add_hi.stop();
auto Vj1_norm = norm( Norm::Fro, Vj1, opts );
scale( 1.0, Vj1_norm, Vj1, opts );
if (H.tileRank( 0, 0 ) == mpi_rank) {
Expand All @@ -316,6 +336,7 @@ int64_t gesv_mixed_gmres(
}

// apply givens rotations
Timer t_gesv_mixed_gmres_rotations;
if (H.tileRank( 0, 0 ) == mpi_rank) {
auto H_00 = H( 0, 0 );
for (int64_t i = 0; i < j; ++i) {
Expand All @@ -331,6 +352,7 @@ int64_t gesv_mixed_gmres(
givens_alpha[j], givens_beta[j] );
arnoldi_residual[0] = cabs1( S_00.at( j+1, 0 ) );
}
timers[ "gesv_mixed_gmres::rotations" ] += t_gesv_mixed_gmres_rotations.stop();
MPI_Bcast(
arnoldi_residual.data(), arnoldi_residual.size(),
mpi_type<scalar_hi>::value, S.tileRank( 0, 0 ),
Expand All @@ -341,13 +363,17 @@ int64_t gesv_mixed_gmres(
auto S_j = S.slice( 0, j-1, 0, 0 );
auto H_tri = TriangularMatrix<scalar_hi>(
Uplo::Upper, Diag::NonUnit, H_j );
Timer t_trsm_hi;
trsm( Side::Left, one, H_tri, S_j, opts );
timers[ "gesv_mixed_gmres::trsm_hi" ] += t_trsm_hi.stop();
auto W_0j = W.slice( 0, W.m()-1, 1, j ); // first column of W is unused
t_gemm_hi.start();
gemm<scalar_hi>(
one, W_0j,
S_j,
one, X,
opts );
timers[ "gesv_mixed_gmres::gemm_hi" ] += t_gemm_hi.stop();
}
}

Expand All @@ -361,13 +387,17 @@ int64_t gesv_mixed_gmres(
if (use_fallback) {
// Fall back to double precision factor and solve.
// Compute the LU factorization of A.
Timer t_getrf_hi;
info = getrf( A, pivots, opts );
timers[ "gesv_mixed_gmres::getrf_hi" ] = t_getrf_hi.stop();

// Solve the system A * X = B.
Timer t_getrs_hi;
if (info == 0) {
slate::copy( B, X, opts );
getrs( A, pivots, X, opts );
}
timers[ "gesv_mixed_gmres::getrs_hi" ] = t_getrs_hi.stop();
}
}

Expand All @@ -377,6 +407,7 @@ int64_t gesv_mixed_gmres(
B.clearWorkspace();
X.clearWorkspace();
}
timers[ "gesv_mixed_gmres" ] = t_gesv_mixed_gmres.stop();
return info;
}

Expand Down
15 changes: 15 additions & 0 deletions src/hegv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,45 @@ void hegv(

bool wantz = (Z.mt() > 0);

Timer t_hegv;

// 1. Form a Cholesky factorization of B.
Timer t_potrf;
potrf( B, opts );
timers[ "hegv::potrf" ] = t_potrf.stop();

// 2. Transform problem to standard eigenvalue problem.
Timer t_hegst;
hegst( itype, A, B, opts );
timers[ "hegv::hegst" ] = t_hegst.stop();

// 3. Solve the standard eigenvalue problem and solve.
Timer t_heev;
heev( A, Lambda, Z, opts );
timers[ "hegv::heev" ] = t_heev.stop();

timers[ "hegv::trsm" ] = 0;
timers[ "hegv::trmm" ] = 0;
if (wantz) {
// 4. Backtransform eigenvectors to the original problem.
auto L = TriangularMatrix<scalar_t>( Diag::NonUnit, B );
if (itype == 1 || itype == 2) {
// For A x = lambda B x and A B x = lambda x,
// backtransform eigenvectors: x = inv(L)^H y.
auto LH = conj_transpose( L );
Timer t_trsm;
trsm( Side::Left, one, LH, Z, opts );
timers[ "hegv::trsm" ] += t_trsm.stop();
}
else {
// For B A x = lambda x,
// backtransform eigenvectors: x = L y.
Timer t_trmm;
trmm( Side::Left, one, L, Z, opts );
timers[ "hegv::trmm" ] += t_trmm.stop();
}
}
timers[ "hegv" ] = t_hegv.stop();
}

//------------------------------------------------------------------------------
Expand Down
Loading
Loading