Merge topic 'refactor_vtkm_buildsystem_to_provide_better_consumer_experience'

28484fc6a Update examples and benchmarks to use new VTK-m CMake helper function
ea50e82aa Move VTK-m CMake testing wrappers to the testing folder
0b7dd7c38 Add CMake vtkm_add_target_information() to make using vtk-m easier
e934e2273 vtkm_library WRAP_FOR_CUDA renamed to clarify the intent of the property
a2e6660fd Remove unused vtkm_compile_as_cuda CMake function

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Matt Larsen <larsen30@llnl.gov>
Merge-request: !1718
This commit is contained in:
Robert Maynard 2019-07-16 12:45:48 +00:00 committed by Kitware Robot
commit c80c1d09c0
27 changed files with 433 additions and 371 deletions

@ -14,6 +14,10 @@ include(VTKmDeviceAdapters)
include(VTKmCPUVectorization)
include(VTKmMPI)
#-----------------------------------------------------------------------------
# INTERNAL FUNCTIONS
# No promises when used from outside VTK-m
#-----------------------------------------------------------------------------
# Utility to build a kit name from the current directory.
function(vtkm_get_kit_name kitvar)
@ -50,43 +54,6 @@ function(vtkm_pyexpander_generated_file generated_file_name)
endif()
endfunction(vtkm_pyexpander_generated_file)
#-----------------------------------------------------------------------------
# This function is not needed by the core infrastructure of VTK-m
# as we now require CMake 3.11 on windows, and for tests we compile a single
# executable for all backends, instead of compiling for each backend.
# It is currently kept around so that examples which haven't been updated
# continue to work
function(vtkm_compile_as_cuda output)
# We can't use set_source_files_properties(<> PROPERTIES LANGUAGE "CUDA")
# for the following reasons:
#
# 1. As of CMake 3.10 MSBuild cuda language support has a bug where files
# aren't passed to nvcc with the explicit '-x cu' flag which will cause
# them to be compiled without CUDA actually enabled.
# 2. If the source file is used by multiple targets(libraries/executable)
# they will all see the source file marked as being CUDA. This will cause
# tests / examples that reuse sources with different backends to use CUDA
# by mistake
#
# The result of this is that instead we will use file(GENERATE ) to construct
# a proxy cu file
set(_cuda_srcs )
foreach(_to_be_cuda_file ${ARGN})
get_filename_component(_fname_ext "${_to_be_cuda_file}" EXT)
if(_fname_ext STREQUAL ".cu")
list(APPEND _cuda_srcs "${_to_be_cuda_file}")
else()
get_filename_component(_cuda_fname "${_to_be_cuda_file}" NAME_WE)
get_filename_component(_not_cuda_fullpath "${_to_be_cuda_file}" ABSOLUTE)
list(APPEND _cuda_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_cuda_fname}.cu")
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_cuda_fname}.cu
CONTENT "#include \"${_not_cuda_fullpath}\"")
endif()
endforeach()
set(${output} ${_cuda_srcs} PARENT_SCOPE)
endfunction()
#-----------------------------------------------------------------------------
function(vtkm_generate_export_header lib_name)
# Get the location of this library in the directory structure
@ -124,7 +91,6 @@ function(vtkm_generate_export_header lib_name)
DESTINATION ${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}
)
endif()
endfunction(vtkm_generate_export_header)
#-----------------------------------------------------------------------------
@ -144,22 +110,147 @@ function(vtkm_declare_headers)
vtkm_install_headers("${dir_prefix}" ${ARGN})
endfunction(vtkm_declare_headers)
#-----------------------------------------------------------------------------
# FORWARD FACING API
#-----------------------------------------------------------------------------
# Pass to consumers extra compile flags they need to add to CMAKE_CUDA_FLAGS
# to have CUDA compatibility.
#
# This is required as currently the -sm/-gencode flags when specified inside
# COMPILE_OPTIONS / target_compile_options are not propagated to the device
# linker. Instead they must be specified in CMAKE_CUDA_FLAGS
#
#
# add_library(lib_that_uses_vtkm ...)
# vtkm_add_cuda_flags(CMAKE_CUDA_FLAGS)
# target_link_libraries(lib_that_uses_vtkm PRIVATE vtkm_filter)
#
function(vtkm_get_cuda_flags settings_var)
if(TARGET vtkm::cuda)
get_property(arch_flags
TARGET vtkm::cuda
PROPERTY INTERFACE_CUDA_Architecture_Flags)
set(${settings_var} "${${settings_var}} ${arch_flags}" PARENT_SCOPE)
endif()
endfunction()
#-----------------------------------------------------------------------------
# Add a relevant information to target that wants to use VTK-m.
#
# This is a higher order function to allow build-systems that use VTK-m
# to compose add_library/add_executable and the required information to have
# VTK-m enabled.
#
# vtkm_add_target_information(
# target
# [ MODIFY_CUDA_FLAGS ]
# [ EXTENDS_VTKM ]
# [ DEVICE_SOURCES <source_list>
# )
#
# Usage:
# add_library(lib_that_uses_vtkm STATIC a.cxx)
# vtkm_add_target_information(lib_that_uses_vtkm
# MODIFY_CUDA_FLAGS
# DEVICE_SOURCES a.cxx
# )
# target_link_libraries(lib_that_uses_vtkm PRIVATE vtkm_filter)
#
# MODIFY_CUDA_FLAGS: If enabled will add the required -arch=<ver> flags
# that VTK-m was compiled with. This functionality is also provided by the
# the standalone `vtkm_get_cuda_flags` function.
#
# DEVICE_SOURCES: The collection of source files that are used by `target` that
# need to be marked as going to a special compiler for certain device adapters
# such as CUDA.
#
# EXTENDS_VTKM: Some programming models have restrictions on how types can be extended.
# For example CUDA doesn't allow device side calls across dynamic library boundaries,
# and requires all polymorphic classes to be reachable at dynamic library/executable
# link time.
#
# To accommodate these restrictions we need to handle the following allowable
# use-cases:
# Object library: do nothing, zero restrictions
# Executable: do nothing, zero restrictions
# Static library: do nothing, zero restrictions
# Dynamic library:
# -> Wanting to extend VTK-m and provide these types to consumers. This
# is supported when CUDA isn't enabled. Otherwise we need to ERROR!
# -> Wanting to use VTK-m as implementation detail, doesn't expose VTK-m
# types to consumers. This is supported no matter if CUDA is enabled.
#
# For most consumers they can ignore the `EXTENDS_VTKM` property as the default
# will be correct.
#
#
function(vtkm_add_target_information uses_vtkm_target)
set(options MODIFY_CUDA_FLAGS EXTENDS_VTKM)
set(multiValueArgs DEVICE_SOURCES)
cmake_parse_arguments(VTKm_TI
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
# Validate that following:
# - We are building with CUDA enabled.
# - We are building a VTK-m library or a library that wants cross library
# device calls.
#
# This is required as CUDA currently doesn't support device side calls across
# dynamic library boundaries.
if(TARGET vtkm::cuda)
get_target_property(lib_type ${uses_vtkm_target} TYPE)
get_target_property(requires_static vtkm::cuda INTERFACE_REQUIRES_STATIC_BUILDS)
if(requires_static AND ${lib_type} STREQUAL "SHARED_LIBRARY")
#We provide different error messages based on if we are building VTK-m
#or being called by a consumer of VTK-m. We use PROJECT_NAME so that we
#produce the correct error message when VTK-m is a subdirectory include
#of another project
if(PROJECT_NAME STREQUAL "VTKm")
message(SEND_ERROR "${uses_vtkm_target} needs to be built STATIC as CUDA doesn't"
" support virtual methods across dynamic library boundaries. You"
" need to set the CMake option BUILD_SHARED_LIBS to `OFF`.")
else()
message(SEND_ERROR "${uses_vtkm_target} needs to be built STATIC as CUDA doesn't"
" support virtual methods across dynamic library boundaries. You"
" should either explicitly call add_library with the `STATIC` keyword"
" or set the CMake option BUILD_SHARED_LIBS to `OFF`.")
endif()
endif()
set_source_files_properties(${VTKm_TI_DEVICE_SOURCES} PROPERTIES LANGUAGE "CUDA")
endif()
set_target_properties(${uses_vtkm_target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(${uses_vtkm_target} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
if(VTKm_TI_MODIFY_CUDA_FLAGS)
vtkm_get_cuda_flags(CMAKE_CUDA_FLAGS)
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} PARENT_SCOPE)
endif()
endfunction()
#-----------------------------------------------------------------------------
# Add a VTK-m library. The name of the library will match the "kit" name
# (e.g. vtkm_rendering) unless the NAME argument is given.
#
# vtkm_library(
# [NAME <name>]
# [ NAME <name> ]
# [ OBJECT | STATIC | SHARED ]
# SOURCES <source_list>
# TEMPLATE_SOURCES <.hxx >
# HEADERS <header list>
# [WRAP_FOR_CUDA <source_list>]
# [ DEVICE_SOURCES <source_list> ]
# )
function(vtkm_library)
set(options OBJECT STATIC SHARED)
set(oneValueArgs NAME)
set(multiValueArgs SOURCES HEADERS TEMPLATE_SOURCES WRAP_FOR_CUDA)
set(multiValueArgs SOURCES HEADERS TEMPLATE_SOURCES DEVICE_SOURCES)
cmake_parse_arguments(VTKm_LIB
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
@ -183,45 +274,20 @@ function(vtkm_library)
${VTKm_LIB_SOURCES}
${VTKm_LIB_HEADERS}
${VTKm_LIB_TEMPLATE_SOURCES}
${VTKm_LIB_WRAP_FOR_CUDA}
${VTKm_LIB_DEVICE_SOURCES}
)
# Validate that following:
# - We are building with CUDA enabled.
# - We are building a VTK-m library or a library that wants cross library
# device calls.
#
# This is required as CUDA currently doesn't support device side calls across
# dynamic library boundaries.
if(TARGET vtkm::cuda)
get_target_property(lib_type ${lib_name} TYPE)
get_target_property(requires_static vtkm::cuda INTERFACE_REQUIRES_STATIC_BUILDS)
if(requires_static AND ${lib_type} STREQUAL "SHARED_LIBRARY")
message(FATAL_ERROR "${lib_name} Needs to be built STATIC as CUDA doesn't"
" support virtual methods across dynamic library boundaries. You"
" need to set the CMake option BUILD_SHARED_LIBS to OFF.")
endif()
# We are a validate target type for CUDA compilation, so mark all the requested
# sources to be compiled by CUDA
set_source_files_properties(${VTKm_LIB_WRAP_FOR_CUDA} PROPERTIES LANGUAGE "CUDA")
vtkm_add_target_information(${lib_name}
DEVICE_SOURCES ${VTKm_LIB_DEVICE_SOURCES}
)
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
set_property(TARGET ${lib_name} PROPERTY CUDA_VISIBILITY_PRESET "hidden")
set_property(TARGET ${lib_name} PROPERTY CXX_VISIBILITY_PRESET "hidden")
endif()
#when building either static or shared we want pic code
set_target_properties(${lib_name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
#specify when building with cuda we want separable compilation
set_property(TARGET ${lib_name} PROPERTY CUDA_SEPARABLE_COMPILATION ON)
#specify where to place the built library
set_property(TARGET ${lib_name} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
set_property(TARGET ${lib_name} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
set_property(TARGET ${lib_name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH})
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
set_property(TARGET ${lib_name} PROPERTY CUDA_VISIBILITY_PRESET "hidden")
set_property(TARGET ${lib_name} PROPERTY CXX_VISIBILITY_PRESET "hidden")
endif()
# allow the static cuda runtime find the driver (libcuda.dyllib) at runtime.
if(APPLE)
@ -268,209 +334,3 @@ function(vtkm_library)
)
endfunction(vtkm_library)
#-----------------------------------------------------------------------------
# Declare unit tests, which should be in the same directory as a kit
# (package, module, whatever you call it). Usage:
#
# vtkm_unit_tests(
# NAME
# SOURCES <source_list>
# BACKEND <type>
# LIBRARIES <dependent_library_list>
# DEFINES <target_compile_definitions>
# TEST_ARGS <argument_list>
# MPI
# ALL_BACKENDS
# <options>
# )
#
# [BACKEND]: mark all source files as being compiled with the proper defines
# to make this backend the default backend
# If the backend is specified as CUDA it will also imply all
# sources should be treated as CUDA sources
# The backend name will also be added to the executable name
# so you can test multiple backends easily
#
# [LIBRARIES] : extra libraries that this set of tests need to link too
#
# [DEFINES] : extra defines that need to be set for all unit test sources
#
# [TEST_ARGS] : arguments that should be passed on the command line to the
# test executable
#
# [MPI] : when specified, the tests should be run in parallel if
# MPI is enabled.
# [ALL_BACKENDS] : when specified, the tests would test against all enabled
# backends. BACKEND argument would be ignored.
#
function(vtkm_unit_tests)
if (NOT VTKm_ENABLE_TESTING)
return()
endif()
set(options)
set(global_options ${options} MPI ALL_BACKENDS)
set(oneValueArgs BACKEND NAME)
set(multiValueArgs SOURCES LIBRARIES DEFINES TEST_ARGS)
cmake_parse_arguments(VTKm_UT
"${global_options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
vtkm_parse_test_options(VTKm_UT_SOURCES "${options}" ${VTKm_UT_SOURCES})
set(test_prog)
set(backend ${VTKm_UT_BACKEND})
set(enable_all_backends ${VTKm_UT_ALL_BACKENDS})
set(all_backends Serial)
if (VTKm_ENABLE_CUDA)
list(APPEND all_backends Cuda)
endif()
if (VTKm_ENABLE_TBB)
list(APPEND all_backends TBB)
endif()
if (VTKm_ENABLE_OPENMP)
list(APPEND all_backends OpenMP)
endif()
if(VTKm_UT_NAME)
set(test_prog "${VTKm_UT_NAME}")
else()
vtkm_get_kit_name(kit)
set(test_prog "UnitTests_${kit}")
endif()
if(backend)
set(test_prog "${test_prog}_${backend}")
set(all_backends ${backend})
elseif(NOT enable_all_backends)
set (all_backends "NO_BACKEND")
endif()
if(VTKm_UT_MPI)
# for MPI tests, suffix test name and add MPI_Init/MPI_Finalize calls.
set(test_prog "${test_prog}_mpi")
set(extraArgs EXTRA_INCLUDE "vtkm/cont/testing/Testing.h"
FUNCTION "vtkm::cont::testing::Environment env")
else()
set(extraArgs)
endif()
#the creation of the test source list needs to occur before the labeling as
#cuda. This is so that we get the correctly named entry points generated
create_test_sourcelist(test_sources ${test_prog}.cxx ${VTKm_UT_SOURCES} ${extraArgs})
#if all backends are enabled, we can use cuda compiler to handle all possible backends.
if(TARGET vtkm::cuda AND (backend STREQUAL "Cuda" OR enable_all_backends))
set_source_files_properties(${VTKm_UT_SOURCES} PROPERTIES LANGUAGE "CUDA")
endif()
add_executable(${test_prog} ${test_prog}.cxx ${VTKm_UT_SOURCES})
set_property(TARGET ${test_prog} PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_property(TARGET ${test_prog} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
set_property(TARGET ${test_prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
set_property(TARGET ${test_prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH})
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
set_property(TARGET ${test_prog} PROPERTY CUDA_VISIBILITY_PRESET "hidden")
set_property(TARGET ${test_prog} PROPERTY CXX_VISIBILITY_PRESET "hidden")
endif()
#Starting in CMake 3.13, cmake will properly drop duplicate libraries
#from the link line so this workaround can be dropped
if (CMAKE_VERSION VERSION_LESS 3.13 AND "vtkm_rendering" IN_LIST VTKm_UT_LIBRARIES)
list(REMOVE_ITEM VTKm_UT_LIBRARIES "vtkm_cont")
target_link_libraries(${test_prog} PRIVATE ${VTKm_UT_LIBRARIES})
else()
target_link_libraries(${test_prog} PRIVATE vtkm_cont ${VTKm_UT_LIBRARIES})
endif()
target_compile_definitions(${test_prog} PRIVATE ${VTKm_UT_DEFINES})
foreach(current_backend ${all_backends})
set (device_command_line_argument --device=${current_backend})
if (current_backend STREQUAL "NO_BACKEND")
set (current_backend "")
set(device_command_line_argument "")
endif()
string(TOUPPER "${current_backend}" upper_backend)
foreach (test ${VTKm_UT_SOURCES})
get_filename_component(tname ${test} NAME_WE)
if(VTKm_UT_MPI AND VTKm_ENABLE_MPI)
add_test(NAME ${tname}${upper_backend}
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS}
$<TARGET_FILE:${test_prog}> ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
${MPIEXEC_POSTFLAGS}
)
else()
add_test(NAME ${tname}${upper_backend}
COMMAND ${test_prog} ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
)
endif()
#determine the timeout for all the tests based on the backend. CUDA tests
#generally require more time because of kernel generation.
if (current_backend STREQUAL "Cuda")
set(timeout 1500)
else()
set(timeout 180)
endif()
if(current_backend STREQUAL "OpenMP")
#We need to have all OpenMP tests run serially as they
#will uses all the system cores, and we will cause a N*N thread
#explosion which causes the tests to run slower than when run
#serially
set(run_serial True)
else()
set(run_serial False)
endif()
set_tests_properties("${tname}${upper_backend}" PROPERTIES
TIMEOUT ${timeout}
RUN_SERIAL ${run_serial}
)
set_tests_properties("${tname}${upper_backend}" PROPERTIES
FAIL_REGULAR_EXPRESSION "runtime error"
)
endforeach (test)
endforeach(current_backend)
endfunction(vtkm_unit_tests)
# -----------------------------------------------------------------------------
# vtkm_parse_test_options(varname options)
# INTERNAL: Parse options specified for individual tests.
#
# Parses the arguments to separate out options specified after the test name
# separated by a comma e.g.
#
# TestName,Option1,Option2
#
# For every option in options, this will set _TestName_Option1,
# _TestName_Option2, etc in the parent scope.
#
function(vtkm_parse_test_options varname options)
set(names)
foreach(arg IN LISTS ARGN)
set(test_name ${arg})
set(test_options)
if(test_name AND "x${test_name}" MATCHES "^x([^,]*),(.*)$")
set(test_name "${CMAKE_MATCH_1}")
string(REPLACE "," ";" test_options "${CMAKE_MATCH_2}")
endif()
foreach(opt IN LISTS test_options)
list(FIND options "${opt}" index)
if(index EQUAL -1)
message(WARNING "Unknown option '${opt}' specified for test '${test_name}'")
else()
set(_${test_name}_${opt} TRUE PARENT_SCOPE)
endif()
endforeach()
list(APPEND names ${test_name})
endforeach()
set(${varname} ${names} PARENT_SCOPE)
endfunction()

@ -0,0 +1,210 @@
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
##
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##============================================================================
include(VTKmWrappers)
#-----------------------------------------------------------------------------
# Declare unit tests, which should be in the same directory as a kit
# (package, module, whatever you call it). Usage:
#
# vtkm_unit_tests(
# NAME
# SOURCES <source_list>
# LIBRARIES <dependent_library_list>
# DEFINES <target_compile_definitions>
# TEST_ARGS <argument_list>
# MPI
# ALL_BACKENDS
# <options>
# )
#
# [LIBRARIES] : extra libraries that this set of tests need to link too
#
# [DEFINES] : extra defines that need to be set for all unit test sources
#
# [TEST_ARGS] : arguments that should be passed on the command line to the
# test executable
#
# [MPI] : when specified, the tests should be run in parallel if
# MPI is enabled.
# [ALL_BACKENDS] : when specified, the tests would test against all enabled
# backends. Otherwise we expect the tests to manage the
# backends at runtime.
#
function(vtkm_unit_tests)
if (NOT VTKm_ENABLE_TESTING)
return()
endif()
set(options)
set(global_options ${options} MPI ALL_BACKENDS)
set(oneValueArgs BACKEND NAME)
set(multiValueArgs SOURCES LIBRARIES DEFINES TEST_ARGS)
cmake_parse_arguments(VTKm_UT
"${global_options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
vtkm_parse_test_options(VTKm_UT_SOURCES "${options}" ${VTKm_UT_SOURCES})
set(test_prog)
set(per_device_command_line_arguments "")
set(per_device_suffix "")
set(per_device_timeout 180)
set(per_device_serial FALSE)
set(enable_all_backends ${VTKm_UT_ALL_BACKENDS})
if(enable_all_backends)
set(per_device_command_line_arguments --device=serial)
set(per_device_suffix "SERIAL")
if (VTKm_ENABLE_CUDA)
list(APPEND per_device_command_line_arguments --device=cuda)
list(APPEND per_device_suffix "CUDA")
#CUDA tests generally require more time because of kernel generation.
list(APPEND per_device_timeout 1500)
list(APPEND per_device_serial FALSE)
endif()
if (VTKm_ENABLE_TBB)
list(APPEND per_device_command_line_arguments --device=tbb)
list(APPEND per_device_suffix "TBB")
list(APPEND per_device_timeout 180)
list(APPEND per_device_serial FALSE)
endif()
if (VTKm_ENABLE_OPENMP)
list(APPEND per_device_command_line_arguments --device=openmp)
list(APPEND per_device_suffix "OPENMP")
list(APPEND per_device_timeout 180)
#We need to have all OpenMP tests run serially as they
#will uses all the system cores, and we will cause a N*N thread
#explosion which causes the tests to run slower than when run
#serially
list(APPEND per_device_serial TRUE)
endif()
endif()
if(VTKm_UT_NAME)
set(test_prog "${VTKm_UT_NAME}")
else()
vtkm_get_kit_name(kit)
set(test_prog "UnitTests_${kit}")
endif()
if(VTKm_UT_MPI)
# for MPI tests, suffix test name and add MPI_Init/MPI_Finalize calls.
set(test_prog "${test_prog}_mpi")
set(extraArgs EXTRA_INCLUDE "vtkm/cont/testing/Testing.h"
FUNCTION "vtkm::cont::testing::Environment env")
else()
set(extraArgs)
endif()
#the creation of the test source list needs to occur before the labeling as
#cuda. This is so that we get the correctly named entry points generated
create_test_sourcelist(test_sources ${test_prog}.cxx ${VTKm_UT_SOURCES} ${extraArgs})
add_executable(${test_prog} ${test_prog}.cxx ${VTKm_UT_SOURCES})
target_compile_definitions(${test_prog} PRIVATE ${VTKm_UT_DEFINES})
#if all backends are enabled, we can use cuda compiler to handle all possible backends.
set(device_sources )
if(TARGET vtkm::cuda AND enable_all_backends)
set(device_sources ${VTKm_UT_SOURCES})
endif()
vtkm_add_target_information(${test_prog} DEVICE_SOURCES ${device_sources})
if(NOT VTKm_USE_DEFAULT_SYMBOL_VISIBILITY)
set_property(TARGET ${test_prog} PROPERTY CUDA_VISIBILITY_PRESET "hidden")
set_property(TARGET ${test_prog} PROPERTY CXX_VISIBILITY_PRESET "hidden")
endif()
set_property(TARGET ${test_prog} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
set_property(TARGET ${test_prog} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${VTKm_LIBRARY_OUTPUT_PATH})
set_property(TARGET ${test_prog} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH})
#Starting in CMake 3.13, cmake will properly drop duplicate libraries
#from the link line so this workaround can be dropped
if (CMAKE_VERSION VERSION_LESS 3.13 AND "vtkm_rendering" IN_LIST VTKm_UT_LIBRARIES)
list(REMOVE_ITEM VTKm_UT_LIBRARIES "vtkm_cont")
target_link_libraries(${test_prog} PRIVATE ${VTKm_UT_LIBRARIES})
else()
target_link_libraries(${test_prog} PRIVATE vtkm_cont ${VTKm_UT_LIBRARIES})
endif()
foreach(index RANGE per_device_command_line_arguments)
if(per_device_command_line_arguments STREQUAL "")
set(device_command_line_argument ${per_device_command_line_arguments})
set(upper_backend ${per_device_suffix})
set(timeout ${per_device_timeout})
set(run_serial ${per_device_serial})
else()
list(GET per_device_command_line_arguments ${index} device_command_line_argument)
list(GET per_device_suffix ${index} upper_backend)
list(GET per_device_timeout ${index} timeout)
list(GET per_device_serial ${index} run_serial)
endif()
foreach (test ${VTKm_UT_SOURCES})
get_filename_component(tname ${test} NAME_WE)
if(VTKm_UT_MPI AND VTKm_ENABLE_MPI)
add_test(NAME ${tname}${upper_backend}
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS}
$<TARGET_FILE:${test_prog}> ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
${MPIEXEC_POSTFLAGS}
)
else()
add_test(NAME ${tname}${upper_backend}
COMMAND ${test_prog} ${tname} ${device_command_line_argument} ${VTKm_UT_TEST_ARGS}
)
endif()
set_tests_properties("${tname}${upper_backend}" PROPERTIES
TIMEOUT ${timeout}
RUN_SERIAL ${run_serial}
FAIL_REGULAR_EXPRESSION "runtime error"
)
endforeach()
endforeach()
endfunction(vtkm_unit_tests)
# -----------------------------------------------------------------------------
# vtkm_parse_test_options(varname options)
# INTERNAL: Parse options specified for individual tests.
#
# Parses the arguments to separate out options specified after the test name
# separated by a comma e.g.
#
# TestName,Option1,Option2
#
# For every option in options, this will set _TestName_Option1,
# _TestName_Option2, etc in the parent scope.
#
function(vtkm_parse_test_options varname options)
set(names)
foreach(arg IN LISTS ARGN)
set(test_name ${arg})
set(test_options)
if(test_name AND "x${test_name}" MATCHES "^x([^,]*),(.*)$")
set(test_name "${CMAKE_MATCH_1}")
string(REPLACE "," ";" test_options "${CMAKE_MATCH_2}")
endif()
foreach(opt IN LISTS test_options)
list(FIND options "${opt}" index)
if(index EQUAL -1)
message(WARNING "Unknown option '${opt}' specified for test '${test_name}'")
else()
set(_${test_name}_${opt} TRUE PARENT_SCOPE)
endif()
endforeach()
list(APPEND names ${test_name})
endforeach()
set(${varname} ${names} PARENT_SCOPE)
endfunction()

@ -143,6 +143,9 @@ include(VTKmCompilerFlags)
#-----------------------------------------------------------------------------
# We include the wrappers unconditionally as VTK-m expects the function to
# always exist (and early terminate when testing is disabled).
include(testing/VTKmTestWrappers)
if (VTKm_ENABLE_TESTING)
enable_testing()
# Only include CTest if it has not been included by a superproject. The
@ -155,6 +158,7 @@ if (VTKm_ENABLE_TESTING)
mark_as_advanced(BUILD_TESTING)
endif()
configure_file(${VTKm_SOURCE_DIR}/CTestCustom.cmake.in
${VTKm_BINARY_DIR}/CTestCustom.cmake @ONLY)
@ -187,7 +191,7 @@ add_subdirectory(vtkm)
#-----------------------------------------------------------------------------
# Build documentation
if (VTKm_ENABLE_DOCUMENTATION)
include(CMake/VTKmBuildDocumentation.cmake)
include(VTKmBuildDocumentation)
endif()
#-----------------------------------------------------------------------------

@ -22,16 +22,10 @@ function(add_benchmark)
set_target_properties(${exe_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH}
CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden"
CUDA_SEPARABLE_COMPILATION ON
)
set_property(TARGET ${exe_name} PROPERTY "hidden")
if (TARGET vtkm::cuda)
set_source_files_properties(${VTKm_AB_FILE} PROPERTIES LANGUAGE "CUDA")
set_target_properties(${exe_name} PROPERTIES
CUDA_VISIBILITY_PRESET "hidden"
CUDA_SEPARABLE_COMPILATION ON
)
endif()
vtkm_add_target_information(${exe_name} DEVICE_SOURCES ${VTKm_AB_FILE})
endfunction()
set(benchmarks
@ -45,7 +39,7 @@ set(benchmarks
)
foreach (benchmark ${benchmarks})
add_benchmark(NAME ${benchmark} FILE ${benchmark}.cxx LIBS vtkm_filter vtkm_cont)
add_benchmark(NAME ${benchmark} FILE ${benchmark}.cxx LIBS vtkm_filter)
endforeach ()
if(TARGET vtkm_rendering)

@ -16,6 +16,6 @@ find_package(VTKm REQUIRED QUIET)
add_executable(Clipping Clipping.cxx)
target_link_libraries(Clipping PRIVATE vtkm_filter)
if(TARGET vtkm::cuda)
set_source_files_properties(Clipping.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(Clipping
MODIFY_CUDA_FLAGS
DEVICE_SOURCES Clipping.cxx)

@ -16,9 +16,12 @@ find_package(VTKm REQUIRED QUIET)
add_executable(ContourTreeMesh2D ContourTreeMesh2D.cxx)
target_link_libraries(ContourTreeMesh2D vtkm_filter)
vtkm_add_target_information(ContourTreeMesh2D
DEVICE_SOURCES ContourTreeMesh2D.cxx)
add_executable(ContourTreeMesh3D ContourTreeMesh3D.cxx)
target_link_libraries(ContourTreeMesh3D vtkm_filter)
if(TARGET vtkm::cuda)
set_source_files_properties(ContourTreeMesh2D.cxx ContourTreeMesh3D.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(ContourTreeMesh3D
MODIFY_CUDA_FLAGS
DEVICE_SOURCES ContourTreeMesh3D.cxx)

@ -56,7 +56,9 @@ find_package(VTKm REQUIRED QUIET)
add_executable(ContourTree ContourTreeApp.cxx)
target_link_libraries(ContourTree vtkm_filter)
vtkm_add_target_information(ContourTree
MODIFY_CUDA_FLAGS
DEVICE_SOURCES ContourTreeApp.cxx)
####################################
# Debug algorithm build
@ -67,7 +69,3 @@ if(TARGET vtkm::tbb)
# TBB 2D/3D/MC
target_compile_definitions(ContourTree PRIVATE ENABLE_SET_NUM_THREADS)
endif()
if(TARGET vtkm::cuda)
set_source_files_properties(ContourTreeApp.cxx PROPERTIES LANGUAGE "CUDA")
endif()

@ -18,6 +18,9 @@ add_executable(CosmoHaloFinder CosmoHaloFinder.cxx)
target_link_libraries(CosmoCenterFinder PRIVATE vtkm_filter)
target_link_libraries(CosmoHaloFinder PRIVATE vtkm_filter)
if(TARGET vtkm::cuda)
set_source_files_properties(CosmoCenterFinder.cxx CosmoCenterFinder.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(CosmoCenterFinder
MODIFY_CUDA_FLAGS
DEVICE_SOURCES CosmoCenterFinder.cxx)
vtkm_add_target_information(CosmoHaloFinder
MODIFY_CUDA_FLAGS
DEVICE_SOURCES CosmoHaloFinder.cxx)

@ -13,15 +13,10 @@ project(VTKmDemo CXX)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET)
set(srcs Demo.cxx)
if(TARGET vtkm_rendering)
if(TARGET vtkm::cuda)
vtkm_compile_as_cuda(cuda_srcs ${srcs})
set(srcs ${cuda_srcs})
endif()
add_executable(Demo ${srcs})
add_executable(Demo Demo.cxx)
target_link_libraries(Demo PRIVATE vtkm_rendering)
vtkm_add_target_information(Demo
MODIFY_CUDA_FLAGS
DEVICE_SOURCES Demo.cxx)
endif()

@ -19,8 +19,8 @@ if(TARGET OpenGL::GL AND
TARGET GLEW::GLEW)
add_executable(GameOfLife GameOfLife.cxx LoadShaders.h)
if(TARGET vtkm::cuda)
set_source_files_properties(GameOfLife.cxx PROPERTIES LANGUAGE "CUDA")
endif()
target_link_libraries(GameOfLife PRIVATE vtkm_filter OpenGL::GL GLEW::GLEW GLUT::GLUT)
vtkm_add_target_information(GameOfLife
MODIFY_CUDA_FLAGS
DEVICE_SOURCES GameOfLife.cxx)
endif()

@ -21,9 +21,9 @@ if(TARGET OpenGL::GL AND
set(gl_libs OpenGL::GL GLEW::GLEW GLUT::GLUT)
add_executable(HelloWorld HelloWorld.cxx LoadShaders.h)
if(TARGET vtkm::cuda)
set_source_files_properties(HelloWorld.cxx PROPERTIES LANGUAGE "CUDA")
endif()
target_link_libraries(HelloWorld PRIVATE vtkm_filter ${gl_libs})
vtkm_add_target_information(HelloWorld
MODIFY_CUDA_FLAGS
DEVICE_SOURCES HelloWorld.cxx)
endif()

@ -15,8 +15,7 @@ find_package(VTKm REQUIRED QUIET)
if (VTKm_ENABLE_MPI)
add_executable(Histogram Histogram.cxx HistogramMPI.h HistogramMPI.hxx)
target_link_libraries(Histogram PRIVATE vtkm_filter)
if(TARGET vtkm::cuda)
set_source_files_properties(Histogram.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(Histogram
MODIFY_CUDA_FLAGS
DEVICE_SOURCES Histogram.cxx)
endif()

@ -21,9 +21,8 @@ if(TARGET OpenGL::GL AND
set(gl_libs OpenGL::GL OpenGL::GLU GLEW::GLEW GLUT::GLUT)
add_executable(IsosurfaceUniformGrid IsosurfaceUniformGrid.cxx quaternion.h)
target_link_libraries(IsosurfaceUniformGrid PRIVATE vtkm_filter ${gl_libs})
if(TARGET vtkm::cuda)
set_source_files_properties(IsosurfaceUniformGrid.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(IsosurfaceUniformGrid
MODIFY_CUDA_FLAGS
DEVICE_SOURCES IsosurfaceUniformGrid.cxx)
endif()

@ -12,9 +12,8 @@ cmake_minimum_required(VERSION 3.8...3.14 FATAL_ERROR)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET)
if(TARGET vtkm::cuda)
set_source_files_properties(lagrangian.cxx PROPERTIES LANGUAGE "CUDA")
endif()
add_executable(Lagrangian lagrangian.cxx ABCfield.h)
target_link_libraries(Lagrangian PRIVATE vtkm_filter)
vtkm_add_target_information(Lagrangian
MODIFY_CUDA_FLAGS
DEVICE_SOURCES Lagrangian.cxx)

@ -29,9 +29,8 @@ set(srcs
MultiBackend.cxx
)
if(TARGET vtkm::cuda)
set_source_files_properties(${device_srcs} PROPERTIES LANGUAGE "CUDA")
endif()
add_executable(MultiBackend ${device_srcs} ${srcs} ${headers})
target_link_libraries(MultiBackend PRIVATE vtkm_filter Threads::Threads)
vtkm_add_target_information(MultiBackend
MODIFY_CUDA_FLAGS
DEVICE_SOURCES ${device_srcs})

@ -13,9 +13,8 @@ project(Oscillator CXX)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET)
if (TARGET vtkm::cuda)
set_source_files_properties(Oscillator.cxx PROPERTIES LANGUAGE "CUDA")
endif()
add_executable(Oscillator Oscillator.cxx)
target_link_libraries(Oscillator PRIVATE vtkm_filter)
vtkm_add_target_information(Oscillator
MODIFY_CUDA_FLAGS
DEVICE_SOURCES Oscillator.cxx)

@ -15,11 +15,9 @@ find_package(VTKm REQUIRED QUIET)
add_executable(Particle_Advection ParticleAdvection.cxx)
target_link_libraries(Particle_Advection PRIVATE vtkm_filter)
vtkm_add_target_information(Particle_Advection
MODIFY_CUDA_FLAGS
DEVICE_SOURCES ParticleAdvection.cxx)
if(TARGET vtkm::tbb)
target_compile_definitions(Particle_Advection PRIVATE BUILDING_TBB_VERSION)
endif()
if(TARGET vtkm::cuda)
set_source_files_properties(ParticleAdvection.cxx PROPERTIES LANGUAGE "CUDA")
endif()

@ -14,7 +14,6 @@ project(RedistributePoints CXX)
find_package(VTKm REQUIRED QUIET)
add_executable(RedistributePoints RedistributePoints.cxx RedistributePoints.h)
target_link_libraries(RedistributePoints PRIVATE vtkm_filter)
if(TARGET vtkm::cuda)
set_source_files_properties(RedistributePoints.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(RedistributePoints
MODIFY_CUDA_FLAGS
DEVICE_SOURCES RedistributePoints.cxx)

@ -22,9 +22,7 @@ if(TARGET OpenGL::GL AND
add_executable(StreamLineUniformGrid StreamLineUniformGrid.cxx)
target_link_libraries(StreamLineUniformGrid PRIVATE vtkm_filter ${gl_libs})
if(TARGET vtkm::cuda)
set_source_files_properties(StreamLineUniformGrid.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(StreamLineUniformGrid
MODIFY_CUDA_FLAGS
DEVICE_SOURCES StreamLineUniformGrid.cxx)
endif()

@ -16,9 +16,8 @@ find_package(VTKm REQUIRED QUIET)
if(TARGET vtkm_rendering)
add_executable(Tau_timing TauTiming.cxx)
vtkm_add_target_information(Tau_timing
MODIFY_CUDA_FLAGS
DEVICE_SOURCES TauTiming.cxx)
target_link_libraries(Tau_timing vtkm_cont)
if(TARGET vtkm::cuda)
set_source_files_properties(TauTiming.cxx PROPERTIES LANGUAGE "CUDA")
endif()
endif()

@ -16,8 +16,7 @@ project(TemporalAdvection CXX)
find_package(VTKm REQUIRED QUIET)
add_executable(Temporal_Advection TemporalAdvection.cxx)
vtkm_add_target_information(Temporal_Advection
MODIFY_CUDA_FLAGS
DEVICE_SOURCES TemporalAdvection.cxx)
target_link_libraries(Temporal_Advection PRIVATE vtkm_filter)
if(TARGET vtkm::cuda)
set_source_files_properties(TemporalAdvection.cxx PROPERTIES LANGUAGE "CUDA")
endif()

@ -30,11 +30,17 @@ if(TARGET OpenGL::GL AND
target_link_libraries(TetrahedralizeUniformGrid PRIVATE vtkm_filter ${gl_libs})
target_link_libraries(TriangulateUniformGrid PRIVATE vtkm_filter ${gl_libs})
if(TARGET vtkm::cuda)
set_source_files_properties(TetrahedralizeExplicitGrid.cxx
TriangulateExplicitGrid.cxx
TetrahedralizeUniformGrid.cxx
TriangulateUniformGrid.cxx PROPERTIES LANGUAGE "CUDA")
endif()
vtkm_add_target_information(TetrahedralizeExplicitGrid
MODIFY_CUDA_FLAGS
DEVICE_SOURCES TetrahedralizeExplicitGrid.cxx)
vtkm_add_target_information(TriangulateExplicitGrid
MODIFY_CUDA_FLAGS
DEVICE_SOURCES TriangulateExplicitGrid.cxx)
vtkm_add_target_information(TetrahedralizeUniformGrid
MODIFY_CUDA_FLAGS
DEVICE_SOURCES TetrahedralizeUniformGrid.cxx)
vtkm_add_target_information(TriangulateUniformGrid
MODIFY_CUDA_FLAGS
DEVICE_SOURCES TriangulateUniformGrid.cxx)
endif()

@ -16,5 +16,6 @@ find_package(VTKm REQUIRED QUIET)
if(TARGET vtkm::cuda)
add_executable(UnifiedMemory_CUDA UnifiedMemory.cu)
target_link_libraries(UnifiedMemory_CUDA PRIVATE vtkm_filter)
vtkm_add_target_information(UnifiedMemory_CUDA MODIFY_CUDA_FLAGS)
endif()

@ -183,7 +183,7 @@ vtkm_library( NAME vtkm_cont
SOURCES ${sources}
TEMPLATE_SOURCES ${template_sources}
HEADERS ${headers}
WRAP_FOR_CUDA ${device_sources}
DEVICE_SOURCES ${device_sources}
)
add_subdirectory(internal)

@ -178,7 +178,7 @@ vtkm_library(
NAME vtkm_rendering
SOURCES ${sources}
HEADERS ${headers}
WRAP_FOR_CUDA ${device_sources}
DEVICE_SOURCES ${device_sources}
)
# Install all headers no matter what backend was selected

@ -45,4 +45,4 @@ set(unit_tests
UnitTestVecVariable.cxx
)
VTKM_unit_tests(SOURCES ${unit_tests})
vtkm_unit_tests(SOURCES ${unit_tests})

@ -132,7 +132,7 @@ vtkm_library(
SOURCES ${sources_no_device}
TEMPLATE_SOURCES ${header_impls}
HEADERS ${headers}
WRAP_FOR_CUDA ${sources_device}
DEVICE_SOURCES ${sources_device}
)
target_link_libraries(vtkm_worklet PUBLIC vtkm_cont)