Skip to content

Commit 758c614

Browse files
authored
Merge pull request #1483 from nrspruit/fix_inorder_lists_reuse
[L0] Fix regular in order command list reuse given inorder queue
2 parents e2b5b7f + e2e4472 commit 758c614

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

source/adapters/level_zero/context.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
712712

713713
for (auto ZeCommandListIt = ZeCommandListCache.begin();
714714
ZeCommandListIt != ZeCommandListCache.end(); ++ZeCommandListIt) {
715+
// If this is an InOrder Queue, then only allow lists which are in order.
716+
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue() &&
717+
!(ZeCommandListIt->second.InOrderList)) {
718+
continue;
719+
}
715720
auto &ZeCommandList = ZeCommandListIt->first;
716721
auto it = Queue->CommandListMap.find(ZeCommandList);
717722
if (it != Queue->CommandListMap.end()) {
@@ -766,6 +771,12 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
766771
if (UseCopyEngine != it->second.isCopy(Queue))
767772
continue;
768773

774+
// If this is an InOrder Queue, then only allow lists which are in order.
775+
if (Queue->Device->useDriverInOrderLists() && Queue->isInOrderQueue() &&
776+
!(it->second.IsInOrderList)) {
777+
continue;
778+
}
779+
769780
ze_result_t ZeResult =
770781
ZE_CALL_NOCHECK(zeFenceQueryStatus, (it->second.ZeFence));
771782
if (ZeResult == ZE_RESULT_SUCCESS) {

source/adapters/level_zero/context.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
#include <umf_helpers.hpp>
2929

30+
struct l0_command_list_cache_info {
31+
ZeStruct<ze_command_queue_desc_t> ZeQueueDesc;
32+
bool InOrderList = false;
33+
};
34+
3035
struct ur_context_handle_t_ : _ur_object {
3136
ur_context_handle_t_(ze_context_handle_t ZeContext, uint32_t NumDevices,
3237
const ur_device_handle_t *Devs, bool OwnZeContext)
@@ -87,11 +92,11 @@ struct ur_context_handle_t_ : _ur_object {
8792
//
8893
std::unordered_map<ze_device_handle_t,
8994
std::list<std::pair<ze_command_list_handle_t,
90-
ZeStruct<ze_command_queue_desc_t>>>>
95+
l0_command_list_cache_info>>>
9196
ZeComputeCommandListCache;
9297
std::unordered_map<ze_device_handle_t,
9398
std::list<std::pair<ze_command_list_handle_t,
94-
ZeStruct<ze_command_queue_desc_t>>>>
99+
l0_command_list_cache_info>>>
95100
ZeCopyCommandListCache;
96101

97102
// Store USM pool for USM shared and device allocations. There is 1 memory

source/adapters/level_zero/queue.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueRelease(
449449
->ZeCopyCommandListCache[Queue->Device->ZeDevice]
450450
: Queue->Context
451451
->ZeComputeCommandListCache[Queue->Device->ZeDevice];
452-
ZeCommandListCache.push_back({it->first, it->second.ZeQueueDesc});
452+
struct l0_command_list_cache_info ListInfo;
453+
ListInfo.ZeQueueDesc = it->second.ZeQueueDesc;
454+
ListInfo.InOrderList = it->second.IsInOrderList;
455+
ZeCommandListCache.push_back({it->first, ListInfo});
453456
} else {
454457
// A non-reusable comamnd list that came from a make_queue call is
455458
// destroyed since it cannot be recycled.
@@ -1708,8 +1711,10 @@ ur_result_t ur_queue_handle_t_::resetCommandList(
17081711
UseCopyEngine
17091712
? this->Context->ZeCopyCommandListCache[this->Device->ZeDevice]
17101713
: this->Context->ZeComputeCommandListCache[this->Device->ZeDevice];
1711-
ZeCommandListCache.push_back(
1712-
{CommandList->first, CommandList->second.ZeQueueDesc});
1714+
struct l0_command_list_cache_info ListInfo;
1715+
ListInfo.ZeQueueDesc = CommandList->second.ZeQueueDesc;
1716+
ListInfo.InOrderList = CommandList->second.IsInOrderList;
1717+
ZeCommandListCache.push_back({CommandList->first, ListInfo});
17131718
}
17141719

17151720
return UR_RESULT_SUCCESS;
@@ -1870,8 +1875,10 @@ ur_result_t ur_queue_handle_t_::createCommandList(
18701875
ZeStruct<ze_command_list_desc_t> ZeCommandListDesc;
18711876
ZeCommandListDesc.commandQueueGroupOrdinal = QueueGroupOrdinal;
18721877

1878+
bool IsInOrderList = false;
18731879
if (Device->useDriverInOrderLists() && isInOrderQueue()) {
18741880
ZeCommandListDesc.flags = ZE_COMMAND_LIST_FLAG_IN_ORDER;
1881+
IsInOrderList = true;
18751882
}
18761883

18771884
ZE2UR_CALL(zeCommandListCreate, (Context->ZeContext, Device->ZeDevice,
@@ -1882,7 +1889,8 @@ ur_result_t ur_queue_handle_t_::createCommandList(
18821889
ZeQueueDesc.ordinal = QueueGroupOrdinal;
18831890
std::tie(CommandList, std::ignore) = CommandListMap.insert(
18841891
std::pair<ze_command_list_handle_t, ur_command_list_info_t>(
1885-
ZeCommandList, {ZeFence, false, false, ZeCommandQueue, ZeQueueDesc}));
1892+
ZeCommandList,
1893+
{ZeFence, false, false, ZeCommandQueue, ZeQueueDesc, IsInOrderList}));
18861894

18871895
UR_CALL(insertStartBarrierIfDiscardEventsMode(CommandList));
18881896
UR_CALL(insertActiveBarriers(CommandList, UseCopyEngine));
@@ -2011,7 +2019,7 @@ ur_command_list_ptr_t &ur_queue_handle_t_::ur_queue_group_t::getImmCmdList() {
20112019
->ZeComputeCommandListCache[Queue->Device->ZeDevice];
20122020
for (auto ZeCommandListIt = ZeCommandListCache.begin();
20132021
ZeCommandListIt != ZeCommandListCache.end(); ++ZeCommandListIt) {
2014-
const auto &Desc = (*ZeCommandListIt).second;
2022+
const auto &Desc = (*ZeCommandListIt).second.ZeQueueDesc;
20152023
if (Desc.index == ZeCommandQueueDesc.index &&
20162024
Desc.flags == ZeCommandQueueDesc.flags &&
20172025
Desc.mode == ZeCommandQueueDesc.mode &&

source/adapters/level_zero/queue.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ struct ur_command_list_info_t {
6565
// the make_queue API the descriptor is unavailable so a dummy descriptor is
6666
// used and then this entry is marked as not eligible for recycling.
6767
ZeStruct<ze_command_queue_desc_t> ZeQueueDesc;
68+
// Indicates if this is an inorder list
69+
bool IsInOrderList{false};
6870
bool CanReuse{true};
6971

7072
// Helper functions to tell if this is a copy command-list.

0 commit comments

Comments
 (0)