diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 51baf4cf2c..6a36ccb0b3 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -5375,8 +5375,8 @@ cl_int CL_API_CALL clSetProgramReleaseCallback(cl_program program, void(CL_CALLBACK *pfnNotify)(cl_program /* program */, void * /* user_data */), void *userData) { DBG_LOG_INPUTS("program", program, - "pfn_notify", pfnNotify, - "user_data", userData); + "pfnNotify", pfnNotify, + "userData", userData); cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); @@ -5586,3 +5586,23 @@ cl_int CL_API_CALL clEnqueueNDCountKernelINTEL(cl_command_queue commandQueue, DBG_LOG_INPUTS("event", NEO::FileLoggerInstance().getEvents(reinterpret_cast(event), 1u)); return retVal; } + +cl_int CL_API_CALL clSetContextDestructorCallback(cl_context context, + void(CL_CALLBACK *pfnNotify)(cl_context /* context */, void * /* user_data */), + void *userData) { + DBG_LOG_INPUTS("program", context, + "pfnNotify", pfnNotify, + "userData", userData); + + cl_int retVal = CL_SUCCESS; + API_ENTER(&retVal); + + retVal = validateObjects(context, + reinterpret_cast(pfnNotify)); + + if (retVal == CL_SUCCESS) { + retVal = CL_OUT_OF_HOST_MEMORY; + } + + return retVal; +} diff --git a/opencl/source/api/api.h b/opencl/source/api/api.h index afd2cec574..d9661bf0d6 100644 --- a/opencl/source/api/api.h +++ b/opencl/source/api/api.h @@ -1088,3 +1088,8 @@ cl_mem CL_API_CALL clCreateImageWithProperties( const cl_image_desc *imageDesc, void *hostPtr, cl_int *errcodeRet); + +cl_int CL_API_CALL clSetContextDestructorCallback( + cl_context context, + void(CL_CALLBACK *pfn_notify)(cl_context /* context */, void * /* user_data */), + void *user_data); diff --git a/opencl/source/api/dispatch.cpp b/opencl/source/api/dispatch.cpp index c50fe111f3..299e93e089 100644 --- a/opencl/source/api/dispatch.cpp +++ b/opencl/source/api/dispatch.cpp @@ -186,7 +186,8 @@ SDispatchTable icdGlobalDispatchTable = /* OpenCL 3.0 */ clCreateBufferWithProperties, - clCreateImageWithProperties}; + clCreateImageWithProperties, + clSetContextDestructorCallback}; SCRTDispatchTable crtGlobalDispatchTable = { clGetKernelArgInfo, diff --git a/opencl/source/api/dispatch.h b/opencl/source/api/dispatch.h index a6b3941db0..0bccd485f8 100644 --- a/opencl/source/api/dispatch.h +++ b/opencl/source/api/dispatch.h @@ -1006,6 +1006,11 @@ typedef CL_API_ENTRY cl_mem(CL_API_CALL *KHRpfn_clCreateImageWithProperties)( void *hostPtr, cl_int *errcodeRet) CL_API_SUFFIX__VERSION_3_0; +typedef CL_API_ENTRY cl_int(CL_API_CALL *KHRpfn_clSetContextDestructorCallback)( + cl_context context, + void(CL_CALLBACK *pfnNotify)(cl_context context, void *userData), + void *userData) CL_API_SUFFIX__VERSION_3_0; + /* clCreateImage */ typedef CL_API_ENTRY cl_int(CL_API_CALL *INTELpfn_clGetImageParamsINTEL)( @@ -1277,6 +1282,7 @@ struct SDispatchTable { /* OpenCL 3.0 */ KHRpfn_clCreateBufferWithProperties clCreateBufferWithProperties; KHRpfn_clCreateImageWithProperties clCreateImageWithProperties; + KHRpfn_clSetContextDestructorCallback clSetContextDestructorCallback; }; struct SCRTDispatchTable { diff --git a/opencl/test/unit_test/api/CMakeLists.txt b/opencl/test/unit_test/api/CMakeLists.txt index cda9a11948..c6ade5fb83 100644 --- a/opencl/test/unit_test/api/CMakeLists.txt +++ b/opencl/test/unit_test/api/CMakeLists.txt @@ -108,6 +108,7 @@ set(IGDRCL_SRCS_tests_api ${CMAKE_CURRENT_SOURCE_DIR}/cl_retain_release_context_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_retain_release_device_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_retain_release_sampler_tests.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_context_destructor_callback.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_default_device_command_queue_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_event_callback_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_kernel_arg_svm_pointer_tests.inl diff --git a/opencl/test/unit_test/api/api_tests_wrapper3.cpp b/opencl/test/unit_test/api/api_tests_wrapper3.cpp index 1a58c0c255..a5995f1509 100644 --- a/opencl/test/unit_test/api/api_tests_wrapper3.cpp +++ b/opencl/test/unit_test/api/api_tests_wrapper3.cpp @@ -30,6 +30,7 @@ #include "opencl/test/unit_test/api/cl_retain_release_context_tests.inl" #include "opencl/test/unit_test/api/cl_retain_release_device_tests.inl" #include "opencl/test/unit_test/api/cl_retain_release_sampler_tests.inl" +#include "opencl/test/unit_test/api/cl_set_context_destructor_callback.inl" #include "opencl/test/unit_test/api/cl_set_default_device_command_queue_tests.inl" #include "opencl/test/unit_test/api/cl_set_event_callback_tests.inl" #include "opencl/test/unit_test/api/cl_set_kernel_arg_svm_pointer_tests.inl" diff --git a/opencl/test/unit_test/api/cl_set_context_destructor_callback.inl b/opencl/test/unit_test/api/cl_set_context_destructor_callback.inl new file mode 100644 index 0000000000..96c10ffa06 --- /dev/null +++ b/opencl/test/unit_test/api/cl_set_context_destructor_callback.inl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "opencl/test/unit_test/api/cl_api_tests.h" + +using namespace NEO; + +namespace ULT { + +TEST(clSetContextDestructorCallbackTest, givenNullptrContextWhenSettingContextDestructorCallbackThenInvalidContextErrorIsReturned) { + auto retVal = clSetContextDestructorCallback(nullptr, nullptr, nullptr); + EXPECT_EQ(CL_INVALID_CONTEXT, retVal); +} + +using clSetContextDestructorCallbackTests = api_tests; + +TEST_F(clSetContextDestructorCallbackTests, givenPfnNotifyNullptrWhenSettingContextDestructorCallbackThenInvalidValueErrorIsReturned) { + auto retVal = clSetContextDestructorCallback(pContext, nullptr, nullptr); + EXPECT_EQ(CL_INVALID_VALUE, retVal); +} + +TEST_F(clSetContextDestructorCallbackTests, WhenSettingContextDestructorCallbackThenOutOfHostMemoryErrorIsReturned) { + using NotifyFunctionType = void(CL_CALLBACK *)(cl_context, void *); + NotifyFunctionType pfnNotify = reinterpret_cast(0x1234); + void *userData = reinterpret_cast(0x4321); + auto retVal = clSetContextDestructorCallback(pContext, pfnNotify, userData); + EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal); +} + +} // namespace ULT