Skip to content

Commit 4942cb3

Browse files
committed
update cmakelist
1 parent 933fc95 commit 4942cb3

File tree

20 files changed

+119
-503
lines changed

20 files changed

+119
-503
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,14 @@ if(ENABLE_ASAN)
459459
target_link_libraries(${ABACUS_BIN_NAME} -fsanitize=address)
460460
endif()
461461

462+
add_library(math_connector OBJECT
463+
${ABACUS_SOURCE_DIR}/source_base/module_external/blas_connector_base.cpp
464+
${ABACUS_SOURCE_DIR}/source_base/module_external/blas_connector_l1.cpp
465+
${ABACUS_SOURCE_DIR}/source_base/module_external/blas_connector_l2.cpp
466+
${ABACUS_SOURCE_DIR}/source_base/module_external/blas_connector_l3.cpp
467+
${ABACUS_SOURCE_DIR}/source_base/module_external/lapack_connector.cpp
468+
)
469+
list(APPEND math_libs math_connector)
462470
if(DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
463471
set(MKLROOT "$ENV{MKLROOT}")
464472
endif()
@@ -479,7 +487,7 @@ else()
479487
find_package(FFTW3 REQUIRED)
480488
find_package(Lapack REQUIRED)
481489
include_directories(${FFTW3_INCLUDE_DIRS})
482-
list(APPEND math_libs FFTW3::FFTW3 LAPACKE::LAPACKE LAPACK::LAPACK BLAS::BLAS)
490+
list(APPEND math_libs FFTW3::FFTW3 LAPACKE::LAPACKE BLAS::BLAS)
483491
find_package(ScaLAPACK REQUIRED)
484492
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
485493
if(USE_OPENMP)

cmake/FindLapack.cmake

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ endif()
99
find_package(Blas REQUIRED)
1010
find_package(LAPACK REQUIRED)
1111

12+
find_path(LAPACKE_INCLUDE_DIR
13+
NAMES lapacke.h
14+
PATHS ${LAPACK_DIR} ${LAPACKE_DIR} ${CMAKE_PREFIX_PATH}
15+
PATH_SUFFIXES include include/lapacke
16+
DOC "Path to LAPACKE include directory"
17+
)
1218
# find LAPACKE libraries
1319
find_library(LAPACKE_LIBRARY
1420
NAMES lapacke
@@ -17,20 +23,10 @@ find_library(LAPACKE_LIBRARY
1723
DOC "Path to LAPACKE library"
1824
)
1925

20-
if(NOT TARGET LAPACK::LAPACK)
21-
add_library(LAPACK::LAPACK UNKNOWN IMPORTED)
22-
set_target_properties(LAPACK::LAPACK PROPERTIES
23-
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
24-
IMPORTED_LOCATION "${LAPACK_LIBRARIES}")
25-
endif()
26-
2726
if(NOT TARGET LAPACKE::LAPACKE)
2827
add_library(LAPACKE::LAPACKE UNKNOWN IMPORTED)
2928
set_target_properties(LAPACKE::LAPACKE PROPERTIES
29+
INTERFACE_INCLUDE_DIRECTORIES "${LAPACKE_INCLUDE_DIR}"
3030
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
3131
IMPORTED_LOCATION "${LAPACKE_LIBRARY}")
32-
33-
set_target_properties(LAPACKE::LAPACKE PROPERTIES
34-
INTERFACE_LINK_LIBRARIES "LAPACK::LAPACK"
35-
)
3632
endif()

source/source_base/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ add_library(
1010
base
1111
OBJECT
1212
assoc_laguerre.cpp
13-
module_external/blas_connector_base.cpp
14-
module_external/blas_connector_l1.cpp
15-
module_external/blas_connector_l2.cpp
16-
module_external/blas_connector_l3.cpp
17-
module_external/lapack_connector.cpp
1813
clebsch_gordan_coeff.cpp
1914
complexarray.cpp
2015
complexmatrix.cpp

source/source_base/kernels/test/math_kernel_test.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,18 @@ TEST_F(TestModuleHsolverMathKernel, gemv_op_cpu)
347347
int inc = 1;
348348
int row = 2;
349349
int col = 3;
350-
zgemv_(&trans,
351-
&row,
352-
&col,
353-
&ModuleBase::ONE,
350+
BlasConnector::gemv_cm(
351+
trans,
352+
row,
353+
col,
354+
ModuleBase::ONE,
354355
A_gemv.data(),
355-
&row,
356+
row,
356357
X_gemv.data(),
357-
&inc,
358-
&ModuleBase::ONE,
358+
inc,
359+
ModuleBase::ONE,
359360
Y_test_gemv.data(),
360-
&inc);
361+
inc);
361362
for (int i = 0; i < Y_gemv.size(); i++)
362363
{
363364
EXPECT_LT(fabs(Y_gemv[i].imag() - Y_test_gemv[i].imag()), 1e-12);
@@ -607,17 +608,18 @@ TEST_F(TestModuleHsolverMathKernel, gemv_op_gpu)
607608
int inc = 1;
608609
int row = 2;
609610
int col = 3;
610-
zgemv_(&trans,
611-
&row,
612-
&col,
613-
&ModuleBase::ONE,
611+
BlasConnector::gemv(
612+
trans,
613+
row,
614+
col,
615+
ModuleBase::ONE,
614616
A_gemv.data(),
615-
&row,
617+
row,
616618
X_gemv.data(),
617-
&inc,
618-
&ModuleBase::ONE,
619+
inc,
620+
ModuleBase::ONE,
619621
Y_test_gemv.data(),
620-
&inc);
622+
inc);
621623

622624
for (int i = 0; i < Y_gemv.size(); i++)
623625
{

source/source_base/module_external/blas_connector.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,6 @@ class BlasConnector
221221

222222
static
223223
void 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 = base_device::AbacusDevice_t::CpuDevice);
224-
225-
// There is some other operators needed, so implemented manually here
226-
template <typename T>
227-
static
228-
void vector_mul_vector(const int& dim, T* result, const T* vector1, const T* vector2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
229-
230-
template <typename T>
231-
static
232-
void vector_div_vector(const int& dim, T* result, const T* vector1, const T* vector2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
233-
234-
// y = alpha * x + beta * y
235-
static
236-
void vector_add_vector(const int& dim, float *result, const float *vector1, const float constant1, const float *vector2, const float constant2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
237-
238-
static
239-
void vector_add_vector(const int& dim, double *result, const double *vector1, const double constant1, const double *vector2, const double constant2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
240-
241-
static
242-
void vector_add_vector(const int& dim, std::complex<float> *result, const std::complex<float> *vector1, const float constant1, const std::complex<float> *vector2, const float constant2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
243-
244-
static
245-
void vector_add_vector(const int& dim, std::complex<double> *result, const std::complex<double> *vector1, const double constant1, const std::complex<double> *vector2, const double constant2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
246224
};
247225

248226
namespace BlasUtils {

source/source_base/module_external/blas_connector_l1.cpp

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -374,133 +374,4 @@ double BlasConnector::nrm2( const int n, const std::complex<double> *X, const in
374374
else {
375375
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
376376
}
377-
}
378-
379-
template <typename T>
380-
void vector_mul_vector(const int& dim, T* result, const T* vector1, const T* vector2, base_device::AbacusDevice_t device_type){
381-
using Real = typename GetTypeReal<T>::type;
382-
if (device_type == base_device::AbacusDevice_t::CpuDevice) {
383-
#ifdef _OPENMP
384-
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
385-
#endif
386-
for (int i = 0; i < dim; i++)
387-
{
388-
result[i] = vector1[i] * vector2[i];
389-
}
390-
}
391-
#ifdef __CUDA
392-
else if (device_type == base_device::AbacusDevice_t::GpuDevice) {
393-
ModuleBase::vector_mul_vector_op<T, base_device::DEVICE_GPU>()(dim, result, vector1, vector2);
394-
}
395-
#endif
396-
else {
397-
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
398-
}
399-
}
400-
401-
402-
template <typename T>
403-
void vector_div_vector(const int& dim, T* result, const T* vector1, const T* vector2, base_device::AbacusDevice_t device_type){
404-
using Real = typename GetTypeReal<T>::type;
405-
if (device_type == base_device::AbacusDevice_t::CpuDevice) {
406-
#ifdef _OPENMP
407-
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
408-
#endif
409-
for (int i = 0; i < dim; i++)
410-
{
411-
result[i] = vector1[i] / vector2[i];
412-
}
413-
}
414-
#ifdef __CUDA
415-
else if (device_type == base_device::AbacusDevice_t::GpuDevice) {
416-
ModuleBase::vector_div_vector_op<T, base_device::DEVICE_GPU>()(dim, result, vector1, vector2);
417-
}
418-
#endif
419-
else {
420-
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
421-
}
422-
}
423-
424-
void vector_add_vector(const int& dim, float *result, const float *vector1, const float constant1, const float *vector2, const float constant2, base_device::AbacusDevice_t device_type)
425-
{
426-
if (device_type == base_device::CpuDevice){
427-
#ifdef _OPENMP
428-
#pragma omp parallel for schedule(static, 8192 / sizeof(float))
429-
#endif
430-
for (int i = 0; i < dim; i++)
431-
{
432-
result[i] = vector1[i] * constant1 + vector2[i] * constant2;
433-
}
434-
}
435-
#ifdef __CUDA
436-
else if (device_type == base_device::GpuDevice) {
437-
ModuleBase::vector_add_vector_op<float, base_device::DEVICE_GPU>()(dim, result, vector1, constant1, vector2, constant2);
438-
}
439-
#endif
440-
else {
441-
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
442-
}
443-
}
444-
445-
void vector_add_vector(const int& dim, double *result, const double *vector1, const double constant1, const double *vector2, const double constant2, base_device::AbacusDevice_t device_type)
446-
{
447-
if (device_type == base_device::CpuDevice){
448-
#ifdef _OPENMP
449-
#pragma omp parallel for schedule(static, 8192 / sizeof(double))
450-
#endif
451-
for (int i = 0; i < dim; i++)
452-
{
453-
result[i] = vector1[i] * constant1 + vector2[i] * constant2;
454-
}
455-
}
456-
#ifdef __CUDA
457-
else if (device_type == base_device::GpuDevice) {
458-
ModuleBase::vector_add_vector_op<double, base_device::DEVICE_GPU>()(dim, result, vector1, constant1, vector2, constant2);
459-
}
460-
#endif
461-
else {
462-
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
463-
}
464-
}
465-
466-
void vector_add_vector(const int& dim, std::complex<float> *result, const std::complex<float> *vector1, const float constant1, const std::complex<float> *vector2, const float constant2, base_device::AbacusDevice_t device_type)
467-
{
468-
if (device_type == base_device::CpuDevice){
469-
#ifdef _OPENMP
470-
#pragma omp parallel for schedule(static, 8192 / sizeof(std::complex<float>))
471-
#endif
472-
for (int i = 0; i < dim; i++)
473-
{
474-
result[i] = vector1[i] * constant1 + vector2[i] * constant2;
475-
}
476-
}
477-
#ifdef __CUDA
478-
else if (device_type == base_device::GpuDevice) {
479-
ModuleBase::vector_add_vector_op<std::complex<float>, base_device::DEVICE_GPU>()(dim, result, vector1, constant1, vector2, constant2);
480-
}
481-
#endif
482-
else {
483-
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
484-
}
485-
}
486-
487-
void vector_add_vector(const int& dim, std::complex<double> *result, const std::complex<double> *vector1, const double constant1, const std::complex<double> *vector2, const double constant2, base_device::AbacusDevice_t device_type)
488-
{
489-
if (device_type == base_device::CpuDevice){
490-
#ifdef _OPENMP
491-
#pragma omp parallel for schedule(static, 8192 / sizeof(std::complex<double>))
492-
#endif
493-
for (int i = 0; i < dim; i++)
494-
{
495-
result[i] = vector1[i] * constant1 + vector2[i] * constant2;
496-
}
497-
}
498-
#ifdef __CUDA
499-
else if (device_type == base_device::GpuDevice) {
500-
ModuleBase::vector_add_vector_op<std::complex<double>, base_device::DEVICE_GPU>()(dim, result, vector1, constant1, vector2, constant2);
501-
}
502-
#endif
503-
else {
504-
throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));
505-
}
506377
}

0 commit comments

Comments
 (0)