Skip to content

Commit

Permalink
Merge branch 'dev-master' into refactor-types
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanaGyro authored Nov 29, 2024
2 parents 710c98c + f6a9e28 commit cb0ea68
Show file tree
Hide file tree
Showing 89 changed files with 3,063 additions and 11,476 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci-cmake_pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
shell: bash -l {0}
run: |
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl beartype
mamba install gcovr gtest
python -m pip install gcovr
mamba install gtest
- name: CPU info
shell: bash -l {0}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-cmake_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
shell: bash -l {0}
run: |
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl beartype
mamba install gcovr gtest
python -m pip install gcovr
mamba install gtest
mamba install pytest pytest-cov
- name: CPU info
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -142,7 +141,9 @@ if(USE_DEBUG)
endif()

if(RUN_TESTS)
enable_testing()
# Include CTest explicitly to suppress the error that DartConfiguration.tcl
# is not found
include(CTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
target_link_libraries(cytnx PUBLIC "-lgcov --coverage")
add_subdirectory(tests)
Expand Down
23 changes: 2 additions & 21 deletions CytnxBKNDCMakeLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ if(USE_CUDA)
include_directories(${install_dir}/include)
message(STATUS "cutt install dir: ${install_dir}")
add_dependencies(cytnx cutt)
set_property(TARGET cytnx PROPERTY CUDA_ARCHITECTURES 52 53 60 61 62 70 72 75 80 86)
# set_property(TARGET cytnx PROPERTY CUDA_ARCHITECTURES 52 53 60 61 62 70 72 75 80 86)
set_property(TARGET cytnx PROPERTY CUDA_ARCHITECTURES native)
target_compile_definitions(cytnx PRIVATE UNI_CUTT)
target_link_libraries(cytnx PUBLIC ${install_dir}/lib/libcutt.a)
# relocate cutt
Expand All @@ -168,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
2 changes: 1 addition & 1 deletion include/Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace cytnx {
const int &device = Device.cpu);

/**
@brief create an square rank-2 Tensor with all diagonal to be one.
@brief create a square rank-2 Tensor with all diagonal to be one.
@param Dim the dimension of diagonal.
@param dtype the dtype of the Tensor. It can be any type defined in \link cytnx::Type cytnx::Type
\endlink
Expand Down
18 changes: 12 additions & 6 deletions include/Tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,13 @@ namespace cytnx {
*/
const bool &is_contiguous() const { return this->_impl->is_contiguous(); }

Tensor permute_(const std::vector<cytnx_uint64> &rnks) {
Tensor &permute_(const std::vector<cytnx_uint64> &rnks) {
this->_impl->permute_(rnks);
return *this;
}
/// @cond
template <class... Ts>
Tensor permute_(const cytnx_uint64 &e1, const Ts &...elems) {
Tensor &permute_(const cytnx_uint64 &e1, const Ts &...elems) {
std::vector<cytnx_uint64> argv = dynamic_arg_uint64_resolver(e1, elems...);
this->_impl->permute_(argv);
return *this;
Expand Down Expand Up @@ -778,21 +778,27 @@ namespace cytnx {
#### output>
\verbinclude example/Tensor/reshape_.py.out
*/
void reshape_(const std::vector<cytnx_int64> &new_shape) { this->_impl->reshape_(new_shape); }
Tensor &reshape_(const std::vector<cytnx_int64> &new_shape) {
this->_impl->reshape_(new_shape);
return *this;
}
/// @cond
void reshape_(const std::vector<cytnx_uint64> &new_shape) {
Tensor &reshape_(const std::vector<cytnx_uint64> &new_shape) {
std::vector<cytnx_int64> shape(new_shape.begin(), new_shape.end());
this->_impl->reshape_(shape);
return *this;
}
void reshape_(const std::initializer_list<cytnx_int64> &new_shape) {
Tensor &reshape_(const std::initializer_list<cytnx_int64> &new_shape) {
std::vector<cytnx_int64> shape = new_shape;
this->_impl->reshape_(shape);
return *this;
}
template <class... Ts>
void reshape_(const cytnx_int64 &e1, const Ts... elems) {
Tensor &reshape_(const cytnx_int64 &e1, const Ts... elems) {
std::vector<cytnx_int64> shape = dynamic_arg_int64_resolver(e1, elems...);
// std::cout << shape << std::endl;
this->_impl->reshape_(shape);
return *this;
}
/// @endcond

Expand Down
22 changes: 15 additions & 7 deletions include/UniTensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,32 +1169,36 @@ namespace cytnx {
};

unsigned int dtype() const {
//[21 Aug 2024] This is a copy from BlockUniTensor;
#ifdef UNI_DEBUG
cytnx_error_msg(this->_blocks.size() == 0, "[ERROR][internal] empty blocks for blockform.%s",
"\n");
#endif
return this->_blocks[0].dtype();
return this->_blocks.size() < 1 ? Type.Void : this->_blocks[0].dtype();
};
int device() const {
//[21 Aug 2024] This is a copy from BlockUniTensor;
#ifdef UNI_DEBUG
cytnx_error_msg(this->_blocks.size() == 0, "[ERROR][internal] empty blocks for blockform.%s",
"\n");
#endif
return this->_blocks[0].device();
return this->_blocks.size() < 1 ? -404 : this->_blocks[0].device();
};
std::string dtype_str() const {
//[21 Aug 2024] This is a copy from BlockUniTensor;
#ifdef UNI_DEBUG
cytnx_error_msg(this->_blocks.size() == 0, "[ERROR][internal] empty blocks for blockform.%s",
"\n");
#endif
return this->_blocks[0].dtype_str();
return this->_blocks.size() < 1 ? "Void, no valid blocks" : this->_blocks[0].dtype_str();
};
std::string device_str() const {
//[21 Aug 2024] This is a copy from BlockUniTensor;
#ifdef UNI_DEBUG
cytnx_error_msg(this->_blocks.size() == 0, "[ERROR][internal] empty blocks for blockform.%s",
"\n");
#endif
return this->_blocks[0].device_str();
return this->_blocks.size() < 1 ? "None, no valid blocks" : this->_blocks[0].device_str();
};

Tensor get_block(const cytnx_uint64 &idx = 0) const {
Expand Down Expand Up @@ -2714,8 +2718,9 @@ namespace cytnx {
@param[in] rowrank the row rank after the permutation
@warning \p by_label will be deprecated!
*/
void permute_(const std::vector<cytnx_int64> &mapper, const cytnx_int64 &rowrank = -1) {
UniTensor &permute_(const std::vector<cytnx_int64> &mapper, const cytnx_int64 &rowrank = -1) {
this->_impl->permute_(mapper, rowrank);
return *this;
}

/**
Expand All @@ -2724,8 +2729,9 @@ namespace cytnx {
@param[in] rowrank the row rank after the permutation
@see permute(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1)
*/
void permute_(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1) {
UniTensor &permute_(const std::vector<std::string> &mapper, const cytnx_int64 &rowrank = -1) {
this->_impl->permute_(mapper, rowrank);
return *this;
}

// void permute_( const std::initializer_list<char*> &mapper, const cytnx_int64 &rowrank= -1){
Expand Down Expand Up @@ -3333,8 +3339,10 @@ namespace cytnx {
cannot be UTenType::Block.
@see reshape(const std::vector<cytnx_int64> &new_shape, const cytnx_uint64 &rowrank)
*/
void reshape_(const std::vector<cytnx_int64> &new_shape, const cytnx_uint64 &rowrank = 0) {
UniTensor &reshape_(const std::vector<cytnx_int64> &new_shape,
const cytnx_uint64 &rowrank = 0) {
this->_impl->reshape_(new_shape, rowrank);
return *this;
}

/**
Expand Down
Loading

0 comments on commit cb0ea68

Please sign in to comment.