@@ -19,6 +19,7 @@ PW_Basis_K::~PW_Basis_K()
1919 delete[] igl2ig_k;
2020 delete[] gk2;
2121 delete[] ig2ixyz_k_;
22+ #if defined(__CUDA) || defined(__ROCM)
2223 if (GlobalV::device_flag == " gpu" ) {
2324 if (GlobalV::precision_flag == " single" ) {
2425 delmem_sd_op ()(gpu_ctx, this ->s_kvec_c );
@@ -34,13 +35,16 @@ PW_Basis_K::~PW_Basis_K()
3435 delmem_int_op ()(gpu_ctx, this ->d_igl2isz_k );
3536 }
3637 else {
38+ #endif
3739 if (GlobalV::precision_flag == " single" ) {
3840 delmem_sh_op ()(cpu_ctx, this ->s_kvec_c );
3941 delmem_sh_op ()(cpu_ctx, this ->s_gcar );
4042 delmem_sh_op ()(cpu_ctx, this ->s_gk2 );
4143 }
4244 // There's no need to delete double pointers while in a CPU environment.
45+ #if defined(__CUDA) || defined(__ROCM)
4346 }
47+ #endif
4448}
4549
4650void PW_Basis_K:: initparameters (
@@ -86,6 +90,7 @@ void PW_Basis_K:: initparameters(
8690 this ->fftnxy = this ->fftnx * this ->fftny ;
8791 this ->fftnxyz = this ->fftnxy * this ->fftnz ;
8892 this ->distribution_type = distribution_type_in;
93+ #if defined(__CUDA) || defined(__ROCM)
8994 if (GlobalV::device_flag == " gpu" ) {
9095 if (GlobalV::precision_flag == " single" ) {
9196 resmem_sd_op ()(gpu_ctx, this ->s_kvec_c , this ->nks * 3 );
@@ -97,6 +102,7 @@ void PW_Basis_K:: initparameters(
97102 }
98103 }
99104 else {
105+ #endif
100106 if (GlobalV::precision_flag == " single" ) {
101107 resmem_sh_op ()(cpu_ctx, this ->s_kvec_c , this ->nks * 3 );
102108 castmem_d2s_h2h_op ()(cpu_ctx, cpu_ctx, this ->s_kvec_c , reinterpret_cast <double *>(&this ->kvec_c [0 ][0 ]), this ->nks * 3 );
@@ -105,7 +111,9 @@ void PW_Basis_K:: initparameters(
105111 this ->d_kvec_c = reinterpret_cast <double *>(&this ->kvec_c [0 ][0 ]);
106112 }
107113 // There's no need to allocate double pointers while in a CPU environment.
114+ #if defined(__CUDA) || defined(__ROCM)
108115 }
116+ #endif
109117}
110118
111119void PW_Basis_K::setupIndGk ()
@@ -151,10 +159,12 @@ void PW_Basis_K::setupIndGk()
151159 }
152160 }
153161 }
162+ #if defined(__CUDA) || defined(__ROCM)
154163 if (GlobalV::device_flag == " gpu" ) {
155164 resmem_int_op ()(gpu_ctx, this ->d_igl2isz_k , this ->npwk_max * this ->nks );
156165 syncmem_int_h2d_op ()(gpu_ctx, cpu_ctx, this ->d_igl2isz_k , this ->igl2isz_k , this ->npwk_max * this ->nks );
157166 }
167+ #endif
158168 return ;
159169}
160170
@@ -210,6 +220,7 @@ void PW_Basis_K::collect_local_pw()
210220 this ->gcar [ik * npwk_max + igl] = f * this ->G ;
211221 }
212222 }
223+ #if defined(__CUDA) || defined(__ROCM)
213224 if (GlobalV::device_flag == " gpu" ) {
214225 if (GlobalV::precision_flag == " single" ) {
215226 resmem_sd_op ()(gpu_ctx, this ->s_gk2 , this ->npwk_max * this ->nks );
@@ -225,6 +236,7 @@ void PW_Basis_K::collect_local_pw()
225236 }
226237 }
227238 else {
239+ #endif
228240 if (GlobalV::precision_flag == " single" ) {
229241 resmem_sh_op ()(cpu_ctx, this ->s_gk2 , this ->npwk_max * this ->nks , " PW_B_K::s_gk2" );
230242 resmem_sh_op ()(cpu_ctx, this ->s_gcar , this ->npwk_max * this ->nks * 3 , " PW_B_K::s_gcar" );
@@ -236,7 +248,9 @@ void PW_Basis_K::collect_local_pw()
236248 this ->d_gk2 = this ->gk2 ;
237249 }
238250 // There's no need to allocate double pointers while in a CPU environment.
251+ #if defined(__CUDA) || defined(__ROCM)
239252 }
253+ #endif
240254}
241255
242256ModuleBase::Vector3<double > PW_Basis_K:: cal_GplusK_cartesian (const int ik, const int ig) const {
@@ -293,7 +307,7 @@ int& PW_Basis_K::getigl2ig(const int ik, const int igl) const
293307
294308void PW_Basis_K::get_ig2ixyz_k ()
295309{
296-
310+ delete[] this -> ig2ixyz_k_ ;
297311 this ->ig2ixyz_k_ = new int [this ->npwk_max * this ->nks ];
298312 ModuleBase::Memory::record (" PW_B_K::ig2ixyz" , sizeof (int ) * this ->npwk_max * this ->nks );
299313 assert (gamma_only == false ); // We only finish non-gamma_only fft on GPU temperarily.
@@ -310,10 +324,12 @@ void PW_Basis_K::get_ig2ixyz_k()
310324 ig2ixyz_k_[igl + ik * npwk_max] = iz + iy * nz + ix * ny * nz;
311325 }
312326 }
327+ #if defined(__CUDA) || defined(__ROCM)
313328 if (GlobalV::device_flag == " gpu" ) {
314329 resmem_int_op ()(gpu_ctx, ig2ixyz_k, this ->npwk_max * this ->nks );
315330 syncmem_int_h2d_op ()(gpu_ctx, cpu_ctx, this ->ig2ixyz_k , this ->ig2ixyz_k_ , this ->npwk_max * this ->nks );
316331 }
332+ #endif
317333}
318334
319335template <>
0 commit comments