Skip to content

Commit d8ce9cb

Browse files
authored
Merge branch 'develop' into ieiue-ABACUS-3.9.0.26
2 parents 047e6f2 + 3cab0f0 commit d8ce9cb

25 files changed

Lines changed: 277 additions & 78 deletions

File tree

source/source_base/kernels/dsp/dsp_connector.cpp

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,66 @@ void zgemm_mth_(const char* transa,
403403
free_ht(bet);
404404
} // zgemm that needn't malloc_ht or free_ht
405405

406+
void zgemm_pack_mth_(const char* transa,
407+
const char* transb,
408+
const int* m,
409+
const int* n,
410+
const int* k,
411+
const std::complex<double>* alpha,
412+
const std::complex<double>* a,
413+
const int* lda,
414+
const std::complex<double>* b,
415+
const int* ldb,
416+
const std::complex<double>* beta,
417+
std::complex<double>* c,
418+
const int* ldc,
419+
int cluster_id)
420+
{
421+
const bool transa_not = (transa[0] == 'N' || transa[0] == 'n');
422+
const bool transb_not = (transb[0] == 'N' || transb[0] == 'n');
423+
// const size_t a_elems = static_cast<size_t>(*lda) * (transa_not ? static_cast<size_t>(*k) : static_cast<size_t>(*m));
424+
// const size_t b_elems = static_cast<size_t>(*ldb) * (transb_not ? static_cast<size_t>(*n) : static_cast<size_t>(*k));
425+
const size_t c_elems = static_cast<size_t>(*ldc) * static_cast<size_t>(*n);
426+
427+
// std::complex<double>* A_dsp = static_cast<std::complex<double>*>(malloc_ht(a_elems * sizeof(std::complex<double>), cluster_id));
428+
// std::complex<double>* B_dsp = static_cast<std::complex<double>*>(malloc_ht(b_elems * sizeof(std::complex<double>), cluster_id));
429+
std::complex<double>* C_dsp = static_cast<std::complex<double>*>(malloc_ht(c_elems * sizeof(std::complex<double>), cluster_id));
430+
std::complex<double>* alp = static_cast<std::complex<double>*>(malloc_ht(sizeof(std::complex<double>), cluster_id));
431+
std::complex<double>* bet = static_cast<std::complex<double>*>(malloc_ht(sizeof(std::complex<double>), cluster_id));
432+
433+
// memcpy(A_dsp, a, a_elems * sizeof(std::complex<double>));
434+
// memcpy(B_dsp, b, b_elems * sizeof(std::complex<double>));
435+
memcpy(C_dsp, c, c_elems * sizeof(std::complex<double>));
436+
*alp = *alpha;
437+
*bet = *beta;
438+
439+
mt_hthread_zgemm(CBLAS_ORDER::CblasColMajor,
440+
convertBLASTranspose(transa),
441+
convertBLASTranspose(transb),
442+
*m,
443+
*n,
444+
*k,
445+
alp,
446+
a,
447+
// A_dsp,
448+
*lda,
449+
b,
450+
// B_dsp,
451+
*ldb,
452+
bet,
453+
// c,
454+
C_dsp,
455+
*ldc,
456+
cluster_id);
457+
memcpy(c, C_dsp, c_elems * sizeof(std::complex<double>));
458+
459+
// free_ht(A_dsp);
460+
// free_ht(B_dsp);
461+
free_ht(C_dsp);
462+
free_ht(alp);
463+
free_ht(bet);
464+
}
465+
406466
void cgemm_mth_(const char* transa,
407467
const char* transb,
408468
const int* m,
@@ -443,6 +503,64 @@ void cgemm_mth_(const char* transa,
443503
free_ht(bet);
444504
} // cgemm that needn't malloc_ht or free_ht
445505

506+
void cgemm_pack_mth_(const char* transa,
507+
const char* transb,
508+
const int* m,
509+
const int* n,
510+
const int* k,
511+
const std::complex<float>* alpha,
512+
const std::complex<float>* a,
513+
const int* lda,
514+
const std::complex<float>* b,
515+
const int* ldb,
516+
const std::complex<float>* beta,
517+
std::complex<float>* c,
518+
const int* ldc,
519+
int cluster_id)
520+
{
521+
const bool transa_not = (transa[0] == 'N' || transa[0] == 'n');
522+
const bool transb_not = (transb[0] == 'N' || transb[0] == 'n');
523+
const size_t a_elems = static_cast<size_t>(*lda) * (transa_not ? static_cast<size_t>(*k) : static_cast<size_t>(*m));
524+
const size_t b_elems = static_cast<size_t>(*ldb) * (transb_not ? static_cast<size_t>(*n) : static_cast<size_t>(*k));
525+
const size_t c_elems = static_cast<size_t>(*ldc) * static_cast<size_t>(*n);
526+
527+
std::complex<float>* A_dsp = static_cast<std::complex<float>*>(malloc_ht(a_elems * sizeof(std::complex<float>), cluster_id));
528+
std::complex<float>* B_dsp = static_cast<std::complex<float>*>(malloc_ht(b_elems * sizeof(std::complex<float>), cluster_id));
529+
std::complex<float>* C_dsp = static_cast<std::complex<float>*>(malloc_ht(c_elems * sizeof(std::complex<float>), cluster_id));
530+
std::complex<float>* alp = static_cast<std::complex<float>*>(malloc_ht(sizeof(std::complex<float>), cluster_id));
531+
std::complex<float>* bet = static_cast<std::complex<float>*>(malloc_ht(sizeof(std::complex<float>), cluster_id));
532+
533+
memcpy(A_dsp, a, a_elems * sizeof(std::complex<float>));
534+
memcpy(B_dsp, b, b_elems * sizeof(std::complex<float>));
535+
memcpy(C_dsp, c, c_elems * sizeof(std::complex<float>));
536+
*alp = *alpha;
537+
*bet = *beta;
538+
539+
mt_hthread_cgemm(CBLAS_ORDER::CblasColMajor,
540+
convertBLASTranspose(transa),
541+
convertBLASTranspose(transb),
542+
*m,
543+
*n,
544+
*k,
545+
(const void*)alp,
546+
(const void*)A_dsp,
547+
*lda,
548+
(const void*)B_dsp,
549+
*ldb,
550+
(const void*)bet,
551+
(void*)C_dsp,
552+
*ldc,
553+
cluster_id);
554+
555+
memcpy(c, C_dsp, c_elems * sizeof(std::complex<float>));
556+
557+
free_ht(A_dsp);
558+
free_ht(B_dsp);
559+
free_ht(C_dsp);
560+
free_ht(alp);
561+
free_ht(bet);
562+
}
563+
446564
void sgemv_mth_(const char* transa,
447565
const int* m,
448566
const int* n,
@@ -570,4 +688,4 @@ void cgemv_mth_(const char* transa,
570688
free_ht(alp);
571689
free_ht(bet);
572690
}
573-
} // namespace mtfunc
691+
} // namespace mtfunc

source/source_base/kernels/dsp/dsp_connector.h

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,21 @@ void zgemm_mt_(const char* transa,
6262
int cluster_id);
6363

6464
void cgemm_mt_(const char* transa,
65-
const char* transb,
66-
const int* m,
67-
const int* n,
68-
const int* k,
69-
const std::complex<float>* alpha,
70-
const std::complex<float>* a,
71-
const int* lda,
72-
const std::complex<float>* b,
73-
const int* ldb,
74-
const std::complex<float>* beta,
75-
std::complex<float>* c,
76-
const int* ldc,
77-
int cluster_id);
65+
const char* transb,
66+
const int* m,
67+
const int* n,
68+
const int* k,
69+
const std::complex<float>* alpha,
70+
const std::complex<float>* a,
71+
const int* lda,
72+
const std::complex<float>* b,
73+
const int* ldb,
74+
const std::complex<float>* beta,
75+
std::complex<float>* c,
76+
const int* ldc,
77+
int cluster_id);
78+
79+
7880

7981
void sgemv_mt_(const char* transa,
8082
const int* m,
@@ -173,6 +175,21 @@ void zgemm_mth_(const char* transa,
173175
const int* ldc,
174176
int cluster_id);
175177

178+
void zgemm_pack_mth_(const char* transa,
179+
const char* transb,
180+
const int* m,
181+
const int* n,
182+
const int* k,
183+
const std::complex<double>* alpha,
184+
const std::complex<double>* a,
185+
const int* lda,
186+
const std::complex<double>* b,
187+
const int* ldb,
188+
const std::complex<double>* beta,
189+
std::complex<double>* c,
190+
const int* ldc,
191+
int cluster_id);
192+
176193
void cgemm_mth_(const char* transa,
177194
const char* transb,
178195
const int* m,
@@ -188,6 +205,21 @@ void cgemm_mth_(const char* transa,
188205
const int* ldc,
189206
int cluster_id);
190207

208+
void cgemm_pack_mth_(const char* transa,
209+
const char* transb,
210+
const int* m,
211+
const int* n,
212+
const int* k,
213+
const std::complex<float>* alpha,
214+
const std::complex<float>* a,
215+
const int* lda,
216+
const std::complex<float>* b,
217+
const int* ldb,
218+
const std::complex<float>* beta,
219+
std::complex<float>* c,
220+
const int* ldc,
221+
int cluster_id);
222+
191223
void sgemv_mth_(const char* transa,
192224
const int* m,
193225
const int* n,
@@ -282,4 +314,4 @@ void dsp_dav_subspace_reduce(T* hcc, T* scc, int nbase, int nbase_x, int notconv
282314
} // namespace mtfunc
283315

284316
#endif
285-
#endif
317+
#endif

source/source_base/math_bspline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Bspline
3737
int norder; // the order of bezier base; norder >= 0
3838
double Dx; // Dx: the interval of control node
3939
double xi; // xi: the starting point
40-
double *bezier; // bezier[n] = Bk[n]
40+
double * bezier = nullptr; // bezier[n] = Bk[n]
4141

4242
public:
4343
Bspline();

source/source_base/math_chebyshev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class Chebyshev
210210
std::complex<REAL>* coefc_cpu = nullptr; //[CPU] expansion coefficient of each order
211211

212212
FFTW<REAL> fftw; // use for fftw
213-
REAL* polytrace; //[CPU] w_n = \sum_i v^+ * T_n(A) * v, only
213+
REAL* polytrace = nullptr; //[CPU] w_n = \sum_i v^+ * T_n(A) * v, only
214214

215215
bool getcoef_real; // coef_real has been calculated
216216
bool getcoef_complex; // coef_complex has been calculated
@@ -248,7 +248,7 @@ class FFTW<double>
248248
FFTW(const int norder2_in);
249249
~FFTW();
250250
void execute_fftw();
251-
double* dcoef; //[norder2]
251+
double* dcoef = nullptr; //[norder2]
252252
fftw_complex* ccoef = nullptr;
253253
fftw_plan coef_plan;
254254
};
@@ -261,7 +261,7 @@ class FFTW<float>
261261
FFTW(const int norder2_in);
262262
~FFTW();
263263
void execute_fftw();
264-
float* dcoef; //[norder2]
264+
float* dcoef = nullptr; //[norder2]
265265
fftwf_complex* ccoef = nullptr;
266266
fftwf_plan coef_plan;
267267
};

source/source_base/mcd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ typedef struct ChunkS
6464
#else
6565
long long id; // 64bit allocation ID
6666
#endif
67-
char *function; //creating function
68-
char *file; //file function is in
69-
void *ptr; //pointer to allocation
67+
char * function = nullptr; //creating function
68+
char * file = nullptr; //file function is in
69+
void * ptr = nullptr; //pointer to allocation
7070
struct ChunkS *next, //next chunk (null if nonw)
7171
*prev; //previous chunk (null if nonw)
7272
}Chunk;
@@ -706,7 +706,7 @@ int MCD_sscanf(const char *str,const char *fmt,char*fun,char*file,int line,...)
706706
void scan_args(const char *fmt,va_list argptr,char*fun,char*file,int line)
707707
{
708708
char **ptr;
709-
void *dummy; // clear up the unused warning
709+
void * dummy = nullptr; // clear up the unused warning
710710

711711
for(;*fmt;fmt++) {
712712
if(*fmt!='%')

source/source_base/module_container/base/core/bfc_allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class BFCAllocator : public Allocator {
122122
}
123123

124124
private:
125-
BFCAllocator* allocator_; // The parent allocator
125+
BFCAllocator* allocator_ = nullptr; // The parent allocator
126126
};
127127

128128
using free_chunk_set_t = std::set<ChunkHandle, ChunkComparator>;

source/source_base/module_device/memory_op.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,19 @@ struct resize_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
471471
}
472472
};
473473

474+
template <typename FPTYPE>
475+
struct set_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
476+
{
477+
void operator()(FPTYPE* arr, const int var, const size_t size)
478+
{
479+
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
480+
int beg = 0, len = 0;
481+
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, size, (size_t)4096 / sizeof(FPTYPE), beg, len);
482+
memset(arr + beg, var, sizeof(FPTYPE) * len);
483+
});
484+
}
485+
};
486+
474487
template <typename FPTYPE>
475488
struct delete_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
476489
{
@@ -487,6 +500,12 @@ template struct resize_memory_op_mt<double, base_device::DEVICE_CPU>;
487500
template struct resize_memory_op_mt<std::complex<float>, base_device::DEVICE_CPU>;
488501
template struct resize_memory_op_mt<std::complex<double>, base_device::DEVICE_CPU>;
489502

503+
template struct set_memory_op_mt<int, base_device::DEVICE_CPU>;
504+
template struct set_memory_op_mt<float, base_device::DEVICE_CPU>;
505+
template struct set_memory_op_mt<double, base_device::DEVICE_CPU>;
506+
template struct set_memory_op_mt<std::complex<float>, base_device::DEVICE_CPU>;
507+
template struct set_memory_op_mt<std::complex<double>, base_device::DEVICE_CPU>;
508+
490509
template struct delete_memory_op_mt<int, base_device::DEVICE_CPU>;
491510
template struct delete_memory_op_mt<float, base_device::DEVICE_CPU>;
492511
template struct delete_memory_op_mt<double, base_device::DEVICE_CPU>;

source/source_base/module_device/memory_op.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ struct resize_memory_op_mt
234234
void operator()(FPTYPE*& arr, const size_t size, const char* record_in = nullptr);
235235
};
236236

237+
template <typename FPTYPE, typename Device>
238+
struct set_memory_op_mt
239+
{
240+
/// @brief memset for DSP memory allocated by mt allocator.
241+
///
242+
/// Input Parameters
243+
/// \param var : the specified constant byte value
244+
/// \param size : array size
245+
///
246+
/// Output Parameters
247+
/// \param arr : output array initialized by the input value
248+
void operator()(FPTYPE* arr, const int var, const size_t size);
249+
};
250+
237251
template <typename FPTYPE, typename Device>
238252
struct delete_memory_op_mt
239253
{

source/source_base/module_external/blas_connector_matrix.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ void BlasConnector::gemm(const char transa,
107107
#ifdef __DSP
108108
else if (device_type == base_device::AbacusDevice_t::DspDevice)
109109
{
110-
mtfunc::cgemm_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
110+
mtfunc::cgemm_pack_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
111+
// cgemm_mth_ for raw dsp mth;
112+
// cgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
111113
}
112114
#endif
113115
else if (device_type == base_device::AbacusDevice_t::GpuDevice)
@@ -158,7 +160,9 @@ void BlasConnector::gemm(const char transa,
158160
#ifdef __DSP
159161
else if (device_type == base_device::AbacusDevice_t::DspDevice)
160162
{
161-
mtfunc::zgemm_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
163+
mtfunc::zgemm_pack_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
164+
// zgemm_mth_ for raw dsp mth;
165+
// zgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
162166
}
163167
#endif
164168
else if (device_type == base_device::AbacusDevice_t::GpuDevice)
@@ -277,7 +281,9 @@ void BlasConnector::gemm_cm(const char transa,
277281
#ifdef __DSP
278282
else if (device_type == base_device::AbacusDevice_t::DspDevice)
279283
{
280-
mtfunc::cgemm_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
284+
mtfunc::cgemm_pack_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
285+
// cgemm_mth_ for raw dsp mth;
286+
// cgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
281287
}
282288
#endif
283289
#ifdef __CUDA
@@ -328,7 +334,9 @@ void BlasConnector::gemm_cm(const char transa,
328334
#ifdef __DSP
329335
else if (device_type == base_device::AbacusDevice_t::DspDevice)
330336
{
331-
mtfunc::zgemm_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
337+
mtfunc::zgemm_pack_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
338+
// zgemm_mth_ for raw dsp mth;
339+
// zgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
332340
}
333341
#endif
334342
#ifdef __CUDA

source/source_basis/module_ao/ORB_nonlocal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Numerical_Nonlocal
4242
const int& nproj_in,
4343
const Numerical_Nonlocal_Lm* ps_orbital_in);
4444

45-
Numerical_Nonlocal_Lm* Proj; ///< length: nproj(only store radial function )
45+
Numerical_Nonlocal_Lm* Proj = nullptr; ///< length: nproj(only store radial function )
4646

4747
const double& get_rcut_max() const { return rcut_max; }
4848
const int& get_nproj() const { return nproj; }

0 commit comments

Comments
 (0)