From 2f614a469e686dca06f77da6356af12adcb95bd4 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Thu, 30 Nov 2023 16:52:44 -0600 Subject: [PATCH] Added test with ICD 2.0.0 compatible stub driver. --- test/CMakeLists.txt | 11 +- test/driver_stub/CMakeLists.txt | 12 ++ test/driver_stub/cl.c | 61 ++++--- test/driver_stub/driver_stub_icd2.def | 4 + test/driver_stub/icd.c | 243 ++++++++++++++++++++++++++ test/driver_stub/icd_structs.h | 41 ++++- test/log/icd_test_log.c | 34 +++- 7 files changed, 365 insertions(+), 41 deletions(-) create mode 100644 test/driver_stub/driver_stub_icd2.def diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0d78a79f..77921d4c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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}" @@ -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 ( @@ -38,6 +42,11 @@ set_tests_properties(opencl_icd_loader_test ENVIRONMENT OCL_ICD_FILENAMES=$ WORKING_DIRECTORY "${TEST_WORKING_DIRECTORY}" ) +set_tests_properties(opencl_icd_loader_icd2_test + PROPERTIES + ENVIRONMENT "OCL_ICD_FILENAMES=$;CL_ICD2=1" + WORKING_DIRECTORY "${TEST_WORKING_DIRECTORY}" +) if (ENABLE_OPENCL_LAYERINFO) set_tests_properties(cllayerinfo_test PROPERTIES diff --git a/test/driver_stub/CMakeLists.txt b/test/driver_stub/CMakeLists.txt index e3b0ebff..309452f0 100644 --- a/test/driver_stub/CMakeLists.txt +++ b/test/driver_stub/CMakeLists.txt @@ -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) diff --git a/test/driver_stub/cl.c b/test/driver_stub/cl.c index 9b78e580..0759e49a 100644 --- a/test/driver_stub/cl.c +++ b/test/driver_stub/cl.c @@ -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; @@ -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; @@ -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) { @@ -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, platform); test_icd_stub_log("clCreateContext(%p, %u, %p, %p, %p, %p)\n", properties, num_devices, @@ -297,7 +297,7 @@ 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_INIT_OBJECT(obj, platform); test_icd_stub_log("clCreateContextFromType(%p, %x, %p, %p, %p)\n", properties, device_type, @@ -383,7 +383,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, platform); test_icd_stub_log("clCreateCommandQueue(%p, %p, %x, %p)\n", context, device, @@ -460,7 +460,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, platform); test_icd_stub_log("clCreateBuffer(%p, %x, %u, %p, %p)\n", context, flags, @@ -480,7 +480,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, platform); test_icd_stub_log("clCreateSubBuffer(%p, %x, %u, %p, %p)\n", buffer, flags, @@ -501,7 +501,7 @@ clCreateImage(cl_context context, 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, platform); test_icd_stub_log("clCreateImage(%p, %x, %p, %p, %p, %p)\n", context, flags, @@ -526,7 +526,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, platform); test_icd_stub_log("clCreateImage2D(%p, %x, %p, %u, %u, %u, %p, %p)\n", context, flags, @@ -554,7 +554,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, platform); test_icd_stub_log("clCreateImage3D(%p, %x, %p, %u, %u, %u, %u, %u, %p, %p)\n", context, flags, @@ -580,7 +580,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, platform); test_icd_stub_log("clCreateBufferWithProperties(%p, %p, %x, %u, %p, %p)\n", context, properties, @@ -603,7 +603,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, platform); test_icd_stub_log("clCreateImageWithProperties(%p, %p, %x, %p, %p, %p, %p)\n", context, properties, @@ -723,7 +723,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, platform); test_icd_stub_log("clCreateSampler(%p, %u, %u, %u, %p)\n", context, normalized_coords, @@ -782,7 +782,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, platform); test_icd_stub_log("clCreateProgramWithSource(%p, %u, %p, %p, %p)\n", context, count, @@ -804,7 +804,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, platform); test_icd_stub_log("clCreateProgramWithBinary(%p, %u, %p, %p, %p, %p, %p)\n", context, num_devices, @@ -826,7 +826,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, platform); test_icd_stub_log("clCreateProgramWithBuiltInKernels(%p, %u, %p, %p, %p)\n", context, num_devices, @@ -930,8 +930,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, platform); test_icd_stub_log("clLinkProgram(%p, %u, %p, %p, %u, %p, %p, %p, %p)\n", context, num_devices, @@ -1005,7 +1005,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, platform); test_icd_stub_log("clCreateKernel(%p, %p, %p)\n", program, kernel_name, @@ -1167,7 +1167,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, platform); test_icd_stub_log("clCreateUserEvent(%p, %p)\n", context, errcode_ret); test_icd_stub_log("Value returned: %p\n", obj); return obj; @@ -1954,14 +1954,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; } diff --git a/test/driver_stub/driver_stub_icd2.def b/test/driver_stub/driver_stub_icd2.def new file mode 100644 index 00000000..d31a03b5 --- /dev/null +++ b/test/driver_stub/driver_stub_icd2.def @@ -0,0 +1,4 @@ +EXPORTS +clGetExtensionFunctionAddress +clIcdGetFunctionAddressForPlatformKHR +clIcdSetPlatformDispatchDataKHR diff --git a/test/driver_stub/icd.c b/test/driver_stub/icd.c index 3f12d779..b6f27994 100644 --- a/test/driver_stub/icd.c +++ b/test/driver_stub/icd.c @@ -18,6 +18,20 @@ #include "CL/cl.h" #include "CL/cl_gl.h" +#if defined(CL_ENABLE_ICD2) && !defined(CL_ICD2_TAG_KHR) +#define CL_ICD2_TAG_KHR ((size_t)0x4F50454E434C3331ULL) + +typedef void * CL_API_CALL +clIcdGetFunctionAddressForPlatformKHR_t( + cl_platform_id platform, + const char* func_name); + +typedef cl_int CL_API_CALL +clIcdSetPlatformDispatchDataKHR_t( + cl_platform_id platform, + void *disp_data); +#endif + /* * Prototypes for deprecated functions no longer present in cl.h */ @@ -45,7 +59,11 @@ cl_int cliIcdDispatchTableCreate(CLIicdDispatchTable **outDispatchTable) memset(dispatchTable, 0, sizeof(*dispatchTable)); // OpenCL 1.0 +#ifdef CL_ENABLE_ICD2 + ICD_DISPATCH_TABLE_ENTRY ( CL_ICD2_TAG_KHR ); +#else ICD_DISPATCH_TABLE_ENTRY ( clGetPlatformIDs ); +#endif ICD_DISPATCH_TABLE_ENTRY ( clGetPlatformInfo ); ICD_DISPATCH_TABLE_ENTRY ( clGetDeviceIDs ); ICD_DISPATCH_TABLE_ENTRY ( clGetDeviceInfo ); @@ -247,3 +265,228 @@ cliIcdDispatchTableDestroy(CLIicdDispatchTable *dispatchTable) { free(dispatchTable); } + +#ifdef CL_ENABLE_ICD2 + +#define ICD_GET_FUNCITON_ADDRESS(fn) \ +do \ +{ \ + if (!strcmp(#fn, func_name)) \ + return (void*)(intptr_t)(fn); \ +} while (0) + +extern clIcdGetFunctionAddressForPlatformKHR_t clIcdGetFunctionAddressForPlatformKHR; +void * CL_API_CALL clIcdGetFunctionAddressForPlatformKHR( + cl_platform_id platform, + const char* func_name) +{ + (void)platform; + ICD_GET_FUNCITON_ADDRESS ( clGetPlatformIDs ); + ICD_GET_FUNCITON_ADDRESS ( clGetPlatformInfo ); + ICD_GET_FUNCITON_ADDRESS ( clGetDeviceIDs ); + ICD_GET_FUNCITON_ADDRESS ( clGetDeviceInfo ); + ICD_GET_FUNCITON_ADDRESS ( clCreateContext ); + ICD_GET_FUNCITON_ADDRESS ( clCreateContextFromType ); + ICD_GET_FUNCITON_ADDRESS ( clRetainContext ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseContext ); + ICD_GET_FUNCITON_ADDRESS ( clGetContextInfo ); + ICD_GET_FUNCITON_ADDRESS ( clCreateCommandQueue ); + ICD_GET_FUNCITON_ADDRESS ( clRetainCommandQueue ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseCommandQueue ); + ICD_GET_FUNCITON_ADDRESS ( clGetCommandQueueInfo ); + ICD_GET_FUNCITON_ADDRESS ( clSetCommandQueueProperty ); + ICD_GET_FUNCITON_ADDRESS ( clCreateBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clCreateImage2D ); + ICD_GET_FUNCITON_ADDRESS ( clCreateImage3D ); + ICD_GET_FUNCITON_ADDRESS ( clRetainMemObject ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseMemObject ); + ICD_GET_FUNCITON_ADDRESS ( clGetSupportedImageFormats ); + ICD_GET_FUNCITON_ADDRESS ( clGetMemObjectInfo ); + ICD_GET_FUNCITON_ADDRESS ( clGetImageInfo ); + ICD_GET_FUNCITON_ADDRESS ( clCreateSampler ); + ICD_GET_FUNCITON_ADDRESS ( clRetainSampler ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseSampler ); + ICD_GET_FUNCITON_ADDRESS ( clGetSamplerInfo ); + ICD_GET_FUNCITON_ADDRESS ( clCreateProgramWithSource ); + ICD_GET_FUNCITON_ADDRESS ( clCreateProgramWithBinary ); + ICD_GET_FUNCITON_ADDRESS ( clRetainProgram ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseProgram ); + ICD_GET_FUNCITON_ADDRESS ( clBuildProgram ); + ICD_GET_FUNCITON_ADDRESS ( clUnloadCompiler ); + ICD_GET_FUNCITON_ADDRESS ( clGetProgramInfo ); + ICD_GET_FUNCITON_ADDRESS ( clGetProgramBuildInfo ); + ICD_GET_FUNCITON_ADDRESS ( clCreateKernel ); + ICD_GET_FUNCITON_ADDRESS ( clCreateKernelsInProgram ); + ICD_GET_FUNCITON_ADDRESS ( clRetainKernel ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseKernel ); + ICD_GET_FUNCITON_ADDRESS ( clSetKernelArg ); + ICD_GET_FUNCITON_ADDRESS ( clGetKernelInfo ); + ICD_GET_FUNCITON_ADDRESS ( clGetKernelWorkGroupInfo ); + ICD_GET_FUNCITON_ADDRESS ( clWaitForEvents ); + ICD_GET_FUNCITON_ADDRESS ( clGetEventInfo ); + ICD_GET_FUNCITON_ADDRESS ( clRetainEvent ); + ICD_GET_FUNCITON_ADDRESS ( clReleaseEvent ); + ICD_GET_FUNCITON_ADDRESS ( clGetEventProfilingInfo ); + ICD_GET_FUNCITON_ADDRESS ( clFlush ); + ICD_GET_FUNCITON_ADDRESS ( clFinish ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueReadBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueWriteBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueCopyBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueReadImage ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueWriteImage ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueCopyImage ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueCopyImageToBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueCopyBufferToImage ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueMapBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueMapImage ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueUnmapMemObject ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueNDRangeKernel ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueTask ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueNativeKernel ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueMarker ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueWaitForEvents ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueBarrier ); + ICD_GET_FUNCITON_ADDRESS ( clGetExtensionFunctionAddress ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromGLBuffer ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromGLTexture2D ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromGLTexture3D ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromGLRenderbuffer ); + ICD_GET_FUNCITON_ADDRESS ( clGetGLObjectInfo ); + ICD_GET_FUNCITON_ADDRESS ( clGetGLTextureInfo ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueAcquireGLObjects ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueReleaseGLObjects ); + + // cl_khr_gl_sharing + ICD_GET_FUNCITON_ADDRESS ( clGetGLContextInfoKHR ); + +#if 0 + // cl_khr_d3d10_sharing (windows-only) +#if 0 && defined(_WIN32) + ICD_GET_FUNCITON_ADDRESS ( clGetDeviceIDsFromD3D10KHR ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromD3D10BufferKHR ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromD3D10Texture2DKHR ); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromD3D10Texture3DKHR ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueAcquireD3D10ObjectsKHR ); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueReleaseD3D10ObjectsKHR ); +#else + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); +#endif +#endif + + // OpenCL 1.1 + ICD_GET_FUNCITON_ADDRESS ( clSetEventCallback); + ICD_GET_FUNCITON_ADDRESS ( clCreateSubBuffer); + ICD_GET_FUNCITON_ADDRESS ( clSetMemObjectDestructorCallback); + ICD_GET_FUNCITON_ADDRESS ( clCreateUserEvent); + ICD_GET_FUNCITON_ADDRESS ( clSetUserEventStatus); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueReadBufferRect); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueWriteBufferRect); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueCopyBufferRect); + +#if 0 + /* cl_ext_device_fission */ + ICD_GET_FUNCITON_ADDRESS ( /*clCreateSubDevicesEXT*/NULL); + ICD_GET_FUNCITON_ADDRESS ( /*clRetainDeviceEXT*/ NULL); + ICD_GET_FUNCITON_ADDRESS ( /*clReleaseDevice*/NULL); +#endif + + /* cl_khr_gl_event */ + ICD_GET_FUNCITON_ADDRESS ( clCreateEventFromGLsyncKHR); + + /* OpenCL 1.2 */ + ICD_GET_FUNCITON_ADDRESS ( clCreateSubDevices); + ICD_GET_FUNCITON_ADDRESS ( clRetainDevice); + ICD_GET_FUNCITON_ADDRESS ( clReleaseDevice); + ICD_GET_FUNCITON_ADDRESS ( clCreateImage); + ICD_GET_FUNCITON_ADDRESS ( clCreateProgramWithBuiltInKernels); + ICD_GET_FUNCITON_ADDRESS ( clCompileProgram); + ICD_GET_FUNCITON_ADDRESS ( clLinkProgram); + ICD_GET_FUNCITON_ADDRESS ( clUnloadPlatformCompiler); + ICD_GET_FUNCITON_ADDRESS ( clGetKernelArgInfo); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueFillBuffer); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueFillImage); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueMigrateMemObjects); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueMarkerWithWaitList); + ICD_GET_FUNCITON_ADDRESS ( clEnqueueBarrierWithWaitList); + ICD_GET_FUNCITON_ADDRESS ( clGetExtensionFunctionAddressForPlatform); + ICD_GET_FUNCITON_ADDRESS ( clCreateFromGLTexture); + +#if 0 + /* cl_khr_d3d11_sharing */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* cl_khr_dx9_media_sharing */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* cl_khr_egl_image */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* cl_khr_egl_event */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* OpenCL 2.0 */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* cl_khr_sub_groups */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* OpenCL 2.1 */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); + + /* OpenCL 2.2 */ + ICD_GET_FUNCITON_ADDRESS( NULL ); + ICD_GET_FUNCITON_ADDRESS( NULL ); +#endif + + /* OpenCL 3.0 */ + ICD_GET_FUNCITON_ADDRESS ( clCreateBufferWithProperties ); + ICD_GET_FUNCITON_ADDRESS ( clCreateImageWithProperties ); + ICD_GET_FUNCITON_ADDRESS ( clSetContextDestructorCallback ); + + return NULL; +} + +extern clIcdSetPlatformDispatchDataKHR_t clIcdSetPlatformDispatchDataKHR; + +cl_int CL_API_CALL +clIcdSetPlatformDispatchDataKHR( + cl_platform_id platform, + void *disp_data) +{ + ((struct CLIplatform_st *)platform)->dispData = disp_data; + return CL_SUCCESS; +} +#endif //CL_ENABLE_ICD2 diff --git a/test/driver_stub/icd_structs.h b/test/driver_stub/icd_structs.h index 4b7e68b1..591618d2 100644 --- a/test/driver_stub/icd_structs.h +++ b/test/driver_stub/icd_structs.h @@ -10,9 +10,48 @@ struct CLIicdDispatchTable_st int entryCount; }; +#ifdef CL_ENABLE_ICD2 + +#define CL_OBJECT_BODY \ + CLIicdDispatchTable* dispatch; \ + void* dispData + +#define CL_INIT_OBJECT(obj, parent) \ +do \ +{ \ + obj->dispatch = parent->dispatch; \ + obj->dispData = parent->dispData; \ +} while (0) + +#define CL_INIT_PLATFORM(obj, table) \ +do \ +{ \ + obj->dispatch = table; \ + obj->dispData = NULL; \ +} while (0) + +#else //defined(CL_ENABLE_ICD2) + +#define CL_OBJECT_BODY \ + CLIicdDispatchTable* dispatch + +#define CL_INIT_OBJECT(obj, parent) \ +do \ +{ \ + obj->dispatch = parent->dispatch; \ +} while (0) + +#define CL_INIT_PLATFORM(obj, table) \ +do \ +{ \ + obj->dispatch = table; \ +} while (0) + +#endif //defined(CL_ENABLE_ICD2) + struct CLIplatform_st { - CLIicdDispatchTable* dispatch; + CL_OBJECT_BODY; }; #endif /* _ICD_STRUCTS_H_ */ diff --git a/test/log/icd_test_log.c b/test/log/icd_test_log.c index cd7cc7d7..13682a49 100644 --- a/test/log/icd_test_log.c +++ b/test/log/icd_test_log.c @@ -7,18 +7,25 @@ #define APP_LOG_FILE "icd_test_app_log.txt" #define STUB_LOG_FILE "icd_test_stub_log.txt" +#define APP_LOG_FILE_ICD2 "icd_test_app_log_icd2.txt" +#define STUB_LOG_FILE_ICD2 "icd_test_stub_log_icd2.txt" static FILE *app_log_file; static FILE *stub_log_file; int test_icd_initialize_app_log(void) { - app_log_file = fopen(APP_LOG_FILE, "w"); + const char *app_log_file_name = NULL; + if (getenv("CL_ICD2")) + app_log_file_name = APP_LOG_FILE_ICD2; + else + app_log_file_name = APP_LOG_FILE; + app_log_file = fopen(app_log_file_name, "w"); if (!app_log_file) { - printf("Unable to open file %s\n", APP_LOG_FILE); + printf("Unable to open file %s\n", app_log_file_name); return -1; } - + return 0; } @@ -37,12 +44,17 @@ void test_icd_app_log(const char *format, ...) int test_icd_initialize_stub_log(void) { - stub_log_file = fopen(STUB_LOG_FILE, "w"); + const char *stub_log_file_name = NULL; + if (getenv("CL_ICD2")) + stub_log_file_name = STUB_LOG_FILE_ICD2; + else + stub_log_file_name = STUB_LOG_FILE; + stub_log_file = fopen(stub_log_file_name, "w"); if (!stub_log_file) { - printf("Unable to open file %s\n", STUB_LOG_FILE); + printf("Unable to open file %s\n", stub_log_file_name); return -1; } - + return 0; } @@ -94,10 +106,16 @@ static char *test_icd_get_log(const char *filename) char *test_icd_get_app_log(void) { - return test_icd_get_log(APP_LOG_FILE); + if (getenv("CL_ICD2")) + return test_icd_get_log(APP_LOG_FILE_ICD2); + else + return test_icd_get_log(APP_LOG_FILE); } char *test_icd_get_stub_log(void) { - return test_icd_get_log(STUB_LOG_FILE); + if (getenv("CL_ICD2")) + return test_icd_get_log(STUB_LOG_FILE_ICD2); + else + return test_icd_get_log(STUB_LOG_FILE); }