Skip to content

Commit

Permalink
rapids_cpm_nvbench properly specify usage of external fmt library (#376)
Browse files Browse the repository at this point in the history
When we are inside a conda env the linker will be set to ld.bfd which will try to resolve all undefined symbols at link time.

Since we could be using a shared library version of fmt we need it on the final link line of consumers. So patch nvbench to understand this requirement.

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #376
  • Loading branch information
robertmaynard authored Feb 27, 2023
1 parent 08a851f commit 7db9ade
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies:
cuda: "11.4"
packages:
- cudatoolkit=11.4
- gcc<11.0.0
- matrix:
cuda: "11.5"
packages:
Expand Down
31 changes: 31 additions & 0 deletions rapids-cmake/cpm/patches/nvbench/public_fmt_dep_in_conda.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/nvbench/CMakeLists.txt b/nvbench/CMakeLists.txt
index f86bd41..ba6418f 100644
--- a/nvbench/CMakeLists.txt
+++ b/nvbench/CMakeLists.txt
@@ -76,10 +76,25 @@ target_link_libraries(nvbench
PUBLIC
${ctk_libraries}
PRIVATE
- fmt::fmt
nvbench_json
nvbench_git_revision
)
+
+# ##################################################################################################
+# * conda environment -----------------------------------------------------------------------------
+rapids_cmake_support_conda_env(conda_env MODIFY_PREFIX_PATH)
+if(TARGET conda_env)
+ # When we are inside a conda env the linker will be set to
+ # `ld.bfd` which will try to resolve all undefined symbols at link time.
+ #
+ # Since we could be using a shared library version of fmt we need
+ # it on the final link line of consumers
+ target_link_libraries(nvbench PRIVATE $<BUILD_INTERFACE:conda_env>
+ PUBLIC fmt::fmt)
+else()
+ target_link_libraries(nvbench PRIVATE fmt::fmt)
+endif()
+
target_compile_features(nvbench PUBLIC cuda_std_17 PRIVATE cxx_std_17)
add_dependencies(nvbench.all nvbench)

5 changes: 5 additions & 0 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"file" : "nvbench/use_existing_fmt.diff",
"issue" : "Fix add support for using an existing fmt [https://github.com/NVIDIA/nvbench/pull/125]",
"fixed_in" : ""
},
{
"file" : "nvbench/public_fmt_dep_in_conda.diff",
"issue" : "Propagate fmt requirement in conda envs [https://github.com/NVIDIA/nvbench/pull/127]",
"fixed_in" : ""
}
]
},
Expand Down
1 change: 1 addition & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ add_cmake_config_test( cpm_libcudacxx-simple.cmake )
add_cmake_config_test( cpm_nvbench-export.cmake )
add_cmake_config_test( cpm_nvbench-simple.cmake )
add_cmake_config_test( cpm_nvbench-already-found-fmt.cmake )
add_cmake_build_test( cpm_nvbench-conda-fmt.cmake )

add_cmake_config_test( cpm_nvcomp-export.cmake )
add_cmake_config_test( cpm_nvcomp-proprietary-off.cmake )
Expand Down
55 changes: 55 additions & 0 deletions testing/cpm/cpm_nvbench-conda-fmt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#=============================================================================
# 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/rmm.cmake)
include(${rapids-cmake-dir}/cpm/nvbench.cmake)

enable_language(CUDA)
enable_language(CXX)

include(${rapids-cmake-dir}/cuda/set_architectures.cmake)
rapids_cuda_set_architectures(RAPIDS)

# Force shared libs so that nvbench doesn't have a chance to use a static fmt
set(BUILD_SHARED_LIBS ON)
set(NVBench_ENABLE_CUPTI OFF)
rapids_cpm_init()
rapids_cpm_rmm()
rapids_cpm_nvbench()

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/use_fmt.cpp" [=[
#include <spdlog/spdlog.h>
#include <nvbench/nvbench.cuh>

template <typename Type>
void nvbench_distinct(nvbench::state& state, nvbench::type_list<Type>)
{
}

using data_type = nvbench::type_list<bool, int8_t, int32_t, int64_t, float>;

NVBENCH_BENCH_TYPES(nvbench_distinct, NVBENCH_TYPE_AXES(data_type))
.set_name("distinct")
.set_type_axes_names({"Type"})
.add_int64_axis("NumRows", {10'000, 100'000, 1'000'000, 10'000'000});

int main() { return 0; }
]=])


add_library(uses_fmt SHARED "${CMAKE_CURRENT_BINARY_DIR}/use_fmt.cpp")
target_link_libraries(uses_fmt PRIVATE rmm::rmm nvbench::nvbench)
target_compile_features(uses_fmt PRIVATE cxx_std_17)

0 comments on commit 7db9ade

Please sign in to comment.