@@ -22,7 +22,6 @@ PW_Basis_K::~PW_Basis_K()
2222 delete[] igl2isz_k;
2323 delete[] igl2ig_k;
2424 delete[] gk2;
25- delete[] ig2ixyz_k_;
2625#if defined(__CUDA) || defined(__ROCM)
2726 if (this ->device == " gpu" ) {
2827 if (this ->precision == " single" ) {
@@ -169,6 +168,7 @@ void PW_Basis_K::setupIndGk()
169168 syncmem_int_h2d_op ()(gpu_ctx, cpu_ctx, this ->d_igl2isz_k , this ->igl2isz_k , this ->npwk_max * this ->nks );
170169 }
171170#endif
171+ this ->get_ig2ixyz_k ();
172172 return ;
173173}
174174
@@ -334,8 +334,12 @@ int& PW_Basis_K::getigl2ig(const int ik, const int igl) const
334334
335335void PW_Basis_K::get_ig2ixyz_k ()
336336{
337- delete[] this ->ig2ixyz_k_ ;
338- this ->ig2ixyz_k_ = new int [this ->npwk_max * this ->nks ];
337+ if (this ->device != " gpu" )
338+ {
339+ // only GPU need to get ig2ixyz_k
340+ return ;
341+ }
342+ int * ig2ixyz_k_cpu = new int [this ->npwk_max * this ->nks ];
339343 ModuleBase::Memory::record (" PW_B_K::ig2ixyz" , sizeof (int ) * this ->npwk_max * this ->nks );
340344 assert (gamma_only == false ); // We only finish non-gamma_only fft on GPU temperarily.
341345 for (int ik = 0 ; ik < this ->nks ; ++ik)
@@ -348,15 +352,12 @@ void PW_Basis_K::get_ig2ixyz_k()
348352 int ixy = this ->is2fftixy [is];
349353 int iy = ixy % this ->ny ;
350354 int ix = ixy / this ->ny ;
351- ig2ixyz_k_ [igl + ik * npwk_max] = iz + iy * nz + ix * ny * nz;
355+ ig2ixyz_k_cpu [igl + ik * npwk_max] = iz + iy * nz + ix * ny * nz;
352356 }
353357 }
354- #if defined(__CUDA) || defined(__ROCM)
355- if (this ->device == " gpu" ) {
356- resmem_int_op ()(gpu_ctx, ig2ixyz_k, this ->npwk_max * this ->nks );
357- syncmem_int_h2d_op ()(gpu_ctx, cpu_ctx, this ->ig2ixyz_k , this ->ig2ixyz_k_ , this ->npwk_max * this ->nks );
358- }
359- #endif
358+ resmem_int_op ()(gpu_ctx, ig2ixyz_k, this ->npwk_max * this ->nks );
359+ syncmem_int_h2d_op ()(gpu_ctx, cpu_ctx, this ->ig2ixyz_k , ig2ixyz_k_cpu, this ->npwk_max * this ->nks );
360+ delete[] ig2ixyz_k_cpu;
360361}
361362
362363std::vector<int > PW_Basis_K::get_ig2ix (const int ik) const
0 commit comments