Skip to content

Commit d453ba9

Browse files
committed
restructured Lanczos for ChaseMpiMultiGPU
1 parent 94b1b22 commit d453ba9

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

ChASE-MPI/impl/chase_mpidla.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,10 @@ class ChaseMpiDLA : public ChaseMpiDLAInterface<T>
15731573
#ifdef USE_NSIGHT
15741574
nvtxRangePushA("Lanczos: loop");
15751575
#endif
1576-
Base<T> real_alpha = t_norm_p2(m_, v1_);
1577-
MPI_Allreduce(MPI_IN_PLACE, &real_alpha, 1, getMPI_Type<Base<T>>(),
1576+
//Base<T> real_alpha = t_norm_p2(m_, v1_);
1577+
Base<T> real_alpha = t_nrm2(m_, v1_, 1);
1578+
real_alpha = std::pow(real_alpha,2);
1579+
MPI_Allreduce(MPI_IN_PLACE, &real_alpha, 1, getMPI_Type<Base<T>>(),
15781580
MPI_SUM, col_comm_);
15791581
real_alpha = std::sqrt(real_alpha);
15801582
alpha = T(1 / real_alpha);
@@ -1603,8 +1605,10 @@ class ChaseMpiDLA : public ChaseMpiDLAInterface<T>
16031605
t_axpy(m_, &beta, v0_, 1, v2_, 1);
16041606
beta = -beta;
16051607

1606-
real_beta = t_norm_p2(m_, v2_);
1607-
MPI_Allreduce(MPI_IN_PLACE, &real_beta, 1, getMPI_Type<Base<T>>(),
1608+
//real_beta = t_norm_p2(m_, v2_);
1609+
real_beta = t_nrm2(m_, v2_, 1);
1610+
real_beta = std::pow(real_beta, 2);
1611+
MPI_Allreduce(MPI_IN_PLACE, &real_beta, 1, getMPI_Type<Base<T>>(),
16081612
MPI_SUM, col_comm_);
16091613
real_beta = std::sqrt(real_beta);
16101614

ChASE-MPI/impl/chase_mpidla_mgpu.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ class ChaseMpiDLAMultiGPU : public ChaseMpiDLAInterface<T>
259259
cudaMalloc((void**)&d_ritz_, sizeof(Base<T>) * (nev_ + nex_)));
260260
cuda_exec(
261261
cudaMalloc((void**)&states_, sizeof(curandStatePhilox4_32_10_t) * (256 * 32)));
262+
cuda_exec(cudaMalloc((void**)&d_v_, sizeof(T) * m_));
263+
cuda_exec(cudaMalloc((void**)&d_w_, sizeof(T) * n_));
262264

263265
cublasCreate(&cublasH_);
264266
cusolverDnCreate(&cusolverH_);
@@ -486,7 +488,21 @@ class ChaseMpiDLAMultiGPU : public ChaseMpiDLAInterface<T>
486488
//! - All required operations for this function has been done in for
487489
//! ChaseMpiDLA::applyVec().
488490
//! - This function contains nothing in this class.
489-
void applyVec(T* B, T* C) override {}
491+
void applyVec(T* v, T* w) override
492+
{
493+
T alpha = T(1.0);
494+
T beta = T(0.0);
495+
496+
cuda_exec(cudaMemcpy(d_v_, v, m_ * sizeof(T), cudaMemcpyHostToDevice));
497+
std::size_t k = 1;
498+
cublas_status_ = cublasTgemm(
499+
cublasH_, CUBLAS_OP_C, CUBLAS_OP_N, n_, k, m_, &alpha, d_H_, m_,
500+
d_v_, m_, &beta, d_w_, n_);
501+
assert(cublas_status_ == CUBLAS_STATUS_SUCCESS);
502+
503+
cuda_exec(cudaMemcpy(w, d_w_, n_ * sizeof(T), cudaMemcpyDeviceToHost));
504+
505+
}
490506
int get_nprocs() const override { return matrix_properties_->get_nprocs(); }
491507
void Start() override {}
492508
void End() override {}
@@ -786,6 +802,9 @@ class ChaseMpiDLAMultiGPU : public ChaseMpiDLAInterface<T>
786802
T* d_work_ =
787803
NULL; //!< a pointer to a local buffer on GPU, which is reserved for the
788804
//!< extra buffer required for any cuSOLVER routines
805+
T *d_v_;
806+
T *d_w_;
807+
789808
std::size_t pitchB; //!< pitch for `B_` and `d_B_`
790809
std::size_t pitchB2; //!< pitch for `B2_` and `d_B2_`
791810
std::size_t pitchC; //!< pitch for `C_` and `d_C_`

0 commit comments

Comments
 (0)