Skip to content

Commit

Permalink
Add test multi_flag_creation
Browse files Browse the repository at this point in the history
This tests that the `CL_COMMAND_BUFFER_FLAGS_KHR` bitfield is parsed
correctly when multiple flags are set.

Signed-off-by: Gorazd Sumkovski <gorazd.sumkovski@arm.com>
  • Loading branch information
gorazd-sumkovski-arm committed Nov 5, 2024
1 parent 5e1e551 commit b594210
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,71 @@ cl_int BasicCommandBufferTest::SetUp(int elements)

namespace {

// Test that the CL_COMMAND_BUFFER_FLAGS_KHR bitfield is parsed correctly when
// multiple flags are set.
struct MultiFlagCreationTest : public BasicCommandBufferTest
{
using BasicCommandBufferTest::BasicCommandBufferTest;

cl_int Run() override
{
cl_command_buffer_properties_khr flags = 0;
size_t num_flags_set = 0;
bool mutli_flags_supported = true;
cl_int error = CL_SUCCESS;

// First try to find mutliple flags that are supported by the driver and
// device.
if (simultaneous_use_support)
{
flags |= CL_COMMAND_BUFFER_SIMULTANEOUS_USE_KHR;
num_flags_set++;
}

if (device_side_enqueue_support)
{
flags |= CL_COMMAND_BUFFER_DEVICE_SIDE_SYNC_KHR;
num_flags_set++;
}

if (is_extension_available(
device, CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_NAME))
{
flags |= CL_COMMAND_BUFFER_MUTABLE_KHR;
num_flags_set++;
}

// If we can't find mutliple supported flags, still set a bitfield but
// expect CL_INVALID_PROPERTY to be returned on creation.
if (num_flags_set < 2)
{
flags = CL_COMMAND_BUFFER_SIMULTANEOUS_USE_KHR
| CL_COMMAND_BUFFER_DEVICE_SIDE_SYNC_KHR;

mutli_flags_supported = false;
}

cl_command_buffer_properties_khr props[] = {
CL_COMMAND_BUFFER_FLAGS_KHR, flags, 0
};

command_buffer = clCreateCommandBufferKHR(1, &queue, props, &error);
if (mutli_flags_supported)
{
test_error(error, "clCreateCommandBufferKHR failed");
}
else
{
test_failure_error_ret(
error, CL_INVALID_PROPERTY,
"clCreateCommandBufferKHR should return CL_INVALID_PROPERTY",
TEST_FAIL);
}

return CL_SUCCESS;
}
};

// Test enqueuing a command-buffer containing a single NDRange command once
struct BasicEnqueueTest : public BasicCommandBufferTest
{
Expand Down Expand Up @@ -424,6 +489,13 @@ struct InterleavedEnqueueTest : public BasicCommandBufferTest

} // anonymous namespace

int test_multi_flag_creation(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
return MakeAndRunTest<MultiFlagCreationTest>(device, context, queue,
num_elements);
}

int test_single_ndrange(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
Expand Down
1 change: 1 addition & 0 deletions test_conformance/extensions/cl_khr_command_buffer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "harness/testHarness.h"

test_definition test_list[] = {
ADD_TEST(multi_flag_creation),
ADD_TEST(single_ndrange),
ADD_TEST(interleaved_enqueue),
ADD_TEST(mixed_commands),
Expand Down
2 changes: 2 additions & 0 deletions test_conformance/extensions/cl_khr_command_buffer/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <CL/cl.h>

// Basic command-buffer tests
extern int test_multi_flag_creation(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_single_ndrange(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_interleaved_enqueue(cl_device_id device, cl_context context,
Expand Down

0 comments on commit b594210

Please sign in to comment.