Skip to content

Commit 9f5fe08

Browse files
committed
Error if updatable command-buffer created without device support
1 parent 7e40f62 commit 9f5fe08

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

include/ur_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7929,6 +7929,8 @@ typedef struct ur_exp_command_buffer_command_handle_t_ *ur_exp_command_buffer_co
79297929
/// + `NULL == phCommandBuffer`
79307930
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
79317931
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
7932+
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
7933+
/// + If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP.
79327934
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
79337935
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
79347936
UR_APIEXPORT ur_result_t UR_APICALL

scripts/core/exp-command-buffer.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ params:
261261
returns:
262262
- $X_RESULT_ERROR_INVALID_CONTEXT
263263
- $X_RESULT_ERROR_INVALID_DEVICE
264+
- $X_RESULT_ERROR_INVALID_OPERATION:
265+
- "If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP."
264266
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
265267
- $X_RESULT_ERROR_OUT_OF_RESOURCES
266268
--- #--------------------------------------------------------------------------

source/adapters/opencl/command_buffer.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
4848
CLContext, cl_ext::ExtFuncPtrCache->clReleaseCommandBufferKHRCache,
4949
cl_ext::ReleaseCommandBufferName, &clReleaseCommandBufferKHR);
5050
assert(Res == CL_SUCCESS);
51+
(void)Res;
5152

5253
clReleaseCommandBufferKHR(CLCommandBuffer);
5354
}
@@ -73,23 +74,25 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
7374
const bool IsUpdatable =
7475
pCommandBufferDesc ? pCommandBufferDesc->isUpdatable : false;
7576

76-
bool SupportsUpdate = false;
77+
bool DeviceSupportsUpdate = false;
7778
cl_device_id CLDevice = cl_adapter::cast<cl_device_id>(hDevice);
78-
CL_RETURN_ON_FAILURE(
79-
deviceSupportsURCommandBufferKernelUpdate(CLDevice, SupportsUpdate));
79+
CL_RETURN_ON_FAILURE(deviceSupportsURCommandBufferKernelUpdate(
80+
CLDevice, DeviceSupportsUpdate));
8081

81-
const bool Updatable = IsUpdatable && SupportsUpdate;
82+
if (IsUpdatable && !DeviceSupportsUpdate) {
83+
return UR_RESULT_ERROR_INVALID_OPERATION;
84+
}
8285

8386
cl_command_buffer_properties_khr Properties[3] = {
8487
CL_COMMAND_BUFFER_FLAGS_KHR,
85-
Updatable ? CL_COMMAND_BUFFER_MUTABLE_KHR : 0u, 0};
88+
IsUpdatable ? CL_COMMAND_BUFFER_MUTABLE_KHR : 0u, 0};
8689
auto CLCommandBuffer = clCreateCommandBufferKHR(
8790
1, cl_adapter::cast<cl_command_queue *>(&Queue), Properties, &Res);
8891
CL_RETURN_ON_FAILURE_AND_SET_NULL(Res, phCommandBuffer);
8992

9093
try {
9194
auto URCommandBuffer = std::make_unique<ur_exp_command_buffer_handle_t_>(
92-
Queue, hContext, CLCommandBuffer, Updatable);
95+
Queue, hContext, CLCommandBuffer, IsUpdatable);
9396
*phCommandBuffer = URCommandBuffer.release();
9497
} catch (...) {
9598
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
@@ -499,7 +502,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
499502
ArgPointerList[i];
500503
cl_mutable_dispatch_arg_khr &USMArg = CLUSMArgs[i];
501504
USMArg.arg_index = URPointerArg.argIndex;
502-
USMArg.arg_value = *(void **)URPointerArg.pNewPointerArg;
505+
USMArg.arg_value = *(void *const *)URPointerArg.pNewPointerArg;
503506
}
504507

505508
// Find the memory object and scalar arguments to the kernel.

source/loader/ur_libapi.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7030,6 +7030,8 @@ ur_result_t UR_APICALL urBindlessImagesSignalExternalSemaphoreExp(
70307030
/// + `NULL == phCommandBuffer`
70317031
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
70327032
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
7033+
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
7034+
/// + If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP.
70337035
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
70347036
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
70357037
ur_result_t UR_APICALL urCommandBufferCreateExp(

source/ur_api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5966,6 +5966,8 @@ ur_result_t UR_APICALL urBindlessImagesSignalExternalSemaphoreExp(
59665966
/// + `NULL == phCommandBuffer`
59675967
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
59685968
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
5969+
/// - ::UR_RESULT_ERROR_INVALID_OPERATION
5970+
/// + If `pCommandBufferDesc->isUpdatable` is true and `hDevice` does not support UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP.
59695971
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
59705972
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
59715973
ur_result_t UR_APICALL urCommandBufferCreateExp(

test/conformance/exp_command_buffer/invalid_update.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ struct InvalidUpdateTest
4343
void TearDown() override {
4444
// Workaround an issue with the OpenCL adapter implementing urUsmFree
4545
// using a blocking free where hangs
46-
EXPECT_SUCCESS(urCommandBufferFinalizeExp(updatable_cmd_buf_handle));
46+
if (updatable_cmd_buf_handle) {
47+
EXPECT_SUCCESS(
48+
urCommandBufferFinalizeExp(updatable_cmd_buf_handle));
49+
}
4750

4851
if (shared_ptr) {
4952
EXPECT_SUCCESS(urUSMFree(context, shared_ptr));

0 commit comments

Comments
 (0)