From 86c2869a6ef6d3c38cbc7e5195e48cb75518b7be Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 14 May 2020 13:54:53 +0200 Subject: [PATCH] Add clSetProgramReleaseCallback function implementation Related-To: NEO-4368 Change-Id: I5dff2759abcff457930a06226b71ad64e2f69c28 Signed-off-by: Filip Hazubski --- opencl/source/api/api.cpp | 20 +++++++++++ opencl/source/api/api.h | 5 +++ opencl/source/api/dispatch.cpp | 2 +- opencl/source/dll/linux/ocl_internal.exports | 1 + .../dll/windows/OpenCLInternalExports.def.in | 1 + opencl/test/unit_test/api/CMakeLists.txt | 1 + .../test/unit_test/api/api_tests_wrapper3.cpp | 1 + .../api/cl_set_program_release_callback.inl | 34 +++++++++++++++++++ 8 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 opencl/test/unit_test/api/cl_set_program_release_callback.inl diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 518d74f465..6af729b0c0 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -5334,6 +5334,26 @@ cl_int CL_API_CALL clGetDeviceFunctionPointerINTEL( return retVal; } +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); + + cl_int retVal = CL_SUCCESS; + API_ENTER(&retVal); + + retVal = validateObjects(program, + reinterpret_cast(pfnNotify)); + + if (retVal == CL_SUCCESS) { + retVal = CL_INVALID_OPERATION; + } + + return retVal; +} + cl_int CL_API_CALL clSetProgramSpecializationConstant(cl_program program, cl_uint specId, size_t specSize, const void *specValue) { cl_int retVal = CL_SUCCESS; API_ENTER(&retVal); diff --git a/opencl/source/api/api.h b/opencl/source/api/api.h index 1a2d85d324..9ba798f489 100644 --- a/opencl/source/api/api.h +++ b/opencl/source/api/api.h @@ -1059,6 +1059,11 @@ cl_int CL_API_CALL clEnqueueNDCountKernelINTEL( // OpenCL 2.2 +cl_int CL_API_CALL clSetProgramReleaseCallback( + cl_program program, + void(CL_CALLBACK *pfnNotify)(cl_program /* program */, void * /* user_data */), + void *userData); + cl_int CL_API_CALL clSetProgramSpecializationConstant( cl_program program, cl_uint specId, diff --git a/opencl/source/api/dispatch.cpp b/opencl/source/api/dispatch.cpp index 3abb0b67cf..488913b795 100644 --- a/opencl/source/api/dispatch.cpp +++ b/opencl/source/api/dispatch.cpp @@ -181,7 +181,7 @@ SDispatchTable icdGlobalDispatchTable = clSetDefaultDeviceCommandQueue, /* OpenCL 2.2 */ - nullptr, // clSetProgramReleaseCallback + clSetProgramReleaseCallback, clSetProgramSpecializationConstant}; SCRTDispatchTable crtGlobalDispatchTable = { diff --git a/opencl/source/dll/linux/ocl_internal.exports b/opencl/source/dll/linux/ocl_internal.exports index 9a127d68dc..c9eb83424e 100644 --- a/opencl/source/dll/linux/ocl_internal.exports +++ b/opencl/source/dll/linux/ocl_internal.exports @@ -117,6 +117,7 @@ clGetHostTimer; clGetKernelSubGroupInfo; clSetDefaultDeviceCommandQueue; + clSetProgramReleaseCallback; clSetProgramSpecializationConstant; clGetKernelArgInfo; clGetImageParamsINTEL; diff --git a/opencl/source/dll/windows/OpenCLInternalExports.def.in b/opencl/source/dll/windows/OpenCLInternalExports.def.in index 0c049614a0..7c8b31e0f9 100644 --- a/opencl/source/dll/windows/OpenCLInternalExports.def.in +++ b/opencl/source/dll/windows/OpenCLInternalExports.def.in @@ -132,6 +132,7 @@ clGetDeviceAndHostTimer clGetHostTimer clGetKernelSubGroupInfo clSetDefaultDeviceCommandQueue +clSetProgramReleaseCallback clSetProgramSpecializationConstant clGetKernelArgInfo clGetImageParamsINTEL diff --git a/opencl/test/unit_test/api/CMakeLists.txt b/opencl/test/unit_test/api/CMakeLists.txt index 4f30076900..cda9a11948 100644 --- a/opencl/test/unit_test/api/CMakeLists.txt +++ b/opencl/test/unit_test/api/CMakeLists.txt @@ -114,6 +114,7 @@ set(IGDRCL_SRCS_tests_api ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_kernel_exec_info_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_mem_object_destructor_callback_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_performance_configuration_tests.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_program_release_callback.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_set_program_specialization_constant_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_svm_alloc_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_svm_free_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 80a431ae99..1a58c0c255 100644 --- a/opencl/test/unit_test/api/api_tests_wrapper3.cpp +++ b/opencl/test/unit_test/api/api_tests_wrapper3.cpp @@ -36,6 +36,7 @@ #include "opencl/test/unit_test/api/cl_set_kernel_exec_info_tests.inl" #include "opencl/test/unit_test/api/cl_set_mem_object_destructor_callback_tests.inl" #include "opencl/test/unit_test/api/cl_set_performance_configuration_tests.inl" +#include "opencl/test/unit_test/api/cl_set_program_release_callback.inl" #include "opencl/test/unit_test/api/cl_set_program_specialization_constant_tests.inl" #include "opencl/test/unit_test/api/cl_svm_alloc_tests.inl" #include "opencl/test/unit_test/api/cl_svm_free_tests.inl" diff --git a/opencl/test/unit_test/api/cl_set_program_release_callback.inl b/opencl/test/unit_test/api/cl_set_program_release_callback.inl new file mode 100644 index 0000000000..407a77b917 --- /dev/null +++ b/opencl/test/unit_test/api/cl_set_program_release_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(clSetProgramReleaseCallbackTest, givenNullptrProgramWhenSettingProgramReleaseCallbackThenInvalidProgramErrorIsReturned) { + auto retVal = clSetProgramReleaseCallback(nullptr, nullptr, nullptr); + EXPECT_EQ(CL_INVALID_PROGRAM, retVal); +} + +using clSetProgramReleaseCallbackTests = api_tests; + +TEST_F(clSetProgramReleaseCallbackTests, givenPfnNotifyNullptrWhenSettingProgramReleaseCallbackThenInvalidValueErrorIsReturned) { + auto retVal = clSetProgramReleaseCallback(pProgram, nullptr, nullptr); + EXPECT_EQ(CL_INVALID_VALUE, retVal); +} + +TEST_F(clSetProgramReleaseCallbackTests, WhenSettingProgramReleaseCallbackThenInvalidOperationErrorIsReturned) { + using NotifyFunctionType = void(CL_CALLBACK *)(cl_program, void *); + NotifyFunctionType pfnNotify = reinterpret_cast(0x1234); + void *userData = reinterpret_cast(0x4321); + auto retVal = clSetProgramReleaseCallback(pProgram, pfnNotify, userData); + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} + +} // namespace ULT