-
Notifications
You must be signed in to change notification settings - Fork 125
[CUDA][HIP] Add Event Caching #1538
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
92b6d49
Cache events instead of destroying them for CUDA
4cb82d9
Cache events instead of destroying them for AMD
b883f80
Use mutexes for cached events storing and loading
af8eed4
Copy thread-safety event caching changes for HIP
ffa30c7
Fix thread-safe destruction of cached events
4552eb0
Fix return vals for event release
852d02f
Return ur_result_t error directly in catch block
30a6602
Don't call mutex locking function
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
#include <algorithm> | ||
#include <cuda.h> | ||
#include <stack> | ||
#include <vector> | ||
|
||
using ur_stream_guard_ = std::unique_lock<std::mutex>; | ||
|
@@ -35,6 +36,9 @@ struct ur_queue_handle_t_ { | |
// keep track of which streams have applied barrier | ||
std::vector<bool> ComputeAppliedBarrier; | ||
std::vector<bool> TransferAppliedBarrier; | ||
// CachedEvents assumes ownership of events. | ||
// Events on the stack are destructed when queue is destructed as well. | ||
std::stack<ur_event_handle_t> CachedEvents; | ||
ur_context_handle_t_ *Context; | ||
ur_device_handle_t_ *Device; | ||
CUevent BarrierEvent = nullptr; | ||
|
@@ -57,6 +61,8 @@ struct ur_queue_handle_t_ { | |
std::mutex ComputeStreamMutex; | ||
std::mutex TransferStreamMutex; | ||
std::mutex BarrierMutex; | ||
// The event cache might be accessed in multiple threads. | ||
std::mutex CacheMutex; | ||
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. I might be inclined to have this close in code to the CachedEvents |
||
bool HasOwnership; | ||
|
||
ur_queue_handle_t_(std::vector<CUstream> &&ComputeStreams, | ||
|
@@ -77,10 +83,7 @@ struct ur_queue_handle_t_ { | |
urDeviceRetain(Device); | ||
} | ||
|
||
~ur_queue_handle_t_() { | ||
urContextRelease(Context); | ||
urDeviceRelease(Device); | ||
} | ||
~ur_queue_handle_t_(); | ||
|
||
void computeStreamWaitForBarrierIfNeeded(CUstream Strean, uint32_t StreamI); | ||
void transferStreamWaitForBarrierIfNeeded(CUstream Stream, uint32_t StreamI); | ||
|
@@ -245,4 +248,23 @@ struct ur_queue_handle_t_ { | |
uint32_t getNextEventID() noexcept { return ++EventCount; } | ||
|
||
bool backendHasOwnership() const noexcept { return HasOwnership; } | ||
|
||
bool has_cached_events() { | ||
std::lock_guard<std::mutex> CacheGuard(CacheMutex); | ||
return !CachedEvents.empty(); | ||
} | ||
|
||
void cache_event(ur_event_handle_t Event) { | ||
std::lock_guard<std::mutex> CacheGuard(CacheMutex); | ||
CachedEvents.push(Event); | ||
} | ||
|
||
// Returns and removes an event from the CachedEvents stack. | ||
ur_event_handle_t get_cached_event() { | ||
std::lock_guard<std::mutex> CacheGuard(CacheMutex); | ||
assert(!CachedEvents.empty()); | ||
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. @konradkusiak97 spotted this. Need to change this to detail::ur::assertion |
||
auto RetEv = CachedEvents.top(); | ||
CachedEvents.pop(); | ||
return RetEv; | ||
} | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.