Skip to content

Commit

Permalink
Merge pull request #1802 from nrspruit/fix_immediate_cmdlist_reuse
Browse files Browse the repository at this point in the history
[L0] Fix immediate command list use in Command Queues
  • Loading branch information
aarongreig committed Jul 5, 2024
2 parents 4030080 + 665d4a6 commit 731376d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
!(ZeCommandListIt->second.InOrderList)) {
continue;
}
// Only allow to reuse Regular Command Lists
if (ZeCommandListIt->second.IsImmediate) {
continue;
}
auto &ZeCommandList = ZeCommandListIt->first;
auto it = Queue->CommandListMap.find(ZeCommandList);
if (it != Queue->CommandListMap.end()) {
Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
struct l0_command_list_cache_info {
ZeStruct<ze_command_queue_desc_t> ZeQueueDesc;
bool InOrderList = false;
bool IsImmediate = false;
};

struct ur_context_handle_t_ : _ur_object {
Expand Down
11 changes: 7 additions & 4 deletions source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ ur_result_t ur_queue_handle_legacy_t_::queueRelease() {
struct l0_command_list_cache_info ListInfo;
ListInfo.ZeQueueDesc = it->second.ZeQueueDesc;
ListInfo.InOrderList = it->second.IsInOrderList;
ListInfo.IsImmediate = it->second.IsImmediate;
ZeCommandListCache.push_back({it->first, ListInfo});
} else {
// A non-reusable comamnd list that came from a make_queue call is
Expand Down Expand Up @@ -745,7 +746,8 @@ void ur_queue_handle_legacy_t_::ur_queue_group_t::setImmCmdList(
.insert(std::pair<ze_command_list_handle_t, ur_command_list_info_t>{
ZeCommandList,
ur_command_list_info_t(nullptr, true, false, nullptr, ZeQueueDesc,
queue->useCompletionBatching(), false)})
queue->useCompletionBatching(), false,
false, true)})
.first);
}

Expand Down Expand Up @@ -2080,6 +2082,7 @@ ur_result_t ur_queue_handle_legacy_t_::resetCommandList(
struct l0_command_list_cache_info ListInfo;
ListInfo.ZeQueueDesc = CommandList->second.ZeQueueDesc;
ListInfo.InOrderList = CommandList->second.IsInOrderList;
ListInfo.IsImmediate = CommandList->second.IsImmediate;
ZeCommandListCache.push_back({CommandList->first, ListInfo});
}

Expand Down Expand Up @@ -2430,9 +2433,9 @@ ur_queue_handle_legacy_t_::ur_queue_group_t::getImmCmdList() {
Queue->CommandListMap
.insert(std::pair<ze_command_list_handle_t, ur_command_list_info_t>{
ZeCommandList,
ur_command_list_info_t(nullptr, true, false, nullptr,
ZeCommandQueueDesc,
Queue->useCompletionBatching())})
ur_command_list_info_t(
nullptr, true, false, nullptr, ZeCommandQueueDesc,
Queue->useCompletionBatching(), true, false, true)})
.first;

return ImmCmdLists[Index];
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/level_zero/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ struct ur_command_list_info_t {
bool IsClosed, ze_command_queue_handle_t ZeQueue,
ZeStruct<ze_command_queue_desc_t> ZeQueueDesc,
bool UseCompletionBatching, bool CanReuse = true,
bool IsInOrderList = false)
bool IsInOrderList = false, bool IsImmediate = false)
: ZeFence(ZeFence), ZeFenceInUse(ZeFenceInUse), IsClosed(IsClosed),
ZeQueue(ZeQueue), ZeQueueDesc(ZeQueueDesc),
IsInOrderList(IsInOrderList), CanReuse(CanReuse) {
IsInOrderList(IsInOrderList), CanReuse(CanReuse),
IsImmediate(IsImmediate) {
if (UseCompletionBatching) {
completions = ur_completion_batches();
}
Expand Down Expand Up @@ -204,6 +205,7 @@ struct ur_command_list_info_t {
// Indicates if this is an inorder list
bool IsInOrderList;
bool CanReuse;
bool IsImmediate;

// Helper functions to tell if this is a copy command-list.
bool isCopy(ur_queue_handle_legacy_t Queue) const;
Expand Down

0 comments on commit 731376d

Please sign in to comment.