Skip to content

Commit

Permalink
introduced FindOrFetchTiledArray, use tiledarray instead of BTAS to p…
Browse files Browse the repository at this point in the history
…rovide needed functionality to spmm
  • Loading branch information
evaleev committed Jul 12, 2023
1 parent 0ef697a commit 20690b9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions cmake/modules/FindOrFetchTiledArray.cmake
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 5 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 20690b9

Please sign in to comment.