From 555013cdda270f2387b22909f6fd57456e7cbbec Mon Sep 17 00:00:00 2001 From: Vicente Adolfo Bolea Sanchez Date: Wed, 10 Nov 2021 15:03:11 -0500 Subject: [PATCH 1/2] CMAKE: add unity builds support --- CMake/VTKmWrappers.cmake | 16 ++++++++++++++-- CMakeLists.txt | 8 ++++++++ docs/changelog/EnableUnityBuild.md | 12 ++++++++++++ vtkm/filter/CMakeLists.txt | 8 ++++---- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 docs/changelog/EnableUnityBuild.md diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index ac4872197..ebb5e780a 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -464,6 +464,16 @@ function(vtkm_library) set(VTKm_LIB_type SHARED) endif() + # Skip unity builds unless explicitly asked + foreach(source IN LISTS VTKm_LIB_SOURCES VTKm_LIB_DEVICE_SOURCES) + get_source_file_property(is_candidate ${source} UNITY_BUILD_CANDIDATE) + if (NOT is_candidate) + list(APPEND non_unity_sources ${source}) + endif() + endforeach() + + set_source_files_properties(${non_unity_sources} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) + add_library(${lib_name} ${VTKm_LIB_type} ${VTKm_LIB_SOURCES} @@ -615,8 +625,10 @@ function(vtkm_add_instantiations instantiations_list) math(EXPR counter "${counter} + 1") endforeach(instantiation) - set_source_files_properties(${_instantiations_list} - PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON + # Force unity builds here + set_source_files_properties(${_instantiations_list} PROPERTIES + SKIP_UNITY_BUILD_INCLUSION OFF + UNITY_BUILD_CANDIDATE ON ) set(${instantiations_list} ${_instantiations_list} PARENT_SCOPE) endfunction(vtkm_add_instantiations) diff --git a/CMakeLists.txt b/CMakeLists.txt index d039b8e09..99b3efe32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,14 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(VTKm_CMAKE_MODULE_PATH ${VTKm_SOURCE_DIR}/CMake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH}) +# While disabled system-wide, VTK-m uses UNITY builds in some modules +set(CMAKE_UNITY_BUILD OFF) + +# By default effectively disable unity builds +if (NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE) + set(CMAKE_UNITY_BUILD_BATCH_SIZE 1) +endif() + # Determine VTK-m version include(Utilities/Git/Git.cmake) include(VTKmDetermineVersion) diff --git a/docs/changelog/EnableUnityBuild.md b/docs/changelog/EnableUnityBuild.md new file mode 100644 index 000000000..4f8adbfbb --- /dev/null +++ b/docs/changelog/EnableUnityBuild.md @@ -0,0 +1,12 @@ +## Enable Unity build ## + +VTK-m now partially supports unity builds in a subset its sources files which +are known to take the longer time/memory to build. Particularly, this enables +you to speedup compilation in VTK-m not memory intensive builds (HIP, CUDA) in a +system with sufficient resources. + +We use `BATCH` unity builds type and the number of source files per batch can be +controlled by the canonical _CMake_ variable: `CMAKE_UNITY_BUILD_BATCH_SIZE`. + +Unity builds requires _CMake_ >= 3.16, if using a older version, unity build +will be disabled a regular build will be performed. diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index a46fdffbe..fc9829d56 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -234,8 +234,6 @@ set(gradient_sources_device vtkm_pyexpander_generated_file(ClipWithFieldExternInstantiations.h) vtkm_pyexpander_generated_file(ClipWithImplicitFunctionExternInstantiations.h) -set_source_files_properties(Contour.cxx ExtractStructured.cxx PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) - add_library(vtkm_filter INTERFACE) vtkm_library( @@ -270,12 +268,14 @@ vtkm_library( USE_VTKM_JOB_POOL ) -set_property(TARGET +set_target_properties( vtkm_filter_common vtkm_filter_extra vtkm_filter_contour vtkm_filter_gradient - PROPERTY UNITY_BUILD_MODE GROUP + PROPERTIES + UNITY_BUILD ON + UNITY_BUILD_MODE BATCH ) target_link_libraries(vtkm_filter_common PUBLIC vtkm_worklet) From b680269811da1b24840aa588e9508e037354dc4e Mon Sep 17 00:00:00 2001 From: Vicente Adolfo Bolea Sanchez Date: Fri, 19 Nov 2021 15:57:21 -0500 Subject: [PATCH 2/2] CI: use latest master GBench --- .gitlab/ci/config/google_benchmarks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab/ci/config/google_benchmarks.sh b/.gitlab/ci/config/google_benchmarks.sh index 3cd69cde8..9866ed4c7 100755 --- a/.gitlab/ci/config/google_benchmarks.sh +++ b/.gitlab/ci/config/google_benchmarks.sh @@ -2,10 +2,10 @@ set -xe -readonly version="v1.5.2" +readonly version="91ed7eea6856f8785139c58fbcc827e82579243c" readonly tarball="$version.tar.gz" readonly url="https://github.com/google/benchmark/archive/$tarball" -readonly sha256sum="dccbdab796baa1043f04982147e67bb6e118fe610da2c65f88912d73987e700c" +readonly sha256sum="039054b7919b0af1082b121df35f4c24fccdd97f308e3dc28f36a0d3a3c64c69" readonly install_dir="$HOME/gbench" if ! [[ "$VTKM_SETTINGS" =~ "benchmarks" ]]; then