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

Refactor: modify arguments of gemm and gemv #4238

Closed
wants to merge 1 commit into from
Closed
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
112 changes: 58 additions & 54 deletions source/module_elecstate/elecstate_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,35 +276,37 @@ void ElecStatePW<T, Device>::add_usrho(const psi::Psi<T, Device>& psi)
if (nbands == 1)
{
int inc = 1;
gemv_op()(this->ctx,
transa,
npw,
this->ppcell->nkb,
&one,
this->vkb,
this->ppcell->vkb.nc,
psi_now,
inc,
&zero,
becp,
inc);
gemv_op()({
.d = this->ctx,
.trans = transa,
.m = npw,
.n = this->ppcell->nkb,
.alpha = &one,
.A = this->vkb,
.lda = this->ppcell->vkb.nc,
.X = psi_now,
.incx = inc,
.beta = &zero,
.Y = becp,
.incy = inc});
}
else
{
gemm_op()(this->ctx,
transa,
transb,
this->ppcell->nkb,
nbands,
npw,
&one,
this->vkb,
this->ppcell->vkb.nc,
psi_now,
npwx,
&zero,
becp,
this->ppcell->nkb);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = this->ppcell->nkb,
.n = nbands,
.k = npw,
.alpha = &one,
.a = this->vkb,
.lda = this->ppcell->vkb.nc,
.b = psi_now,
.ldb = npwx,
.beta = &zero,
.c = becp,
.ldc = this->ppcell->nkb});
}
Parallel_Reduce::reduce_pool(becp, this->ppcell->nkb * nbands);

Expand Down Expand Up @@ -343,20 +345,21 @@ void ElecStatePW<T, Device>::add_usrho(const psi::Psi<T, Device>& psi)

char transa = 'C';
char transb = 'N';
gemm_op()(this->ctx,
transa,
transb,
atom->ncpp.nh,
atom->ncpp.nh,
nbands,
&one,
auxk1,
nbands,
auxk2,
nbands,
&zero,
aux_gk,
atom->ncpp.nh);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = atom->ncpp.nh,
.n = atom->ncpp.nh,
.k = nbands,
.alpha = &one,
.a = auxk1,
.lda = nbands,
.b = auxk2,
.ldb = nbands,
.beta = &zero,
.c = aux_gk,
.ldc = atom->ncpp.nh});
}

// copy output from GEMM into desired format
Expand Down Expand Up @@ -480,20 +483,21 @@ void ElecStatePW<T, Device>::addusdens_g(const Real* becsum, T* rhog)
// sum over atoms
char transa = 'N';
char transb = 'T';
gemm_op()(this->ctx,
transa,
transb,
npw,
nij,
atom->na,
&one,
skk,
npw,
&tbecsum[is * atom->na * nij],
nij,
&zero,
aux2,
npw);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = npw,
.n = nij,
.k = atom->na,
.alpha = &one,
.a = skk,
.lda = npw,
.b = &tbecsum[is * atom->na * nij],
.ldb = nij,
.beta = &zero,
.c = aux2,
.ldc = npw});

// sum over lm indices of Q_{lm}
int ijh = 0;
Expand Down
58 changes: 30 additions & 28 deletions source/module_hamilt_pw/hamilt_pwdft/forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,20 +1055,21 @@ void Forces<FPTYPE, Device>::cal_force_nl(ModuleBase::matrix& forcenl,
}
}
int npm = GlobalV::NPOL * nbands_occ;
gemm_op()(this->ctx,
transa,
transb,
nkb,
npm,
nbasis,
&ModuleBase::ONE,
vkb,
this->npwx,
psi_in[0].get_pointer(),
this->npwx,
&ModuleBase::ZERO,
becp,
nkb);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = nkb,
.n = npm,
.k = nbasis,
.alpha = &ModuleBase::ONE,
.a = vkb,
.lda = this->npwx,
.b = psi_in[0].get_pointer(),
.ldb = this->npwx,
.beta = &ModuleBase::ZERO,
.c = becp,
.ldc = nkb});
if (this->device == base_device::GpuDevice)
{
std::complex<FPTYPE>* h_becp = nullptr;
Expand Down Expand Up @@ -1101,20 +1102,21 @@ void Forces<FPTYPE, Device>::cal_force_nl(ModuleBase::matrix& forcenl,
gcar,
vkb1);
std::complex<double>* pdbecp = dbecp + ipol * GlobalV::NBANDS * nkb;
gemm_op()(this->ctx,
transa,
transb,
nkb,
npm,
nbasis,
&ModuleBase::ONE,
vkb1,
this->npwx,
psi_in[0].get_pointer(),
this->npwx,
&ModuleBase::ZERO,
pdbecp,
nkb);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = nkb,
.n = npm,
.k = nbasis,
.alpha = &ModuleBase::ONE,
.a = vkb1,
.lda = this->npwx,
.b = psi_in[0].get_pointer(),
.ldb = this->npwx,
.beta = &ModuleBase::ZERO,
.c = pdbecp,
.ldc = nkb});
} // end ipol

// don't need to reduce here, keep dbecp different in each processor,
Expand Down
138 changes: 72 additions & 66 deletions source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,35 +237,37 @@ void HamiltPW<T, Device>::sPsi(const T* psi_in, // psi
if (nbands == 1)
{
int inc = 1;
gemv_op()(this->ctx,
transa,
npw,
this->ppcell->nkb,
&one,
this->vkb,
this->ppcell->vkb.nc,
psi_in,
inc,
&zero,
becp,
inc);
gemv_op()({
.d = this->ctx,
.trans = transa,
.m = npw,
.n = this->ppcell->nkb,
.alpha = &one,
.A = this->vkb,
.lda = this->ppcell->vkb.nc,
.X = psi_in,
.incx = inc,
.beta = &zero,
.Y = becp,
.incy = inc});
}
else
{
gemm_op()(this->ctx,
transa,
transb,
this->ppcell->nkb,
nbands,
npw,
&one,
this->vkb,
this->ppcell->vkb.nc,
psi_in,
nrow,
&zero,
becp,
this->ppcell->nkb);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = this->ppcell->nkb,
.n = nbands,
.k = npw,
.alpha = &one,
.a = this->vkb,
.lda = this->ppcell->vkb.nc,
.b = psi_in,
.ldb = nrow,
.beta = &zero,
.c = becp,
.ldc = this->ppcell->nkb});
}

Parallel_Reduce::reduce_pool(becp, this->ppcell->nkb * nbands);
Expand Down Expand Up @@ -306,20 +308,21 @@ void HamiltPW<T, Device>::sPsi(const T* psi_in, // psi
for (int ia = 0; ia < atoms->na; ia++)
{
const int iat = GlobalC::ucell.itia2iat(it, ia);
gemm_op()(this->ctx,
transa,
transb,
nh,
nbands,
nh,
&one,
qqc,
nh,
&becp[this->ppcell->indv_ijkb0[iat]],
this->ppcell->nkb,
&zero,
&ps[this->ppcell->indv_ijkb0[iat]],
this->ppcell->nkb);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = nh,
.n = nbands,
.k = nh,
.alpha = &one,
.a = qqc,
.lda = nh,
.b = &becp[this->ppcell->indv_ijkb0[iat]],
.ldb = this->ppcell->nkb,
.beta = &zero,
.c = &ps[this->ppcell->indv_ijkb0[iat]],
.ldc = this->ppcell->nkb});
}
delmem_complex_op()(ctx, qqc);
}
Expand All @@ -328,35 +331,38 @@ void HamiltPW<T, Device>::sPsi(const T* psi_in, // psi
if (nbands == 1)
{
const int inc = 1;
gemv_op()(this->ctx,
transa,
npw,
this->ppcell->nkb,
&one,
this->vkb,
this->ppcell->vkb.nc,
ps,
inc,
&one,
spsi,
inc);
gemv_op()({
.d = this->ctx,
.trans = transa,
.m = npw,
.n = this->ppcell->nkb,
.alpha = &one,
.A = this->vkb,
.lda = this->ppcell->vkb.nc,
.X = ps,
.incx = inc,
.beta = &one,
.Y = spsi,
.incy = inc});

}
else
{
gemm_op()(this->ctx,
transa,
transb,
npw,
nbands,
this->ppcell->nkb,
&one,
this->vkb,
this->ppcell->vkb.nc,
ps,
this->ppcell->nkb,
&one,
spsi,
nrow);
gemm_op()({
.d = this->ctx,
.transa = transa,
.transb = transb,
.m = npw,
.n = nbands,
.k = this->ppcell->nkb,
.alpha = &one,
.a = this->vkb,
.lda = this->ppcell->vkb.nc,
.b = ps,
.ldb = this->ppcell->nkb,
.beta = &one,
.c = spsi,
.ldc = nrow});
}
}
delmem_complex_op()(this->ctx, ps);
Expand Down
Loading