Skip to content

Commit 232146b

Browse files
fix: synchronize resubmission of the same command buffer
synchronization implemented as the host thread waiting for an event to be signalled after the completion of the command buffer execution
1 parent a8b1b8f commit 232146b

File tree

3 files changed

+63
-86
lines changed

3 files changed

+63
-86
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,11 @@ ur_result_t ur_queue_immediate_in_order_t::enqueueCommandBufferExp(
10251025
ur_event_handle_t executionEvent =
10261026
hCommandBuffer->getExecutionEventUnlocked();
10271027

1028+
if (executionEvent != nullptr) {
1029+
ZE2UR_CALL(zeEventHostSynchronize,
1030+
(executionEvent->getZeEvent(), UINT64_MAX));
1031+
}
1032+
10281033
UR_CALL(enqueueGenericCommandListsExp(
10291034
1, &commandBufferCommandList, phEvent, numEventsInWaitList,
10301035
phEventWaitList, UR_COMMAND_ENQUEUE_COMMAND_BUFFER_EXP, executionEvent));

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

Lines changed: 51 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@
1717
// enqueue_update.cpp test for a test verifying the order of submissions, as
1818
// the input/output to the kernels can be modified between the submissions.
1919
struct urEnqueueCommandBufferExpTest
20-
: uur::command_buffer::urCommandBufferExpExecutionTestWithParam<ur_queue_flags_t> {
20+
: uur::command_buffer::urCommandBufferExpExecutionTestWithParam<
21+
ur_queue_flags_t> {
2122
virtual void SetUp() override {
2223
program_name = "increment";
23-
UUR_RETURN_ON_FATAL_FAILURE(urCommandBufferExpExecutionTestWithParam::SetUp());
24+
UUR_RETURN_ON_FATAL_FAILURE(
25+
urCommandBufferExpExecutionTestWithParam::SetUp());
2426

25-
// Create an in-order queue
26-
queue_type = std::get<1>(GetParam());
27+
// Create an in-order or out-of-order queue, depending on the passed parameter
28+
ur_queue_flags_t queue_type = std::get<1>(GetParam());
2729
ur_queue_properties_t queue_properties = {
28-
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr, queue_type}; //GetParam()}; //0};
29-
ASSERT_SUCCESS(
30-
urQueueCreate(context, device, &queue_properties, &in_or_out_of_order_queue));
31-
32-
// // Create an out-of-order queue
33-
// queue_properties.flags = UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE;
34-
// ASSERT_SUCCESS(
35-
// urQueueCreate(context, device, &queue_properties, &out_of_order_queue));
36-
// ASSERT_NE(out_of_order_queue, nullptr);
30+
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr, queue_type};
31+
ASSERT_SUCCESS(urQueueCreate(context, device, &queue_properties,
32+
&in_or_out_of_order_queue));
3733

3834
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
3935
allocation_size, &device_ptr));
@@ -44,16 +40,19 @@ struct urEnqueueCommandBufferExpTest
4440
&zero_pattern, allocation_size, 0, nullptr,
4541
nullptr));
4642

47-
std::vector<int> temp_val(buffer_size, 3);
48-
4943
for (int i = 0; i < num_copy_buffers; i++) {
50-
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr, buffer_size * sizeof(int), (void**) &(dst_buffers[i])));
51-
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr, buffer_size * sizeof(int), (void**) &(src_buffers[i])));
52-
53-
ASSERT_SUCCESS(urEnqueueUSMMemcpy(in_or_out_of_order_queue, false, src_buffers[i], temp_val.data(), buffer_size * sizeof(int), 0, nullptr, nullptr));
44+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
45+
buffer_size * sizeof(int32_t),
46+
(void **)&(dst_buffers[i])));
47+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
48+
buffer_size * sizeof(int32_t),
49+
(void **)&(src_buffers[i])));
50+
51+
ASSERT_SUCCESS(urEnqueueUSMFill(
52+
queue, src_buffers[i], sizeof(zero_pattern), &zero_pattern,
53+
buffer_size * sizeof(int32_t), 0, nullptr, nullptr));
5454
}
5555

56-
5756
ASSERT_SUCCESS(urQueueFinish(queue));
5857

5958
// Create command-buffer with a single kernel that does "Ptr[i] += 1;"
@@ -63,9 +62,12 @@ struct urEnqueueCommandBufferExpTest
6362
nullptr, 0, nullptr, 0, nullptr, 0, nullptr, nullptr, nullptr,
6463
nullptr));
6564

66-
65+
// Schedule memory copying in order to prolong the buffer execution
6766
for (int i = 0; i < num_copy_buffers; i++) {
68-
ASSERT_SUCCESS(urCommandBufferAppendUSMMemcpyExp(cmd_buf_handle, dst_buffers[i], src_buffers[i], buffer_size * sizeof(int), 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr));
67+
ASSERT_SUCCESS(urCommandBufferAppendUSMMemcpyExp(
68+
cmd_buf_handle, dst_buffers[i], src_buffers[i],
69+
buffer_size * sizeof(int32_t), 0, nullptr, 0, nullptr, nullptr,
70+
nullptr, nullptr));
6971
}
7072

7173
ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));
@@ -76,10 +78,6 @@ struct urEnqueueCommandBufferExpTest
7678
EXPECT_SUCCESS(urQueueRelease(in_or_out_of_order_queue));
7779
}
7880

79-
// if (out_of_order_queue) {
80-
// EXPECT_SUCCESS(urQueueRelease(out_of_order_queue));
81-
// }
82-
8381
if (device_ptr) {
8482
EXPECT_SUCCESS(urUSMFree(context, device_ptr));
8583
}
@@ -94,13 +92,11 @@ struct urEnqueueCommandBufferExpTest
9492
}
9593
}
9694

97-
UUR_RETURN_ON_FATAL_FAILURE(urCommandBufferExpExecutionTestWithParam::TearDown());
95+
UUR_RETURN_ON_FATAL_FAILURE(
96+
urCommandBufferExpExecutionTestWithParam::TearDown());
9897
}
9998

10099
ur_queue_handle_t in_or_out_of_order_queue = nullptr;
101-
ur_queue_flags_t queue_type; // = 0;
102-
103-
// ur_queue_handle_t out_of_order_queue = nullptr;
104100

105101
static constexpr size_t global_size = 16;
106102
static constexpr size_t global_offset = 0;
@@ -110,56 +106,52 @@ struct urEnqueueCommandBufferExpTest
110106

111107
static constexpr int num_copy_buffers = 10;
112108
static constexpr int buffer_size = 512;
113-
int* dst_buffers[num_copy_buffers];
114-
int* src_buffers[num_copy_buffers];
109+
int32_t *dst_buffers[num_copy_buffers] = {};
110+
int32_t *src_buffers[num_copy_buffers] = {};
115111
};
116112

117-
118113
std::string deviceTestWithQueueTypePrinter(
119-
const ::testing::TestParamInfo<std::tuple<uur::DeviceTuple, ur_queue_flags_t>> &info) {
114+
const ::testing::TestParamInfo<
115+
std::tuple<uur::DeviceTuple, ur_queue_flags_t>> &info) {
120116
auto device = std::get<0>(info.param).device;
121117
auto queue_type = std::get<1>(info.param);
122118

123119
std::stringstream ss;
124120

125121
switch (queue_type) {
126-
case 0:
127-
ss << "InOrderQueue";
128-
break;
122+
case 0:
123+
ss << "InOrderQueue";
124+
break;
129125

130-
// change to if and bitwise and?
131-
case UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE:
132-
ss << "OutOfOrderQueue";
133-
break;
126+
case UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE:
127+
ss << "OutOfOrderQueue";
128+
break;
134129

135-
default:
136-
ss << "UnspecifiedQueueType" << queue_type;
130+
default:
131+
ss << "UnspecifiedQueueType" << queue_type;
137132
}
138133

139-
140134
return uur::GetPlatformAndDeviceName(device) + "__" +
141135
uur::GTestSanitizeString(ss.str());
142136
}
143137

144-
// UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEnqueueCommandBufferExpTest);
145-
UUR_DEVICE_TEST_SUITE_WITH_PARAM(urEnqueueCommandBufferExpTest, testing::Values(0, UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE), deviceTestWithQueueTypePrinter);
138+
UUR_DEVICE_TEST_SUITE_WITH_PARAM(
139+
urEnqueueCommandBufferExpTest,
140+
testing::Values(0, UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE),
141+
deviceTestWithQueueTypePrinter);
146142

147143
// Tests that the same command-buffer submitted across different in-order
148144
// queues has an implicit dependency on first submission
149145
TEST_P(urEnqueueCommandBufferExpTest, SerializeAcrossQueues) {
150146
// Execute command-buffer to first in-order queue (created by parent
151-
// urQueueTest fixture)
152-
if (queue_type == UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE) {
153-
GTEST_SKIP() << "unwantedoutoforder";
154-
}
155-
147+
// urQueueTestWithParam fixture)
156148
ASSERT_SUCCESS(
157149
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
158150

159151
// Execute command-buffer to second in-order queue, should have implicit
160152
// dependency on first submission.
161-
ASSERT_SUCCESS(urEnqueueCommandBufferExp(in_or_out_of_order_queue, cmd_buf_handle, 0,
162-
nullptr, nullptr));
153+
ASSERT_SUCCESS(urEnqueueCommandBufferExp(
154+
in_or_out_of_order_queue, cmd_buf_handle, 0, nullptr, nullptr));
163155

164156
// Wait for both submissions to complete
165157
ASSERT_SUCCESS(urQueueFlush(queue));
@@ -177,47 +169,24 @@ TEST_P(urEnqueueCommandBufferExpTest, SerializeAcrossQueues) {
177169
}
178170
}
179171

180-
// // Tests that submitting a command-buffer twice to an out-of-order queue
181-
// // relying on implicit serialization semantics for dependencies.
182-
// TEST_P(urEnqueueCommandBufferExpTest, SerializeOutofOrderQueue) {
183-
// ASSERT_SUCCESS(urEnqueueCommandBufferExp(out_of_order_queue, cmd_buf_handle,
184-
// 0, nullptr, nullptr));
185-
// ASSERT_SUCCESS(urEnqueueCommandBufferExp(out_of_order_queue, cmd_buf_handle,
186-
// 0, nullptr, nullptr));
187-
188-
// // Wait for both submissions to complete
189-
// ASSERT_SUCCESS(urQueueFinish(out_of_order_queue));
190-
191-
// std::vector<uint32_t> Output(global_size);
192-
// ASSERT_SUCCESS(urEnqueueUSMMemcpy(out_of_order_queue, true, Output.data(),
193-
// device_ptr, allocation_size, 0, nullptr,
194-
// nullptr));
195-
196-
// // Verify
197-
// const uint32_t reference = 2;
198-
// for (size_t i = 0; i < global_size; i++) {
199-
// ASSERT_EQ(reference, Output[i]);
200-
// }
201-
// }
202-
203172
TEST_P(urEnqueueCommandBufferExpTest, SerializeInOrOutOfOrderQueue) {
204173
const int iterations = 5;
205174
for (int i = 0; i < iterations; i++) {
206-
ASSERT_SUCCESS(urEnqueueCommandBufferExp(in_or_out_of_order_queue, cmd_buf_handle,
207-
0, nullptr, nullptr));
175+
ASSERT_SUCCESS(urEnqueueCommandBufferExp(
176+
in_or_out_of_order_queue, cmd_buf_handle, 0, nullptr, nullptr));
208177
}
209178

210179
// Wait for both submissions to complete
211180
ASSERT_SUCCESS(urQueueFinish(in_or_out_of_order_queue));
212181

213182
std::vector<uint32_t> Output(global_size);
214-
ASSERT_SUCCESS(urEnqueueUSMMemcpy(in_or_out_of_order_queue, true, Output.data(),
215-
device_ptr, allocation_size, 0, nullptr,
216-
nullptr));
183+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(in_or_out_of_order_queue, true,
184+
Output.data(), device_ptr, allocation_size,
185+
0, nullptr, nullptr));
217186

218187
// Verify
219188
const uint32_t reference = iterations;
220189
for (size_t i = 0; i < global_size; i++) {
221190
ASSERT_EQ(reference, Output[i]);
222191
}
223-
}
192+
}

unified-runtime/test/conformance/exp_command_buffer/fixtures.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct urCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
9898
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
9999

100100
ur_exp_command_buffer_desc_t desc{UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC,
101-
nullptr, false, false /* WAS: false */, false};
101+
nullptr, false, false, false};
102102
ASSERT_SUCCESS(
103103
urCommandBufferCreateExp(context, device, &desc, &cmd_buf_handle));
104104
ASSERT_NE(cmd_buf_handle, nullptr);
@@ -115,9 +115,11 @@ struct urCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
115115
};
116116

117117
template <class T>
118-
struct urCommandBufferExpExecutionTestWithParam : urKernelExecutionTestWithParam<T> {
118+
struct urCommandBufferExpExecutionTestWithParam
119+
: urKernelExecutionTestWithParam<T> {
119120
void SetUp() override {
120-
UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTestWithParam<T>::SetUp());
121+
UUR_RETURN_ON_FATAL_FAILURE(
122+
uur::urKernelExecutionTestWithParam<T>::SetUp());
121123

122124
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(this->device));
123125

@@ -132,7 +134,8 @@ struct urCommandBufferExpExecutionTestWithParam : urKernelExecutionTestWithParam
132134
if (cmd_buf_handle) {
133135
EXPECT_SUCCESS(urCommandBufferReleaseExp(cmd_buf_handle));
134136
}
135-
UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTestWithParam<T>::TearDown());
137+
UUR_RETURN_ON_FATAL_FAILURE(
138+
uur::urKernelExecutionTestWithParam<T>::TearDown());
136139
}
137140

138141
ur_exp_command_buffer_handle_t cmd_buf_handle = nullptr;

0 commit comments

Comments
 (0)