Skip to content

Commit 0173bf6

Browse files
committed
[UR] Make command-buffer creation descriptor mandatory
As discussed in oneapi-src/unified-runtime#2670 (comment) the `pCommandBufferDesc` parameter to `urCommandBufferCreateExp` is optional. However, the UR spec doesn't state what the configuration of the created command-buffer is when this isn't passed, and being optional is also inconsistent with the description parameters to urSamplerCreate & urMemImageCreate which are not optional. This PR updates the descriptor parameter to command-buffer creation to be mandatory to address these concerns. Closes oneapi-src/unified-runtime#2673
1 parent 0f7fca9 commit 0173bf6

File tree

16 files changed

+49
-40
lines changed

16 files changed

+49
-40
lines changed

unified-runtime/include/ur_api.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -10111,6 +10111,7 @@ typedef struct ur_exp_command_buffer_command_handle_t_
1011110111
/// + `NULL == hContext`
1011210112
/// + `NULL == hDevice`
1011310113
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
10114+
/// + `NULL == pCommandBufferDesc`
1011410115
/// + `NULL == phCommandBuffer`
1011510116
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
1011610117
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
@@ -10125,7 +10126,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
1012510126
ur_context_handle_t hContext,
1012610127
/// [in] Handle of the device object.
1012710128
ur_device_handle_t hDevice,
10128-
/// [in][optional] command-buffer descriptor.
10129+
/// [in] Command-buffer descriptor.
1012910130
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
1013010131
/// [out][alloc] Pointer to command-Buffer handle.
1013110132
ur_exp_command_buffer_handle_t *phCommandBuffer);

unified-runtime/scripts/core/exp-command-buffer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ params:
282282
desc: "[in] Handle of the device object."
283283
- type: "const $x_exp_command_buffer_desc_t*"
284284
name: pCommandBufferDesc
285-
desc: "[in][optional] command-buffer descriptor."
285+
desc: "[in] Command-buffer descriptor."
286286
- type: "$x_exp_command_buffer_handle_t*"
287287
name: phCommandBuffer
288288
desc: "[out][alloc] Pointer to command-Buffer handle."

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
352352
ur_context_handle_t hContext, ur_device_handle_t hDevice,
353353
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
354354
ur_exp_command_buffer_handle_t *phCommandBuffer) {
355-
356-
const bool IsUpdatable =
357-
pCommandBufferDesc ? pCommandBufferDesc->isUpdatable : false;
358-
355+
const bool IsUpdatable = pCommandBufferDesc->isUpdatable;
359356
try {
360357
*phCommandBuffer =
361358
new ur_exp_command_buffer_handle_t_(hContext, hDevice, IsUpdatable);

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
233233
ur_context_handle_t hContext, ur_device_handle_t hDevice,
234234
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
235235
ur_exp_command_buffer_handle_t *phCommandBuffer) {
236-
const bool IsUpdatable =
237-
pCommandBufferDesc ? pCommandBufferDesc->isUpdatable : false;
238-
236+
const bool IsUpdatable = pCommandBufferDesc->isUpdatable;
239237
try {
240238
*phCommandBuffer =
241239
new ur_exp_command_buffer_handle_t_(hContext, hDevice, IsUpdatable);

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,7 @@ bool canBeInOrder(ur_context_handle_t Context,
586586
bool CompatibleDriver = Context->getPlatform()->isDriverVersionNewerOrSimilar(
587587
1, 3, L0_DRIVER_INORDER_MIN_VERSION);
588588
bool CanUseDriverInOrderLists = CompatibleDriver && DriverInOrderRequested;
589-
return CanUseDriverInOrderLists
590-
? (CommandBufferDesc ? CommandBufferDesc->isInOrder : false)
591-
: false;
589+
return CanUseDriverInOrderLists ? CommandBufferDesc->isInOrder : false;
592590
}
593591

594592
/**
@@ -624,9 +622,8 @@ urCommandBufferCreateExp(ur_context_handle_t Context, ur_device_handle_t Device,
624622
const ur_exp_command_buffer_desc_t *CommandBufferDesc,
625623
ur_exp_command_buffer_handle_t *CommandBuffer) {
626624
bool IsInOrder = canBeInOrder(Context, CommandBufferDesc);
627-
bool EnableProfiling =
628-
CommandBufferDesc && CommandBufferDesc->enableProfiling && !IsInOrder;
629-
bool IsUpdatable = CommandBufferDesc && CommandBufferDesc->isUpdatable;
625+
bool EnableProfiling = CommandBufferDesc->enableProfiling && !IsInOrder;
626+
bool IsUpdatable = CommandBufferDesc->isUpdatable;
630627
bool ImmediateAppendPath = checkImmediateAppendSupport(Context, Device);
631628
const bool WaitEventPath = !ImmediateAppendPath;
632629
bool UseCounterBasedEvents = checkCounterBasedEventsSupport(Device) &&

unified-runtime/source/adapters/mock/ur_mockddi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8403,7 +8403,7 @@ __urdlllocal ur_result_t UR_APICALL urCommandBufferCreateExp(
84038403
ur_context_handle_t hContext,
84048404
/// [in] Handle of the device object.
84058405
ur_device_handle_t hDevice,
8406-
/// [in][optional] command-buffer descriptor.
8406+
/// [in] Command-buffer descriptor.
84078407
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
84088408
/// [out][alloc] Pointer to command-Buffer handle.
84098409
ur_exp_command_buffer_handle_t *phCommandBuffer) try {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
4343
CLContext, cl_ext::ExtFuncPtrCache->clCreateCommandBufferKHRCache,
4444
cl_ext::CreateCommandBufferName, &clCreateCommandBufferKHR));
4545

46-
const bool IsUpdatable =
47-
pCommandBufferDesc ? pCommandBufferDesc->isUpdatable : false;
46+
const bool IsUpdatable = pCommandBufferDesc->isUpdatable;
4847

4948
ur_device_command_buffer_update_capability_flags_t UpdateCapabilities;
5049
cl_device_id CLDevice = cl_adapter::cast<cl_device_id>(hDevice);

unified-runtime/source/loader/layers/tracing/ur_trcddi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6978,7 +6978,7 @@ __urdlllocal ur_result_t UR_APICALL urCommandBufferCreateExp(
69786978
ur_context_handle_t hContext,
69796979
/// [in] Handle of the device object.
69806980
ur_device_handle_t hDevice,
6981-
/// [in][optional] command-buffer descriptor.
6981+
/// [in] Command-buffer descriptor.
69826982
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
69836983
/// [out][alloc] Pointer to command-Buffer handle.
69846984
ur_exp_command_buffer_handle_t *phCommandBuffer) {

unified-runtime/source/loader/layers/validation/ur_valddi.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -7615,7 +7615,7 @@ __urdlllocal ur_result_t UR_APICALL urCommandBufferCreateExp(
76157615
ur_context_handle_t hContext,
76167616
/// [in] Handle of the device object.
76177617
ur_device_handle_t hDevice,
7618-
/// [in][optional] command-buffer descriptor.
7618+
/// [in] Command-buffer descriptor.
76197619
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
76207620
/// [out][alloc] Pointer to command-Buffer handle.
76217621
ur_exp_command_buffer_handle_t *phCommandBuffer) {
@@ -7632,6 +7632,9 @@ __urdlllocal ur_result_t UR_APICALL urCommandBufferCreateExp(
76327632
if (NULL == hDevice)
76337633
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
76347634

7635+
if (NULL == pCommandBufferDesc)
7636+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
7637+
76357638
if (NULL == phCommandBuffer)
76367639
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
76377640
}

unified-runtime/source/loader/ur_ldrddi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7044,7 +7044,7 @@ __urdlllocal ur_result_t UR_APICALL urCommandBufferCreateExp(
70447044
ur_context_handle_t hContext,
70457045
/// [in] Handle of the device object.
70467046
ur_device_handle_t hDevice,
7047-
/// [in][optional] command-buffer descriptor.
7047+
/// [in] Command-buffer descriptor.
70487048
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
70497049
/// [out][alloc] Pointer to command-Buffer handle.
70507050
ur_exp_command_buffer_handle_t *phCommandBuffer) {

unified-runtime/source/loader/ur_libapi.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7619,6 +7619,7 @@ ur_result_t UR_APICALL urBindlessImagesSignalExternalSemaphoreExp(
76197619
/// + `NULL == hContext`
76207620
/// + `NULL == hDevice`
76217621
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
7622+
/// + `NULL == pCommandBufferDesc`
76227623
/// + `NULL == phCommandBuffer`
76237624
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
76247625
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
@@ -7633,7 +7634,7 @@ ur_result_t UR_APICALL urCommandBufferCreateExp(
76337634
ur_context_handle_t hContext,
76347635
/// [in] Handle of the device object.
76357636
ur_device_handle_t hDevice,
7636-
/// [in][optional] command-buffer descriptor.
7637+
/// [in] Command-buffer descriptor.
76377638
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
76387639
/// [out][alloc] Pointer to command-Buffer handle.
76397640
ur_exp_command_buffer_handle_t *phCommandBuffer) try {

unified-runtime/source/ur_api.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -6664,6 +6664,7 @@ ur_result_t UR_APICALL urBindlessImagesSignalExternalSemaphoreExp(
66646664
/// + `NULL == hContext`
66656665
/// + `NULL == hDevice`
66666666
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
6667+
/// + `NULL == pCommandBufferDesc`
66676668
/// + `NULL == phCommandBuffer`
66686669
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
66696670
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
@@ -6678,7 +6679,7 @@ ur_result_t UR_APICALL urCommandBufferCreateExp(
66786679
ur_context_handle_t hContext,
66796680
/// [in] Handle of the device object.
66806681
ur_device_handle_t hDevice,
6681-
/// [in][optional] command-buffer descriptor.
6682+
/// [in] Command-buffer descriptor.
66826683
const ur_exp_command_buffer_desc_t *pCommandBufferDesc,
66836684
/// [out][alloc] Pointer to command-Buffer handle.
66846685
ur_exp_command_buffer_handle_t *phCommandBuffer) {

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

+16-13
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ struct urCommandBufferExpTest : uur::urContextTest {
6060
UUR_RETURN_ON_FATAL_FAILURE(uur::urContextTest::SetUp());
6161

6262
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
63+
64+
ur_exp_command_buffer_desc_t desc{
65+
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC, nullptr, false, false, false,
66+
};
6367
ASSERT_SUCCESS(
64-
urCommandBufferCreateExp(context, device, nullptr, &cmd_buf_handle));
68+
urCommandBufferCreateExp(context, device, &desc, &cmd_buf_handle));
6569
ASSERT_NE(cmd_buf_handle, nullptr);
6670
}
6771

@@ -83,8 +87,11 @@ struct urCommandBufferExpTestWithParam : urQueueTestWithParam<T> {
8387
UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTestWithParam<T>::SetUp());
8488

8589
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(this->device));
86-
ASSERT_SUCCESS(urCommandBufferCreateExp(this->context, this->device,
87-
nullptr, &cmd_buf_handle));
90+
91+
ur_exp_command_buffer_desc_t desc{UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC,
92+
nullptr, false, false, false};
93+
ASSERT_SUCCESS(urCommandBufferCreateExp(this->context, this->device, &desc,
94+
&cmd_buf_handle));
8895
ASSERT_NE(cmd_buf_handle, nullptr);
8996
}
9097

@@ -105,8 +112,11 @@ struct urCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
105112
UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());
106113

107114
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
115+
116+
ur_exp_command_buffer_desc_t desc{UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC,
117+
nullptr, false, false, false};
108118
ASSERT_SUCCESS(
109-
urCommandBufferCreateExp(context, device, nullptr, &cmd_buf_handle));
119+
urCommandBufferCreateExp(context, device, &desc, &cmd_buf_handle));
110120
ASSERT_NE(cmd_buf_handle, nullptr);
111121
}
112122

@@ -333,15 +343,8 @@ struct urCommandEventSyncTest : urCommandBufferExpTest {
333343
ASSERT_NE(buffer, nullptr);
334344
}
335345

336-
// Create a command-buffer with update enabled.
337-
ur_exp_command_buffer_desc_t desc{
338-
/*.stype=*/UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC,
339-
/*.pNext =*/nullptr,
340-
/*.isUpdatable =*/false,
341-
/*.isInOrder =*/false,
342-
/*.enableProfiling =*/false,
343-
};
344-
346+
ur_exp_command_buffer_desc_t desc{UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC,
347+
nullptr, true, false, false};
345348
ASSERT_SUCCESS(urCommandBufferCreateExp(context, device, &desc,
346349
&second_cmd_buf_handle));
347350
ASSERT_NE(second_cmd_buf_handle, nullptr);

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ struct KernelCommandEventSyncTest
4040
ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 3, nullptr, device_ptrs[1]));
4141

4242
// Create second command-buffer
43-
ASSERT_SUCCESS(urCommandBufferCreateExp(context, device, nullptr,
43+
ur_exp_command_buffer_desc_t desc{
44+
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC, nullptr, false, false, false,
45+
};
46+
ASSERT_SUCCESS(urCommandBufferCreateExp(context, device, &desc,
4447
&second_cmd_buf_handle));
4548
ASSERT_NE(second_cmd_buf_handle, nullptr);
4649
}

unified-runtime/test/conformance/exp_command_buffer/update/invalid_update.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ TEST_P(InvalidUpdateTest, NotFinalizedCommandBuffer) {
109109
TEST_P(InvalidUpdateTest, NotUpdatableCommandBuffer) {
110110
// Create a command-buffer without isUpdatable
111111
ur_exp_command_buffer_handle_t test_cmd_buf_handle = nullptr;
112+
ur_exp_command_buffer_desc_t desc{
113+
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC, nullptr, false, false, false,
114+
};
112115
ASSERT_SUCCESS(
113-
urCommandBufferCreateExp(context, device, nullptr, &test_cmd_buf_handle));
116+
urCommandBufferCreateExp(context, device, &desc, &test_cmd_buf_handle));
114117
EXPECT_NE(test_cmd_buf_handle, nullptr);
115118

116119
// Append a kernel commands to command-buffer and close command-buffer

unified-runtime/test/conformance/program/urMultiDeviceProgramCreateWithBinary.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ TEST_P(urMultiDeviceCommandBufferExpTest, Enqueue) {
311311
}
312312

313313
// Create command-buffer
314+
ur_exp_command_buffer_desc_t desc{
315+
UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC, nullptr, false, false, false,
316+
};
314317
uur::raii::CommandBuffer cmd_buf_handle;
315-
ASSERT_SUCCESS(urCommandBufferCreateExp(context, device, nullptr,
316-
cmd_buf_handle.ptr()));
318+
ASSERT_SUCCESS(
319+
urCommandBufferCreateExp(context, device, &desc, cmd_buf_handle.ptr()));
317320

318321
// Append kernel command to command-buffer and close command-buffer
319322
ASSERT_SUCCESS(urCommandBufferAppendKernelLaunchExp(

0 commit comments

Comments
 (0)