2022-07-31 21:43:26 +08:00
# TODO: check the minimum cmake version
cmake_minimum_required ( VERSION 3.9 ) # Required by find_package(OpenMP)
include ( CMakeDependentOption )
project ( InfiniTensor C CXX )
# Do not change these options in this file. Use cmake.config, cmake -DOPTION=VALUE, or ccmake to specify them.
2022-08-22 15:01:03 +08:00
option ( USE_CUDA "Support CUDA GPU" ON )
2022-09-01 20:30:12 +08:00
option ( USE_BACKTRACE "Print backtrace on exception and segmentation fault" ON )
2022-08-08 16:02:07 +08:00
option ( BUILD_TEST "Build tests" ON )
2022-09-01 20:30:12 +08:00
2022-07-31 21:43:26 +08:00
cmake_dependent_option ( BUILD_TEST_CORE "Build tests for core components" ON BUILD_TEST OFF )
2022-08-08 16:02:07 +08:00
cmake_dependent_option ( BUILD_TEST_PET "Build tests for PET" OFF BUILD_TEST OFF )
cmake_dependent_option ( BUILD_TEST_EINNET "Build tests for EINNET" OFF BUILD_TEST OFF )
2022-07-31 21:43:26 +08:00
set ( DEFAULT_BUILD_TYPE "RelWithDebInfo" )
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_EXTENSIONS OFF ) # -std=gnu++11 when on, -std=c++11 when off
2022-08-31 14:44:53 +08:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Werror -Wno-error=deprecated-declarations" )
2022-07-31 21:43:26 +08:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG" ) # Enable assertion
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG" ) # Enable assertion
find_package (
P y t h o n
C O M P O N E N T S I n t e r p r e t e r D e v e l o p m e n t
R E Q U I R E D )
# OpenMP
find_package ( OpenMP )
if ( OpenMP_C_FOUND )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
endif ( )
if ( OpenMP_CXX_FOUND )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
endif ( )
include_directories ( include )
2022-08-08 16:02:07 +08:00
# # Pybind11
# add_subdirectory(3rd-party/pybind11)
2022-07-31 21:43:26 +08:00
# include_directories(3rd-party/pybind11/include)
2022-08-08 16:02:07 +08:00
# nlohmann_json
add_subdirectory ( 3rd-party/nlohmann_json_cmake_fetchcontent )
include_directories ( 3rd-party/nlohmann_json_cmake_fetchcontent/single_include )
2022-07-31 21:43:26 +08:00
if ( BUILD_TEST )
2022-08-08 16:02:07 +08:00
set ( BUILD_GMOCK
O F F
C A C H E B O O L " D o n o t b u i l d g m o c k " F O R C E )
set ( INSTALL_GTEST
O F F
C A C H E B O O L " D o n o t i n s t a l l g t e s t " F O R C E )
2022-07-31 21:43:26 +08:00
add_subdirectory ( 3rd-party/googletest )
include_directories ( 3rd-party/googletest/googletest/include )
endif ( )
file ( GLOB_RECURSE SRC src/*.cc src/*.cu )
add_library ( InfiniTensor SHARED ${ SRC } )
2022-08-22 15:01:03 +08:00
2022-09-01 20:30:12 +08:00
if ( USE_BACKTRACE )
add_definitions ( -D BACKWARD_TRACE )
add_subdirectory ( 3rd-party/backward-cpp )
include_directories ( 3rd-party/backward-cpp )
add_backward ( InfiniTensor )
target_link_libraries ( InfiniTensor dw )
endif ( )
2022-08-22 15:01:03 +08:00
if ( USE_CUDA )
# set(CUDA_HOST_COMPILER /home/spack/spack/opt/spack/linux-ubuntu22.04-broadwell/gcc-9.4.0/gcc-9.4.0-st36klijpsnquihiy463hmedsyhoc3g6/bin/gcc)
enable_language ( CUDA )
# TODO: how to set option for CUDA_HOST_COMPILER. Now env var CUDAHOSTCXX=/home/spack/spack/opt/spack/linux-ubuntu22.04-broadwell/gcc-9.4.0/gcc-9.4.0-st36klijpsnquihiy463hmedsyhoc3g6/bin/gcc takes effect.
# option(CUDA_HOST_COMPILER "" ${CMAKE_C_COMPILER})
# TODO: find_package seems unnecessary for CMake >= 3.8
find_package ( CUDA REQUIRED )
# message("CUBLAS_LIBRARIES: ${CUDA_LIBRARIES}")
target_link_libraries ( InfiniTensor cudnn curand cublas ${ CUDA_LIBRARIES } )
endif ( )
2022-07-31 21:43:26 +08:00
# # Python bindings
# pybind11_add_module(infini MODULE ${FFI})
# target_link_libraries(infini PRIVATE infini_cpp)
2022-08-08 16:02:07 +08:00
function ( build_test files )
# Non-recursive glob for skip failed tests
file ( GLOB TEST_SOURCES ${ files } )
2022-07-31 21:43:26 +08:00
foreach ( testsourcefile ${ TEST_SOURCES } )
get_filename_component ( testname ${ testsourcefile } NAME_WE )
add_executable ( ${ testname } ${ testsourcefile } )
2022-08-08 16:02:07 +08:00
target_link_libraries ( ${ testname } InfiniTensor GTest::gtest_main )
2022-07-31 21:43:26 +08:00
add_test ( NAME ${ testname } COMMAND ${ testname } )
endforeach ( testsourcefile ${ TEST_SOURCES } )
2022-08-08 16:02:07 +08:00
endfunction ( )
if ( BUILD_TEST )
enable_testing ( )
2022-09-01 20:30:12 +08:00
if ( USE_TRACE )
build_test ( test/trace/*.cc )
endif ( )
2022-08-08 16:02:07 +08:00
if ( BUILD_TEST_CORE )
build_test ( test/core/*.cc )
2022-08-17 14:16:01 +08:00
build_test ( test/operators/*.cc )
2022-08-08 16:02:07 +08:00
endif ( )
if ( BUILD_TEST_PET )
build_test ( test/pet/*.cc )
endif ( )
if ( BUILD_TEST_EINNET )
build_test ( test/nnet/*.cc )
endif ( )
2022-07-31 21:43:26 +08:00
endif ( )