Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/benchmarks/fixture/nvbench_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct nvbench_base_fixture {

nvbench_base_fixture(int argc, char const* const* argv)
{
cudf::initialize(cudf::init_flags::ALL);
cudf::detail::initialize(cudf::init_flags::ALL);

for (int i = 1; i < argc - 1; ++i) {
std::string arg = argv[i];
Expand Down
35 changes: 17 additions & 18 deletions cpp/include/cudf/context.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -18,12 +18,10 @@ enum class init_flags : std::uint32_t {
NONE = 0,
/// @brief Load the nvCOMP library during initialization
LOAD_NVCOMP = 1 << 0,
/// @brief Initialize the JIT program cache during initialization
INIT_JIT_CACHE = 1 << 1,
/// @brief Pre-load the JIT program cache from disk during initialization
DEFAULT = INIT_JIT_CACHE,
/// @brief All initialization steps (default behavior)
ALL = LOAD_NVCOMP | INIT_JIT_CACHE
/// @brief Default initialization steps
DEFAULT = LOAD_NVCOMP,
/// @brief All initialization steps
ALL = LOAD_NVCOMP
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

/// @brief Bitwise OR operator for init_flags
Expand Down Expand Up @@ -66,19 +64,20 @@ constexpr bool has_flag(init_flags flags, init_flags flag) noexcept
return (flags | flag) == flags;
}

/// @brief Initialize the cudf global context
/// @param flags Optional flags to control which initialization steps to perform.
/// Can be called multiple times to initialize additional components. If all selected
/// steps are already performed, the call has no effect.
namespace detail {

/// @brief Ensure the cudf global context is initialized. Only the first call to this function will
/// have an effect, subsequent calls are no-ops regardless of the initialization flags.
/// This function is thread-safe and can be called from multiple threads concurrently.
///
/// It is intended for advanced users who need to explicitly control the initialization order of the
/// cuDF context. Most users should not need to call this function directly, as the context is
/// automatically initialized when needed.
///
/// @param flags Flags controlling which components to initialize
void initialize(init_flags flags = init_flags::DEFAULT);
Comment on lines +67 to 78

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.

question: Moving this to the detail namespace removes it from our publicly blessed APIs. I presume this is deliberate. But, officially, external users of the libcudf library aren't allowed to call detail APIs.

So what gives?

@lamarrr lamarrr Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From my understanding, detail APIs are not explicitly disallowed. It means we don't provide strong guarantees or that it is a second-class API that most users shouldn't depend on, and it could break at any time.
The API in question was intended as a workaround for an initialization order bug in our unit tests, which only happened in debug builds, and it allowed us to explicitly specify when the global objects are initialized/destroyed.
I believe it should have been a detail API from the start, but I'm open to suggestions


/// @brief Destroy the cudf global context, resetting it to an uninitialized state. This is
/// primarily intended for testing purposes, allowing for re-initialization of the context after
/// teardown.
/// @warning This is not intended for general use and may lead to undefined behavior if used
/// improperly. The caller must ensure that no threads are concurrently accessing the context during
/// teardown and that only one thread calls teardown at a time.
void teardown();
} // namespace detail

/**
* @brief Enable or disable the JIT program cache
Expand Down
6 changes: 2 additions & 4 deletions cpp/include/cudf_test/testing_main.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -252,20 +252,18 @@ inline void init_cudf_test(int argc, char** argv, cudf::test::config const& conf
#define CUDF_TEST_PROGRAM_MAIN() \
int main(int argc, char** argv) \
{ \
cudf::initialize(); \
cudf::detail::initialize(); \
::testing::InitGoogleTest(&argc, argv); \
init_cudf_test(argc, argv); \
if (std::getenv("GTEST_CUDF_MEMORY_PEAK")) { \
auto mr = rmm::mr::statistics_resource_adaptor(cudf::get_current_device_resource_ref()); \
cudf::set_current_device_resource(mr); \
auto rc = RUN_ALL_TESTS(); \
std::cout << "Peak memory usage " << mr.get_bytes_counter().peak << " bytes" << std::endl; \
cudf::teardown(); \
rmm::mr::reset_current_device_resource(); \
return rc; \
} else { \
auto rc = RUN_ALL_TESTS(); \
cudf::teardown(); \
rmm::mr::reset_current_device_resource(); \
return rc; \
} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ int main(int argc, char** argv)
{
rapidsmpf::ndsh::FinalizeMPI finalize{};
CUDF_CUDA_TRY(cudaFree(nullptr));
// work around https://github.com/NVIDIA/cudf/issues/20849
cudf::initialize();
auto mr = rmm::mr::cuda_async_memory_resource{};
auto arguments = parse_arguments(argc, argv);
rapidsmpf::ndsh::ProgramOptions ctx_arguments{
Expand Down
2 changes: 0 additions & 2 deletions cpp/libcudf_streaming/benchmarks/streaming/ndsh/q01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ int main(int argc, char** argv)
{
rapidsmpf::ndsh::FinalizeMPI finalize{};
CUDF_CUDA_TRY(cudaFree(nullptr));
// work around https://github.com/NVIDIA/cudf/issues/20849
cudf::initialize();
auto mr = rmm::mr::cuda_async_memory_resource{};
auto arguments = rapidsmpf::ndsh::parse_arguments(argc, argv);
auto [ctx, comm] = rapidsmpf::ndsh::create_context(arguments, std::move(mr));
Expand Down
2 changes: 0 additions & 2 deletions cpp/libcudf_streaming/benchmarks/streaming/ndsh/q03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ int main(int argc, char** argv)
{
rapidsmpf::ndsh::FinalizeMPI finalize{};
CUDF_CUDA_TRY(cudaFree(nullptr));
// work around https://github.com/NVIDIA/cudf/issues/20849
cudf::initialize();
auto mr = rmm::mr::cuda_async_memory_resource{};
auto arguments = rapidsmpf::ndsh::parse_arguments(argc, argv);
auto [ctx, comm] = rapidsmpf::ndsh::create_context(arguments, std::move(mr));
Expand Down
2 changes: 0 additions & 2 deletions cpp/libcudf_streaming/benchmarks/streaming/ndsh/q04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ int main(int argc, char** argv)
{
rapidsmpf::ndsh::FinalizeMPI finalize{};
CUDF_CUDA_TRY(cudaFree(nullptr));
// work around https://github.com/NVIDIA/cudf/issues/20849
cudf::initialize();
auto mr = rmm::mr::cuda_async_memory_resource{};
auto arguments = rapidsmpf::ndsh::parse_arguments(argc, argv);
auto [ctx, comm] = rapidsmpf::ndsh::create_context(arguments, std::move(mr));
Expand Down
2 changes: 0 additions & 2 deletions cpp/libcudf_streaming/benchmarks/streaming/ndsh/q09.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ int main(int argc, char** argv)
{
rapidsmpf::ndsh::FinalizeMPI finalize{};
CUDF_CUDA_TRY(cudaFree(nullptr));
// work around https://github.com/NVIDIA/cudf/issues/20849
cudf::initialize();
auto mr = rmm::mr::cuda_async_memory_resource{};
auto arguments = rapidsmpf::ndsh::parse_arguments(argc, argv);
auto [ctx, comm] = rapidsmpf::ndsh::create_context(arguments, std::move(mr));
Expand Down
1 change: 0 additions & 1 deletion cpp/libcudf_streaming/benchmarks/streaming/ndsh/q21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ int main(int argc, char** argv)
{
rapidsmpf::ndsh::FinalizeMPI finalize{};
CUDF_CUDA_TRY(cudaFree(nullptr));
cudf::initialize();
auto mr = rmm::mr::cuda_async_memory_resource{};
auto arguments = rapidsmpf::ndsh::parse_arguments(argc, argv);
auto [ctx, comm] = rapidsmpf::ndsh::create_context(arguments, std::move(mr));
Expand Down
Loading
Loading