Skip to content

Move more implementations to precompiled shared library (part 2) - #1983

Merged
rapids-bot[bot] merged 7 commits into
rapidsai:branch-25.10from
bdice:more-precompilation
Jul 28, 2025
Merged

Move more implementations to precompiled shared library (part 2)#1983
rapids-bot[bot] merged 7 commits into
rapidsai:branch-25.10from
bdice:more-precompilation

Conversation

@bdice

@bdice bdice commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator

Description

Continues from #1980.

Contributes to #1779.

Checklist

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

@bdice
bdice requested review from a team as code owners July 11, 2025 12:50
@bdice
bdice requested review from shrshi and ttnghia July 11, 2025 12:50
@github-actions github-actions Bot added the CMake label Jul 11, 2025
@bdice bdice self-assigned this Jul 11, 2025
@bdice bdice added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Jul 11, 2025
@bdice
bdice requested a review from a team as a code owner July 17, 2025 21:00
@bdice
bdice requested a review from gforsyth July 17, 2025 21:00
@github-actions github-actions Bot added the conda label Jul 17, 2025
Comment thread cpp/src/logger.cpp Outdated
Comment on lines +41 to +47
#if RMM_LOG_ACTIVE_LEVEL <= RMM_LOG_LEVEL_DEBUG
#ifdef CUDA_API_PER_THREAD_DEFAULT_STREAM
logger_.debug("----- RMM LOG [PTDS ENABLED] -----");
#else
logger_.debug("----- RMM LOG [PTDS DISABLED] -----");
#endif
#endif

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Previously, because librmm was header-only, these macros could be controlled when the application using librmm (such as libcudf) was built.

However, moving these to a precompiled library means that the behavior could change, because it's controlled when librmm.so is built rather than the downstream application.

@vyasr @wence- @vuule Do you have thoughts on this? Part of me wants to remove the "PTDS enabled" macros and logger lines.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can this feature be queried at runtime?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's another call in the code that is more of a runtime check:

return *this == cuda_stream_per_thread || value() == nullptr;
. This affects allocators (for example):
if (stream.is_per_thread_default()) {
.

So I do agree with @ttnghia we may need a runtime check, some sort of static we are going to set at the beginning of the process.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IMO, if we want to have a pre-compiled library that can be compiled once and work with multiple downstream applications that can have different settings for per-thread stream, this macro (CUDA_API_PER_THREAD_DEFAULT_STREAM) should better be removed completely and replaced by a static variable, which can be set by the downstream application.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would also like to remove the PTDS lines but I think that is wholly separate from most of the other considerations around what the loggers should do.

There are different ways to tell CUDA to use a stream per thread. Compiling with CUDA_API_PER_THREAD_DEFAULT_STREAM is the easiest one and what Spark does. You can also pass a stream value of cudaStreamPerThread (which rmm wraps as the cuda_stream_per_thread variable shown in that snippet linked by @abellina above) to each API at runtime. The runtime model is the more flexible, obviously, and it is what we plan to do in the Python layer (see NVIDIA/cudf#17626). The reason that Spark didn't start that way is because libcudf didn't fully support stream-ordering in all APIs until fairly recently.

Whether or not code should contain the CUDA_API_PER_THREAD_DEFAULT_STREAM macro is really a question of safety. If you still want someone to be able to clone the source and build a binary that behaves as expected, you should include the compile-time guard where appropriate. That is complementary to (not a replacement of) a runtime check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed PTDS lines in 9074974.

Comment thread cpp/src/logger.cpp Outdated
@bdice
bdice changed the base branch from branch-25.08 to branch-25.10 July 28, 2025 20:05
Comment thread cpp/src/prefetch.cpp
Comment on lines +29 to +30
// cudaErrorInvalidValue is returned when non-managed memory is passed to
// cudaMemPrefetchAsync. We treat this as a no-op.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it possible if the result is still cudaErrorInvalidValue in the situations other than "non-managed memory is passed to"?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Prefetching is safe to ignore on errors like this. We aren't aware of any other situations that trigger this error, but even if there were, it's okay to do nothing.

(Also this is only code movement, not a change in the behavior or comments from what we had in the header before.)

@bdice

bdice commented Jul 28, 2025

Copy link
Copy Markdown
Collaborator Author

/merge

@rapids-bot
rapids-bot Bot merged commit e1d777a into rapidsai:branch-25.10 Jul 28, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake conda improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants