-
Notifications
You must be signed in to change notification settings - Fork 981
Allow multiple calls to cudf::initialize and cudf::deinitialize
#20111
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
Changes from all commits
b823a57
c8913e7
c836292
56730d7
008a79f
4d7d53f
d2ab7d3
01ff6fb
9c61849
d79000a
960646b
8393111
778e33b
940a63b
b876505
73b86f7
a15887b
6c651f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright (c) 2025, NVIDIA CORPORATION. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <cudf_test/base_fixture.hpp> | ||
|
|
||
| #include <cudf/context.hpp> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| struct ContextTest : public cudf::test::BaseFixture { | ||
| ~ContextTest() override | ||
| { | ||
| try { | ||
| cudf::deinitialize(); | ||
| } catch (...) { | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(ContextTest, MultipleInitializeCalls) | ||
| { | ||
| cudf::initialize(cudf::init_flags::INIT_JIT_CACHE); | ||
|
|
||
| EXPECT_NO_THROW(cudf::initialize(cudf::init_flags::LOAD_NVCOMP)); | ||
| EXPECT_NO_THROW(cudf::initialize(cudf::init_flags::ALL)); | ||
| } | ||
|
|
||
| TEST_F(ContextTest, InitializeAfterDeinitialize) | ||
| { | ||
| cudf::initialize(cudf::init_flags::ALL); | ||
| cudf::deinitialize(); | ||
|
|
||
| EXPECT_NO_THROW(cudf::initialize(cudf::init_flags::INIT_JIT_CACHE)); | ||
| } | ||
|
|
||
| TEST_F(ContextTest, DeinitializeWithoutInitialize) { EXPECT_NO_THROW(cudf::deinitialize()); } | ||
|
|
||
| TEST_F(ContextTest, MultipleDeinitializeCalls) | ||
| { | ||
| cudf::initialize(cudf::init_flags::ALL); | ||
| cudf::deinitialize(); | ||
|
|
||
| EXPECT_NO_THROW(cudf::deinitialize()); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would the expected behavior be if we deinitialize before initialization? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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() != nullptrseems better to inform the user about this error.There was a problem hiding this comment.
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_ptrhere. When the context is not initialized,get_context_ptr_refreturns a reference to an emptyunique_ptrand we callreseton this object, which is well-defined. Anything that includesget_context_ptr_ref->would be ill-formed.