Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to allow spdlog to be compiled. #1232

Closed

Conversation

cjnolet
Copy link
Member

@cjnolet cjnolet commented Mar 15, 2023

This change allows the spdlog cmake target to be configurable so the user can choose whether it should be spdlog_header_only or just spdlog to use the compiled library. Some investigation of RAFT's long compile times showed that we can get a speedup from using spdlog's compiled library instead of header-only. We're going to pass this option through RAFT's build as well but would like @robertmaynard's thoughts on whether this is a reasonable approach given RMM is used across RAPIDS.

@cjnolet cjnolet requested a review from a team as a code owner March 15, 2023 21:54
@github-actions github-actions bot added the CMake label Mar 15, 2023
@cjnolet
Copy link
Member Author

cjnolet commented Mar 15, 2023

@robertmaynard it's unclear to me whether

  1. we should just turn off the header-only by default, and
  2. whether this will be able to work for an RMM which has already been installed (and may have RMM_SPDLOG_COMPILED=OFF already set)

Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this affect install? Need any changes for that?

Interested to know the impact of setting this when compiling all RAPIDS libraries.

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@harrism
Copy link
Member

harrism commented Mar 16, 2023

Please add a description with motivation for this change.

@robertmaynard
Copy link
Contributor

@robertmaynard it's unclear to me whether

  1. we should just turn off the header-only by default, and
  2. whether this will be able to work for an RMM which has already been installed (and may have RMM_SPDLOG_COMPILED=OFF already set)

This approach won't work when a consumer of rmm gets it via conda or other means where rmm is built ahead of time.
What we need to do is move this logic into the string that is used with rapids_export( FINAL_CODE_BLOCK) so that this logic is executed by consumers.

@cjnolet
Copy link
Member Author

cjnolet commented Mar 23, 2023

@robertmaynard what would an example of the string that we'd use in FINAL_CODE_BLOCK look like? Are you saying we'd set the RMM_SPDLOG_COMPILED variable in the FINAL_CODE_BLOCK?

@harrism
Copy link
Member

harrism commented Mar 28, 2023

Would like @robertmaynard to approve before merging.

@cjnolet
Copy link
Member Author

cjnolet commented Mar 29, 2023

Would like @robertmaynard to approve before merging.

@harrism, yeah I think the problem with my current change is that the default is going to apply to all the rapids projects, so unless someone manually builds and installs it locally, they won't be able to change the value. Ideally, the consuming libraries would be able to have different settings for this (so, for example, RAFT users could prefer to use the pre-built binary while cudf might still use header-only). At least I think that's what @robertmaynard's previous response is addressing.

I've looked at the docs for the FINAL_CODE_BLOCK but I'm still unclear as to how to use it. I'm waiting on guidance there.

@robertmaynard
Copy link
Contributor

robertmaynard commented Mar 29, 2023

To defer the selection of the spdlog to consumers we would want the following changes:

commit 0bc2a771eb5b009638dd2927166bb4bc52d68b03 (HEAD -> imp-2304-allow_spdlog_compiled)
Author: Robert Maynard <rmaynard@nvidia.com>
Date:   Wed Mar 29 09:37:36 2023 -0400

    Allow consuming project to specify what spdlog to use

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d8670576..4fbe8d6f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,8 +39,6 @@ rapids_cmake_build_type(Release)
 # build options
 option(BUILD_TESTS "Configure CMake to build tests" ON)
 option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF)
-option(RMM_HEADER_ONLY_SPDLOG "Use spdlog header-only library. Compiled version is used otherwise"
-       ON)
 set(RMM_LOGGING_LEVEL
     "INFO"
     CACHE STRING "Choose the logging level.")
@@ -82,9 +80,6 @@ endif()
 message(STATUS "RMM: Using header-only SPDLOG: ${RMM_HEADER_ONLY_SPDLOG}")
 
 target_link_libraries(rmm INTERFACE rmm::Thrust)
-target_link_libraries(rmm INTERFACE fmt::fmt-header-only)
-target_link_libraries(rmm INTERFACE $<$<BOOL:NOT ${RMM_HEADER_ONLY_SPDLOG}>:spdlog::spdlog>)
-target_link_libraries(rmm INTERFACE $<$<BOOL:${RMM_HEADER_ONLY_SPDLOG}>:spdlog::spdlog_header_only>)
 target_link_libraries(rmm INTERFACE dl)
 target_compile_features(rmm INTERFACE cxx_std_17 $<BUILD_INTERFACE:cuda_std_17>)
 
@@ -142,6 +137,10 @@ set(code_string
 if(NOT TARGET rmm::Thrust)
   thrust_create_target(rmm::Thrust FROM_OPTIONS)
 endif()
+
+option(RMM_HEADER_ONLY_SPDLOG "Use spdlog header-only library. Compiled version is used otherwise" ON)
+mark_as_advanced(RMM_HEADER_ONLY_SPDLOG)
+target_link_libraries(rmm::rmm INTERFACE $<IF:$<BOOL:${RMM_HEADER_ONLY_SPDLOG}>,spdlog::spdlog_header_only,spdlog::spdlog>)
 ]=])
 
 rapids_export(
diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt
index 9dfb2c53..0d77211b 100644
--- a/benchmarks/CMakeLists.txt
+++ b/benchmarks/CMakeLists.txt
@@ -34,7 +34,7 @@ function(ConfigureBench BENCH_NAME)
                RUNTIME_OUTPUT_DIRECTORY "$<BUILD_INTERFACE:${RMM_BINARY_DIR}/gbenchmarks>"
                CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}"
                INSTALL_RPATH "\$ORIGIN/../../../lib")
-  target_link_libraries(${BENCH_NAME} benchmark::benchmark pthread rmm)
+  target_link_libraries(${BENCH_NAME} benchmark::benchmark pthread rmm spdlog::spdlog)
   target_compile_definitions(${BENCH_NAME}
                              PUBLIC "SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL}")
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ecb44a49..4e2e559d 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -22,7 +22,7 @@ function(ConfigureTestInternal TEST_NAME)
   add_executable(${TEST_NAME} ${ARGN})
   target_include_directories(${TEST_NAME} PRIVATE "$<BUILD_INTERFACE:${RMM_SOURCE_DIR}>")
   target_link_libraries(${TEST_NAME} GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main
-                        pthread rmm)
+                        pthread rmm spdlog::spdlog)
   set_target_properties(
     ${TEST_NAME}
     PROPERTIES POSITION_INDEPENDENT_CODE ON

This will allow consumers to do:

# Need to specify RMM_HEADER_ONLY_SPDLOG before `find_package` so that the rmm targets get the correct
# spdlog dependency
set(RMM_HEADER_ONLY_SPDLOG OFF)
find_package(rmm REQUIRED)

I was also curious if rmm tests would benifit from using a pre-compiled spdlog, and in testing on full clean builds with zero cache hits I see using a pre-built spdlog saving me 16sec, so I added those changes to the diff

build times:

spdlog::spdlog__________________________________________
Executed in   44.47 secs    fish           external
   usr time  693.39 secs  362.00 micros  693.39 secs
   sys time   33.57 secs   15.00 micros   33.57 secs


spdlog::spdlog_headeronly_______________________________
Executed in   60.92 secs    fish           external
   usr time   21.10 mins  286.00 micros   21.10 mins
   sys time    0.76 mins   17.00 micros    0.76 mins

@github-actions github-actions bot added the cpp Pertains to C++ code label Mar 29, 2023
@bdice
Copy link
Contributor

bdice commented Mar 29, 2023

Can this retarget 23.06? I would like to avoid merging changes to spdlog just before rmm’s code freeze.

@harrism
Copy link
Member

harrism commented Mar 29, 2023

Agree. Moving to 23.06 in the project board.

@cjnolet
Copy link
Member Author

cjnolet commented Mar 29, 2023

@bdice I'm certainly not against it

@bdice bdice changed the base branch from branch-23.04 to branch-23.06 April 19, 2023 18:33
rapids-bot bot pushed a commit that referenced this pull request Apr 20, 2023
Related to issue #1222 and also PR #1232. Compared to #1232, this PR might make it able to also have fast builds without precompiling spdlog. 

I include a table below showing which headers transitively include `rmm/logger.hpp` before and after PR (in debug and release builds). These are the rmm headers used by RAFT.

| Header                                              | Before         | After          |
|-----------------------------------------------------|----------------|----------------|
| rmm/cuda_device.hpp                                 | debug  release |                |
| rmm/cuda_stream.hpp                                 | debug  release | debug          |
| rmm/cuda_stream_pool.hpp                            | debug  release | debug          |
| rmm/cuda_stream_view.hpp                            | debug  release |                |
| rmm/device_buffer.hpp                               | debug  release |                |
| rmm/device_scalar.hpp                               | debug  release |                |
| rmm/device_uvector.hpp                              | debug  release |                |
| rmm/device_vector.hpp                               | debug  release |                |
| rmm/exec_policy.hpp                                 | debug  release |                |
| rmm/logger.hpp                                      | debug  release | debug  release |
| rmm/mr/device/aligned_resource_adaptor.hpp          | debug  release |                |
| rmm/mr/device/arena_memory_resource.hpp             | debug  release | debug  release |
| rmm/mr/device/binning_memory_resource.hpp           | debug  release | debug  release |
| rmm/mr/device/callback_memory_resource.hpp          | debug  release |                |
| rmm/mr/device/cuda_async_memory_resource.hpp        | debug  release |                |
| rmm/mr/device/cuda_async_view_memory_resource.hpp   | debug  release |                |
| rmm/mr/device/cuda_memory_resource.hpp              | debug  release |                |
| rmm/mr/device/device_memory_resource.hpp            | debug  release |                |
| rmm/mr/device/failure_callback_resource_adaptor.hpp | debug  release |                |
| rmm/mr/device/fixed_size_memory_resource.hpp        | debug  release | debug  release |
| rmm/mr/device/limiting_resource_adaptor.hpp         | debug  release |                |
| rmm/mr/device/logging_resource_adaptor.hpp          | debug  release | debug  release |
| rmm/mr/device/managed_memory_resource.hpp           | debug  release |                |
| rmm/mr/device/owning_wrapper.hpp                    | debug  release |                |
| rmm/mr/device/per_device_resource.hpp               | debug  release |                |
| rmm/mr/device/polymorphic_allocator.hpp             | debug  release |                |
| rmm/mr/device/pool_memory_resource.hpp              | debug  release | debug  release |
| rmm/mr/device/statistics_resource_adaptor.hpp       | debug  release |                |
| rmm/mr/device/thread_safe_resource_adaptor.hpp      | debug  release |                |
| rmm/mr/device/thrust_allocator_adaptor.hpp          | debug  release |                |
| rmm/mr/device/tracking_resource_adaptor.hpp         | debug  release | debug  release |
| rmm/mr/host/host_memory_resource.hpp                |                |                |
| rmm/mr/host/new_delete_resource.hpp                 |                |                |
| rmm/mr/host/pinned_memory_resource.hpp              | debug  release |                |

Authors:
  - Allard Hendriksen (https://github.com/ahendriksen)
  - Vyas Ramasubramani (https://github.com/vyasr)

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

URL: #1241
@cjnolet cjnolet closed this May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake cpp Pertains to C++ code
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants