Skip to content

Conversation

vuule
Copy link
Contributor

@vuule vuule commented Sep 25, 2025

Description

Closes #20022

Allow cudf::initialize to incrementally perform initialization steps if called multiple times. Also allow multiple calls to cudf::deinitialize. In both cases, redundant calls have no effect.

Also adds tests for this utility, since the logic is now non-trivial.

Checklist

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

Copy link

copy-pr-bot bot commented Sep 25, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@vuule vuule self-assigned this Sep 25, 2025
@github-actions github-actions bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Sep 25, 2025
@vuule vuule added feature request New feature or request non-breaking Non-breaking change and removed libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Sep 25, 2025
@github-actions github-actions bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Sep 25, 2025
@vuule vuule marked this pull request as ready for review September 25, 2025 20:58
@vuule vuule requested review from a team as code owners September 25, 2025 20:58
@vuule vuule requested review from shrshi and ttnghia September 25, 2025 20:58
Removed comments for clarity in context tests.
get_context_ptr_ref() != nullptr, "context has already been deinitialized", std::runtime_error);
get_context_ptr_ref().reset();
}
void deinitialize() { get_context_ptr_ref().reset(); }
Copy link
Contributor

@ttnghia ttnghia Sep 30, 2025

Choose a reason for hiding this comment

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

If this is called before initialization, deref of nullptr will happen! So keeping the check CUDF_EXPECTS(get_context_ptr_ref() != nullptr seems better to inform the user about this error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not dereferencing the unique_ptr here. When the context is not initialized, get_context_ptr_ref returns a reference to an empty unique_ptr and we call reset on this object, which is well-defined. Anything that includes get_context_ptr_ref-> would be ill-formed.

cudf::deinitialize();

EXPECT_NO_THROW(cudf::deinitialize());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What would the expected behavior be if we deinitialize before initialization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current behavior is to return without any real impact, since the function will call reset on an already empty unique_ptr. I added a test for this.

Copy link
Contributor Author

@vuule vuule left a comment

Choose a reason for hiding this comment

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

apparently I clicked a wrong button and my comments are a part of a review 🤦

get_context_ptr_ref() != nullptr, "context has already been deinitialized", std::runtime_error);
get_context_ptr_ref().reset();
}
void deinitialize() { get_context_ptr_ref().reset(); }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not dereferencing the unique_ptr here. When the context is not initialized, get_context_ptr_ref returns a reference to an empty unique_ptr and we call reset on this object, which is well-defined. Anything that includes get_context_ptr_ref-> would be ill-formed.

cudf::deinitialize();

EXPECT_NO_THROW(cudf::deinitialize());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current behavior is to return without any real impact, since the function will call reset on an already empty unique_ptr. I added a test for this.

@vuule
Copy link
Contributor Author

vuule commented Sep 30, 2025

/ok to test b876505

@vuule
Copy link
Contributor Author

vuule commented Oct 1, 2025

/ok to test 73b86f7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake CMake build issue feature request New feature or request libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Allow multiple calls to cudf::initialize
5 participants