Skip to content

Commit 7e15b46

Browse files
Removed explicit sync where necessary
1 parent c397c4a commit 7e15b46

File tree

7 files changed

+10
-50
lines changed

7 files changed

+10
-50
lines changed

unified-runtime/source/adapters/cuda/command_buffer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,6 @@ urCommandBufferRetainExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
387387
UR_APIEXPORT ur_result_t UR_APICALL
388388
urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
389389
if (hCommandBuffer->decrementReferenceCount() == 0) {
390-
if (hCommandBuffer->CurrentExecution) {
391-
UR_CHECK_ERROR(hCommandBuffer->CurrentExecution->wait());
392-
}
393390
// Ref count has reached zero, release of created commands
394391
for (auto &Command : hCommandBuffer->CommandHandles) {
395392
commandHandleDestroy(Command);
@@ -1172,10 +1169,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueCommandBufferExp(
11721169
// Launch graph
11731170
UR_CHECK_ERROR(cuGraphLaunch(hCommandBuffer->CudaGraphExec, CuStream));
11741171

1175-
UR_CHECK_ERROR(RetImplEvent->record());
1176-
hCommandBuffer->CurrentExecution = RetImplEvent.release();
11771172
if (phEvent) {
1178-
*phEvent = hCommandBuffer->CurrentExecution;
1173+
UR_CHECK_ERROR(RetImplEvent->record());
1174+
*phEvent = RetImplEvent.release();
11791175
}
11801176
return UR_RESULT_SUCCESS;
11811177
} catch (ur_result_t Err) {

unified-runtime/source/adapters/cuda/command_buffer.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ struct ur_exp_command_buffer_handle_t_ : ur::cuda::handle_base {
192192
// Atomic variable counting the number of reference to this command_buffer
193193
// using std::atomic prevents data race when incrementing/decrementing.
194194
std::atomic_uint32_t RefCount;
195-
// Track the event of the current graph execution.
196-
ur_event_handle_t CurrentExecution = nullptr;
197195

198196
// Ordered map of sync_points to ur_events, so that we can find the last
199197
// node added to an in-order command-buffer.

unified-runtime/source/adapters/hip/command_buffer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ urCommandBufferRetainExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
273273
UR_APIEXPORT ur_result_t UR_APICALL
274274
urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
275275
if (hCommandBuffer->decrementReferenceCount() == 0) {
276-
if (hCommandBuffer->CurrentExecution) {
277-
UR_CHECK_ERROR(hCommandBuffer->CurrentExecution->wait());
278-
}
279276
delete hCommandBuffer;
280277
}
281278
return UR_RESULT_SUCCESS;
@@ -811,10 +808,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueCommandBufferExp(
811808
// Launch graph
812809
UR_CHECK_ERROR(hipGraphLaunch(hCommandBuffer->HIPGraphExec, HIPStream));
813810

814-
UR_CHECK_ERROR(RetImplEvent->record());
815-
hCommandBuffer->CurrentExecution = RetImplEvent.release();
816811
if (phEvent) {
817-
*phEvent = hCommandBuffer->CurrentExecution;
812+
UR_CHECK_ERROR(RetImplEvent->record());
813+
*phEvent = RetImplEvent.release();
818814
}
819815
} catch (ur_result_t Err) {
820816
return Err;

unified-runtime/source/adapters/hip/command_buffer.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ struct ur_exp_command_buffer_handle_t_ : ur::hip::handle_base {
128128
// Atomic variable counting the number of reference to this command_buffer
129129
// using std::atomic prevents data race when incrementing/decrementing.
130130
std::atomic_uint32_t RefCount;
131-
// Track the event of the current graph execution.
132-
ur_event_handle_t CurrentExecution = nullptr;
133131

134132
// Ordered map of sync_points to ur_events
135133
std::map<ur_exp_command_buffer_sync_point_t, hipGraphNode_t> SyncPoints;

unified-runtime/source/adapters/level_zero/command_buffer.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,12 @@ ur_result_t createMainCommandList(ur_context_handle_t Context,
672672
}
673673

674674
/**
675-
* Waits for any ongoing executions of the command-buffer to finish.
675+
* Waits for any ongoing executions of the command-buffer to finish
676676
* @param CommandBuffer The command-buffer to wait for.
677677
* @return UR_RESULT_SUCCESS or an error code on failure
678678
*/
679679
ur_result_t
680-
waitForLastSubmission(ur_exp_command_buffer_handle_t CommandBuffer) {
680+
waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
681681

682682
if (ur_event_handle_t &CurrentSubmissionEvent =
683683
CommandBuffer->CurrentSubmissionEvent) {
@@ -690,30 +690,6 @@ waitForLastSubmission(ur_exp_command_buffer_handle_t CommandBuffer) {
690690
return UR_RESULT_SUCCESS;
691691
}
692692

693-
/**
694-
* Waits for any ongoing executions of the command-buffer to finish
695-
* but put fence in case of wait event path.
696-
* @param CommandBuffer The command-buffer to wait for.
697-
* @return UR_RESULT_SUCCESS or an error code on failure
698-
*/
699-
ur_result_t
700-
waitForOngoingExecution(ur_exp_command_buffer_handle_t CommandBuffer) {
701-
702-
if (CommandBuffer->UseImmediateAppendPath) {
703-
if (ur_event_handle_t &CurrentSubmissionEvent =
704-
CommandBuffer->CurrentSubmissionEvent) {
705-
ZE2UR_CALL(zeEventHostSynchronize,
706-
(CurrentSubmissionEvent->ZeEvent, UINT64_MAX));
707-
UR_CALL(urEventReleaseInternal(CurrentSubmissionEvent));
708-
CurrentSubmissionEvent = nullptr;
709-
}
710-
} else if (ze_fence_handle_t &ZeFence = CommandBuffer->ZeActiveFence) {
711-
ZE2UR_CALL(zeFenceHostSynchronize, (ZeFence, UINT64_MAX));
712-
}
713-
714-
return UR_RESULT_SUCCESS;
715-
}
716-
717693
/**
718694
* Checks whether the command-buffer can be constructed using in order
719695
* command-lists.
@@ -1767,7 +1743,7 @@ ur_result_t urEnqueueCommandBufferExp(
17671743

17681744
std::scoped_lock<ur_shared_mutex> Lock(UrQueue->Mutex);
17691745

1770-
UR_CALL(waitForLastSubmission(CommandBuffer));
1746+
UR_CALL(waitForOngoingExecution(CommandBuffer));
17711747

17721748
const bool IsInternal = (Event == nullptr);
17731749
const bool DoProfiling =

unified-runtime/source/adapters/opencl/command_buffer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ urCommandBufferRetainExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
115115
UR_APIEXPORT ur_result_t UR_APICALL
116116
urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
117117
if (hCommandBuffer->decrementReferenceCount() == 0) {
118-
if (hCommandBuffer->LastSubmission) {
119-
cl_int RetErr = clWaitForEvents(1, &(hCommandBuffer->LastSubmission));
120-
CL_RETURN_ON_FAILURE(RetErr);
121-
}
122118
delete hCommandBuffer;
123119
}
124120

unified-runtime/test/conformance/exp_command_buffer/enqueue.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ TEST_P(urEnqueueCommandBufferExpTest, SerializeInOrOutOfOrderQueue) {
194194
// Tests releasing command-buffer while it is still executing relying
195195
// on synchronization during urCommandBufferReleaseExp call.
196196
TEST_P(urEnqueueCommandBufferExpTest, EnqueueAndRelease) {
197-
ASSERT_SUCCESS(urEnqueueCommandBufferExp(out_of_order_queue, cmd_buf_handle,
198-
0, nullptr, nullptr));
197+
ASSERT_SUCCESS(urEnqueueCommandBufferExp(
198+
in_or_out_of_order_queue, cmd_buf_handle, 0, nullptr, nullptr));
199199

200200
// Release the command buffer without explicitly waiting beforehand
201201
EXPECT_SUCCESS(urCommandBufferReleaseExp(cmd_buf_handle));
202202

203203
// Wait before exiting
204-
ASSERT_SUCCESS(urQueueFinish(out_of_order_queue));
204+
ASSERT_SUCCESS(urQueueFinish(in_or_out_of_order_queue));
205205
}

0 commit comments

Comments
 (0)