Skip to content

Commit

Permalink
Return correct clEnqueueCommandBufferKHR errors
Browse files Browse the repository at this point in the history
We aren't returning the correct errors as specified by
`clEnqueueCommandBufferKHR`.

Issues we're found based on testing of CTS PR KhronosGroup/OpenCL-CTS#1931
that verifies these errors.

UnitCL tests need updating too, which were checking for incorrect
error codes.
  • Loading branch information
EwanC committed Apr 9, 2024
1 parent b7afa18 commit b7c150b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
17 changes: 13 additions & 4 deletions source/cl/source/extension/source/khr_command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,15 +1251,24 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueCommandBufferKHR(
const tracer::TraceGuard<tracer::OpenCL> guard("clEnqueueCommandBufferKHR");

// Verify queue arguments.
OCL_CHECK(!queues ^ !num_queues, return CL_INVALID_COMMAND_QUEUE);
OCL_CHECK(!queues ^ !num_queues, return CL_INVALID_VALUE);
// We currently only support one queue associated with the command buffer.
OCL_CHECK(num_queues > 0 && num_queues != 1, return CL_INVALID_COMMAND_QUEUE);
OCL_CHECK(queues && !command_buffer->isQueueCompatible(*queues),
return CL_INVALID_COMMAND_QUEUE);
OCL_CHECK(num_queues > 0 && num_queues != 1, return CL_INVALID_VALUE);

OCL_CHECK(!command_buffer, return CL_INVALID_COMMAND_BUFFER_KHR);
OCL_CHECK(!command_buffer->is_finalized, return CL_INVALID_OPERATION);

OCL_CHECK(queues && !(*queues), return CL_INVALID_COMMAND_QUEUE);

OCL_CHECK(queues && !command_buffer->isQueueCompatible(*queues),
return CL_INCOMPATIBLE_COMMAND_QUEUE_KHR);

if (auto error = cl::validate::EventWaitList(
num_events_in_wait_list, event_wait_list,
command_buffer->command_queue->context, return_event)) {
return error;
}

// Command-buffer property needs to be set to support re-enqueue while
// a previous instance is in flight
if (!command_buffer->supportsSimultaneousUse() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ TEST_F(SubstituteCommandQueueTest, CompatibleQueueSimultaneousWithFlag) {
TEST_F(SubstituteCommandQueueTest, NullQueues) {
// Enqueue the command buffer substituting with null command queue parameter
// but non-zero command queue length.
ASSERT_EQ_ERRCODE(CL_INVALID_COMMAND_QUEUE,
ASSERT_EQ_ERRCODE(CL_INVALID_VALUE,
clEnqueueCommandBufferKHR(1, nullptr, command_buffer, 0,
nullptr, nullptr));
}
Expand All @@ -893,8 +893,8 @@ TEST_F(SubstituteCommandQueueTest, ZeroQueues) {

// Enqueue the command buffer substituting with non-null command queue
// parameter but zero command queue length.
ASSERT_EQ_ERRCODE(
CL_INVALID_COMMAND_QUEUE,
EXPECT_EQ_ERRCODE(
CL_INVALID_VALUE,
clEnqueueCommandBufferKHR(0, &compatible_command_queue, command_buffer, 0,
nullptr, nullptr));

Expand All @@ -917,7 +917,7 @@ TEST_F(SubstituteCommandQueueTest, InvalidNumberQueues) {
// buffer creation.
cl_command_queue command_queues[] = {first_compatible_command_queue,
second_compatible_command_queue};
ASSERT_EQ_ERRCODE(CL_INVALID_COMMAND_QUEUE,
EXPECT_EQ_ERRCODE(CL_INVALID_VALUE,
clEnqueueCommandBufferKHR(2, command_queues, command_buffer,
0, nullptr, nullptr));

Expand All @@ -936,8 +936,8 @@ TEST_F(SubstituteCommandQueueTest, IncompatibleQueueProperties) {
EXPECT_SUCCESS(error);

// Enqueue the command buffer substituting with incompatible command queue.
ASSERT_EQ_ERRCODE(
CL_INVALID_COMMAND_QUEUE,
EXPECT_EQ_ERRCODE(
CL_INCOMPATIBLE_COMMAND_QUEUE_KHR,
clEnqueueCommandBufferKHR(1, &incompatible_command_queue, command_buffer,
0, nullptr, nullptr));

Expand Down Expand Up @@ -1002,8 +1002,8 @@ TEST_F(SubstituteCommandQueueTest, IncompatibleQueueContext) {
EXPECT_SUCCESS(error);

// Enqueue the command buffer substituting with incompatible command queue.
ASSERT_EQ_ERRCODE(
CL_INVALID_COMMAND_QUEUE,
EXPECT_EQ_ERRCODE(
CL_INCOMPATIBLE_COMMAND_QUEUE_KHR,
clEnqueueCommandBufferKHR(1, &incompatible_command_queue, command_buffer,
0, nullptr, nullptr));

Expand Down

0 comments on commit b7c150b

Please sign in to comment.