Skip to content

Commit

Permalink
Added missing test cases for CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR quer…
Browse files Browse the repository at this point in the history
…ies (#2063)

According to comments from issue #1875

---------

Co-authored-by: Nikhil Joshi <nikhilj@nvidia.com>
  • Loading branch information
shajder and nikhiljnv authored Oct 15, 2024
1 parent 1527c4e commit 2998463
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(${MODULE_NAME}_SOURCES
test_semaphores_negative_release_retain.cpp
test_semaphores_negative_getinfo.cpp
test_semaphores_negative_create.cpp
test_semaphores_queries.cpp
semaphore_base.h
)

Expand Down
4 changes: 3 additions & 1 deletion test_conformance/extensions/cl_khr_semaphore/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ test_definition test_list[] = {
ADD_TEST_VERSION(semaphores_cross_queues_io, Version(1, 2)),
ADD_TEST_VERSION(semaphores_multi_signal, Version(1, 2)),
ADD_TEST_VERSION(semaphores_multi_wait, Version(1, 2)),
ADD_TEST_VERSION(semaphores_queries, Version(1, 2)),
ADD_TEST_VERSION(semaphores_device_list_queries, Version(1, 2)),
ADD_TEST_VERSION(semaphores_no_device_list_queries, Version(1, 2)),
ADD_TEST_VERSION(semaphores_multi_device_context_queries, Version(1, 2)),
ADD_TEST_VERSION(semaphores_import_export_fd, Version(1, 2)),
ADD_TEST_VERSION(semaphores_negative_create_invalid_context, Version(1, 2)),
ADD_TEST_VERSION(semaphores_negative_create_invalid_property,
Expand Down
14 changes: 12 additions & 2 deletions test_conformance/extensions/cl_khr_semaphore/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ extern int test_semaphores_multi_signal(cl_device_id deviceID,
int num_elements);
extern int test_semaphores_multi_wait(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_semaphores_queries(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_semaphores_device_list_queries(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_semaphores_no_device_list_queries(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_semaphores_multi_device_context_queries(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_semaphores_import_export_fd(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
Expand Down
24 changes: 23 additions & 1 deletion test_conformance/extensions/cl_khr_semaphore/semaphore_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@
#define CL_KHR_SEMAPHORE_BASE_H

#include <CL/cl_ext.h>

#include <vector>

#include "harness/deviceInfo.h"
#include "harness/testHarness.h"

#include "harness/typeWrappers.h"

// scope guard helper to ensure proper releasing of sub devices
struct SubDevicesScopeGuarded
{
SubDevicesScopeGuarded(const cl_int dev_count)
{
sub_devices.resize(dev_count);
}
~SubDevicesScopeGuarded()
{
for (auto &device : sub_devices)
{
cl_int err = clReleaseDevice(device);
if (err != CL_SUCCESS)
log_error("\n Releasing sub-device failed \n");
}
}

std::vector<cl_device_id> sub_devices;
};

struct SemaphoreBase
{
SemaphoreBase(cl_device_id device): device(device) {}
Expand Down
125 changes: 2 additions & 123 deletions test_conformance/extensions/cl_khr_semaphore/test_semaphores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,13 @@
// limitations under the License.
//


#include "harness/typeWrappers.h"
#include "harness/errorHelpers.h"
#include <system_error>
#include <thread>
#include <chrono>
#include <vector>

#include "semaphore_base.h"

#define FLUSH_DELAY_S 5
#include "semaphore_base.h"

#define SEMAPHORE_PARAM_TEST(param_name, param_type, expected) \
do \
{ \
param_type value; \
size_t size; \
cl_int error = clGetSemaphoreInfoKHR(semaphore, param_name, \
sizeof(value), &value, &size); \
test_error(error, "Unable to get " #param_name " from semaphore"); \
if (value != expected) \
{ \
test_fail("ERROR: Parameter %s did not validate! (expected %d, " \
"got %d)\n", \
#param_name, expected, value); \
} \
if (size != sizeof(value)) \
{ \
test_fail( \
"ERROR: Returned size of parameter %s does not validate! " \
"(expected %d, got %d)\n", \
#param_name, (int)sizeof(value), (int)size); \
} \
} while (false)

#define SEMAPHORE_PARAM_TEST_ARRAY(param_name, param_type, num_params, \
expected) \
do \
{ \
param_type value[num_params]; \
size_t size; \
cl_int error = clGetSemaphoreInfoKHR(semaphore, param_name, \
sizeof(value), &value, &size); \
test_error(error, "Unable to get " #param_name " from semaphore"); \
if (size != sizeof(value)) \
{ \
test_fail( \
"ERROR: Returned size of parameter %s does not validate! " \
"(expected %d, got %d)\n", \
#param_name, (int)sizeof(value), (int)size); \
} \
if (memcmp(value, expected, size) != 0) \
{ \
test_fail("ERROR: Parameter %s did not validate!\n", #param_name); \
} \
} while (false)
#define FLUSH_DELAY_S 5

namespace {

Expand Down Expand Up @@ -515,71 +466,6 @@ struct SemaphoreMultiWait : public SemaphoreTestBase
clSemaphoreWrapper semaphore_second = nullptr;
};

struct SemaphoreQueries : public SemaphoreTestBase
{
SemaphoreQueries(cl_device_id device, cl_context context,
cl_command_queue queue)
: SemaphoreTestBase(device, context, queue)
{}

cl_int Run() override
{
cl_int err = CL_SUCCESS;
// Create binary semaphore
cl_semaphore_properties_khr sema_props[] = {
static_cast<cl_semaphore_properties_khr>(CL_SEMAPHORE_TYPE_KHR),
static_cast<cl_semaphore_properties_khr>(
CL_SEMAPHORE_TYPE_BINARY_KHR),
static_cast<cl_semaphore_properties_khr>(
CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR),
(cl_semaphore_properties_khr)device,
CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR,
0
};
semaphore =
clCreateSemaphoreWithPropertiesKHR(context, sema_props, &err);
test_error(err, "Could not create semaphore");

// Confirm that querying CL_SEMAPHORE_TYPE_KHR returns
// CL_SEMAPHORE_TYPE_BINARY_KHR
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_TYPE_KHR, cl_semaphore_type_khr,
CL_SEMAPHORE_TYPE_BINARY_KHR);

// Confirm that querying CL_SEMAPHORE_CONTEXT_KHR returns the right
// context
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_CONTEXT_KHR, cl_context, context);

// Confirm that querying CL_SEMAPHORE_REFERENCE_COUNT_KHR returns the
// right value
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 1);

err = clRetainSemaphoreKHR(semaphore);
test_error(err, "Could not retain semaphore");
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 2);

err = clReleaseSemaphoreKHR(semaphore);
test_error(err, "Could not release semaphore");
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint, 1);

// Confirm that querying CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR returns the
// same device id the semaphore was created with
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, cl_device_id,
device);

// Confirm that querying CL_SEMAPHORE_PROPERTIES_KHR returns the same
// properties the semaphore was created with
SEMAPHORE_PARAM_TEST_ARRAY(CL_SEMAPHORE_PROPERTIES_KHR,
cl_semaphore_properties_khr, 6, sema_props);

// Confirm that querying CL_SEMAPHORE_PAYLOAD_KHR returns the unsignaled
// state
SEMAPHORE_PARAM_TEST(CL_SEMAPHORE_PAYLOAD_KHR, cl_semaphore_payload_khr,
0);

return CL_SUCCESS;
}
};

struct SemaphoreImportExportFD : public SemaphoreTestBase
{
SemaphoreImportExportFD(cl_device_id device, cl_context context,
Expand Down Expand Up @@ -726,13 +612,6 @@ int test_semaphores_multi_wait(cl_device_id deviceID, cl_context context,
return MakeAndRunTest<SemaphoreMultiWait>(deviceID, context, defaultQueue);
}

// Confirm the semaphores can be successfully queried
int test_semaphores_queries(cl_device_id deviceID, cl_context context,
cl_command_queue defaultQueue, int num_elements)
{
return MakeAndRunTest<SemaphoreQueries>(deviceID, context, defaultQueue);
}

// Test it is possible to export a semaphore to a sync fd and import the same
// sync fd to a new semaphore
int test_semaphores_import_export_fd(cl_device_id deviceID, cl_context context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <chrono>
#include <system_error>
#include <thread>
#include <vector>

namespace {

Expand Down Expand Up @@ -51,26 +50,6 @@ struct CreateInvalidContext : public SemaphoreTestBase
}
};

// scope guard helper to ensure proper releasing of sub devices
struct SubDevicesScopeGuarded
{
SubDevicesScopeGuarded(const cl_int dev_count)
{
sub_devices.resize(dev_count);
}
~SubDevicesScopeGuarded()
{
for (auto& device : sub_devices)
{
cl_int err = clReleaseDevice(device);
if (err != CL_SUCCESS)
log_error("\n Releasing sub-device failed \n");
}
}

std::vector<cl_device_id> sub_devices;
};

// (1) property name in sema_props is not a supported property name,
// (2) value specified for a supported property name is not valid,
// (3) the same property name is specified more than once.
Expand Down
Loading

0 comments on commit 2998463

Please sign in to comment.