Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Magma dependency by using CuSolver Routines #483

Merged
merged 6 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ option(BUILD_DOC "Build API docuemntation" OFF)
option(USE_HPTT "Build Cytnx with HPTT" OFF)
option(RUN_TESTS "Run Cytnx tests" OFF)
option(USE_CUTT "Build Cytnx with CUTT" OFF)
option(USE_MAGMA "Build Cytnx with MAGMA (requires CUDA)" ON)
option(USE_CUTENSOR "Build Cytnx with CuTensor (requires CUDA)" ON)
option(USE_CUQUANTUM "Build Cytnx with CUQuantum (requires CUDA)" ON)

Expand Down
20 changes: 0 additions & 20 deletions CytnxBKNDCMakeLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,6 @@ if(USE_CUDA)

endif()

if(USE_MAGMA)
find_package( MAGMA REQUIRED)
if(NOT MAGMA_FOUND)
message(FATAL_ERROR "MAGMA not found!")
endif()
message(STATUS "^^^magma root aft: ${MAGMA_ROOT}")
message(STATUS "^^^magma inc dr: ${MAGMA_INCLUDE_DIRS}")
message(STATUS "^^^magma lib dr: ${MAGMA_LIBRARY_DIRS}")
message(STATUS "^^^magma libs: ${MAGMA_LIBRARIES}")
#add_dependencies(cytnx magma)
target_include_directories(cytnx PRIVATE ${MAGMA_INCLUDE_DIRS})
target_compile_definitions(cytnx PRIVATE UNI_MAGMA)
target_link_libraries(cytnx PUBLIC ${MAGMA_LIBRARIES})

message( STATUS "Build with MAGMA: YES")
FILE(APPEND "${CMAKE_BINARY_DIR}/cxxflags.tmp" "-DUNI_MAGMA\n" "")
FILE(APPEND "${CMAKE_BINARY_DIR}/cxxflags.tmp" "-I${MAGMA_INCLUDE_DIRS}\n" "")
FILE(APPEND "${CMAKE_BINARY_DIR}/linkflags.tmp" "${MAGMA_LIBRARIES} -ldl\n" "") # use > to indicate special rt processing
message( STATUS "MAGMA: libdir:${MAGMA_LIBRARY_DIRS} incdir:${MAGMA_INCLUDE_DIRS} libs:${MAGMA_LIBRARIES}")
endif()

message( STATUS " Build CUDA Support: YES")
message( STATUS " - CUDA Version: ${CUDA_VERSION_STRING}")
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/FindCUQUANTUM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
# CUQUANTUM_INCLUDE_DIRS ... cutensor include directory
# CUQUANTUM_LIBRARIES ... cutensor libraries
#
# MAGMA_ROOT this is required to set!
# CUQUANTUM_ROOT this is required to set!
#

#If environment variable MAGMA_ROOT is specified, it has same effect as MAGMA_ROOT
#If environment variable CUQUANTUM_ROOT is specified, it has same effect as CUQUANTUM_ROOT

if(NOT DEFINED ENV{CUQUANTUM_ROOT} AND NOT DEFINED CUQUANTUM_ROOT)
message(FATAL_ERROR "CUQUANTUM_ROOT not set!")
Expand Down
16 changes: 1 addition & 15 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <omp.h>
#endif

#ifdef UNI_MAGMA
#include "magma_v2.h"
#endif

using namespace std;
namespace cytnx {

Expand Down Expand Up @@ -43,12 +39,6 @@ namespace cytnx {
}
}

// #ifdef UNI_MAGMA
// int magma_status = magma_init();
// cytnx_error_msg(magma_status!=MAGMA_SUCCESS,"[ERROR] magma system cannot
// initialize!%s","\n");
// #endif

#endif

#ifdef UNI_OMP
Expand All @@ -62,11 +52,7 @@ namespace cytnx {
};

Device_class::~Device_class(){
// #ifdef UNI_MAGMA
// int magma_status = magma_finalize();
// cytnx_error_msg(magma_status!=MAGMA_SUCCESS,"[ERROR] magma system cannot
// finalize!%s","\n");
// #endif

};

string Device_class::getname(const int& device_id) {
Expand Down
20 changes: 16 additions & 4 deletions src/backend/linalg_internal_cpu/Det_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ namespace cytnx {
lapack_int N = L;
lapack_int info;
info = LAPACKE_zgetrf(LAPACK_COL_MAJOR, N, N, _Rin, N, ipiv);
// If the info > 0, that means the U factor is exactly singular, and the det is 0.
cytnx_error_msg(
info != 0, "%s %d",
info < 0, "%s %d",
"[ERROR][Det_internal] Error in Lapack function 'zgetrf': Lapack INFO = ", info);

// Whether lapack_complex_T is defined as std::complex<T> (c++ complex) or T _Complex
Expand All @@ -51,6 +52,8 @@ namespace cytnx {
free(ipiv);
free(_Rin);
if (neg) od[0] *= -1;

if (info > 0) od[0] = 0;
}
void Det_internal_cf(void *out, const boost::intrusive_ptr<Storage_base> &Rin,
const cytnx_uint64 &L) {
Expand All @@ -63,8 +66,9 @@ namespace cytnx {
lapack_int N = L;
lapack_int info;
info = LAPACKE_cgetrf(LAPACK_COL_MAJOR, N, N, _Rin, N, ipiv);
// If the info > 0, that means the U factor is exactly singular, and the det is 0.
cytnx_error_msg(
info != 0, "%s %d",
info < 0, "%s %d",
"[ERROR][Det_internal] Error in Lapack function 'cgetrf': Lapack INFO = ", info);

// Whether lapack_complex_T is defined as std::complex<T> (c++ complex) or T _Complex
Expand All @@ -87,6 +91,8 @@ namespace cytnx {
free(ipiv);
free(_Rin);
if (neg) od[0] *= -1;

if (info > 0) od[0] = 0;
}
void Det_internal_d(void *out, const boost::intrusive_ptr<Storage_base> &Rin,
const cytnx_uint64 &L) {
Expand All @@ -98,8 +104,9 @@ namespace cytnx {
lapack_int N = L;
lapack_int info;
info = LAPACKE_dgetrf(LAPACK_COL_MAJOR, N, N, _Rin, N, ipiv);
// If the info > 0, that means the U factor is exactly singular, and the det is 0.
cytnx_error_msg(
info != 0, "%s %d",
info < 0, "%s %d",
"[ERROR][Det_internal] Error in Lapack function 'dgetrf': Lapack INFO = ", info);
od[0] = 1;
bool neg = 0;
Expand All @@ -110,6 +117,8 @@ namespace cytnx {
free(ipiv);
free(_Rin);
if (neg) od[0] *= -1;

if (info > 0) od[0] = 0;
}
void Det_internal_f(void *out, const boost::intrusive_ptr<Storage_base> &Rin,
const cytnx_uint64 &L) {
Expand All @@ -121,8 +130,9 @@ namespace cytnx {
lapack_int N = L;
lapack_int info;
info = LAPACKE_sgetrf(LAPACK_COL_MAJOR, N, N, _Rin, N, ipiv);
// If the info > 0, that means the U factor is exactly singular, and the det is 0.
cytnx_error_msg(
info != 0, "%s %d",
info < 0, "%s %d",
"[ERROR][Det_internal] Error in Lapack function 'sgetrf': Lapack INFO = ", info);
od[0] = 1;
bool neg = 0;
Expand All @@ -133,6 +143,8 @@ namespace cytnx {
free(ipiv);
free(_Rin);
if (neg) od[0] *= -1;

if (info > 0) od[0] = 0;
}

} // namespace linalg_internal
Expand Down
Loading
Loading