Skip to content

Commit 3a13d92

Browse files
fix enqueueCommandBufferExp
1 parent 9f88383 commit 3a13d92

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

unified-runtime/source/adapters/level_zero/v2/queue_batched.cpp

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace v2 {
3737
ur_queue_batched_t::ur_queue_batched_t(
3838
ur_context_handle_t hContext, ur_device_handle_t hDevice, uint32_t ordinal,
3939
ze_command_queue_priority_t priority, std::optional<int32_t> index,
40-
[[maybe_unused]] event_flags_t eventFlags, ur_queue_flags_t flags)
40+
event_flags_t eventFlags, ur_queue_flags_t flags)
4141
: regularCmdListDesc(v2::command_list_desc_t{
4242
true /* isInOrder*/, ordinal /* Ordinal*/,
4343
true /* copyOffloadEnable*/, false /*isMutable*/}),
@@ -69,6 +69,9 @@ ur_queue_batched_t::ur_queue_batched_t(
6969

7070
eventPoolRegular = hContext->getEventPoolCache(PoolCacheType::Regular)
7171
.borrow(hDevice->Id.value(), v2::EVENT_FLAGS_COUNTER);
72+
73+
eventPoolImmediate = hContext->getEventPoolCache(PoolCacheType::Immediate)
74+
.borrow(hDevice->Id.value(), eventFlags);
7275
}
7376

7477
ur_event_handle_t ur_queue_batched_t::createEventIfRequestedRegular(
@@ -229,9 +232,13 @@ ur_queue_batched_t::queueFinishUnlocked(locked<batch_manager> &batchLocked) {
229232
UR_CALL(batchLocked->enqueueCurrentBatchUnlocked());
230233
UR_CALL(batchLocked->hostSynchronize());
231234

232-
UR_CALL(queueFinishPoolsUnlocked());
235+
// UR_CALL(queueFinishPoolsUnlocked());
236+
237+
// return batchLocked->batchFinish();
238+
239+
UR_CALL(batchLocked->batchFinish());
233240

234-
return batchLocked->batchFinish();
241+
return queueFinishPoolsUnlocked();
235242
}
236243

237244
ur_result_t ur_queue_batched_t::queueFinish() {
@@ -792,11 +799,20 @@ ur_result_t ur_queue_batched_t::enqueueUSMDeviceAllocExp(
792799

793800
lockedBatch->markIssuedCommand();
794801

795-
return lockedBatch->getActiveBatch().appendUSMAllocHelper(
802+
// return lockedBatch->getActiveBatch().appendUSMAllocHelper(
803+
// this, pPool, size, pProperties, waitListView, ppMem,
804+
// createEventIfRequestedRegular(phEvent,
805+
// lockedBatch->getCurrentGeneration()),
806+
// UR_USM_TYPE_DEVICE);
807+
UR_CALL(lockedBatch->getActiveBatch().appendUSMAllocHelper(
796808
this, pPool, size, pProperties, waitListView, ppMem,
797809
createEventIfRequestedRegular(phEvent,
798810
lockedBatch->getCurrentGeneration()),
799-
UR_USM_TYPE_DEVICE);
811+
// createEventAndRetainRegular(phEvent,
812+
// lockedBatch->getCurrentGeneration()),
813+
UR_USM_TYPE_DEVICE));
814+
815+
return queueFlushUnlocked(lockedBatch);
800816
}
801817

802818
ur_result_t ur_queue_batched_t::enqueueUSMSharedAllocExp(
@@ -812,11 +828,21 @@ ur_result_t ur_queue_batched_t::enqueueUSMSharedAllocExp(
812828

813829
lockedBatch->markIssuedCommand();
814830

815-
return lockedBatch->getActiveBatch().appendUSMAllocHelper(
831+
// return lockedBatch->getActiveBatch().appendUSMAllocHelper(
832+
// this, pPool, size, pProperties, waitListView, ppMem,
833+
// createEventIfRequestedRegular(phEvent,
834+
// lockedBatch->getCurrentGeneration()),
835+
// UR_USM_TYPE_SHARED);
836+
837+
UR_CALL(lockedBatch->getActiveBatch().appendUSMAllocHelper(
816838
this, pPool, size, pProperties, waitListView, ppMem,
817839
createEventIfRequestedRegular(phEvent,
818840
lockedBatch->getCurrentGeneration()),
819-
UR_USM_TYPE_SHARED);
841+
// createEventAndRetainRegular(phEvent,
842+
// lockedBatch->getCurrentGeneration()),
843+
UR_USM_TYPE_SHARED));
844+
845+
return queueFlushUnlocked(lockedBatch);
820846
}
821847

822848
ur_result_t ur_queue_batched_t::enqueueUSMHostAllocExp(
@@ -831,11 +857,21 @@ ur_result_t ur_queue_batched_t::enqueueUSMHostAllocExp(
831857

832858
lockedBatch->markIssuedCommand();
833859

834-
return lockedBatch->getActiveBatch().appendUSMAllocHelper(
860+
// return lockedBatch->getActiveBatch().appendUSMAllocHelper(
861+
// this, pPool, size, pProperties, waitListView, ppMem,
862+
// createEventIfRequestedRegular(phEvent,
863+
// lockedBatch->getCurrentGeneration()),
864+
// UR_USM_TYPE_HOST);
865+
866+
UR_CALL(lockedBatch->getActiveBatch().appendUSMAllocHelper(
835867
this, pPool, size, pProperties, waitListView, ppMem,
836868
createEventIfRequestedRegular(phEvent,
837869
lockedBatch->getCurrentGeneration()),
838-
UR_USM_TYPE_HOST);
870+
// createEventAndRetainRegular(phEvent,
871+
// lockedBatch->getCurrentGeneration()),
872+
UR_USM_TYPE_HOST));
873+
874+
return queueFlushUnlocked(lockedBatch);
839875
}
840876

841877
ur_result_t ur_queue_batched_t::bindlessImagesImageCopyExp(
@@ -944,12 +980,13 @@ ur_result_t ur_queue_batched_t::enqueueCommandBufferExp(
944980

945981
auto lockedBatch = currentCmdLists.lock();
946982

947-
lockedBatch->markIssuedCommand();
983+
if (!lockedBatch->isActiveBatchEmpty()) {
984+
UR_CALL(queueFlushUnlocked(lockedBatch));
985+
}
948986

949-
return lockedBatch->getActiveBatch().appendCommandBufferExp(
987+
return lockedBatch->getImmediateManager().appendCommandBufferExp(
950988
hCommandBuffer, waitListView,
951-
createEventAndRetainRegular(phEvent,
952-
lockedBatch->getCurrentGeneration()));
989+
createEventAndRetain(eventPoolImmediate.get(), phEvent, this));
953990
}
954991

955992
ur_result_t ur_queue_batched_t::enqueueNativeCommandExp(

unified-runtime/source/adapters/level_zero/v2/queue_batched.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ struct batch_manager {
108108

109109
ur_command_list_manager &getActiveBatch() { return activeBatch; }
110110

111+
ur_command_list_manager &getImmediateManager() { return immediateList; }
112+
111113
ur_event_generation_t getCurrentGeneration() {
112114
return regularGenerationNumber;
113115
}
@@ -151,6 +153,8 @@ struct ur_queue_batched_t : ur_object, ur_queue_t_ {
151153

152154
v2::raii::cache_borrowed_event_pool eventPoolRegular;
153155

156+
v2::raii::cache_borrowed_event_pool eventPoolImmediate;
157+
154158
v2::raii::command_list_unique_handle getNewRegularCmdList() {
155159
TRACK_SCOPE_LATENCY("ur_queue_batched_t::getNewRegularCmdList");
156160

0 commit comments

Comments
 (0)