Commit 984ac786 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh
Browse files

Added cuTensor and cuQuantum as optional external dependencies in the build system.

parent c190582a
Loading
Loading
Loading
Loading
+53 −30
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPATH_MAX=4096 -Wno-attributes")

project(exatn LANGUAGES CXX Fortran)

option(EXATN_BUILD_TESTS "Build ExaTN tests" OFF)
option(EXATN_BUILD_TESTS "Build ExaTN tests" ON)
option(CUDA_HOST_COMPILER "Provide the host compiler for nvcc" "")
option(BLAS_LIB "Provide the BLAS implementation: ATLAS,MKL,OPENBLAS,ACML,ESSL" "")
option(BLAS_PATH "Provide the path to the BLAS libraries" "")
@@ -35,11 +35,11 @@ option(ENABLE_CUDA "Turn on CUDA support" OFF)
if(MPI_LIB)

  if(NOT MPI_LIB STREQUAL "MPICH" AND NOT MPI_LIB STREQUAL "OPENMPI")
    message(FATAL_ERROR "Invalid MPI_LIB choice: Available choices: MPICH (incl. Cray-MPICH), OPENMPI (incl. Spectrum-MPI). CMake is exiting.")
    message(FATAL_ERROR "Invalid MPI_LIB choice: Available choices: MPICH (incl. Cray-MPICH), OPENMPI (incl. Spectrum-MPI)! CMake is exiting.")
  endif()

  if(NOT MPI_ROOT_DIR)
    message(FATAL_ERROR "If you specify the MPI implementation, you must also specify the MPI root path (-DMPI_ROOT_DIR). CMake is exiting.")
    message(FATAL_ERROR "If you specify the MPI implementation, you must also specify the MPI root path (-DMPI_ROOT_DIR)! CMake is exiting.")
  endif()

  if(NOT MPI_BIN_PATH)
@@ -51,7 +51,7 @@ if(MPI_LIB)
else()

  if(MPI_ROOT_DIR OR MPI_BIN_PATH)
    message(FATAL_ERROR "If you specify the MPI root and/or bin paths, you should also specify the MPI_LIB choice (-DMPI_LIB). CMake is exiting.")
    message(FATAL_ERROR "If you specify the MPI root and/or bin paths, you should also specify the MPI_LIB choice (-DMPI_LIB)! CMake is exiting.")
  endif()

endif()
@@ -60,67 +60,62 @@ endif()
if(BLAS_LIB)

  if(NOT BLAS_PATH AND NOT BLAS_LIB STREQUAL "MKL")
    message(FATAL_ERROR "Your choice of BLAS implementation requires specification of the path to the BLAS libraries (-DBLAS_PATH). CMake is exiting.")
    message(FATAL_ERROR "Your choice of BLAS implementation requires specification of the path to the BLAS libraries (-DBLAS_PATH)! CMake is exiting.")
  endif()

  if(BLAS_LIB STREQUAL "ATLAS")
    if(NOT EXISTS "${BLAS_PATH}/libblas.so")
      message(FATAL_ERROR "The ATLAS BLAS library path does not contain libblas.so. CMake is exiting.")
      message(FATAL_ERROR "The ATLAS BLAS library path does not contain libblas.so! CMake is exiting.")
    endif()
  elseif(BLAS_LIB STREQUAL "MKL")
    if(NOT PATH_INTEL_ROOT)
      message(FATAL_ERROR "The MKL BLAS choice requires the Intel root directory (-DPATH_INTEL_ROOT), for example /opt/intel. CMake is exiting.")
      message(FATAL_ERROR "The MKL BLAS choice requires the Intel root directory (-DPATH_INTEL_ROOT), for example /opt/intel! CMake is exiting.")
    endif()
    set(BLAS_PATH ${PATH_INTEL_ROOT}/mkl/lib/intel64)
    if(NOT EXISTS "${BLAS_PATH}/libmkl_core.so")
      message(FATAL_ERROR "The MKL BLAS library path does not contain libmkl_core.so. CMake is exiting.")
      message(FATAL_ERROR "The MKL BLAS library path does not contain libmkl_core.so! CMake is exiting.")
    endif()
  elseif(BLAS_LIB STREQUAL "OPENBLAS")
    if(NOT EXISTS "${BLAS_PATH}/libopenblas.so")
      message(FATAL_ERROR "The OPENBLAS BLAS library path does not contain libopenblas.so. CMake is exiting.")
      message(FATAL_ERROR "The OPENBLAS BLAS library path does not contain libopenblas.so! CMake is exiting.")
    endif()
  elseif(BLAS_LIB STREQUAL "ACML")
    if(NOT EXISTS "${BLAS_PATH}/libacml_mp.so")
      message(FATAL_ERROR "The ACML BLAS library path does not contain libacml_mp.so. CMake is exiting.")
      message(FATAL_ERROR "The ACML BLAS library path does not contain libacml_mp.so! CMake is exiting.")
    endif()
  elseif(BLAS_LIB STREQUAL "ESSL")
    if(NOT EXISTS "${BLAS_PATH}/libessl.so")
      message(FATAL_ERROR "The ESSL BLAS library path does not contain libessl.so. CMake is exiting.")
      message(FATAL_ERROR "The ESSL BLAS library path does not contain libessl.so! CMake is exiting.")
    endif()
    if(NOT PATH_IBM_XL_CPP)
      message(FATAL_ERROR "The ESSL BLAS choice requires the path to IBM XL C++ runtime libraries (-DPATH_IBM_XL_CPP). CMake is exiting.")
      message(FATAL_ERROR "The ESSL BLAS choice requires the path to IBM XL C++ runtime libraries (-DPATH_IBM_XL_CPP)! CMake is exiting.")
    endif()
    if(NOT PATH_IBM_XL_FOR)
      message(FATAL_ERROR "The ESSL BLAS choice requires the path to IBM XL Fortran runtime libraries (-DPATH_IBM_XL_FOR). CMake is exiting.")
      message(FATAL_ERROR "The ESSL BLAS choice requires the path to IBM XL Fortran runtime libraries (-DPATH_IBM_XL_FOR)! CMake is exiting.")
    endif()
    if(NOT PATH_IBM_XL_SMP)
      message(FATAL_ERROR "The ESSL BLAS choice requires the path to IBM XL SMP runtime libraries (-DPATH_IBM_XL_SMP). CMake is exiting.")
      message(FATAL_ERROR "The ESSL BLAS choice requires the path to IBM XL SMP runtime libraries (-DPATH_IBM_XL_SMP)! CMake is exiting.")
    endif()
  else()
    message(FATAL_ERROR "Invalid BLAS_LIB choice: ATLAS (default Linux), MKL, OPENBLAS, ACML, ESSL. CMake is exiting.")
    message(FATAL_ERROR "Invalid BLAS_LIB choice: ATLAS (default Linux), MKL, OPENBLAS, ACML, ESSL! CMake is exiting.")
  endif()

else()

  if(BLAS_PATH)
    message(FATAL_ERROR "If you specify the path to the BLAS libraries, you must also specify which BLAS (-DBLAS_LIB): ATLAS, MKL, OPENBLAS, ACML, ESSL. CMake is exiting.")
    message(FATAL_ERROR "If you specify the path to the BLAS libraries, you must also specify which BLAS (-DBLAS_LIB): ATLAS, MKL, OPENBLAS, ACML, ESSL! CMake is exiting.")
  endif()

endif()

if(NOT CMAKE_BUILD_TYPE)
  set(
    CMAKE_BUILD_TYPE "Release"
    CACHE
      STRING
      "Choose the type of build, options are: Debug, Release, RelWithDebInfo, MinSizeRel"
    FORCE)
  set(CMAKE_BUILD_TYPE "Release"
      CACHE STRING "Choose the type of build, options are: Debug, Release, RelWithDebInfo, MinSizeRel" FORCE)
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.exatn"
      CACHE PATH "default install path"
      FORCE)
      CACHE PATH "default install path" FORCE)
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
@@ -131,14 +126,43 @@ find_package(OpenMP REQUIRED)
find_package(MPI)

if(ENABLE_CUDA)

  find_package(CUDAExaTN)
  if(NOT CUDA_FOUND)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_GPU")
    message(WARNING "You specified ENABLE_CUDA=TRUE but find_package(CUDA) could not find CUDA development headers or libraries")
  endif()

  if(CUTENSOR)
    set(WITH_CUTENSOR "YES")
    if(CUTENSOR_PATH)
      if(NOT EXISTS "${CUTENSOR_PATH}/lib/11/libcutensor.so")
        message(FATAL_ERROR "The provided cuTensor path/lib/11 does not contain libcutensor.so! CMake is exiting.")
      endif()
    else()
      set(CUTENSOR_PATH ".")
      message(WARNING "cuTensor path (-DCUTENSOR_PATH) is not explicitly provided, assuming system directories.")
    endif()
    if(CUQUANTUM)
      set(WITH_CUQUANTUM "YES")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCUQUANTUM")
      if(CUQUANTUM_PATH)
        if(NOT EXISTS "${CUQUANTUM_PATH}/lib64/libcutensornet.so")
          message(FATAL_ERROR "The provided cuQuantum path/lib64 does not contain libcutensornet.so! CMake is exiting.")
        endif()
      else()
        message(FATAL_ERROR "cuQuantum path (-DCUQUANTUM_PATH) is not explicitly provided! Cmake is exiting.")
      endif()
    endif()
  endif()

else()

  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_GPU")
  set(CUDA_FOUND FALSE)
  set(CUTENSOR FALSE)
  set(CUQUANTUM FALSE)

endif()

#If BLAS implementation is not user specified, proceed with "NONE"
@@ -202,4 +226,3 @@ if(Python_FOUND)
else()
  message(STATUS "${BoldYellow}Python interpreter or development headers not found. Skipping Python API build.${ColorReset}")
endif()
+26 −27
Original line number Diff line number Diff line
add_library(ExaTensor::ExaTensor SHARED IMPORTED)

set(REQUIRED_EXATENSOR_LIBS
    "${OpenMP_CXX_LIBRARIES};${OpenMP_Fortran_LIBRARIES};gfortran")
set(REQUIRED_EXATENSOR_LIBS "${OpenMP_CXX_LIBRARIES};${OpenMP_Fortran_LIBRARIES};gfortran")
set(REQUIRED_EXATENSOR_INCLUDES "${CMAKE_SOURCE_DIR}/tpls/ExaTensor/include")

if(CUDA_FOUND)
  message(STATUS "CUDA ROOT DIR ${CUDA_TOOLKIT_ROOT_DIR}")
  message(STATUS "CUDA LIBS ${CUDA_LIBRARIES}")

  set(
    REQUIRED_EXATENSOR_LIBS
    "${REQUIRED_EXATENSOR_LIBS};${CUDA_LIBRARIES};${CUDA_CUBLAS_LIBRARIES};${CUDA_cudadevrt_LIBRARY};${CUDA_TOOLKIT_ROOT_DIR}/lib64/libnvToolsExt.so"
    )
  set(REQUIRED_EXATENSOR_INCLUDES
      "${REQUIRED_EXATENSOR_INCLUDES};${CUDA_INCLUDE_DIRS}")
  set(REQUIRED_EXATENSOR_LIBS "${REQUIRED_EXATENSOR_LIBS};${CUDA_LIBRARIES};${CUDA_CUBLAS_LIBRARIES};${CUDA_cudadevrt_LIBRARY};${CUDA_TOOLKIT_ROOT_DIR}/lib64/libnvToolsExt.so")
  set(REQUIRED_EXATENSOR_INCLUDES "${REQUIRED_EXATENSOR_INCLUDES};${CUDA_INCLUDE_DIRS}")

  if(CUTENSOR)
    if(CUTENSOR_PATH AND NOT CUTENSOR_PATH STREQUAL ".")
      message(STATUS "CUTENSOR ROOT DIR ${CUTENSOR_PATH}")
      set(REQUIRED_EXATENSOR_INCLUDES "${REQUIRED_EXATENSOR_INCLUDES};${CUTENSOR_PATH}/include")
    else()
      message(STATUS "CUTENSOR IS IN SYSTEM DIRECTORIES")
    endif()
    set(REQUIRED_EXATENSOR_LIBS "cutensor;${REQUIRED_EXATENSOR_LIBS}")
    if(CUQUANTUM AND CUQUANTUM_PATH)
      message(STATUS "CUQUANTUM ROOT DIR ${CUQUANTUM_PATH}")
    endif()
  endif()
endif()

if(BLAS_LIB AND BLAS_PATH)
@@ -56,6 +64,7 @@ if(BLAS_LIB AND BLAS_PATH)

  message(STATUS "Appending ${BLAS_LIBRARIES} to ExaTensor Libraries")
  set(REQUIRED_EXATENSOR_LIBS "${BLAS_LIBRARIES};${REQUIRED_EXATENSOR_LIBS}")

endif()

if(WITH_LAPACK)
@@ -80,6 +89,7 @@ if(WITH_LAPACK)
    set(LAPACK_LIBRARIES "${LAPACK_LIBRARY}")

  elseif(BLAS_LIB STREQUAL "ACML")

    find_library(acml_mp acml_mp HINTS ${BLAS_PATH})
    set(LAPACK_LIBRARIES "${acml_mp}")

@@ -97,13 +107,8 @@ if(WITH_LAPACK)
endif()

if(MPI_ROOT_DIR)
  set(
    REQUIRED_EXATENSOR_LIBS
    "${REQUIRED_EXATENSOR_LIBS};${MPI_CXX_LIBRARIES};${MPI_Fortran_LIBRARIES}")
  set(
    REQUIRED_EXATENSOR_INCLUDES
    "${REQUIRED_EXATENSOR_INCLUDES};${MPI_CXX_INCLUDE_DIRS};${MPI_Fortran_INCLUDE_DIRS}"
    )
  set(REQUIRED_EXATENSOR_LIBS "${REQUIRED_EXATENSOR_LIBS};${MPI_CXX_LIBRARIES};${MPI_Fortran_LIBRARIES}")
  set(REQUIRED_EXATENSOR_INCLUDES "${REQUIRED_EXATENSOR_INCLUDES};${MPI_CXX_INCLUDE_DIRS};${MPI_Fortran_INCLUDE_DIRS}")
endif()

set_target_properties(ExaTensor::ExaTensor
@@ -132,17 +137,11 @@ if(EXA_TALSH_ONLY)
                                   ${NOTFULLPATHLIBS})

else()
  set(
    FULLPATHLIBS
    "${CMAKE_INSTALL_PREFIX}/lib/libtalsh${CMAKE_SHARED_LIBRARY_SUFFIX};${CMAKE_INSTALL_PREFIX}/lib/libexatensor${CMAKE_SHARED_LIBRARY_SUFFIX}"
    )
  set(FULLPATHLIBS "${CMAKE_INSTALL_PREFIX}/lib/libtalsh${CMAKE_SHARED_LIBRARY_SUFFIX};${CMAKE_INSTALL_PREFIX}/lib/libexatensor${CMAKE_SHARED_LIBRARY_SUFFIX}")
  set(NOTFULLPATHLIBS "libtalsh${CMAKE_SHARED_LIBRARY_SUFFIX};libexatensor${CMAKE_SHARED_LIBRARY_SUFFIX}")

  if(APPLE)
    set(
      FULLPATHLIBS
      "${CMAKE_INSTALL_PREFIX}/lib/libtalsh.a;${CMAKE_INSTALL_PREFIX}/lib/libexatensor.a"
      )
    set(FULLPATHLIBS "${CMAKE_INSTALL_PREFIX}/lib/libtalsh.a;${CMAKE_INSTALL_PREFIX}/lib/libexatensor.a")
    set(NOTFULLPATHLIBS "libtalsh.a;libexatensor.a")
  endif()

+0 −1
Original line number Diff line number Diff line


if(NOT ${MPI_LIB} STREQUAL "NONE")
  add_subdirectory(mpi)
endif()
+18 −16
Original line number Diff line number Diff line
@@ -10,17 +10,16 @@ file(GLOB SRC
usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC)
usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC)

add_library(${LIBRARY_NAME}
            SHARED
            ${SRC}
            )
add_library(${LIBRARY_NAME} SHARED ${SRC})

target_include_directories(
  ${LIBRARY_NAME}
target_include_directories(${LIBRARY_NAME}
  PUBLIC . ..
         node_executors/talsh node_executors/exatensor
         graph_executors/eager graph_executors/lazy
         ../graph ${CMAKE_SOURCE_DIR}/src/exatn
  node_executors/talsh
  node_executors/exatensor
  graph_executors/eager
  graph_executors/lazy
  ../graph
  ${CMAKE_SOURCE_DIR}/src/exatn
)

set(_bundle_name exatn_runtime_executor)
@@ -37,12 +36,15 @@ usfunctionembedresources(TARGET
                         FILES
                         manifest.json)

target_link_libraries(${LIBRARY_NAME} PUBLIC CppMicroServices exatn-numerics exatn-runtime PRIVATE ExaTensor::ExaTensor)
target_link_libraries(${LIBRARY_NAME}
  PUBLIC CppMicroServices exatn-numerics exatn-runtime exatn_runtime_cuquantum
  PRIVATE ExaTensor::ExaTensor
)

exatn_configure_plugin_rpath(${LIBRARY_NAME})

if(EXATN_BUILD_TESTS)
  #add_subdirectory(boost/tests)
if(CUQUANTUM)
  add_subdirectory(cuquantum)
endif()

file (GLOB HEADERS *.hpp)
+40 −0
Original line number Diff line number Diff line
set(LIBRARY_NAME exatn_runtime_cuquantum)

file(GLOB SRC cuquantum_executor.cu)

set(CUDA_LIBRARIES PUBLIC ${CUDA_LIBRARIES})

set(CUDA_ARCH_BIN 86)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -shared -std c++17 -gencode arch=compute_${CUDA_ARCH_BIN},code=sm_${CUDA_ARCH_BIN} -rdc=true --compiler-options -fPIC")

cuda_add_library(${LIBRARY_NAME} SHARED ${SRC})

set_target_properties(${LIBRARY_NAME} PROPERTIES DEFINE_SYMBOL "")

target_include_directories(${LIBRARY_NAME}
  PUBLIC .
  ${CMAKE_SOURCE_DIR}/src/exatn
)

target_link_libraries(${LIBRARY_NAME} PUBLIC exatn-numerics)

if(CUQUANTUM)
  target_include_directories(${LIBRARY_NAME} PUBLIC ${CUQUANTUM_PATH}/include)
  target_link_libraries(${LIBRARY_NAME} PRIVATE ${CUQUANTUM_PATH}/lib64/libcutensornet.so)
endif()

if(CUTENSOR AND NOT CUTENSOR_PATH STREQUAL ".")
  target_include_directories(${LIBRARY_NAME} PUBLIC ${CUTENSOR_PATH}/include)
  target_link_libraries(${LIBRARY_NAME} PRIVATE ${CUTENSOR_PATH}/lib/11/libcutensor.so)
endif()

exatn_configure_plugin_rpath(${LIBRARY_NAME})

if(EXATN_BUILD_TESTS)
  #add_subdirectory(boost/tests)
endif()

file (GLOB HEADERS *.hpp)

install(FILES ${HEADERS} DESTINATION include/exatn)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
Loading