-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fixes cudaErrorInvalidValue when running on nvbench-created cuda stream #113
Open
elstehle
wants to merge
11
commits into
NVIDIA:main
Choose a base branch
from
elstehle:fix/per-device-stream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
eac79ef
create cuda stream on each device
elstehle 8e85886
fixes include order
elstehle 1301b52
adds device documentation on stream ctor
elstehle 8b191fe
adds back default ctor for cuda_stream
elstehle ff4e811
adds tests for cuda_stream
elstehle 7c82037
adds check for status returned from cuda driver api
elstehle 14079ae
guard cuda driver API calls by cupti macro
elstehle b6a29ec
limit states test to available devices
elstehle 7281bbd
revert state_generator test changes
elstehle 85645cb
lazily initializes cuda stream during measurements
elstehle 78fa3c6
fixes format
elstehle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2023 NVIDIA Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 with the LLVM exception | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://llvm.org/foundation/relicensing/LICENSE.txt | ||
* | ||
* 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 <nvbench/config.cuh> | ||
#include <nvbench/cuda_stream.cuh> | ||
#include <nvbench/device_manager.cuh> | ||
#include <nvbench/types.cuh> | ||
|
||
#include "test_asserts.cuh" | ||
|
||
#include <fmt/format.h> | ||
|
||
namespace | ||
{ | ||
#ifdef NVBENCH_HAS_CUPTI | ||
/** | ||
* @brief Queries and returns the device id that the given \p cuda_stream is associated with | ||
* | ||
* @param cuda_stream The stream to get the device id for | ||
* @return The device id that \p cuda_stream is associated with | ||
*/ | ||
int get_device_of_stream(cudaStream_t cuda_stream) | ||
{ | ||
CUcontext ctx; | ||
NVBENCH_DRIVER_API_CALL(cuStreamGetCtx(CUstream{cuda_stream}, &ctx)); | ||
NVBENCH_DRIVER_API_CALL(cuCtxPushCurrent(ctx)); | ||
CUdevice device_id{}; | ||
NVBENCH_DRIVER_API_CALL(cuCtxGetDevice(&device_id)); | ||
NVBENCH_DRIVER_API_CALL(cuCtxPopCurrent(&ctx)); | ||
return static_cast<int>(device_id); | ||
elstehle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
#endif | ||
} // namespace | ||
|
||
void test_basic() | ||
{ | ||
#ifdef NVBENCH_HAS_CUPTI | ||
// Get devices | ||
auto devices = nvbench::device_manager::get().get_devices(); | ||
|
||
// Iterate over devices | ||
for (auto const &device_info : devices) | ||
{ | ||
// Create stream on the device before it becomes the active device | ||
nvbench::cuda_stream device_stream(device_info); | ||
|
||
// Verify cuda stream is associated with the correct cuda device | ||
ASSERT(get_device_of_stream(device_stream.get_stream()) == device_info.get_id()); | ||
|
||
// Set the device as active device | ||
device_info.set_active(); | ||
|
||
// Create the stream (implicitly) on the device that is currently active | ||
nvbench::cuda_stream current_device_stream{}; | ||
|
||
// Verify the cuda stream was in fact associated with the currently active device | ||
ASSERT(get_device_of_stream(current_device_stream.get_stream()) == device_info.get_id()); | ||
} | ||
#endif | ||
} | ||
|
||
int main() { test_basic(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This feels weird to have the initialization of the
optional
external tostate
.How about putting this logic inside
state::get_cuda_stream
instead and don't expose theoptional
externally.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.
@allisonvacanti and I have discussed that option too but agreed to prefer explicitly setting the stream over implicitly initializing it as a byproduct, if it didn't exist. Considering the user interfacing with the API, I feel that, for multi-GPU systems, it's safer to make it explicit when resources are created and what device they are associated with. Especially, when the
current device
may influence what device a resource is associated with.That said, I'm fine to have it any way we decide makes more sense. @allisonvacanti what do you think?