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

Create logger wrapper around spdlog that can be easily reused in other libraries #1722

Merged
merged 122 commits into from
Nov 26, 2024

Conversation

vyasr
Copy link
Contributor

@vyasr vyasr commented Nov 6, 2024

Description

This PR defines a new way to produce a logger wrapping spdlog. The logger's interface is declared in a template header file that can be processed by CMake to produce an interface that may be customized for placement into any project. The new implementation uses the PImpl idiom to isolate the spdlog (and transitively, fmt) dependency from the public API of the logger. The implementation is defined in an impl header. A corresponding source template file is provided that simply includes this header. All of these files are wrapped in some CMake logic for producing a custom target for a given project.

rmm leverages this new logger by requesting the creation of a logger target and a corresponding implementation. This is a breaking change because consumers of rmm will need to link the new rmm_logger_impl target into their own libraries to get logging support. Once this gets merged, the plan is to move this implementation out of rmm into its own repository. At that point, the logger may also be used to completely replace logger implementations in cudf, raft, and cuml (as well as any other RAPIDS libraries that are aiming to provide their own logging implementation). Once everything in RAPIDS is migrated to using the new logger, we will update the way that it uses spdlog to completely hide all spdlog symbols, which solves a half dozen different problems for us when it comes to packaging (symbol collision issues, ABI compatibility, conda environment conflicts, bundling of headers into conda packages, etc).

Resolves #1709

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@vyasr vyasr requested review from a team as code owners November 6, 2024 22:05
@vyasr vyasr requested review from harrism and jrhemstad November 6, 2024 22:05
@github-actions github-actions bot added CMake Python Related to RMM Python API cpp Pertains to C++ code labels Nov 6, 2024
@vyasr vyasr self-assigned this Nov 6, 2024
@vyasr vyasr added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Nov 6, 2024
@vyasr vyasr marked this pull request as draft November 6, 2024 22:47
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.

Couple comments.

rapids_logger/logger.hpp.in Outdated Show resolved Hide resolved
rapids_logger/logger.hpp.in Outdated Show resolved Hide resolved
tests/CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
rapids_logger/CMakeLists.txt Outdated Show resolved Hide resolved
rapids_logger/CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@vyasr
Copy link
Contributor Author

vyasr commented Nov 7, 2024

I should note that a lot of the complexity here is from supporting the backwards compatibility modes. I wanted to get this ready now so that we could easily test all cases and flip the switch as needed, but if it becomes too cumbersome we could just wait for 25.02 and delete the compatibility paths before merging anything.

@vyasr
Copy link
Contributor Author

vyasr commented Nov 26, 2024

/merge

@rapids-bot rapids-bot bot merged commit 4cfa31f into rapidsai:branch-25.02 Nov 26, 2024
60 checks passed
@vyasr vyasr deleted the feat/logger branch November 26, 2024 20:45
rapids-bot bot pushed a commit that referenced this pull request Nov 26, 2024
It looks like while #1722 introduced usage of the modern target_link_libraries syntax it did not adjust all other calls because I wasn't setting up coverage usage locally or anywhere else in CI.

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

Approvers:
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)
  - Robert Maynard (https://github.com/robertmaynard)

URL: #1738
@vyasr vyasr mentioned this pull request Nov 27, 2024
3 tasks
rapids-bot bot pushed a commit that referenced this pull request Nov 27, 2024
This fixes a handful of issues uncovered in downstream CI after #1722.

The following are bugs introduced in #1722:
- When using rmm from the build directory rather than an installation, the namespaced targets are not present so we must generate aliases.
- The `RMM_LOGGING_ASSERT` macro is never used in rmm itself, so we didn't catch that it was still using the old version of the logger.

While fixing the above, I also uncovered that building fmt in this environment unearths a gcc bug.

The following are underlying issues uncovered by #1722:
- spdlog's fmt CMake linkage is determined at build time. As a result, the conda package for spdlog is hardcoded to use fmt as a library (static or shared depends on what the `fmt::fmt` target winds up being when a consumer using spdlog finds fmt in CMake), which means that is propagated to all consumers of the librmm package via its CMake. This means that we often wind up with both fmt_header_only and fmt as link targets for many RAPIDS libraries. For now, this PR makes it so that if `rapids_cpm_find(spdlog)` does not find a copy of spdlog locally, the cloned version will use an external header-only fmt via rapids-cmake's logic, which ensures that packages like wheels do not export a libfmt or libspdlog dependency. However, in environments where `rapids_cpm_find(spdlog)` does find a preexisting package, we allow that package's fmt linkage to propagate. In conda environments, we know that this fmt linkage is to the library, so we keep fmt as part of rmm's runtime dependencies (by placing it in host and relying on the run export) so that libfmt is always available in environments using rmm.

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

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #1739
rapids-bot bot pushed a commit to rapidsai/ucxx that referenced this pull request Nov 27, 2024
This PR adapts to breaking changes in rmm in rapidsai/rmm#1722.

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

Approvers:
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)

URL: #336
rapids-bot bot pushed a commit to rapidsai/cudf that referenced this pull request Nov 27, 2024
This PR adapts to breaking changes in rmm in rapidsai/rmm#1722.

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

Approvers:
  - Mark Harris (https://github.com/harrism)
  - Nghia Truong (https://github.com/ttnghia)

URL: #17451
if grep -E 'spdlog\:\:' < "${symbol_file}" \
| grep -v 'std\:\:_Destroy_aux'
then
if grep -E 'spdlog\:\:' < "${symbol_file}"; then
Copy link
Member

Choose a reason for hiding this comment

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

(reviewing after merge just to be sure I understand what's happening)

Love that hiding these symbols also reduced the complexity of these checks! 🎉

rapids-bot bot pushed a commit to rapidsai/raft that referenced this pull request Nov 27, 2024
This PR adapts to breaking changes in rmm in rapidsai/rmm#1722.

This PR is a breaking change because consumers of raft that use any functionality that touches rmm logging will need to link to the rmm::rmm_logger_impl target as well now.

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

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #2513
rapids-bot bot pushed a commit to rapidsai/cuvs that referenced this pull request Nov 30, 2024
This PR adapts to breaking changes in rmm in rapidsai/rmm#1722.

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

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Ben Frederickson (https://github.com/benfred)

URL: #499
raydouglass pushed a commit to rapidsai/cuml that referenced this pull request Dec 2, 2024
This PR adapts to breaking changes in rmm in
rapidsai/rmm#1722.

---------

Co-authored-by: Bradley Dice <[email protected]>
rapids-bot bot pushed a commit to rapidsai/cugraph that referenced this pull request Dec 2, 2024
This PR adapts to breaking changes in rmm in rapidsai/rmm#1722.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - James Lamb (https://github.com/jameslamb)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - James Lamb (https://github.com/jameslamb)
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)
  - Don Acosta (https://github.com/acostadon)

URL: #4794
rapids-bot bot pushed a commit to rapidsai/rapids-cmake that referenced this pull request Dec 16, 2024
As of rapidsai/rmm#1722, rmm no longer depends on spdlog. However, some tests were depending on spdlog transitively through rmm. This PR adds spdlog as an explicit dependency to correct those failures.

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

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

URL: #733
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change ci CMake cpp Pertains to C++ code improvement Improvement / enhancement to an existing function Python Related to RMM Python API
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[FEA] Implement wrapper around spdlog in rmm
5 participants