From 49e788a36cb26d4c4fb05b512dc90b02529d6b66 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 | 75 ++++---- 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, 374 insertions(+), 46 deletions(-) create mode 100644 test/driver_stub/driver_stub_icd2.def diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0d78a79f..ea94490b 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=$;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 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..ef5fcd08 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, devices[0]); test_icd_stub_log("clCreateContext(%p, %u, %p, %p, %p, %p)\n", properties, num_devices, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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; @@ -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; } 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..400e6bb0 100644 --- a/test/log/icd_test_log.c +++ b/test/log/icd_test_log.c @@ -11,14 +11,31 @@ static FILE *app_log_file; static FILE *stub_log_file; +static const char *test_icd_get_app_log_file_name(void) +{ + const char *app_log_file_name = getenv("APP_LOG_FILE"); + if (!app_log_file_name) + app_log_file_name = APP_LOG_FILE; + return app_log_file_name; +} + +static const char *test_icd_get_stub_log_file_name(void) +{ + const char *stub_log_file_name = getenv("APP_STUB_FILE"); + if (!stub_log_file_name) + stub_log_file_name = STUB_LOG_FILE; + return stub_log_file_name; +} + int test_icd_initialize_app_log(void) { - app_log_file = fopen(APP_LOG_FILE, "w"); + const char *app_log_file_name = test_icd_get_app_log_file_name(); + 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 +54,13 @@ 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 = test_icd_get_stub_log_file_name(); + 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 +112,10 @@ static char *test_icd_get_log(const char *filename) char *test_icd_get_app_log(void) { - return test_icd_get_log(APP_LOG_FILE); + return test_icd_get_log(test_icd_get_app_log_file_name()); } char *test_icd_get_stub_log(void) { - return test_icd_get_log(STUB_LOG_FILE); + return test_icd_get_log(test_icd_get_stub_log_file_name()); }