diff --git a/CMakeLists.txt b/CMakeLists.txt index 09cbf150373ac1f9496792d65907bd648f8c4240..3e92d6eef8a916ecfd980b47d22a596b5b8a5ecc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,17 @@ project( tnl ) set( tnlVersion "0.1" ) +# declare all custom build options +option(OFFLINE_BUILD "Offline build (i.e. without downloading libraries such as pybind11)" OFF) +option(WITH_MIC "Build with MIC support" OFF) +option(WITH_CUDA "Build with CUDA support" ON) +set(WITH_CUDA_ARCH "auto" CACHE STRING "Build for these CUDA architectures") +option(WITH_OPENMP "Build with OpenMP support" ON) +option(WITH_TESTS "Build tests" ON) +option(WITH_COVERAGE "Enable code coverage reports from unit tests" OFF) +option(WITH_EXAMPLES "Compile the 'examples' directory" ON) +option(WITH_TEMPLATES_INSTANTIATION "Enable explicit template instantiation" OFF) + # install paths relative to the cmake's prefix set( TNL_TARGET_INCLUDE_DIRECTORY "include/TNL" ) set( TNL_TARGET_DATA_DIRECTORY "share/TNL" ) @@ -65,15 +76,15 @@ if( CXX_COMPILER_NAME MATCHES "icpc" ) ##### # Ckeck for MIC # - if( WITH_MIC STREQUAL "yes" ) - message( "Compile MIC support..." ) - set( MIC_CXX_FLAGS "-DHAVE_MIC") - # build all tests with MIC support - set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_MIC ) - set( WITH_CUDA "no") + if( ${WITH_MIC} ) + message( "Enabled MIC support." ) + set( MIC_CXX_FLAGS "-DHAVE_MIC") + # build all tests with MIC support + set( CXX_TESTS_FLAGS ${CXX_TESTS_FLAGS} -DHAVE_MIC ) + set( WITH_CUDA OFF CACHE BOOL "Build with CUDA support" ) else() - set( MIC_CXX_FLAGS "") - endif( ) + set( MIC_CXX_FLAGS "") + endif() endif() # force colorized output in continuous integration @@ -89,13 +100,13 @@ endif() ##### # Check for CUDA # -if( WITH_CUDA STREQUAL "yes" ) +if( ${WITH_CUDA} ) find_package( CUDA ) if( CUDA_FOUND ) set( BUILD_CUDA TRUE) set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF) set(BUILD_SHARED_LIBS ON) - set(CUDA_SEPARABLE_COMPILATION ON) + set(CUDA_SEPARABLE_COMPILATION ON) # Use the CUDA_HOST_COMPILER environment variable if the user specified it. if( NOT $ENV{CUDA_HOST_COMPILER} STREQUAL "" ) message( "-- Setting CUDA_HOST_COMPILER to '$ENV{CUDA_HOST_COMPILER}'" ) @@ -160,34 +171,15 @@ if( WITH_CUDA STREQUAL "yes" ) set( CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ; ${CUDA_ARCH} -D_FORCE_INLINES ) # TODO: this is necessary only due to a bug in cmake set( CUDA_ADD_LIBRARY_OPTIONS -shared ) - - #### - # Check for CUSPARSE - # - if( NOT WITH_CUSPARSE STREQUAL "no" ) - find_path( CUSPARSE_INCLUDE_DIR cusparse.h - /usr/local/cuda/include - ${CUDA_INCLUDE_DIR} - DOC "CUSPARSE headers." ) - if( ${CUSPARSE_INCLUDE_DIR} STREQUAL "CUSPARSE_INCLUDE_DIR-NOTFOUND" ) - message( "CUSPARSE not found." ) - set( HAVE_CUSPARSE "//#define HAVE_CUSPARSE 1" ) - else() - message( "CUSPARSE found. -- ${CUSPARSE_INCLUDE_DIR}" ) - set( HAVE_CUSPARSE "#define HAVE_CUSPARSE 1" ) - cuda_include_directories( ${CUSPARSE_INCLUDE_DIR} ) - set( CUSPARSE_LIBRARY "${CUDA_cusparse_LIBRARY}" ) - endif() - endif( NOT WITH_CUSPARSE STREQUAL "no" ) - endif( CUDA_FOUND ) -endif( WITH_CUDA STREQUAL "yes" ) + endif() +endif() #### # Check for OpenMP # -if( OPENMP_FOUND AND WITH_OPENMP STREQUAL "yes" ) - message( "Compiler supports OpenMP." ) +if( OPENMP_FOUND AND ${WITH_OPENMP} ) + message( "Enabled OpenMP support." ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENMP ${OpenMP_CXX_FLAGS}" ) endif() @@ -271,17 +263,17 @@ else() set( HAVE_SYS_IOCTL_H "#define HAVE_SYS_IOCTL_H 1" ) endif() -if( WITH_TESTS STREQUAL "yes" ) +if( ${WITH_TESTS} ) enable_testing() # build gtest libs include( BuildGtest ) - if( WITH_COVERAGE STREQUAL "yes" AND CMAKE_BUILD_TYPE STREQUAL "Debug" ) + if( ${WITH_COVERAGE} AND CMAKE_BUILD_TYPE STREQUAL "Debug" ) # enable code coverage reports include( UseCodeCoverage ) endif() -endif( WITH_TESTS STREQUAL "yes" ) +endif() #if( BUILD_MPI ) # FIND_PATH( PETSC_INCLUDE_DIR petsc.h @@ -311,7 +303,7 @@ endif( WITH_TESTS STREQUAL "yes" ) #### # Explicit template instantiation # -#if( WITH_TEMPLATE_INSTANTIATION STREQUAL "yes" ) +#if( ${WITH_TEMPLATE_INSTANTIATION} ) # AddCompilerFlag( "-DTEMPLATE_EXPLICIT_INSTANTIATION " ) # # if( INSTANTIATE_INT STREQUAL "yes" ) @@ -352,7 +344,7 @@ add_subdirectory( src ) add_subdirectory( share ) add_subdirectory( tests ) -if( WITH_EXAMPLES STREQUAL "yes" ) +if( ${WITH_EXAMPLES} ) add_subdirectory( examples ) endif() @@ -384,6 +376,17 @@ set(CPACK_SOURCE_STRIP_FILES "Release") #set(CPACK_PACKAGE_EXECUTABLES "MyExecutable" "My Executable") INCLUDE( CPack ) +# Print custom build options +message( "-- Build options:" ) +message( " OFFLINE_BUILD=${OFFLINE_BUILD}" ) +message( " WITH_MIC=${WITH_MIC}" ) +message( " WITH_CUDA=${WITH_CUDA}" ) +message( " WITH_CUDA_ARCH=${WITH_CUDA_ARCH}" ) +message( " WITH_OPENMP=${WITH_OPENMP}" ) +message( " WITH_TESTS=${WITH_TESTS}" ) +message( " WITH_COVERAGE=${WITH_COVERAGE}" ) +message( " WITH_EXAMPLES=${WITH_EXAMPLES}" ) +message( " WITH_TEMPLATES_INSTANTIATION=${WITH_TEMPLATES_INSTANTIATION}" ) # Print compiler options message( "-- Compiler options:" ) message( " CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" ) diff --git a/build b/build index 305a7e5d1ab69130e561afe16046e6329736c45e..8601731d7e2fa19eb701d90a45b23b09ff4941b5 100755 --- a/build +++ b/build @@ -11,6 +11,7 @@ CMAKE="cmake" CMAKE_ONLY="no" HELP="no" VERBOSE="" +OFFLINE_BUILD="no" WITH_CLANG="no" WITH_CUDA="yes" @@ -40,6 +41,7 @@ do --cmake=* ) CMAKE="${option#*=}" ;; --cmake-only=* ) CMAKE_ONLY="${option#*=}" ;; --verbose ) VERBOSE="VERBOSE=1" ;; + --offline-build ) OFFLINE_BUILD="yes" ;; --help ) HELP="yes" ;; --with-clang=* ) WITH_CLANG="${option#*=}" ;; --with-mic=* ) WITH_MIC="${option#*=}" ;; @@ -104,6 +106,7 @@ echo "Configuring ${BUILD} $TARGET ..." ${CMAKE} ${ROOT_DIR} \ -DCMAKE_BUILD_TYPE=${BUILD} \ -DCMAKE_INSTALL_PREFIX=${PREFIX} \ + -DOFFLINE_BUILD=${OFFLINE_BUILD} \ -DWITH_MIC=${WITH_MIC} \ -DWITH_CUDA=${WITH_CUDA} \ -DWITH_CUDA_ARCH=${WITH_CUDA_ARCH} \ diff --git a/cmake/Gtest.cmake.in b/cmake/Gtest.cmake.in index 762cff74ab9f856066a69c97c24fe69bfd076f66..cdb2e45488db5c1a297d77dd0c2eae506c8f3a82 100644 --- a/cmake/Gtest.cmake.in +++ b/cmake/Gtest.cmake.in @@ -19,4 +19,7 @@ ExternalProject_Add(googletest BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" + # Disable update of the external project in an offline build + # reference: https://stackoverflow.com/a/40423683 + UPDATE_DISCONNECTED ${OFFLINE_BUILD} ) diff --git a/src/Python/pybind11.cmake.in b/src/Python/pybind11.cmake.in index 18f1aeac607f719a067a8a61c1c3449cfd64687b..885e62e5e694c86020934ed7260557b1469a4899 100644 --- a/src/Python/pybind11.cmake.in +++ b/src/Python/pybind11.cmake.in @@ -9,4 +9,7 @@ ExternalProject_Add(pybind11 SOURCE_DIR "${CMAKE_BINARY_DIR}/pybind11-src" BINARY_DIR "${CMAKE_BINARY_DIR}/pybind11-build" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DPYBIND11_TEST=FALSE + # Disable update of the external project in an offline build + # reference: https://stackoverflow.com/a/40423683 + UPDATE_DISCONNECTED ${OFFLINE_BUILD} ) diff --git a/src/TNL/Experimental/CMakeLists.txt b/src/TNL/Experimental/CMakeLists.txt index 3cf0e802046f4e6c25aceffba997e78539e08cba..b543baec64ec4d78f1fab9d3a7ae403c4c844541 100644 --- a/src/TNL/Experimental/CMakeLists.txt +++ b/src/TNL/Experimental/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory( Arithmetics ) -if( WITH_EXAMPLES STREQUAL "yes" ) +if( ${WITH_EXAMPLES} ) add_subdirectory( Hamilton-Jacobi ) endif() diff --git a/src/TNL/Solvers/Linear/Preconditioners/ILU0.h b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h index 651f36b73fc3f8773d2063ae7d0dec53f96f82f5..cf44431849bf5732a2fd87efd664dccc0c6f5fc0 100644 --- a/src/TNL/Solvers/Linear/Preconditioners/ILU0.h +++ b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h @@ -18,7 +18,7 @@ #include #include -#ifdef HAVE_CUDA +#if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE) #include #endif @@ -66,7 +66,7 @@ public: ILU0() { -#ifdef HAVE_CUDA +#if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE) cusparseCreate( &handle ); #endif } @@ -84,14 +84,14 @@ public: ~ILU0() { -#ifdef HAVE_CUDA +#if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE) resetMatrices(); cusparseDestroy( handle ); #endif } protected: -#ifdef HAVE_CUDA +#if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE) Matrices::CSR< RealType, DeviceType, IndexType > A; Containers::Vector< RealType, DeviceType, IndexType > y; diff --git a/src/TNL/Solvers/Linear/Preconditioners/ILU0_impl.h b/src/TNL/Solvers/Linear/Preconditioners/ILU0_impl.h index 58d1c4ad8c9cee8572e05e83de81105b5a96086f..0ce43ed8b6a9598e97ad1221e5ebee10f94bfcb2 100644 --- a/src/TNL/Solvers/Linear/Preconditioners/ILU0_impl.h +++ b/src/TNL/Solvers/Linear/Preconditioners/ILU0_impl.h @@ -160,6 +160,7 @@ ILU0< double, Devices::Cuda, int >:: update( const MatrixPointer& matrixPointer ) { #ifdef HAVE_CUDA +#ifdef HAVE_CUSPARSE // TODO: only numerical factorization has to be done every time, split the rest into separate "setup" method which is called less often resetMatrices(); @@ -254,6 +255,9 @@ update( const MatrixPointer& matrixPointer ) std::cerr << "A(" << numerical_zero << ", " << numerical_zero << ") is zero." << std::endl; throw 1; } +#else + throw std::runtime_error("The program was not compiled with the CUSPARSE library. Pass -DHAVE_CUSPARSE -lcusparse to the compiler."); +#endif #else throw Exceptions::CudaSupportMissing(); #endif @@ -265,6 +269,7 @@ ILU0< double, Devices::Cuda, int >:: solve( const Vector1& b, Vector2& x ) const { #ifdef HAVE_CUDA +#ifdef HAVE_CUSPARSE const int m = A.getRows(); const int nnz = A.getValues().getSize(); @@ -289,6 +294,9 @@ solve( const Vector1& b, Vector2& x ) const policy_U, (void*) pBuffer.getData() ); return true; +#else + throw std::runtime_error("The program was not compiled with the CUSPARSE library. Pass -DHAVE_CUSPARSE -lcusparse to the compiler."); +#endif #else throw Exceptions::CudaSupportMissing(); #endif diff --git a/src/UnitTests/CMakeLists.txt b/src/UnitTests/CMakeLists.txt index fb90e6ee3d41fe06dd4e0724b2356a7f046bddad..a96e178c52085ded118ee46a54e8b455ac4facbe 100644 --- a/src/UnitTests/CMakeLists.txt +++ b/src/UnitTests/CMakeLists.txt @@ -1,4 +1,4 @@ -if( WITH_TESTS STREQUAL "yes" ) +if( ${WITH_TESTS} ) ADD_SUBDIRECTORY( Containers ) ADD_SUBDIRECTORY( Matrices ) @@ -41,4 +41,4 @@ ADD_TEST( StringTest ${EXECUTABLE_OUTPUT_PATH}/StringTest${CMAKE_EXECUTABLE_SUFF ADD_TEST( ObjectTest ${EXECUTABLE_OUTPUT_PATH}/ObjectTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( UniquePointerTest ${EXECUTABLE_OUTPUT_PATH}/UniquePointerTest${CMAKE_EXECUTABLE_SUFFIX} ) -endif( WITH_TESTS STREQUAL "yes" ) +endif( ${WITH_TESTS} ) diff --git a/src/UnitTests/Meshes/CMakeLists.txt b/src/UnitTests/Meshes/CMakeLists.txt index 97cdc0333d747c2e6162a6b9ecb115b6c91a001a..c5daaed1fa18e6d887e3a58eb51103fc8a82dac5 100644 --- a/src/UnitTests/Meshes/CMakeLists.txt +++ b/src/UnitTests/Meshes/CMakeLists.txt @@ -4,7 +4,7 @@ TARGET_LINK_LIBRARIES( BoundaryTagsTest ${GTEST_BOTH_LIBRARIES} tnl ) -if( BUILD_CUDA AND ${CMAKE_CXX_COMPILER} MATCHES ".*clang\\+\\+" ) +if( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( MeshTest MeshTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( MeshTest @@ -48,27 +48,26 @@ ADD_TEST( MeshEntityTest ${EXECUTABLE_OUTPUT_PATH}/MeshEntityTest${CMAKE_EXECUTA ## Tests with VTK ## -find_package( VTK ) -if( VTK_FOUND ) - include(${VTK_USE_FILE}) +#find_package( VTK ) +#if( VTK_FOUND ) +# include(${VTK_USE_FILE}) +# +# AddCompilerFlag( "-DHAVE_VTK " ) +# SET( VTK_COMMON_LIBRARIES vtkCommonCore ; vtkIOLegacy ) +#endif( VTK_FOUND ) - AddCompilerFlag( "-DHAVE_VTK " ) - SET( VTK_COMMON_LIBRARIES vtkCommonCore ; vtkIOLegacy ) -endif( VTK_FOUND ) - -# FIXME: compilation fails with nvcc (CUDA 9.0) -#if( BUILD_CUDA AND ${CMAKE_CXX_COMPILER} MATCHES ".*clang\\+\\+" ) -# CUDA_ADD_EXECUTABLE( MeshReaderTest MeshReaderTest.cu -# OPTIONS ${CXX_TESTS_FLAGS} ) -# TARGET_LINK_LIBRARIES( MeshReaderTest -# ${GTEST_BOTH_LIBRARIES} -# ${VTK_COMMON_LIBRARIES} -# tnl ) -#else() +if( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE( MeshReaderTest MeshReaderTest.cu + OPTIONS ${CXX_TESTS_FLAGS} ) + TARGET_LINK_LIBRARIES( MeshReaderTest + ${GTEST_BOTH_LIBRARIES} + ${VTK_COMMON_LIBRARIES} + tnl ) +else() ADD_EXECUTABLE( MeshReaderTest MeshReaderTest.cpp ) TARGET_COMPILE_OPTIONS( MeshReaderTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_LINK_LIBRARIES( MeshReaderTest ${GTEST_BOTH_LIBRARIES} ${VTK_COMMON_LIBRARIES} tnl ) -#endif() +endif() diff --git a/tests/benchmarks/CMakeLists.txt b/tests/benchmarks/CMakeLists.txt index 12fe883c8c50bb59fd1724a528197fc3a394cf2f..e53ba6878070e6b8f8d3b830ab8f64afcccbcf77 100644 --- a/tests/benchmarks/CMakeLists.txt +++ b/tests/benchmarks/CMakeLists.txt @@ -4,13 +4,13 @@ ADD_SUBDIRECTORY( heat-equation-benchmark ) IF( BUILD_CUDA ) CUDA_ADD_EXECUTABLE( tnl-benchmark-blas tnl-benchmark-blas.cu ) CUDA_ADD_CUBLAS_TO_TARGET( tnl-benchmark-blas ) - TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl ${CUSPARSE_LIBRARY} ) + TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl ) CUDA_ADD_EXECUTABLE( tnl-benchmark-spmv tnl-benchmark-spmv.cu ) - TARGET_LINK_LIBRARIES( tnl-benchmark-spmv tnl ${CUSPARSE_LIBRARY} ) + TARGET_LINK_LIBRARIES( tnl-benchmark-spmv tnl ${CUDA_cusparse_LIBRARY} ) CUDA_ADD_EXECUTABLE( tnl-benchmark-linear-solvers tnl-benchmark-linear-solvers.cu ) - TARGET_LINK_LIBRARIES( tnl-benchmark-linear-solvers tnl ${CUSPARSE_LIBRARY} ) + TARGET_LINK_LIBRARIES( tnl-benchmark-linear-solvers tnl ) ELSE() ADD_EXECUTABLE( tnl-benchmark-blas tnl-benchmark-blas.cpp ) TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl ) diff --git a/tnlConfig.h.in b/tnlConfig.h.in index cb352fcf3d0fc29b6fc31d23949b883eb1ca56d3..967ce8e268db25a1be0acf9edb95f81277c3786a 100644 --- a/tnlConfig.h.in +++ b/tnlConfig.h.in @@ -4,10 +4,6 @@ @HAVE_SYS_IOCTL_H@ -#ifdef HAVE_CUDA - @HAVE_CUSPARSE@ -#endif - @HAVE_DCMTK_H@ @HAVE_PNG_H@