Skip to content

Commit

Permalink
Added test with ICD 2.0.0 compatible stub driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Dec 1, 2023
1 parent 26eb0bd commit 49e788a
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 46 deletions.
11 changes: 10 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (ENABLE_OPENCL_LAYERS)
add_subdirectory (layer)
endif ()

set_target_properties (IcdLog OpenCLDriverStub icd_loader_test
set_target_properties (IcdLog OpenCLDriverStub OpenCLDriverStubICD2 icd_loader_test
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
Expand All @@ -18,6 +18,10 @@ add_test (
NAME opencl_icd_loader_test
COMMAND icd_loader_test
)
add_test (
NAME opencl_icd_loader_icd2_test
COMMAND icd_loader_test
)

if (ENABLE_OPENCL_LAYERINFO)
add_test (
Expand All @@ -38,6 +42,11 @@ set_tests_properties(opencl_icd_loader_test
ENVIRONMENT OCL_ICD_FILENAMES=$<TARGET_FILE:OpenCLDriverStub>
WORKING_DIRECTORY "${TEST_WORKING_DIRECTORY}"
)
set_tests_properties(opencl_icd_loader_icd2_test
PROPERTIES
ENVIRONMENT "OCL_ICD_FILENAMES=$<TARGET_FILE:OpenCLDriverStubICD2>;APP_LOG_FILE=icd_test_app_log_icd2.txt;APP_STUB_FILE=icd_test_stub_log_icd2.txt"
WORKING_DIRECTORY "${TEST_WORKING_DIRECTORY}"
)
if (ENABLE_OPENCL_LAYERINFO)
set_tests_properties(cllayerinfo_test
PROPERTIES
Expand Down
12 changes: 12 additions & 0 deletions test/driver_stub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ add_library (OpenCLDriverStub SHARED ${OPENCL_DRIVER_STUB_SOURCES})
target_link_libraries (OpenCLDriverStub IcdLog OpenCL::Headers)

target_compile_definitions (OpenCLDriverStub PRIVATE CL_TARGET_OPENCL_VERSION=300)

set (OPENCL_DRIVER_STUB_ICD2_SOURCES cl.c cl_ext.c cl_gl.c icd.c)

if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
list (APPEND OPENCL_DRIVER_STUB_ICD2_SOURCES driver_stub_icd2.def)
endif ()

add_library (OpenCLDriverStubICD2 SHARED ${OPENCL_DRIVER_STUB_ICD2_SOURCES})

target_link_libraries (OpenCLDriverStubICD2 IcdLog OpenCL::Headers)

target_compile_definitions (OpenCLDriverStubICD2 PRIVATE CL_TARGET_OPENCL_VERSION=300 CL_ENABLE_ICD2=1)
75 changes: 39 additions & 36 deletions test/driver_stub/cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clIcdGetPlatformIDsKHR(cl_uint, cl_platform_id *, cl_uint *);

struct _cl_platform_id
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
const char *profile;
const char *version;
const char *name;
Expand All @@ -35,42 +35,42 @@ struct _cl_platform_id

struct _cl_device_id
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_context
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_command_queue
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_mem
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_program
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_kernel
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_event
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

struct _cl_sampler
{
CLIicdDispatchTable* dispatch;
CL_OBJECT_BODY;
};

static CLIicdDispatchTable* dispatchTable = NULL;
Expand Down Expand Up @@ -177,8 +177,8 @@ clGetDeviceIDs(cl_platform_id platform,
}

if (devices != NULL) {
cl_device_id obj = (cl_device_id) malloc(sizeof(*obj));
obj->dispatch = dispatchTable;
cl_device_id obj = (cl_device_id) malloc(sizeof(struct _cl_device_id));
CL_INIT_OBJECT(obj, platform);
devices[0] = obj;
}
if (num_devices) {
Expand Down Expand Up @@ -269,7 +269,7 @@ clCreateContext(const cl_context_properties * properties,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_context obj = (cl_context) malloc(sizeof(struct _cl_context));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, devices[0]);
test_icd_stub_log("clCreateContext(%p, %u, %p, %p, %p, %p)\n",
properties,
num_devices,
Expand Down Expand Up @@ -297,7 +297,11 @@ clCreateContextFromType(const cl_context_properties * properties,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_context obj = (cl_context) malloc(sizeof(struct _cl_context));
obj->dispatch = dispatchTable;
cl_platform_id plt = platform;
for (const cl_context_properties * property = properties; *property; property += 2)
if (*property == (cl_context_properties)CL_CONTEXT_PLATFORM)
plt = (cl_platform_id)property[1];
CL_INIT_OBJECT(obj, plt);
test_icd_stub_log("clCreateContextFromType(%p, %x, %p, %p, %p)\n",
properties,
device_type,
Expand Down Expand Up @@ -383,7 +387,7 @@ clCreateCommandQueue(cl_context context,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_command_queue obj = (cl_command_queue) malloc(sizeof(struct _cl_command_queue));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateCommandQueue(%p, %p, %x, %p)\n",
context,
device,
Expand Down Expand Up @@ -460,7 +464,7 @@ clCreateBuffer(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateBuffer(%p, %x, %u, %p, %p)\n",
context,
flags,
Expand All @@ -480,7 +484,7 @@ clCreateSubBuffer(cl_mem buffer ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, buffer);
test_icd_stub_log("clCreateSubBuffer(%p, %x, %u, %p, %p)\n",
buffer,
flags,
Expand All @@ -494,14 +498,14 @@ clCreateSubBuffer(cl_mem buffer ,

CL_API_ENTRY cl_mem CL_API_CALL
clCreateImage(cl_context context,
cl_mem_flags flags,
const cl_image_format * image_format,
const cl_image_desc * image_desc,
void * host_ptr,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2
cl_mem_flags flags,
const cl_image_format * image_format,
const cl_image_desc * image_desc,
void * host_ptr,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateImage(%p, %x, %p, %p, %p, %p)\n",
context,
flags,
Expand All @@ -526,7 +530,7 @@ clCreateImage2D(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateImage2D(%p, %x, %p, %u, %u, %u, %p, %p)\n",
context,
flags,
Expand Down Expand Up @@ -554,7 +558,7 @@ clCreateImage3D(cl_context context,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateImage3D(%p, %x, %p, %u, %u, %u, %u, %u, %p, %p)\n",
context,
flags,
Expand All @@ -580,7 +584,7 @@ clCreateBufferWithProperties(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_3_0
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateBufferWithProperties(%p, %p, %x, %u, %p, %p)\n",
context,
properties,
Expand All @@ -603,7 +607,7 @@ clCreateImageWithProperties(cl_context context,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_3_0
{
cl_mem obj = (cl_mem) malloc(sizeof(struct _cl_mem));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateImageWithProperties(%p, %p, %x, %p, %p, %p, %p)\n",
context,
properties,
Expand Down Expand Up @@ -723,7 +727,7 @@ clCreateSampler(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_sampler obj = (cl_sampler) malloc(sizeof(struct _cl_sampler));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateSampler(%p, %u, %u, %u, %p)\n",
context,
normalized_coords,
Expand Down Expand Up @@ -782,7 +786,7 @@ clCreateProgramWithSource(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_program obj = (cl_program) malloc(sizeof(struct _cl_program));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateProgramWithSource(%p, %u, %p, %p, %p)\n",
context,
count,
Expand All @@ -804,7 +808,7 @@ clCreateProgramWithBinary(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_program obj = (cl_program) malloc(sizeof(struct _cl_program));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateProgramWithBinary(%p, %u, %p, %p, %p, %p, %p)\n",
context,
num_devices,
Expand All @@ -826,7 +830,7 @@ clCreateProgramWithBuiltInKernels(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2
{
cl_program obj = (cl_program) malloc(sizeof(struct _cl_program));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateProgramWithBuiltInKernels(%p, %u, %p, %p, %p)\n",
context,
num_devices,
Expand Down Expand Up @@ -930,8 +934,8 @@ clLinkProgram(cl_context context ,
void * user_data ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2
{
cl_program obj = (cl_program) malloc(sizeof(cl_program));
obj->dispatch = dispatchTable;
cl_program obj = (cl_program) malloc(sizeof(struct _cl_program));
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clLinkProgram(%p, %u, %p, %p, %u, %p, %p, %p, %p)\n",
context,
num_devices,
Expand Down Expand Up @@ -1005,7 +1009,7 @@ clCreateKernel(cl_program program ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
{
cl_kernel obj = (cl_kernel) malloc(sizeof(struct _cl_kernel));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, program);
test_icd_stub_log("clCreateKernel(%p, %p, %p)\n",
program,
kernel_name,
Expand Down Expand Up @@ -1167,7 +1171,7 @@ clCreateUserEvent(cl_context context ,
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1
{
cl_event obj = (cl_event) malloc(sizeof(struct _cl_event));
obj->dispatch = dispatchTable;
CL_INIT_OBJECT(obj, context);
test_icd_stub_log("clCreateUserEvent(%p, %p)\n", context, errcode_ret);
test_icd_stub_log("Value returned: %p\n", obj);
return obj;
Expand Down Expand Up @@ -1954,14 +1958,13 @@ clIcdGetPlatformIDsKHR(cl_uint num_entries,
platform = (cl_platform_id) malloc(sizeof(struct _cl_platform_id));
memset(platform, 0, sizeof(struct _cl_platform_id));

platform->dispatch = dispatchTable;
CL_INIT_PLATFORM(platform, dispatchTable);
platform->version = "OpenCL 1.2 Stub";
platform->vendor = "stubvendorxxx";
platform->profile = "stubprofilexxx";
platform->name = "ICD_LOADER_TEST_OPENCL_STUB";
platform->extensions = "cl_khr_icd cl_khr_gl cl_khr_d3d10";
platform->suffix = "ilts";
platform->dispatch = dispatchTable;
initialized = CL_TRUE;
}

Expand Down
4 changes: 4 additions & 0 deletions test/driver_stub/driver_stub_icd2.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXPORTS
clGetExtensionFunctionAddress
clIcdGetFunctionAddressForPlatformKHR
clIcdSetPlatformDispatchDataKHR
Loading

0 comments on commit 49e788a

Please sign in to comment.