-
Notifications
You must be signed in to change notification settings - Fork 124
[L0] Support for counter-based events using L0 driver #1370
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
Merged
kbenzie
merged 3 commits into
oneapi-src:main
from
winstonzhang-intel:counter-based-events
Apr 26, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,9 +146,9 @@ struct ur_context_handle_t_ : _ur_object { | |
// head. | ||
// | ||
// Cache of event pools to which host-visible events are added to. | ||
std::vector<std::list<ze_event_pool_handle_t>> ZeEventPoolCache{4}; | ||
std::vector<std::list<ze_event_pool_handle_t>> ZeEventPoolCache{12}; | ||
std::vector<std::unordered_map<ze_device_handle_t, size_t>> | ||
ZeEventPoolCacheDeviceMap{4}; | ||
ZeEventPoolCacheDeviceMap{12}; | ||
|
||
// This map will be used to determine if a pool is full or not | ||
// by storing number of empty slots available in the pool. | ||
|
@@ -199,48 +199,73 @@ struct ur_context_handle_t_ : _ur_object { | |
ur_result_t getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &, size_t &, | ||
bool HostVisible, | ||
bool ProfilingEnabled, | ||
ur_device_handle_t Device); | ||
ur_device_handle_t Device, | ||
bool CounterBasedEventEnabled, | ||
bool UsingImmCmdList); | ||
|
||
// Get ur_event_handle_t from cache. | ||
ur_event_handle_t getEventFromContextCache(bool HostVisible, | ||
bool WithProfiling, | ||
ur_device_handle_t Device); | ||
ur_device_handle_t Device, | ||
bool CounterBasedEventEnabled); | ||
|
||
// Add ur_event_handle_t to cache. | ||
void addEventToContextCache(ur_event_handle_t); | ||
|
||
enum EventPoolCacheType { | ||
HostVisibleCacheType, | ||
HostInvisibleCacheType, | ||
HostVisibleCounterBasedRegularCacheType, | ||
HostInvisibleCounterBasedRegularCacheType, | ||
HostVisibleCounterBasedImmediateCacheType, | ||
HostInvisibleCounterBasedImmediateCacheType | ||
}; | ||
|
||
std::list<ze_event_pool_handle_t> * | ||
getZeEventPoolCache(bool HostVisible, bool WithProfiling, | ||
bool CounterBasedEventEnabled, bool UsingImmediateCmdList, | ||
ze_device_handle_t ZeDevice) { | ||
if (HostVisible) { | ||
if (ZeDevice) { | ||
auto ZeEventPoolCacheMap = WithProfiling | ||
? &ZeEventPoolCacheDeviceMap[0] | ||
: &ZeEventPoolCacheDeviceMap[1]; | ||
if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { | ||
ZeEventPoolCache.emplace_back(); | ||
ZeEventPoolCacheMap->insert( | ||
std::make_pair(ZeDevice, ZeEventPoolCache.size() - 1)); | ||
} | ||
return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]]; | ||
} else { | ||
return WithProfiling ? &ZeEventPoolCache[0] : &ZeEventPoolCache[1]; | ||
EventPoolCacheType CacheType; | ||
|
||
calculateCacheIndex(HostVisible, CounterBasedEventEnabled, | ||
UsingImmediateCmdList, CacheType); | ||
if (ZeDevice) { | ||
auto ZeEventPoolCacheMap = | ||
WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2] | ||
: &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1]; | ||
if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { | ||
ZeEventPoolCache.emplace_back(); | ||
ZeEventPoolCacheMap->insert( | ||
std::make_pair(ZeDevice, ZeEventPoolCache.size() - 1)); | ||
} | ||
return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]]; | ||
} else { | ||
if (ZeDevice) { | ||
auto ZeEventPoolCacheMap = WithProfiling | ||
? &ZeEventPoolCacheDeviceMap[2] | ||
: &ZeEventPoolCacheDeviceMap[3]; | ||
if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { | ||
ZeEventPoolCache.emplace_back(); | ||
ZeEventPoolCacheMap->insert( | ||
std::make_pair(ZeDevice, ZeEventPoolCache.size() - 1)); | ||
} | ||
return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]]; | ||
} else { | ||
return WithProfiling ? &ZeEventPoolCache[2] : &ZeEventPoolCache[3]; | ||
} | ||
return WithProfiling ? &ZeEventPoolCache[CacheType * 2] | ||
: &ZeEventPoolCache[CacheType * 2 + 1]; | ||
} | ||
} | ||
|
||
ur_result_t calculateCacheIndex(bool HostVisible, | ||
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. how do you differentiate between counter based events for immediate and regular command lists? 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. added immediate detection |
||
bool CounterBasedEventEnabled, | ||
bool UsingImmediateCmdList, | ||
EventPoolCacheType &CacheType) { | ||
if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) { | ||
CacheType = HostVisibleCounterBasedRegularCacheType; | ||
} else if (CounterBasedEventEnabled && !HostVisible && | ||
!UsingImmediateCmdList) { | ||
CacheType = HostInvisibleCounterBasedRegularCacheType; | ||
} else if (CounterBasedEventEnabled && HostVisible && | ||
UsingImmediateCmdList) { | ||
CacheType = HostVisibleCounterBasedImmediateCacheType; | ||
} else if (CounterBasedEventEnabled && !HostVisible && | ||
UsingImmediateCmdList) { | ||
CacheType = HostInvisibleCounterBasedImmediateCacheType; | ||
} else if (!CounterBasedEventEnabled && HostVisible) { | ||
CacheType = HostVisibleCacheType; | ||
} else { | ||
CacheType = HostInvisibleCacheType; | ||
} | ||
return UR_RESULT_SUCCESS; | ||
} | ||
|
||
// Decrement number of events living in the pool upon event destroy | ||
|
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
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.
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.
there's ought to be a better way of allocating an event that doesn't require passing around half a dozen arguments to multiple functions. Maybe some sort of flag?
auto event = Pool->allocateEvent(HOST_VISIBLE | ENABLE_PROFILER | COUNTER_BASED);
having functions that accept multiple boolean values is error prone.
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.
@pbalcer Thanks for the feedback! We could create a new enum just for this case. However, this seems to be a bit overkill just for this one function. It is only used once event.cpp during event creation.
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.
It's not just this function. All the various boolean event parameters are being passed around in multiple functions. Just from a quick search:
createEventAndAssociateQueue, getEventFromQueueCache, EventCreate, getEventFromContextCache, getFreeSlotInExistingOrNewPool, getZeEventPoolCache
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.
@pbalcer This is quite a large refactoring. Functions with these booleans are abundant. Additionally, it would make sense to add this in ur_api, however, we would need to add this in spec before I can do so. Perhaps I can file a new ticket and have this be its own patch?
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.
Sure, this was just a suggestion.