Skip to content

Commit ec160ec

Browse files
author
abacus_fixer
committed
fix(exx): declare explicit specializations before extern template instantiation
The extern template class declarations in op_pw_exx.h trigger implicit instantiation of all template members when the header is included. The explicit specializations of cal_density_recip and rho_recip2real in the .cpp file were therefore "after instantiation", causing a compile error. Fix by adding forward declarations of all 8 explicit specializations (CPU + GPU, cal_density_recip + rho_recip2real, complex<double> + complex<float>) in the header, placed before the extern template block.
1 parent c29975d commit ec160ec

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

source/source_pw/module_pwdft/op_pw_exx.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,63 @@ class OperatorEXXPW : public OperatorPW<T, Device>
175175

176176
};
177177

178+
// Explicit specializations must be declared before any implicit instantiation.
179+
// The extern template declarations below would otherwise instantiate the
180+
// generic cal_density_recip / rho_recip2real members.
181+
template <>
182+
void OperatorEXXPW<std::complex<double>, base_device::DEVICE_CPU>::cal_density_recip(
183+
const std::complex<double>* psi_nk_real,
184+
const std::complex<double>* psi_mq_real,
185+
double omega) const;
186+
187+
template <>
188+
void OperatorEXXPW<std::complex<float>, base_device::DEVICE_CPU>::cal_density_recip(
189+
const std::complex<float>* psi_nk_real,
190+
const std::complex<float>* psi_mq_real,
191+
double omega) const;
192+
193+
template <>
194+
void OperatorEXXPW<std::complex<double>, base_device::DEVICE_CPU>::rho_recip2real(
195+
const std::complex<double>* rho_recip,
196+
std::complex<double>* rho_real,
197+
bool add,
198+
double factor) const;
199+
200+
template <>
201+
void OperatorEXXPW<std::complex<float>, base_device::DEVICE_CPU>::rho_recip2real(
202+
const std::complex<float>* rho_recip,
203+
std::complex<float>* rho_real,
204+
bool add,
205+
float factor) const;
206+
207+
#if ((defined __CUDA) || (defined __ROCM))
208+
template <>
209+
void OperatorEXXPW<std::complex<double>, base_device::DEVICE_GPU>::cal_density_recip(
210+
const std::complex<double>* psi_nk_real,
211+
const std::complex<double>* psi_mq_real,
212+
double omega) const;
213+
214+
template <>
215+
void OperatorEXXPW<std::complex<float>, base_device::DEVICE_GPU>::cal_density_recip(
216+
const std::complex<float>* psi_nk_real,
217+
const std::complex<float>* psi_mq_real,
218+
double omega) const;
219+
220+
template <>
221+
void OperatorEXXPW<std::complex<double>, base_device::DEVICE_GPU>::rho_recip2real(
222+
const std::complex<double>* rho_recip,
223+
std::complex<double>* rho_real,
224+
bool add,
225+
double factor) const;
226+
227+
template <>
228+
void OperatorEXXPW<std::complex<float>, base_device::DEVICE_GPU>::rho_recip2real(
229+
const std::complex<float>* rho_recip,
230+
std::complex<float>* rho_real,
231+
bool add,
232+
float factor) const;
233+
#endif
234+
178235
extern template class OperatorEXXPW<std::complex<float>, base_device::DEVICE_CPU>;
179236
extern template class OperatorEXXPW<std::complex<double>, base_device::DEVICE_CPU>;
180237
#if ((defined __CUDA) || (defined __ROCM))

0 commit comments

Comments
 (0)