diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dfa01696..754cf3d43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,14 +91,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") endif() endif() -#========================================================= -# Allow for multiple CL.EXE to write to the same .PDB file -if(RTK_USE_CUDA) - if(WIN32) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FS") - endif() -endif() - include(cmake/rtkCompilerFlags.cmake) # -------------------------------------------------------- @@ -212,11 +204,7 @@ set(RTK_VERSION_PATCH ${RTK_VERSION_PATCH}) # Whether the compiled version of RTK uses CUDA set(RTK_USE_CUDA ${RTK_USE_CUDA}) -if(${RTK_USE_CUDA}) - list(APPEND CMAKE_MODULE_PATH ${RTK_MODULE_PATH_CONFIG}) - # if we are using CUDA, make sure CUDA libraries are available - find_package(CUDA_wrap REQUIRED) - include_directories(${CUDA_INCLUDE_DIRS}) +if(RTK_USE_CUDA) set(RTK_CUDA_PROJECTIONS_SLAB_SIZE \"16\" CACHE STRING \"Number of projections processed simultaneously in CUDA forward and back projections\") endif() ") @@ -230,9 +218,7 @@ set(RTK_VERSION_PATCH ${RTK_VERSION_PATCH}) # Whether the compiled version of RTK uses CUDA set(RTK_USE_CUDA ${RTK_USE_CUDA}) -if(${RTK_USE_CUDA}) - # if we are using CUDA, make sure CUDA libraries are available - find_package(CUDA_wrap REQUIRED) +if(RTK_USE_CUDA) set(RTK_CUDA_PROJECTIONS_SLAB_SIZE \"16\" CACHE STRING \"Number of projections processed simultaneously in CUDA forward and back projections\") endif() ") @@ -253,11 +239,9 @@ endif() # Install configuration file install(FILES ${RTK_BINARY_DIR}/rtkConfiguration.h DESTINATION ${RTK_INSTALL_INCLUDE_DIR}) -install(FILES ${RTK_SOURCE_DIR}/cmake/FindCUDA_wrap.cmake - ${RTK_SOURCE_DIR}/cmake/FindGengetopt.cmake +install(FILES ${RTK_SOURCE_DIR}/cmake/FindGengetopt.cmake ${RTK_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake ${RTK_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake.in - ${RTK_SOURCE_DIR}/cmake/has_cuda_gpu.cxx DESTINATION ${ITK_INSTALL_PACKAGE_DIR}) if(NOT ITK_SOURCE_DIR) install(CODE "MESSAGE(FATAL_ERROR \"Cannot install, RTK is compiled separately from ITK. Installation is only functional if RTK is compiled within ITK.\")") diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index dd1e0932d..1e1e5e5af 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -116,7 +116,7 @@ if(BUILD_TESTING) set_tests_properties(rtkappprojectshepploganphantomtest PROPERTIES DEPENDS rtkappsimulatedgeometrytest) # FDK test - if(RTK_USE_CUDA AND CUDA_HAVE_GPU) + if(RTK_USE_CUDA) add_test(rtkappfdktest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rtkfdk -g geo -p . -r sheppy.mha -o fdk.mha --hardware cuda --dimension 21) else() add_test(rtkappfdktest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rtkfdk -g geo -p . -r sheppy.mha -o fdk.mha --dimension 21) diff --git a/cmake/FindCUDA_wrap.cmake b/cmake/FindCUDA_wrap.cmake deleted file mode 100644 index 2936de3c2..000000000 --- a/cmake/FindCUDA_wrap.cmake +++ /dev/null @@ -1,77 +0,0 @@ -# - Wrapper around FindCUDA -cmake_minimum_required(VERSION 3.3) - -if (MINGW) - # Cuda doesn't work with mingw at all - set (CUDA_FOUND FALSE) -elseif (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 2.8) - # FindCuda is included with CMake 2.8 - set (CUDA_FOUND FALSE) -else () - # GCS 2011.03.16 - # Make nvcc less whiny - if (CMAKE_COMPILER_IS_GNUCC) - set (CUDA_PROPAGATE_HOST_FLAGS CACHE BOOL OFF) - endif () - - # GCS 2012-05-11: We need to propagate cxx flags to nvcc, but - # the flag -ftest-coverage causes nvcc to barf, so exclude that one - if (CMAKE_COMPILER_IS_GNUCC) - string (REPLACE "-ftest-coverage" "" TMP "${CMAKE_CXX_FLAGS}") - string (REPLACE "-ftemplate-depth-50" "" TMP "${TMP}") - string (REPLACE " " "," TMP "${TMP}") - set (CUDA_CXX_FLAGS ${CUDA_CXX_FLAGS} ${TMP}) - endif () - find_package (CUDA QUIET) -endif () - -# GCS 2012-09-25 - Seems this is needed too -if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -fPIC") -endif () - -# SR Remove warning with shared libs and MSVC -if(MSVC) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DRTK_EXPORTS") -endif() - -set (CUDA_FOUND ${CUDA_FOUND} CACHE BOOL "Did we find cuda?") -mark_as_advanced(CUDA_FOUND) - -if (CUDA_FOUND) - cuda_include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -endif () - -if("${CUDA_VERSION}" VERSION_LESS 9.0) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} - -gencode arch=compute_20,code=sm_20) -endif() -if("${CUDA_VERSION}" VERSION_LESS 11.0) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} - -gencode arch=compute_30,code=sm_30) -endif() -set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} - -Wno-deprecated-gpu-targets - -Wno-deprecated-declarations - -gencode arch=compute_35,code=sm_35 - -gencode arch=compute_35,code=compute_35 - ) - -if(CUDA_FOUND) - try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR - ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_LIST_DIR}/has_cuda_gpu.cxx - CMAKE_FLAGS - -DINCLUDE_DIRECTORIES:STRING=${CUDA_TOOLKIT_INCLUDE} - -DLINK_LIBRARIES:STRING=${CUDA_CUDART_LIBRARY} - COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT_VAR - RUN_OUTPUT_VARIABLE RUN_OUTPUT_VAR) - # COMPILE_RESULT_VAR is TRUE when compile succeeds - # RUN_RESULT_VAR is zero when a GPU is found - if(COMPILE_RESULT_VAR AND NOT RUN_RESULT_VAR) - set(CUDA_HAVE_GPU TRUE CACHE BOOL "Whether CUDA-capable GPU is present") - else() - set(CUDA_HAVE_GPU FALSE CACHE BOOL "Whether CUDA-capable GPU is present") - endif() - mark_as_advanced(CUDA_HAVE_GPU) -endif() diff --git a/cmake/has_cuda_gpu.cxx b/cmake/has_cuda_gpu.cxx deleted file mode 100644 index 2337ab6cd..000000000 --- a/cmake/has_cuda_gpu.cxx +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -int -main() -{ - int deviceCount, device; - int gpuDeviceCount = 0; - struct cudaDeviceProp properties; - cudaError_t cudaResultCode = cudaGetDeviceCount(&deviceCount); - if (cudaResultCode != cudaSuccess) - deviceCount = 0; - /* machines with no GPUs can still report one emulation device */ - for (device = 0; device < deviceCount; ++device) - { - cudaGetDeviceProperties(&properties, device); - if (properties.major != 9999) /* 9999 means emulation only */ - ++gpuDeviceCount; - } - printf("%d GPU CUDA device(s) found\n", gpuDeviceCount); - - /* don't just return the number of gpus, because other runtime cuda - errors can also yield non-zero return values */ - if (gpuDeviceCount > 0) - return 0; /* success */ - else - return 1; /* failure */ -} diff --git a/itk-module-init.cmake b/itk-module-init.cmake index 3c61659c4..564b3fc2c 100644 --- a/itk-module-init.cmake +++ b/itk-module-init.cmake @@ -3,23 +3,32 @@ # list(APPEND CMAKE_MODULE_PATH ${RTK_SOURCE_DIR}/cmake) -find_package(CUDA_wrap QUIET) -if(CUDA_FOUND) - if(${CUDA_VERSION} VERSION_LESS 8.0) - message(WARNING "CUDA version ${CUDA_VERSION} is not supported by RTK.") - set(RTK_USE_CUDA_DEFAULT OFF) +include(CheckLanguage) +check_language(CUDA) + +# Determine default value for RTK_USE_CUDA +set(RTK_USE_CUDA_DEFAULT OFF) +if (CMAKE_CUDA_COMPILER) + find_package(CUDAToolkit) + if(NOT CUDAToolkit_FOUND) + message(WARNING "CUDAToolkit not found (available since CMake v3.17). RTK_USE_CUDA set to OFF.") + elseif(DEFINED CUDAToolkit_VERSION AND "${CUDAToolkit_VERSION}" VERSION_LESS 8.0) + message(WARNING "CUDA version ${CUDAToolkit_VERSION} is not supported by RTK, version 8 is required. RTK_USE_CUDA set to OFF.") else() set(RTK_USE_CUDA_DEFAULT ON) endif() -else() - set(RTK_USE_CUDA_DEFAULT OFF) endif() option(RTK_USE_CUDA "Use CUDA for RTK" ${RTK_USE_CUDA_DEFAULT}) +# Configure CUDA compilation options if(RTK_USE_CUDA) - if(NOT CUDA_FOUND) - find_package(CUDA_wrap REQUIRED) - endif() + enable_language(CUDA) + set(CMAKE_CUDA_RUNTIME_LIBRARY Static) + + include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) + find_package(CUDAToolkit REQUIRED 8.0) + + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets") + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-declarations") set(RTK_CUDA_PROJECTIONS_SLAB_SIZE "16" CACHE STRING "Number of projections processed simultaneously in CUDA forward and back projections") endif() - diff --git a/rtkConfiguration.h.in b/rtkConfiguration.h.in index 0e4e94628..c8ec2f167 100644 --- a/rtkConfiguration.h.in +++ b/rtkConfiguration.h.in @@ -28,9 +28,6 @@ namespace rtk using ThreadIdType = itk::ThreadIdType; } -#ifndef CUDA_FOUND -# cmakedefine CUDA_FOUND -#endif #cmakedefine RTK_PROBE_EACH_FILTER #cmakedefine RTK_USE_CUDA #cmakedefine RTK_BUILD_SHARED_LIBS 1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca7aa4b25..748bad7f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,7 +69,32 @@ set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${defComSansVTK}") # CUDA library #========================================================= if (RTK_USE_CUDA) - set(RTK_CUDA_FILES + set(RTK_SRCS ${RTK_SRCS} + rtkCudaAverageOutOfROIImageFilter.cxx + rtkCudaConstantVolumeSeriesSource.cxx + rtkCudaConstantVolumeSource.cxx + rtkCudaCropImageFilter.cxx + rtkCudaCyclicDeformationImageFilter.cxx + rtkCudaDisplacedDetectorImageFilter.cxx + rtkCudaFDKBackProjectionImageFilter.cxx + rtkCudaFDKConeBeamReconstructionFilter.cxx + rtkCudaFDKWeightProjectionFilter.cxx + rtkCudaForwardWarpImageFilter.cxx + rtkCudaInterpolateImageFilter.cxx + rtkCudaIterativeFDKConeBeamReconstructionFilter.cxx + rtkCudaLagCorrectionImageFilter.cxx + rtkCudaLaplacianImageFilter.cxx + rtkCudaLastDimensionTVDenoisingImageFilter.cxx + rtkCudaParkerShortScanImageFilter.cxx + rtkCudaPolynomialGainCorrectionImageFilter.cxx + rtkCudaRayCastBackProjectionImageFilter.cxx + rtkCudaSplatImageFilter.cxx + rtkCudaTotalVariationDenoisingBPDQImageFilter.cxx + rtkCudaWarpBackProjectionImageFilter.cxx + rtkCudaWarpForwardProjectionImageFilter.cxx + rtkCudaWarpImageFilter.cxx) + + set(RTK_SRCS ${RTK_SRCS} rtkCudaAverageOutOfROIImageFilter.cu rtkCudaBackProjectionImageFilter.cu rtkCudaConjugateGradientImageFilter.cu @@ -99,37 +124,6 @@ if (RTK_USE_CUDA) rtkCudaWarpImageFilter.cu rtkCudaWeidingerForwardModelImageFilter.cu ) - - set(CUDA_PROPAGATE_HOST_FLAGS ON) - set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)#WARNING: mandatory for defining runtime type \MT vs \MD - CUDA_COMPILE(RTK_CUDA_WRAPPERS ${RTK_CUDA_FILES}) - - set(RTK_SRCS ${RTK_SRCS} - rtkCudaAverageOutOfROIImageFilter.cxx - rtkCudaConstantVolumeSeriesSource.cxx - rtkCudaConstantVolumeSource.cxx - rtkCudaCropImageFilter.cxx - rtkCudaCyclicDeformationImageFilter.cxx - rtkCudaDisplacedDetectorImageFilter.cxx - rtkCudaFDKBackProjectionImageFilter.cxx - rtkCudaFDKConeBeamReconstructionFilter.cxx - rtkCudaFDKWeightProjectionFilter.cxx - rtkCudaForwardWarpImageFilter.cxx - rtkCudaInterpolateImageFilter.cxx - rtkCudaIterativeFDKConeBeamReconstructionFilter.cxx - rtkCudaLagCorrectionImageFilter.cxx - rtkCudaLaplacianImageFilter.cxx - rtkCudaLastDimensionTVDenoisingImageFilter.cxx - rtkCudaParkerShortScanImageFilter.cxx - rtkCudaPolynomialGainCorrectionImageFilter.cxx - rtkCudaRayCastBackProjectionImageFilter.cxx - rtkCudaSplatImageFilter.cxx - rtkCudaTotalVariationDenoisingBPDQImageFilter.cxx - rtkCudaWarpBackProjectionImageFilter.cxx - rtkCudaWarpForwardProjectionImageFilter.cxx - rtkCudaWarpImageFilter.cxx - ${RTK_CUDA_WRAPPERS} - ${RTK_CUDA_FILES}) endif() #========================================================= @@ -137,6 +131,8 @@ itk_module_add_library(RTK ${RTK_SRCS}) target_link_libraries(RTK LINK_PUBLIC lpsolve55) if (RTK_USE_CUDA) - target_link_libraries( RTK LINK_PUBLIC ITKCudaCommon ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} ${CUDA_cufft_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ) + target_link_libraries(RTK LINK_PUBLIC CUDA::cuda_driver) + target_link_libraries(RTK LINK_PUBLIC CUDA::cufft) + target_link_libraries(RTK LINK_PUBLIC CUDA::cublas) set_property(TARGET RTK PROPERTY CUDA_STANDARD ${CMAKE_CXX_STANDARD}) endif () diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e5dc6e3ac..760e2dae9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,7 +28,7 @@ endfunction() # rtk_add_cuda_test(testname testfile [DATA{}]) # Add test depending on CUDA function(rtk_add_cuda_test testname testfile) - if(RTK_USE_CUDA AND CUDA_HAVE_GPU) + if(RTK_USE_CUDA) add_executable(${testname} ${testfile}) target_link_libraries( ${testname} ${RTK_LIBRARIES} ${ITK_LIBRARIES}) itk_add_test(NAME ${testname} diff --git a/utilities/ITKCudaCommon/CMakeLists.txt b/utilities/ITKCudaCommon/CMakeLists.txt index 45a8a75bb..dcfdbc55b 100644 --- a/utilities/ITKCudaCommon/CMakeLists.txt +++ b/utilities/ITKCudaCommon/CMakeLists.txt @@ -2,15 +2,14 @@ project(ITKCudaCommon) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake) -find_package(CUDA REQUIRED) -if(NOT ${CUDA_FOUND}) - message(FATAL "Could not find CUDA") -endif() +enable_language(CUDA) +find_package(CUDAToolkit REQUIRED) +include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) +set(CMAKE_CUDA_RUNTIME_LIBRARY Static) set(ITKCudaCommon_LIBRARIES ITKCudaCommon) set(ITKCudaCommon_SYSTEM_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS}) set(ITKCudaCommon_SYSTEM_LIBRARY_DIRS ${CUDA_LIBRARIES}) - set(ITKCudaCommon_INCLUDE_DIRS ${ITKCudaCommon_SYSTEM_INCLUDE_DIRS} ${ITKCudaCommon_SOURCE_DIR}/include PARENT_SCOPE) diff --git a/utilities/ITKCudaCommon/src/CMakeLists.txt b/utilities/ITKCudaCommon/src/CMakeLists.txt index 97cc1a86a..efaa35963 100644 --- a/utilities/ITKCudaCommon/src/CMakeLists.txt +++ b/utilities/ITKCudaCommon/src/CMakeLists.txt @@ -5,16 +5,10 @@ set(ITKCudaCommon_SRC itkCudaMemoryProbe.cxx ) -include_directories(${CUDA_INCLUDE_DIRS}) include_directories(${ITKCudaCommon_SOURCE_DIR}/include) include_directories(${ITK_INCLUDE_DIRS}) add_library(ITKCudaCommon ${ITK_LIBRARY_BUILD_TYPE} ${ITKCudaCommon_SRC}) -target_link_libraries(ITKCudaCommon LINK_PUBLIC ${ITKCommon_LIBRARIES} ${CUDA_CUDA_LIBRARY} ${CUDA_LIBRARIES}) - -# if(ITK_SOURCE_DIR) -# itk_module_link_dependencies() -# itk_module_target(ITKCudaCommon) -# endif() +target_link_libraries(ITKCudaCommon LINK_PUBLIC ${ITKCommon_LIBRARIES} CUDA::cudart CUDA::cuda_driver) if(NOT RTK_INSTALL_NO_LIBRARIES) target_include_directories(ITKCudaCommon PUBLIC $)