Skip to content

Commit 9b74a0a

Browse files
author
chengleizheng
committed
try to reduce transmission times of data
1 parent 6772c4e commit 9b74a0a

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

source/source_estate/elecstate_pw.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ void ElecStatePW<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
136136
psi.fix_k(ik);
137137
this->updateRhoK(psi);
138138
}
139-
140-
this->add_usrho(psi);
141-
139+
142140
if (PARAM.inp.device == "gpu" || PARAM.inp.precision == "single")
143141
{
144142
for (int ii = 0; ii < PARAM.inp.nspin; ii++)
@@ -150,6 +148,8 @@ void ElecStatePW<T, Device>::psiToRho(const psi::Psi<T, Device>& psi)
150148
}
151149
}
152150
}
151+
152+
this->add_usrho(psi);
153153
this->parallelK();
154154
ModuleBase::timer::end("ElecStatePW", "psiToRho");
155155
}
@@ -449,17 +449,7 @@ void ElecStatePW<T, Device>::add_usrho(const psi::Psi<T, Device>& psi)
449449
{
450450
for (int is = 0; is < PARAM.inp.nspin; is++)
451451
{
452-
// D2H rho → CPU buffer (real2recip reads rho via CPU loops)
453-
std::vector<Real> rho_host(this->rhopw_smooth->nrxx);
454-
syncmem_var_d2h_op()(rho_host.data(), this->rho[is], this->rhopw_smooth->nrxx);
455-
// D2H rhog → CPU temp
456-
std::vector<T> rhog_host(this->rhopw_smooth->npw);
457-
syncmem_complex_d2h_op()(rhog_host.data(), this->rhog[is], this->rhopw_smooth->npw);
458-
// CPU real2recip
459-
// TODO: replace with cufft to keep rho/rhog on device
460-
this->rhopw_smooth->real2recip(rho_host.data(), rhog_host.data());
461-
// H2D rhog back to device
462-
syncmem_complex_h2d_op()(this->rhog[is], rhog_host.data(), this->rhopw_smooth->npw);
452+
this->rhopw_smooth->real2recip(this->charge->rho[is], this->charge->rhog[is]);
463453
}
464454
}
465455

@@ -474,16 +464,7 @@ void ElecStatePW<T, Device>::add_usrho(const psi::Psi<T, Device>& psi)
474464
{
475465
for (int is = 0; is < PARAM.inp.nspin; is++)
476466
{
477-
// D2H rhog → CPU temp (recip2real reads rhog via CPU loops)
478-
std::vector<T> rhog_host(this->charge->rhopw->npw);
479-
syncmem_complex_d2h_op()(rhog_host.data(), this->rhog[is], this->charge->rhopw->npw);
480-
// D2H rho → CPU buffer
481-
std::vector<Real> rho_host(this->charge->rhopw->nrxx);
482-
syncmem_var_d2h_op()(rho_host.data(), this->rho[is], this->charge->rhopw->nrxx);
483-
// CPU recip2real
484-
this->charge->rhopw->recip2real(rhog_host.data(), rho_host.data());
485-
// H2D rho back to GPU
486-
syncmem_var_h2d_op()(this->rho[is], rho_host.data(), this->charge->rhopw->nrxx);
467+
this->charge->rhopw->recip2real(this->charge->rhog[is], this->charge->rho[is]);
487468
}
488469
}
489470
}

0 commit comments

Comments
 (0)