@@ -76,6 +76,7 @@ Diago_DavSubspace<T, Device>::Diago_DavSubspace(const std::vector<Real>& precond
7676 {
7777 resmem_real_op ()(this ->d_precondition , nbasis_in);
7878 // syncmem_var_h2d_op()(this->ctx, this->cpu_ctx, this->d_precondition, this->precondition.data(), nbasis_in);
79+ resmem_real_op ()(this ->d_eigenvalue , this ->nbase_x );
7980 }
8081#endif
8182}
@@ -94,6 +95,7 @@ Diago_DavSubspace<T, Device>::~Diago_DavSubspace()
9495 if (this ->device == base_device::GpuDevice)
9596 {
9697 delmem_real_op ()(this ->d_precondition );
98+ delmem_real_op ()(this ->d_eigenvalue );
9799 }
98100#endif
99101}
@@ -316,30 +318,15 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
316318 this ->dim );
317319
318320 // Eigenvalues operation section
319- std::vector<Real> e_temp_cpu (this ->notconv , 0 );
320- Real* e_temp_hd = e_temp_cpu.data ();
321+ Real* e_temp_hd = eigenvalue_iter->data ();
321322 if (this ->device == base_device::GpuDevice)
322323 {
323- e_temp_hd = nullptr ;
324- resmem_real_op ()( e_temp_hd, nbase) ;
324+ syncmem_var_h2d_op ()( this -> d_eigenvalue , eigenvalue_iter-> data (), this -> nbase_x ) ;
325+ e_temp_hd = this -> d_eigenvalue ;
325326 }
326327
327- for (int m = 0 ; m < this ->notconv ; m++)
328- {
329- e_temp_cpu[m] = -(*eigenvalue_iter)[m];
330- }
331-
332- if (this ->device == base_device::GpuDevice)
333- {
334- syncmem_var_h2d_op ()(e_temp_hd, e_temp_cpu.data (), this ->notconv );
335- }
336-
337- apply_eigenvalues_op<T, Device>()(nbase, this ->nbase_x , this ->notconv , this ->vcc , this ->vcc , e_temp_hd);
338-
339- if (this ->device == base_device::GpuDevice)
340- {
341- delmem_real_op ()(e_temp_hd);
342- }
328+ // vcc = - vcc * eigenvalue
329+ ModuleBase::matrix_mul_vector_op<T, Device>()(nbase, notconv, vcc, this ->nbase_x , eigenvalue_iter->data (), -1.0 , vcc, this ->nbase_x );
343330
344331#ifdef __DSP
345332 ModuleBase::gemm_op_mt<T, Device>()
@@ -364,17 +351,12 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
364351#if defined(__CUDA) || defined(__ROCM)
365352 if (this ->device == base_device::GpuDevice)
366353 {
367- Real* eigenvalues_gpu = nullptr ;
368- resmem_real_op ()(eigenvalues_gpu, notconv);
369- syncmem_var_h2d_op ()(eigenvalues_gpu, (*eigenvalue_iter).data (), notconv);
370-
371354 precondition_op<T, Device>()(this ->dim ,
372355 psi_iter,
373356 nbase,
374357 notconv,
375358 d_precondition,
376- eigenvalues_gpu);
377- delmem_real_op ()(eigenvalues_gpu);
359+ this ->d_eigenvalue );
378360 }
379361 else
380362#endif
@@ -395,7 +377,7 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
395377 resmem_real_op ()(psi_norm, notconv);
396378 using setmem_real_op = base_device::memory::set_memory_op<Real, Device>;
397379 setmem_real_op ()(psi_norm, 0.0 , notconv);
398-
380+
399381 normalize_op<T, Device>()(this ->dim ,
400382 psi_iter,
401383 nbase,
@@ -641,7 +623,7 @@ void Diago_DavSubspace<T, Device>::diag_zhegvx(const int& nbase,
641623 }
642624 else
643625 {
644- #ifdef __MPI
626+ #ifdef __MPI
645627 std::vector<T> h_diag;
646628 std::vector<T> s_diag;
647629 std::vector<T> vcc_tmp;
@@ -680,7 +662,7 @@ void Diago_DavSubspace<T, Device>::diag_zhegvx(const int& nbase,
680662 }
681663#else
682664 std::cout << " Error: parallel diagonalization is not supported in serial mode." << std::endl;
683- exit (1 );
665+ exit (1 );
684666#endif
685667 }
686668 }
@@ -772,39 +754,7 @@ void Diago_DavSubspace<T, Device>::refresh(const int& dim,
772754
773755 if (this ->device == base_device::GpuDevice)
774756 {
775- #if defined(__CUDA) || defined(__ROCM)
776- T* hcc_cpu = nullptr ;
777- T* scc_cpu = nullptr ;
778- T* vcc_cpu = nullptr ;
779- base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU >()(hcc_cpu,
780- this ->nbase_x * this ->nbase_x ,
781- " DAV::hcc" );
782- base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU >()(scc_cpu,
783- this ->nbase_x * this ->nbase_x ,
784- " DAV::scc" );
785- base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU >()(vcc_cpu,
786- this ->nbase_x * this ->nbase_x ,
787- " DAV::vcc" );
788-
789- syncmem_d2h_op ()(hcc_cpu, hcc, this ->nbase_x * this ->nbase_x );
790- syncmem_d2h_op ()(scc_cpu, scc, this ->nbase_x * this ->nbase_x );
791- syncmem_d2h_op ()(vcc_cpu, vcc, this ->nbase_x * this ->nbase_x );
792-
793- for (int i = 0 ; i < nbase; i++)
794- {
795- hcc_cpu[i * this ->nbase_x + i] = eigenvalue_in_hsolver[i];
796- scc_cpu[i * this ->nbase_x + i] = this ->one [0 ];
797- vcc_cpu[i * this ->nbase_x + i] = this ->one [0 ];
798- }
799-
800- syncmem_h2d_op ()(hcc, hcc_cpu, this ->nbase_x * this ->nbase_x );
801- syncmem_h2d_op ()(scc, scc_cpu, this ->nbase_x * this ->nbase_x );
802- syncmem_h2d_op ()(vcc, vcc_cpu, this ->nbase_x * this ->nbase_x );
803-
804- base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU >()(hcc_cpu);
805- base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU >()(scc_cpu);
806- base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU >()(vcc_cpu);
807- #endif
757+ refresh_hcc_scc_vcc_op<T, Device>()(nbase, hcc, scc, vcc, this ->nbase_x , this ->d_eigenvalue , this ->one_ );
808758 }
809759 else
810760 {
0 commit comments