Skip to content

Commit cd52ac3

Browse files
authored
Fix: fix declarations of some BLAS and LAPACK functions. (#6637)
* Standardize the declarations of BLAS functions in blas_connector_vector * standardize the declarations of LAPACK functions * add some comments * fix some error * Restore the mistakenly removed const
1 parent 91d71e2 commit cd52ac3

File tree

15 files changed

+596
-415
lines changed

15 files changed

+596
-415
lines changed

source/source_base/gather_math_lib_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void zhegvx_i(const int *itype,
6060
const int *il,
6161
const int *iu,
6262
const double *abstol,
63-
const int *m,
63+
int *m,
6464
double *w,
6565
std::complex<double> *z,
6666
const int *ldz,

source/source_base/global_function.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,17 @@ inline void DCOPY(const T* a, T* b, const int& dim) {
182182
}
183183

184184
template <typename T>
185-
inline void COPYARRAY(const T* a, T* b, const long dim);
185+
inline void COPYARRAY(const T* a, T* b, const int dim);
186186

187187
template <>
188-
inline void COPYARRAY(const std::complex<double>* a, std::complex<double>* b, const long dim)
188+
inline void COPYARRAY(const std::complex<double>* a, std::complex<double>* b, const int dim)
189189
{
190190
const int one = 1;
191191
zcopy_(&dim, a, &one, b, &one);
192192
}
193193

194194
template <>
195-
inline void COPYARRAY(const double* a, double* b, const long dim)
195+
inline void COPYARRAY(const double* a, double* b, const int dim)
196196
{
197197
const int one = 1;
198198
dcopy_(&dim, a, &one, b, &one);

source/source_base/module_container/base/third_party/blas.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ void daxpy_(const int *N, const double *alpha, const double *x, const int *incx,
2525
void caxpy_(const int *N, const std::complex<float> *alpha, const std::complex<float> *x, const int *incx, std::complex<float> *y, const int *incy);
2626
void zaxpy_(const int *N, const std::complex<double> *alpha, const std::complex<double> *x, const int *incx, std::complex<double> *y, const int *incy);
2727

28-
void dcopy_(long const *n, const double *a, int const *incx, double *b, int const *incy);
29-
void zcopy_(long const *n, const std::complex<double> *a, int const *incx, std::complex<double> *b, int const *incy);
28+
void dcopy_(const int *n, const double *a, const int *incx, double *b, const int *incy);
29+
void zcopy_(const int *n, const std::complex<double> *a, const int *incx, std::complex<double> *b, const int *incy);
3030

3131
//reason for passing results as argument instead of returning it:
3232
//see https://www.numbercrunch.de/blog/2014/07/lost-in-translation/
@@ -107,14 +107,26 @@ void dsymm_(const char *side, const char *uplo, const int *m, const int *n,
107107
const double *alpha, const double *a, const int *lda, const double *b, const int *ldb,
108108
const double *beta, double *c, const int *ldc);
109109
//a is hermitian
110-
void zhemm_(char *side, char *uplo, int *m, int *n,std::complex<double> *alpha,
111-
std::complex<double> *a, int *lda, std::complex<double> *b, int *ldb, std::complex<double> *beta, std::complex<double> *c, int *ldc);
110+
void zhemm_(const char *side, const char *uplo,
111+
const int *m, const int *n,
112+
const std::complex<double> *alpha,
113+
const std::complex<double> *a, const int *lda,
114+
const std::complex<double> *b, const int *ldb,
115+
const std::complex<double> *beta,
116+
std::complex<double> *c, const int *ldc);
112117

113118
//solving triangular matrix with multiple right hand sides
114-
void dtrsm_(char *side, char* uplo, char *transa, char *diag, int *m, int *n,
115-
double* alpha, double* a, int *lda, double*b, int *ldb);
116-
void ztrsm_(char *side, char* uplo, char *transa, char *diag, int *m, int *n,
117-
std::complex<double>* alpha, std::complex<double>* a, int *lda, std::complex<double>*b, int *ldb);
119+
void dtrsm_(const char *side, const char *uplo, const char *transa, const char *diag,
120+
const int *m, const int *n,
121+
const double *alpha,
122+
const double *a, const int *lda,
123+
double *b, const int *ldb);
124+
125+
void ztrsm_(const char *side, const char *uplo, const char *transa, const char *diag,
126+
const int *m, const int *n,
127+
const std::complex<double> *alpha,
128+
const std::complex<double> *a, const int *lda,
129+
std::complex<double> *b, const int *ldb);
118130

119131
}
120132

@@ -339,12 +351,12 @@ double nrm2( const int n, const std::complex<double> *x, const int incx )
339351

340352
// copies a into b
341353
static inline
342-
void copy(const long n, const double *a, const int incx, double *b, const int incy)
354+
void copy(const int n, const double *a, const int incx, double *b, const int incy)
343355
{
344356
dcopy_(&n, a, &incx, b, &incy);
345357
}
346358
static inline
347-
void copy(const long n, const std::complex<double> *a, const int incx, std::complex<double> *b, const int incy)
359+
void copy(const int n, const std::complex<double> *a, const int incx, std::complex<double> *b, const int incy)
348360
{
349361
zcopy_(&n, a, &incx, b, &incy);
350362
}

source/source_base/module_container/base/third_party/lapack.h

Lines changed: 119 additions & 84 deletions
Large diffs are not rendered by default.

source/source_base/module_external/blas_connector.h

Lines changed: 188 additions & 134 deletions
Large diffs are not rendered by default.

source/source_base/module_external/blas_connector_vector.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ double BlasConnector::nrm2( const int n, const std::complex<double> *X, const in
322322
}
323323

324324
// copies a into b
325-
void BlasConnector::copy(const long n, const float *a, const int incx, float *b, const int incy, base_device::AbacusDevice_t device_type)
325+
void BlasConnector::copy(const int n, const float *a, const int incx, float *b, const int incy, base_device::AbacusDevice_t device_type)
326326
{
327327
if (device_type == base_device::AbacusDevice_t::CpuDevice) {
328328
scopy_(&n, a, &incx, b, &incy);
@@ -332,7 +332,7 @@ void BlasConnector::copy(const long n, const float *a, const int incx, float *b,
332332
}
333333
}
334334

335-
void BlasConnector::copy(const long n, const double *a, const int incx, double *b, const int incy, base_device::AbacusDevice_t device_type)
335+
void BlasConnector::copy(const int n, const double *a, const int incx, double *b, const int incy, base_device::AbacusDevice_t device_type)
336336
{
337337
if (device_type == base_device::AbacusDevice_t::CpuDevice) {
338338
dcopy_(&n, a, &incx, b, &incy);
@@ -342,7 +342,7 @@ void BlasConnector::copy(const long n, const double *a, const int incx, double *
342342
}
343343
}
344344

345-
void BlasConnector::copy(const long n, const std::complex<float> *a, const int incx, std::complex<float> *b, const int incy, base_device::AbacusDevice_t device_type)
345+
void BlasConnector::copy(const int n, const std::complex<float> *a, const int incx, std::complex<float> *b, const int incy, base_device::AbacusDevice_t device_type)
346346
{
347347
if (device_type == base_device::AbacusDevice_t::CpuDevice) {
348348
ccopy_(&n, a, &incx, b, &incy);
@@ -352,7 +352,7 @@ void BlasConnector::copy(const long n, const std::complex<float> *a, const int i
352352
}
353353
}
354354

355-
void BlasConnector::copy(const long n, const std::complex<double> *a, const int incx, std::complex<double> *b, const int incy, base_device::AbacusDevice_t device_type)
355+
void BlasConnector::copy(const int n, const std::complex<double> *a, const int incx, std::complex<double> *b, const int incy, base_device::AbacusDevice_t device_type)
356356
{
357357
if (device_type == base_device::AbacusDevice_t::CpuDevice) {
358358
zcopy_(&n, a, &incx, b, &incy);

0 commit comments

Comments
 (0)