Skip to content

Commit

Permalink
Added test to verify flush on clReleaseCommandQueue with multiple que…
Browse files Browse the repository at this point in the history
…ues (#2134)

Fixes #2087 according to task description.
  • Loading branch information
shajder authored Jan 28, 2025
1 parent 5b35180 commit c6cfb68
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion test_conformance/api/test_queue.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2020 The Khronos Group Inc.
// Copyright (c) 2024 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,3 +58,61 @@ REGISTER_TEST(queue_flush_on_release)

return success ? TEST_PASS : TEST_FAIL;
}

REGISTER_TEST(multi_queue_flush_on_release)
{
cl_int err;

// Create A command queue
cl_command_queue queue_A = clCreateCommandQueue(context, device, 0, &err);
test_error(err, "Could not create command queue A");

// Create B command queue
cl_command_queue queue_B = clCreateCommandQueue(context, device, 0, &err);
test_error(err, "Could not create command queue B");

// Create a kernel
clProgramWrapper program;
clKernelWrapper kernel;
const char *source = "void kernel test(){}";
err = create_single_kernel_helper(context, &program, &kernel, 1, &source,
"test");
test_error(err, "Could not create kernel");

// Enqueue the kernel on queue_A and obtain event to synchronize with
// queue_B
size_t gws = num_elements;
clEventWrapper event_A;
err = clEnqueueNDRangeKernel(queue_A, kernel, 1, nullptr, &gws, nullptr, 0,
nullptr, &event_A);
test_error(err, "Could not enqueue kernel");

// Enqueue the kernel on queue_B using event_A for synchronization and
// create event_B to track completion
clEventWrapper event_B;
err = clEnqueueNDRangeKernel(queue_B, kernel, 1, nullptr, &gws, nullptr, 1,
&event_A, &event_B);
test_error(err, "Could not enqueue kernel");

// Release queue_A, which performs an implicit flush to issue any previously
// queued OpenCL commands
err = clReleaseCommandQueue(queue_A);
test_error(err, "clReleaseCommandQueue failed");

err = clFlush(queue_B);
test_error(err, "clFlush failed");

// Wait for kernel to execute since the queue must flush on release
bool success = poll_until(2000, 50, [&event_B]() {
cl_int status;
cl_int err = clGetEventInfo(event_B, CL_EVENT_COMMAND_EXECUTION_STATUS,
sizeof(cl_int), &status, nullptr);
if ((err != CL_SUCCESS) || (status != CL_COMPLETE))
{
return false;
}
return true;
});

return success ? TEST_PASS : TEST_FAIL;
}

0 comments on commit c6cfb68

Please sign in to comment.