Merge topic 'update_to_support_CMAKE_CUDA_ARCHITECTURES'
96fc02ebc VTK-m when using CMake 3.18 can propagate cuda flags cleanly Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2149
This commit is contained in:
commit
14333ded1b
@ -105,6 +105,14 @@ if(VTKm_ENABLE_CUDA AND VTKM_FROM_INSTALL_DIR)
|
|||||||
set_target_properties(vtkm::cuda PROPERTIES requires_static_builds TRUE)
|
set_target_properties(vtkm::cuda PROPERTIES requires_static_builds TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(VTKm_ENABLE_CUDA)
|
||||||
|
# If VTK-m is built with 3.18+ and the consumer is < 3.18 we need to drop
|
||||||
|
# these properties as they break the VTK-m cuda flag logic
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.18)
|
||||||
|
set_target_properties(vtkm::cuda PROPERTIES INTERFACE_LINK_OPTIONS "")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# VTKm requires some CMake Find modules not included with CMake, so
|
# VTKm requires some CMake Find modules not included with CMake, so
|
||||||
# include the CMake modules distributed with VTKm.
|
# include the CMake modules distributed with VTKm.
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH})
|
||||||
|
@ -127,10 +127,7 @@ if(VTKm_ENABLE_CUDA)
|
|||||||
requires_static_builds TRUE
|
requires_static_builds TRUE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_compile_options(vtkm_cuda INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr>)
|
||||||
set_target_properties(vtkm_cuda PROPERTIES
|
|
||||||
INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr>
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND
|
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND
|
||||||
CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
|
CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
|
||||||
@ -247,13 +244,24 @@ if(VTKm_ENABLE_CUDA)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
string(REPLACE ";" " " arch_flags "${arch_flags}")
|
string(REPLACE ";" " " arch_flags "${arch_flags}")
|
||||||
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
|
||||||
|
#We propagate cuda flags via target* options so that they
|
||||||
|
#export cleanly
|
||||||
|
set(CMAKE_CUDA_ARCHITECTURES OFF)
|
||||||
|
target_compile_options(vtkm_cuda INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:${arch_flags}>)
|
||||||
|
target_link_options(vtkm_cuda INTERFACE $<DEVICE_LINK:${arch_flags}>)
|
||||||
|
else()
|
||||||
|
# Before 3.18 we had to use CMAKE_CUDA_FLAGS as we had no way
|
||||||
|
# to propagate flags to the device link step
|
||||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${arch_flags}")
|
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${arch_flags}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# This needs to be lower-case for the property to be properly exported
|
# This needs to be lower-case for the property to be properly exported
|
||||||
# CMake 3.15 we can add `cuda_architecture_flags` to the EXPORT_PROPERTIES
|
# CMake 3.15 we can add `cuda_architecture_flags` to the EXPORT_PROPERTIES
|
||||||
# target property to have this automatically exported for us
|
# target property to have this automatically exported for us
|
||||||
set_target_properties(vtkm_cuda PROPERTIES cuda_architecture_flags "${arch_flags}")
|
|
||||||
set(VTKm_CUDA_Architecture_Flags "${arch_flags}")
|
set(VTKm_CUDA_Architecture_Flags "${arch_flags}")
|
||||||
|
set_target_properties(vtkm_cuda PROPERTIES cuda_architecture_flags "${arch_flags}")
|
||||||
|
unset(arch_flags)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -150,9 +150,14 @@ endfunction()
|
|||||||
# Pass to consumers extra compile flags they need to add to CMAKE_CUDA_FLAGS
|
# Pass to consumers extra compile flags they need to add to CMAKE_CUDA_FLAGS
|
||||||
# to have CUDA compatibility.
|
# to have CUDA compatibility.
|
||||||
#
|
#
|
||||||
# This is required as currently the -sm/-gencode flags when specified inside
|
# If VTK-m was built with CMake 3.18+ and you are using CMake 3.18+ and have
|
||||||
# COMPILE_OPTIONS / target_compile_options are not propagated to the device
|
# a cmake_minimum_required of 3.18 or have set policy CMP0105 to new, this will
|
||||||
# linker. Instead they must be specified in CMAKE_CUDA_FLAGS
|
# return an empty string as the `vtkm::cuda` target will correctly propagate
|
||||||
|
# all the necessary flags.
|
||||||
|
#
|
||||||
|
# This is required for CMake < 3.18 as they don't support the `$<DEVICE_LINK>`
|
||||||
|
# generator expression for `target_link_options`. Instead they need to be
|
||||||
|
# specified in CMAKE_CUDA_FLAGS
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# add_library(lib_that_uses_vtkm ...)
|
# add_library(lib_that_uses_vtkm ...)
|
||||||
@ -160,7 +165,18 @@ endfunction()
|
|||||||
# target_link_libraries(lib_that_uses_vtkm PRIVATE vtkm_filter)
|
# target_link_libraries(lib_that_uses_vtkm PRIVATE vtkm_filter)
|
||||||
#
|
#
|
||||||
function(vtkm_get_cuda_flags settings_var)
|
function(vtkm_get_cuda_flags settings_var)
|
||||||
|
|
||||||
if(TARGET vtkm::cuda)
|
if(TARGET vtkm::cuda)
|
||||||
|
if(POLICY CMP0105)
|
||||||
|
cmake_policy(GET CMP0105 does_device_link)
|
||||||
|
get_property(arch_flags
|
||||||
|
TARGET vtkm::cuda
|
||||||
|
PROPERTY INTERFACE_LINK_OPTIONS)
|
||||||
|
if(arch_flags AND CMP0105 STREQUAL "NEW")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
get_property(arch_flags
|
get_property(arch_flags
|
||||||
TARGET vtkm::cuda
|
TARGET vtkm::cuda
|
||||||
PROPERTY cuda_architecture_flags)
|
PROPERTY cuda_architecture_flags)
|
||||||
@ -236,8 +252,14 @@ endfunction()
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
# MODIFY_CUDA_FLAGS: If enabled will add the required -arch=<ver> flags
|
# MODIFY_CUDA_FLAGS: If enabled will add the required -arch=<ver> flags
|
||||||
# that VTK-m was compiled with. If you have multiple libraries that use
|
# that VTK-m was compiled with.
|
||||||
# VTK-m calling `vtkm_add_target_information` multiple times with
|
#
|
||||||
|
# If VTK-m was built with CMake 3.18+ and you are using CMake 3.18+ and have
|
||||||
|
# a cmake_minimum_required of 3.18 or have set policy CMP0105 to new, this will
|
||||||
|
# return an empty string as the `vtkm::cuda` target will correctly propagate
|
||||||
|
# all the necessary flags.
|
||||||
|
#
|
||||||
|
# Note: calling `vtkm_add_target_information` multiple times with
|
||||||
# `MODIFY_CUDA_FLAGS` will cause duplicate compiler flags. To resolve this issue
|
# `MODIFY_CUDA_FLAGS` will cause duplicate compiler flags. To resolve this issue
|
||||||
# you can; pass all targets and sources to a single `vtkm_add_target_information`
|
# you can; pass all targets and sources to a single `vtkm_add_target_information`
|
||||||
# call, have the first one use `MODIFY_CUDA_FLAGS`, or use the provided
|
# call, have the first one use `MODIFY_CUDA_FLAGS`, or use the provided
|
||||||
@ -279,10 +301,11 @@ function(vtkm_add_target_information uses_vtkm_target)
|
|||||||
${ARGN}
|
${ARGN}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if(VTKm_TI_MODIFY_CUDA_FLAGS)
|
if(VTKm_TI_MODIFY_CUDA_FLAGS)
|
||||||
vtkm_get_cuda_flags(CMAKE_CUDA_FLAGS)
|
vtkm_get_cuda_flags(cuda_flags)
|
||||||
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} PARENT_SCOPE)
|
if(cuda_flags)
|
||||||
|
set(CMAKE_CUDA_FLAGS ${cuda_flags} PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(targets ${uses_vtkm_target})
|
set(targets ${uses_vtkm_target})
|
||||||
@ -295,6 +318,8 @@ function(vtkm_add_target_information uses_vtkm_target)
|
|||||||
# set the required target properties
|
# set the required target properties
|
||||||
set_target_properties(${targets} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
set_target_properties(${targets} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
set_target_properties(${targets} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
set_target_properties(${targets} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
||||||
|
# CUDA_ARCHITECTURES added in CMake 3.18
|
||||||
|
set_target_properties(${targets} PROPERTIES CUDA_ARCHITECTURES OFF)
|
||||||
|
|
||||||
if(VTKm_TI_DROP_UNUSED_SYMBOLS)
|
if(VTKm_TI_DROP_UNUSED_SYMBOLS)
|
||||||
foreach(target IN LISTS targets)
|
foreach(target IN LISTS targets)
|
||||||
|
@ -8,16 +8,10 @@
|
|||||||
## PURPOSE. See the above copyright notice for more information.
|
## PURPOSE. See the above copyright notice for more information.
|
||||||
##============================================================================
|
##============================================================================
|
||||||
|
|
||||||
# If you want CUDA support, you will need to have CMake 3.9 on Linux/OSX.
|
# If you want CUDA support, you will need to have CMake 3.13 on Linux/OSX.
|
||||||
# We require CMake 3.11 with the MSVC generator as the $<COMPILE_LANGUAGE:>
|
|
||||||
# generator expression is not supported on older versions.
|
|
||||||
cmake_minimum_required(VERSION 3.12...3.15 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.12...3.15 FATAL_ERROR)
|
||||||
project (VTKm)
|
project (VTKm)
|
||||||
|
|
||||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
|
||||||
cmake_minimum_required(VERSION 3.12...3.15 FATAL_ERROR)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Update module path
|
# Update module path
|
||||||
set(VTKm_CMAKE_MODULE_PATH ${VTKm_SOURCE_DIR}/CMake)
|
set(VTKm_CMAKE_MODULE_PATH ${VTKm_SOURCE_DIR}/CMake)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH})
|
||||||
|
Loading…
Reference in New Issue
Block a user