From 01243458d151806fce03aaba58adc57807c6ac14 Mon Sep 17 00:00:00 2001 From: Chen Nuo <49788094+Cstandardlib@users.noreply.github.com> Date: Wed, 1 Apr 2026 20:55:47 +0800 Subject: [PATCH 1/2] Fix DSP sdft memory op --- source/source_pw/module_stodft/sto_che.h | 9 ++++-- source/source_pw/module_stodft/sto_elecond.h | 11 +++++-- source/source_pw/module_stodft/sto_forces.h | 6 +++- source/source_pw/module_stodft/sto_iter.h | 30 ++++++++++++------- .../source_pw/module_stodft/sto_stress_pw.h | 7 +++++ 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/source/source_pw/module_stodft/sto_che.h b/source/source_pw/module_stodft/sto_che.h index aef324a9fd5..15cbd84e9f7 100644 --- a/source/source_pw/module_stodft/sto_che.h +++ b/source/source_pw/module_stodft/sto_che.h @@ -26,9 +26,14 @@ class StoChe private: Device* ctx = {}; +#ifdef __DSP + using resmem_var_op = base_device::memory::resize_memory_op_mt; + using delmem_var_op = base_device::memory::delete_memory_op_mt; +#else using resmem_var_op = base_device::memory::resize_memory_op; - using syncmem_var_d2h_op = base_device::memory::synchronize_memory_op; using delmem_var_op = base_device::memory::delete_memory_op; +#endif + using syncmem_var_d2h_op = base_device::memory::synchronize_memory_op; }; /** @@ -64,4 +69,4 @@ REAL vTMv(const REAL* v, const REAL* M, const int n) return result; } -#endif \ No newline at end of file +#endif diff --git a/source/source_pw/module_stodft/sto_elecond.h b/source/source_pw/module_stodft/sto_elecond.h index 7a0875c14d7..ca7294e82b5 100644 --- a/source/source_pw/module_stodft/sto_elecond.h +++ b/source/source_pw/module_stodft/sto_elecond.h @@ -6,7 +6,7 @@ #include "source_pw/module_stodft/sto_wf.h" #include "source_hsolver/hsolver_pw_sdft.h" -template +template class Sto_EleCond : protected EleCond { public: @@ -16,8 +16,13 @@ class Sto_EleCond : protected EleCond using lowTYPE = double; #endif using lcomplex = std::complex; - using resmem_lcomplex_op = base_device::memory::resize_memory_op, Device>; +#ifdef __DSP + using resmem_lcomplex_op = base_device::memory::resize_memory_op_mt, Device>; + using delmem_lcomplex_op = base_device::memory::delete_memory_op_mt, Device>; +#else + using resmem_lcomplex_op = base_device::memory::resize_memory_op, Device>; using delmem_lcomplex_op = base_device::memory::delete_memory_op, Device>; +#endif using cpymem_lcomplex_op = base_device::memory::synchronize_memory_op, Device, Device>; using castmem_lcomplex_op = base_device::memory::cast_memory_op, std::complex, Device, Device>; using cpymem_complex_op = base_device::memory::synchronize_memory_op, Device, Device>; @@ -114,4 +119,4 @@ class Sto_EleCond : protected EleCond const std::complex& factor, const int bandinfo[6]); }; -#endif // ELECOND_H \ No newline at end of file +#endif // ELECOND_H diff --git a/source/source_pw/module_stodft/sto_forces.h b/source/source_pw/module_stodft/sto_forces.h index b7aae9f6742..d7c2dbc4d1e 100644 --- a/source/source_pw/module_stodft/sto_forces.h +++ b/source/source_pw/module_stodft/sto_forces.h @@ -44,9 +44,13 @@ class Sto_Forces : public Forces const UnitCell& ucell, const psi::Psi, Device>& psi_in, const Stochastic_WF, Device>& stowf); - +#ifdef __DSP + using resmem_var_op = base_device::memory::resize_memory_op_mt; + using delmem_var_op = base_device::memory::delete_memory_op_mt; +#else using resmem_var_op = base_device::memory::resize_memory_op; using delmem_var_op = base_device::memory::delete_memory_op; +#endif using syncmem_var_h2d_op = base_device::memory::synchronize_memory_op; using syncmem_var_d2h_op = base_device::memory::synchronize_memory_op; }; diff --git a/source/source_pw/module_stodft/sto_iter.h b/source/source_pw/module_stodft/sto_iter.h index 8a977965026..97df2639310 100644 --- a/source/source_pw/module_stodft/sto_iter.h +++ b/source/source_pw/module_stodft/sto_iter.h @@ -46,7 +46,7 @@ class Stochastic_Iter /** * @brief sum demet and eband energies for each k point and each band - * + * * @param stowf stochastic wave function * @param pes elecstate * @param pHamilt hamiltonian @@ -59,7 +59,7 @@ class Stochastic_Iter /** * @brief calculate the density - * + * * @param ucell reference to unit cell * @param stowf stochastic wave function * @param pes elecstate @@ -72,15 +72,15 @@ class Stochastic_Iter /** * @brief calculate total number of electrons - * + * * @param pes elecstate - * @return double + * @return double */ double calne(elecstate::ElecState* pes); /** * @brief solve ne(mu) = ne_target and get chemical potential mu - * + * * @param iter scf iteration index * @param pes elecstate */ @@ -88,7 +88,7 @@ class Stochastic_Iter /** * @brief orthogonalize stochastic wave functions with KS wave functions - * + * * @param ik k point index * @param psi KS wave functions * @param stowf stochastic wave functions @@ -97,7 +97,7 @@ class Stochastic_Iter /** * @brief check emax and emin - * + * * @param ik k point index * @param istep ion step index * @param iter scf iteration index @@ -107,7 +107,7 @@ class Stochastic_Iter /** * @brief check precision of Chebyshev expansion - * + * * @param ref reference value * @param thr threshold * @param info information @@ -153,14 +153,22 @@ class Stochastic_Iter const Device* ctx = {}; const base_device::DEVICE_CPU* cpu_ctx = {}; using ct_Device = typename container::PsiToContainer::type; +#ifdef __DSP + using setmem_var_op = base_device::memory::set_memory_op_mt; + using resmem_var_op = base_device::memory::resize_memory_op_mt; + using delmem_var_op = base_device::memory::delete_memory_op_mt; + using resmem_complex_op = base_device::memory::resize_memory_op_mt; + using delmem_complex_op = base_device::memory::delete_memory_op_mt; +#else using setmem_var_op = base_device::memory::set_memory_op; - using syncmem_var_h2d_op = base_device::memory::synchronize_memory_op; - using syncmem_var_d2h_op = base_device::memory::synchronize_memory_op; - using cpymem_complex_op = base_device::memory::synchronize_memory_op; using resmem_var_op = base_device::memory::resize_memory_op; using delmem_var_op = base_device::memory::delete_memory_op; using resmem_complex_op = base_device::memory::resize_memory_op; using delmem_complex_op = base_device::memory::delete_memory_op; +#endif + using syncmem_var_h2d_op = base_device::memory::synchronize_memory_op; + using syncmem_var_d2h_op = base_device::memory::synchronize_memory_op; + using cpymem_complex_op = base_device::memory::synchronize_memory_op; using castmem_d2z_op = base_device::memory::cast_memory_op; using castmem_var_d2h_op = base_device::memory::cast_memory_op; using gemv_op = ModuleBase::gemv_op; diff --git a/source/source_pw/module_stodft/sto_stress_pw.h b/source/source_pw/module_stodft/sto_stress_pw.h index fd470372493..21edb937978 100644 --- a/source/source_pw/module_stodft/sto_stress_pw.h +++ b/source/source_pw/module_stodft/sto_stress_pw.h @@ -52,9 +52,16 @@ class Sto_Stress_PW : public Stress_Func const Stochastic_WF, Device>& stowf); private: +#ifdef __DSP + using resmem_var_op = base_device::memory::resize_memory_op_mt; + using setmem_var_op = base_device::memory::set_memory_op_mt; + using delmem_var_op = base_device::memory::delete_memory_op_mt; + +#else using resmem_var_op = base_device::memory::resize_memory_op; using setmem_var_op = base_device::memory::set_memory_op; using delmem_var_op = base_device::memory::delete_memory_op; +#endif using syncmem_var_d2h_op = base_device::memory::synchronize_memory_op; }; #endif From 6287e57e759a41a26271218a7f25a43066999198 Mon Sep 17 00:00:00 2001 From: Chen Nuo <49788094+Cstandardlib@users.noreply.github.com> Date: Wed, 1 Apr 2026 21:32:35 +0800 Subject: [PATCH 2/2] Fix include guard --- source/source_pw/module_stodft/sto_elecond.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/source_pw/module_stodft/sto_elecond.h b/source/source_pw/module_stodft/sto_elecond.h index ca7294e82b5..78cb5fcfb6f 100644 --- a/source/source_pw/module_stodft/sto_elecond.h +++ b/source/source_pw/module_stodft/sto_elecond.h @@ -119,4 +119,4 @@ class Sto_EleCond : protected EleCond const std::complex& factor, const int bandinfo[6]); }; -#endif // ELECOND_H +#endif // STOELECOND_H