Skip to content

Commit

Permalink
add proper error checking for non-NULL mutable handles (#104)
Browse files Browse the repository at this point in the history
This change enables the new negative CTS test to pass.
  • Loading branch information
bashbaug authored Jan 25, 2024
1 parent f441f29 commit 3bc2234
Showing 1 changed file with 61 additions and 34 deletions.
95 changes: 61 additions & 34 deletions layers/10_cmdbufemu/emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,26 +1359,18 @@ typedef struct _cl_command_buffer_khr
cl_int checkRecordErrors(
cl_command_queue queue,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr* sync_point_wait_list,
cl_mutable_command_khr* mutable_handle )
const cl_sync_point_khr* sync_point_wait_list )
{
if( State != CL_COMMAND_BUFFER_STATE_RECORDING_KHR )
{
return CL_INVALID_OPERATION;
}
if( queue != NULL )
if( queue != nullptr )
{
return CL_INVALID_COMMAND_QUEUE;
}
// TODO: Change this to a runtime check?
#if !defined(cl_khr_command_buffer_mutable_dispatch)
if( mutable_handle != NULL )
{
return CL_INVALID_VALUE;
}
#endif // !defined(cl_khr_command_buffer_mutable_dispatch)
if( ( sync_point_wait_list == NULL && num_sync_points_in_wait_list > 0 ) ||
( sync_point_wait_list != NULL && num_sync_points_in_wait_list == 0 ) )
if( ( sync_point_wait_list == nullptr && num_sync_points_in_wait_list > 0 ) ||
( sync_point_wait_list != nullptr && num_sync_points_in_wait_list == 0 ) )
{
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR;
}
Expand Down Expand Up @@ -1741,11 +1733,14 @@ cl_int CL_API_CALL clCommandBarrierWithWaitListKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
BarrierWithWaitList::create(cmdbuf, command_queue),
Expand Down Expand Up @@ -1779,11 +1774,14 @@ cl_int CL_API_CALL clCommandCopyBufferKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
CopyBuffer::create(
Expand Down Expand Up @@ -1828,11 +1826,14 @@ cl_int CL_API_CALL clCommandCopyBufferRectKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
CopyBufferRect::create(
Expand Down Expand Up @@ -1877,11 +1878,14 @@ cl_int CL_API_CALL clCommandCopyBufferToImageKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
CopyBufferToImage::create(
Expand Down Expand Up @@ -1922,11 +1926,14 @@ cl_int CL_API_CALL clCommandCopyImageKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
CopyImage::create(
Expand Down Expand Up @@ -1967,11 +1974,14 @@ cl_int CL_API_CALL clCommandCopyImageToBufferKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
CopyImageToBuffer::create(
Expand Down Expand Up @@ -2012,11 +2022,14 @@ cl_int CL_API_CALL clCommandFillBufferKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
FillBuffer::create(
Expand Down Expand Up @@ -2056,11 +2069,14 @@ cl_int CL_API_CALL clCommandFillImageKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
FillImage::create(
Expand Down Expand Up @@ -2098,11 +2114,14 @@ cl_int CL_API_CALL clCommandSVMMemcpyKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
SVMMemcpy::create(
Expand Down Expand Up @@ -2140,11 +2159,14 @@ cl_int CL_API_CALL clCommandSVMMemFillKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}

cmdbuf->addCommand(
SVMMemFill::create(
Expand Down Expand Up @@ -2185,11 +2207,16 @@ cl_int CL_API_CALL clCommandNDRangeKernelKHR_EMU(
if( cl_int errorCode = cmdbuf->checkRecordErrors(
command_queue,
num_sync_points_in_wait_list,
sync_point_wait_list,
mutable_handle) )
sync_point_wait_list) )
{
return errorCode;
}
#if !defined(cl_khr_command_buffer_mutable_dispatch)
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
}
#endif // cl_khr_command_buffer_mutable_dispatch

cl_int errorCode = CL_SUCCESS;
auto command = NDRangeKernel::create(
Expand Down

0 comments on commit 3bc2234

Please sign in to comment.