From 20690b9942e8d13a9d125f729d6ac1395fde8d56 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Wed, 12 Jul 2023 17:14:00 -0400 Subject: [PATCH] introduced FindOrFetchTiledArray, use tiledarray instead of BTAS to provide needed functionality to spmm --- CMakeLists.txt | 4 +- cmake/modules/FindOrFetchTiledArray.cmake | 65 +++++++++++++++++++++++ examples/CMakeLists.txt | 7 ++- 3 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 cmake/modules/FindOrFetchTiledArray.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f0048c2c..7a619a0af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,8 +132,8 @@ if (TTG_EXAMPLES) set_property(TARGET eigen3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIR}) endif (EIGEN3_FOUND) - # BTAS brings in linear algebra (BLAS++/LAPACK++) - include(FindOrFetchBTAS) + # TiledArray brings in BTAS AND linear algebra (BLAS++/LAPACK++) + include(FindOrFetchTiledArray) # OpenMP may also be used by some examples find_package(OpenMP COMPONENTS CXX) # std::execution may also be used by some examples diff --git a/cmake/modules/FindOrFetchTiledArray.cmake b/cmake/modules/FindOrFetchTiledArray.cmake new file mode 100644 index 000000000..b0f3d0bcc --- /dev/null +++ b/cmake/modules/FindOrFetchTiledArray.cmake @@ -0,0 +1,65 @@ +if (NOT TARGET tiledarray AND NOT MPQC_BUILD_DEPENDENCIES_FROM_SOURCE) + if(TiledArray_INSTALL_DIR) + set(TiledArray_DIR ${TiledArray_INSTALL_DIR}/lib/cmake/tiledarray) + endif() + find_package(TiledArray CONFIG QUIET COMPONENTS tiledarray) +endif () + +set(TA_PYTHON OFF) + +if (TARGET tiledarray) + message(STATUS "Found TiledArray CONFIG at ${TiledArray_CONFIG}") + + if ((NOT TA_ASSUMES_ASLR_DISABLED AND MPQC_ASSUMES_ASLR_DISABLED) OR (TA_ASSUMES_ASLR_DISABLED AND NOT MPQC_ASSUMES_ASLR_DISABLED)) + message(FATAL_ERROR "Found TiledArray configured with TA_ASSUMES_ASLR_DISABLED=${TA_ASSUMES_ASLR_DISABLED} but MPQC is configured with MPQC_ASSUMES_ASLR_DISABLED=${MPQC_ASSUMES_ASLR_DISABLED}; MPQC_ASSUMES_ASLR_DISABLED and TA_ASSUMES_ASLR_DISABLED should be the same") + endif() + +else (TARGET tiledarray) + + # enable CUDA if TTG has it + if (TTG_HAVE_CUDA) + set(ENABLE_CUDA ON CACHE BOOL "Enable CUDA") + endif() + + # update CMake cache for TA + if (DEFINED MADNESS_CMAKE_EXTRA_ARGS) + set(MADNESS_CMAKE_EXTRA_ARGS "${MADNESS_CMAKE_EXTRA_ARGS};-DENABLE_DQ_PREBUF=OFF" CACHE STRING "Extra CMake arguments to MADNESS" FORCE) + else(DEFINED MADNESS_CMAKE_EXTRA_ARGS) + set(MADNESS_CMAKE_EXTRA_ARGS "-DENABLE_DQ_PREBUF=OFF" CACHE STRING "Extra CMake arguments to MADNESS") + endif(DEFINED MADNESS_CMAKE_EXTRA_ARGS) + if (NOT DEFINED TA_ASSUMES_ASLR_DISABLED) + set(TA_ASSUMES_ASLR_DISABLED ${MPQC_ASSUMES_ASLR_DISABLED} CACHE BOOL "TA assumes the Address Space Layout Randomization (ASLR) to be disabled") + endif(NOT DEFINED TA_ASSUMES_ASLR_DISABLED) + if (NOT DEFINED TA_ASSERT_POLICY) + string(REPLACE "MPQC_" "TA_" TA_ASSERT_POLICY "${MPQC_ASSERT_POLICY}") + set(TA_ASSERT_POLICY ${TA_ASSERT_POLICY} CACHE STRING "Controls the behavior of TA_ASSERT") + endif (NOT DEFINED TA_ASSERT_POLICY) + if (NOT DEFINED TA_BUILD_UNITTEST) + set(TA_BUILD_UNITTEST FALSE CACHE BOOL "Whether to build TA unit tests") + endif (NOT DEFINED TA_BUILD_UNITTEST) + + include(FetchContent) + FetchContent_Declare( + TILEDARRAY + GIT_REPOSITORY https://github.com/ValeevGroup/tiledarray.git + GIT_TAG ${MPQC_TRACKED_TILEDARRAY_TAG} + ) + FetchContent_MakeAvailable(TILEDARRAY) + FetchContent_GetProperties(TILEDARRAY + SOURCE_DIR TILEDARRAY_SOURCE_DIR + BINARY_DIR TILEDARRAY_BINARY_DIR + ) + # TA includes dependencies that are built manually, not using FetchContent, hence make sure we build them before building any MPQC code + # add_dependencies(deps-mpqc External-tiledarray) + + set(TTG_DOWNLOADED_TILEDARRAY ON CACHE BOOL "Whether TTG downloaded TiledArray") + + include("${TILEDARRAY_BINARY_DIR}/cmake/modules/ReimportTargets.cmake") + if (NOT TARGET MADworld) + message(FATAL_ERROR "did not find re-imported target MADworld") + endif(NOT TARGET MADworld) + + # this is where tiledarray-config.cmake will end up + # must be in sync with the "install(FILES ...tiledarray-config.cmake" statement in https://github.com/ValeevGroup/tiledarray/blob/${MPQC_TRACKED_TILEDARRAY_TAG}/CMakeLists.txt + set(TiledArray_CONFIG "${CMAKE_INSTALL_PREFIX}/${TILEDARRAY_INSTALL_CMAKEDIR}" CACHE INTERNAL "The location of installed tiledarray-config.cmake file") +endif(TARGET tiledarray) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 56895a057..d72712b81 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,10 +11,13 @@ if (TARGET eigen3) # block-sparse needs BTAS if (TARGET BTAS::BTAS) # since only need to use matrices, limit BTAS_TARGET_MAX_INDEX_RANK to 2 - add_ttg_executable(bspmm spmm/spmm.cc LINK_LIBRARIES eigen3 BTAS Boost::boost COMPILE_DEFINITIONS BLOCK_SPARSE_GEMM=1;BTAS_TARGET_MAX_INDEX_RANK=2) + add_ttg_executable(bspmm spmm/spmm.cc LINK_LIBRARIES tiledarray eigen3 BTAS Boost::boost COMPILE_DEFINITIONS BLOCK_SPARSE_GEMM=1;BTAS_TARGET_MAX_INDEX_RANK=2) if (TARGET CUDA::cublas) + if (NOT TARGET tiledarray) + message(FATAL_ERROR "TiledArray is not found; it is required for CUDA-based block-sparse SPMM") + endif() add_ttg_executable(bspmm-cuda spmm/spmm_cuda.cc spmm/cuda_gemm.cc - LINK_LIBRARIES eigen3 BTAS Boost::boost CUDA::cublas + LINK_LIBRARIES tiledarray eigen3 BTAS Boost::boost CUDA::cublas COMPILE_DEFINITIONS BLOCK_SPARSE_GEMM=1;BTAS_TARGET_MAX_INDEX_RANK=2 RUNTIMES "parsec") endif (TARGET CUDA::cublas)