Skip to content

Commit

Permalink
Support static builds of gbench and nvbench.
Browse files Browse the repository at this point in the history
Since we updated nvbench, we also support installing nvbench.
  • Loading branch information
robertmaynard committed Nov 2, 2023
1 parent f5462bc commit 36bc687
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 42 deletions.
9 changes: 6 additions & 3 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
},
"rapids_cpm_gbench": {
"pargs": {
"nargs": 0
"nargs": 0,
"flags": ["BUILD_STATIC"]
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
Expand All @@ -135,10 +136,12 @@
},
"rapids_cpm_nvbench": {
"pargs": {
"nargs": 0
"nargs": 0,
"flags": ["BUILD_STATIC"]
},
"kwargs": {
"BUILD_EXPORT_SET": 1
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},
"rapids_cpm_nvcomp": {
Expand Down
14 changes: 13 additions & 1 deletion rapids-cmake/cpm/gbench.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ across all RAPIDS projects.

rapids_cpm_gbench( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[BUILD_STATIC]
[<CPM_ARGS> ...])

.. |PKG_NAME| replace:: benchmark
.. include:: common_package_args.txt

.. versionadded:: v23.12.00
``BUILD_STATIC``
Will build Google Benchmark statically. No local searching for a previously
built version will occur.

Result Targets
^^^^^^^^^^^^^^
benchmark::benchmark targets will be created
Expand All @@ -49,6 +55,12 @@ function(rapids_cpm_gbench)
set(to_install ON)
endif()

set(build_shared ON)
if(BUILD_STATIC IN_LIST ARGN)
set(build_shared OFF)
set(CPM_DOWNLOAD_benchmark ON) # Since we need static we build from source
endif()

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(benchmark version repository tag shallow exclude)

Expand All @@ -69,7 +81,7 @@ function(rapids_cpm_gbench)
EXCLUDE_FROM_ALL ${exclude}
OPTIONS "BENCHMARK_ENABLE_GTEST_TESTS OFF" "BENCHMARK_ENABLE_TESTING OFF"
"BENCHMARK_ENABLE_INSTALL ${to_install}"
"CMAKE_INSTALL_LIBDIR ${lib_dir}")
"CMAKE_INSTALL_LIBDIR ${lib_dir}" "BUILD_SHARED_LIBS ${build_shared}")

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(benchmark)
Expand Down
34 changes: 19 additions & 15 deletions rapids-cmake/cpm/nvbench.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,19 +30,17 @@ across all RAPIDS projects.
.. code-block:: cmake

rapids_cpm_nvbench( [BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[BUILD_STATIC]
[<CPM_ARGS> ...])

``BUILD_EXPORT_SET``
Record that a :cmake:command:`CPMFindPackage(nvbench)` call needs to occur as part of
our build directory export set.
.. |PKG_NAME| replace:: nvbench
.. include:: common_package_args.txt

``CPM_ARGS``
Any arguments after `CPM_ARGS` will be forwarded to the underlying :cmake:command:`CPMFindPackage(<PackageName> ...)` call

.. note::

RAPIDS-cmake will error out if an INSTALL_EXPORT_SET is provided, as nvbench
doesn't provide any support for installation.
.. versionadded:: v23.12.00
``BUILD_STATIC``
Will build nvbench statically. No local searching for a previously
built version will occur.

Result Targets
^^^^^^^^^^^^^^
Expand All @@ -61,10 +59,15 @@ Result Variables
function(rapids_cpm_nvbench)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.nvbench")

set(to_install FALSE)
set(to_install OFF)
if(INSTALL_EXPORT_SET IN_LIST ARGN)
message(FATAL_ERROR "nvbench doesn't provide install rules.
It can't be part of an INSTALL_EXPORT_SET")
set(to_install ON)
endif()

set(build_shared ON)
if(BUILD_STATIC IN_LIST ARGN)
set(build_shared OFF)
set(CPM_DOWNLOAD_nvbench ON) # Since we need static we build from source
endif()

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
Expand All @@ -90,7 +93,8 @@ function(rapids_cpm_nvbench)
PATCH_COMMAND ${patch_command}
EXCLUDE_FROM_ALL ${exclude}
OPTIONS "NVBench_ENABLE_NVML ${nvbench_with_nvml}" "NVBench_ENABLE_EXAMPLES OFF"
"NVBench_ENABLE_TESTING OFF")
"NVBench_ENABLE_TESTING OFF" "NVBench_ENABLE_INSTALL_RULES ${to_install}"
"BUILD_SHARED_LIBS ${build_shared}")

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(nvbench)
Expand Down
12 changes: 0 additions & 12 deletions rapids-cmake/cpm/patches/nvbench/use_existing_fmt.diff

This file was deleted.

9 changes: 1 addition & 8 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,7 @@
"version" : "0.0",
"git_shallow" : false,
"git_url" : "https://github.com/NVIDIA/nvbench.git",
"git_tag" : "083fdc2fc130d84805827c0129f84bb7449ec059",
"patches" : [
{
"file" : "nvbench/use_existing_fmt.diff",
"issue" : "Fix add support for using an existing fmt [https://github.com/NVIDIA/nvbench/pull/125]",
"fixed_in" : ""
}
]
"git_tag" : "b8f0f6b5832dd632006492fd2434c81fdef0f2de"
},
"nvcomp" : {
"version" : "2.6.1",
Expand Down
4 changes: 3 additions & 1 deletion testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ add_cmake_build_test( cpm_fmt-static-lib.cmake )

add_cmake_config_test( cpm_gbench-export.cmake )
add_cmake_config_test( cpm_gbench-simple.cmake )
add_cmake_config_test( cpm_gbench-explicit-static.cmake)

add_cmake_config_test( cpm_gtest-export.cmake )
add_cmake_config_test( cpm_gtest-simple.cmake )
Expand All @@ -63,11 +64,12 @@ add_cmake_config_test( cpm_libcudacxx-export.cmake )
add_cmake_config_test( cpm_libcudacxx-simple.cmake )
add_cmake_build_test( cpm_libcudacxx-verify-install-custom-libdir )

add_cmake_config_test( cpm_nvbench-export.cmake SERIAL )
add_cmake_config_test( cpm_nvbench-export.cmake SERIAL)
add_cmake_config_test( cpm_nvbench-simple.cmake SERIAL)
add_cmake_config_test( cpm_nvbench-already-found-fmt.cmake SERIAL)
add_cmake_build_test( cpm_nvbench-conda.cmake SERIAL)
add_cmake_build_test( cpm_nvbench-conda-fmt.cmake SERIAL)
add_cmake_config_test( cpm_nvbench-explicit-static.cmake SERIAL)

add_cmake_config_test( cpm_nvcomp-export.cmake )
add_cmake_config_test( cpm_nvcomp-proprietary-off.cmake )
Expand Down
25 changes: 25 additions & 0 deletions testing/cpm/cpm_gbench-explicit-static.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#=============================================================================
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/gbench.cmake)

rapids_cpm_init()
rapids_cpm_gbench(BUILD_STATIC)

get_target_property(type benchmark TYPE)
if(NOT type STREQUAL STATIC_LIBRARY)
message(FATAL_ERROR "rapids_cpm_gbench failed to get a static version of gbench")
endif()
25 changes: 25 additions & 0 deletions testing/cpm/cpm_nvbench-explicit-static.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#=============================================================================
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
include(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/nvbench.cmake)

rapids_cpm_init()
rapids_cpm_nvbench(BUILD_STATIC)

get_target_property(type nvbench TYPE)
if(NOT type STREQUAL STATIC_LIBRARY)
message(FATAL_ERROR "rapids_cpm_nvbench failed to get a static version of nvbench")
endif()
9 changes: 7 additions & 2 deletions testing/cpm/cpm_nvbench-export.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ include(${rapids-cmake-dir}/cpm/nvbench.cmake)
rapids_cpm_init()
set(CMAKE_CUDA_ARCHITECTURES OFF)
rapids_cpm_nvbench(BUILD_EXPORT_SET test)
rapids_cpm_nvbench(BUILD_EXPORT_SET test2)
rapids_cpm_nvbench(BUILD_EXPORT_SET test2 INSTALL_EXPORT_SET test2)

get_target_property(packages rapids_export_build_test PACKAGE_NAMES)
if(NOT nvbench IN_LIST packages)
Expand All @@ -30,3 +30,8 @@ get_target_property(packages rapids_export_build_test2 PACKAGE_NAMES)
if(NOT nvbench IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_nvbench failed to record nvbench needs to be exported")
endif()

get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES)
if(NOT nvbench IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_nvbench failed to record nvbench needs to be exported")
endif()

0 comments on commit 36bc687

Please sign in to comment.