Skip to content

Commit 556b836

Browse files
author
abacus_fixer
committed
fix: add GPU method-level explicit instantiation for split template files
After splitting fs_nonlocal_tools.cpp and onsite_proj_tools.cpp into multiple .cpp files with method-level explicit instantiation, only CPU instantiations were added to the split files. The whole-class explicit instantiation in the main file does not instantiate methods defined in other translation units, causing undefined reference errors for DEVICE_GPU specializations during GPU linking. Add #if ((defined __CUDA) || (defined __ROCM)) guarded GPU method-level explicit instantiations mirroring the existing CPU ones in: - fs_nonlocal_tools_vkb.cpp (cal_vkb/cal_becp/reduce_pool_becp) - fs_nonlocal_tools_stress.cpp (cal_vkb_deri_s/cal_dbecp_s/cal_stress) - fs_nonlocal_tools_force.cpp (cal_vkb_deri_f/cal_dbecp_f/save_vkb/ revert_vkb/transfer_gcar/cal_force) - onsite_proj_tools_dbecp.cpp (cal_dbecp_s/cal_dbecp_f/save_vkb/ revert_vkb/transfer_gcar) - onsite_proj_tools_force.cpp (cal_force_dftu/cal_force_dspin) - onsite_proj_tools_stress.cpp (cal_stress_dftu/cal_stress_dspin) Verified with local GPU build (USE_CUDA=ON): abacus_pw_gpu links cleanly.
1 parent 575be93 commit 556b836

6 files changed

Lines changed: 66 additions & 0 deletions

File tree

source/source_pw/module_pwdft/fs_nonlocal_tools_force.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,27 @@ template void FS_Nonlocal_tools<double, base_device::DEVICE_CPU>::cal_force(cons
325325
const bool&,
326326
double*,
327327
const int&);
328+
#if ((defined __CUDA) || (defined __ROCM))
329+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_vkb_deri_f(const int&,
330+
const int&,
331+
const int&);
332+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_dbecp_f(const int&,
333+
const int&,
334+
const int&,
335+
const int&,
336+
const std::complex<double>*,
337+
const int&);
338+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::save_vkb(const int&, const int&);
339+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::revert_vkb(const int&, const int&);
340+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::transfer_gcar(const int&,
341+
const int&,
342+
const double*);
343+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_force(const int&,
344+
const int&,
345+
const int&,
346+
const bool&,
347+
double*,
348+
const int&);
349+
#endif
328350

329351
} // namespace hamilt

source/source_pw/module_pwdft/fs_nonlocal_tools_stress.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,22 @@ template void FS_Nonlocal_tools<double, base_device::DEVICE_CPU>::cal_stress(con
259259
const int&,
260260
double*,
261261
const int&);
262+
#if ((defined __CUDA) || (defined __ROCM))
263+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_vkb_deri_s(const int&,
264+
const int&,
265+
const int&,
266+
const int&);
267+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_dbecp_s(const int&,
268+
const int&,
269+
const std::complex<double>*,
270+
const int&);
271+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_stress(const int&,
272+
const int&,
273+
const bool&,
274+
const int&,
275+
const int&,
276+
double*,
277+
const int&);
278+
#endif
262279

263280
} // namespace hamilt

source/source_pw/module_pwdft/fs_nonlocal_tools_vkb.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,13 @@ template void FS_Nonlocal_tools<double, base_device::DEVICE_CPU>::cal_becp(const
158158
const std::complex<double>*,
159159
const int&);
160160
template void FS_Nonlocal_tools<double, base_device::DEVICE_CPU>::reduce_pool_becp(const int&);
161+
#if ((defined __CUDA) || (defined __ROCM))
162+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_vkb(const int&, const int&);
163+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::cal_becp(const int&,
164+
const int&,
165+
const std::complex<double>*,
166+
const int&);
167+
template void FS_Nonlocal_tools<double, base_device::DEVICE_GPU>::reduce_pool_becp(const int&);
168+
#endif
161169

162170
} // namespace hamilt

source/source_pw/module_pwdft/onsite_proj_tools_dbecp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,12 @@ template void Onsite_Proj_tools<double, base_device::DEVICE_CPU>::cal_dbecp_f(in
359359
template void Onsite_Proj_tools<double, base_device::DEVICE_CPU>::save_vkb(int, int);
360360
template void Onsite_Proj_tools<double, base_device::DEVICE_CPU>::revert_vkb(int, int);
361361
template void Onsite_Proj_tools<double, base_device::DEVICE_CPU>::transfer_gcar(int, int, const double*);
362+
#if ((defined __CUDA) || (defined __ROCM))
363+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::cal_dbecp_s(int, int, int, int);
364+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::cal_dbecp_f(int, int, int);
365+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::save_vkb(int, int);
366+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::revert_vkb(int, int);
367+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::transfer_gcar(int, int, const double*);
368+
#endif
362369

363370
} // namespace hamilt

source/source_pw/module_pwdft/onsite_proj_tools_force.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,11 @@ template void Onsite_Proj_tools<double, base_device::DEVICE_CPU>::cal_force_dftu
132132
int, int, double*, const int*, const std::complex<double>*, const int, const double*);
133133
template void Onsite_Proj_tools<double, base_device::DEVICE_CPU>::cal_force_dspin(
134134
int, int, double*, const ModuleBase::Vector3<double>*, const double*);
135+
#if ((defined __CUDA) || (defined __ROCM))
136+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::cal_force_dftu(
137+
int, int, double*, const int*, const std::complex<double>*, const int, const double*);
138+
template void Onsite_Proj_tools<double, base_device::DEVICE_GPU>::cal_force_dspin(
139+
int, int, double*, const ModuleBase::Vector3<double>*, const double*);
140+
#endif
135141

136142
} // namespace hamilt

source/source_pw/module_pwdft/onsite_proj_tools_stress.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,11 @@ template double Onsite_Proj_tools<double, base_device::DEVICE_CPU>::cal_stress_d
179179
int, int, const int*, const std::complex<double>*, const int, const double*);
180180
template double Onsite_Proj_tools<double, base_device::DEVICE_CPU>::cal_stress_dspin(
181181
int, int, const ModuleBase::Vector3<double>*, const double*);
182+
#if ((defined __CUDA) || (defined __ROCM))
183+
template double Onsite_Proj_tools<double, base_device::DEVICE_GPU>::cal_stress_dftu(
184+
int, int, const int*, const std::complex<double>*, const int, const double*);
185+
template double Onsite_Proj_tools<double, base_device::DEVICE_GPU>::cal_stress_dspin(
186+
int, int, const ModuleBase::Vector3<double>*, const double*);
187+
#endif
182188

183189
} // namespace hamilt

0 commit comments

Comments
 (0)