From c2e5831c1c514330de8f3b22e620aa32dc540b01 Mon Sep 17 00:00:00 2001 From: "Jobczyk, Lukasz" Date: Mon, 1 Apr 2019 11:39:55 +0200 Subject: [PATCH] Add the clAddCommentINTEL function Related-To: NEO-3047 Change-Id: I4def3e4866e0bf53c00f18d42b3c32c0d0c8a746 Signed-off-by: Jobczyk, Lukasz --- runtime/api/api.cpp | 19 ++++++ runtime/api/api.h | 2 + unit_tests/api/CMakeLists.txt | 1 + unit_tests/api/api_tests_wrapper1.cpp | 3 +- .../api/cl_add_comment_to_aub_tests.inl | 60 +++++++++++++++++++ ...l_get_extension_function_address_tests.inl | 7 +++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 unit_tests/api/cl_add_comment_to_aub_tests.inl diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index c2227cc3dd..ebd494380e 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -8,6 +8,7 @@ #include "api.h" #include "runtime/accelerators/intel_motion_estimation.h" +#include "runtime/aub/aub_center.h" #include "runtime/built_ins/built_ins.h" #include "runtime/command_queue/command_queue.h" #include "runtime/command_stream/command_stream_receiver.h" @@ -3273,6 +3274,7 @@ void *CL_API_CALL clGetExtensionFunctionAddress(const char *func_name) { RETURN_FUNC_PTR_IF_EXIST(clRetainAcceleratorINTEL); RETURN_FUNC_PTR_IF_EXIST(clReleaseAcceleratorINTEL); RETURN_FUNC_PTR_IF_EXIST(clCreateBufferWithPropertiesINTEL); + RETURN_FUNC_PTR_IF_EXIST(clAddCommentINTEL); RETURN_FUNC_PTR_IF_EXIST(clEnqueueVerifyMemory); void *ret = sharingFactory.getExtensionFunctionAddress(func_name); @@ -4227,3 +4229,20 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueVerifyMemory(cl_command_queue commandQu retVal = csr.expectMemory(allocationPtr, expectedData, sizeOfComparison, comparisonMode); return retVal; } + +cl_int CL_API_CALL clAddCommentINTEL(const char *comment) { + cl_int retVal = CL_SUCCESS; + API_ENTER(&retVal); + + auto executionEnvironment = platform()->peekExecutionEnvironment(); + auto aubCenter = executionEnvironment->aubCenter.get(); + + if (!comment || !aubCenter || !aubCenter->getAubManager()) { + retVal = CL_INVALID_VALUE; + } + + if (retVal == CL_SUCCESS) { + aubCenter->getAubManager()->addComment(comment); + } + return retVal; +} diff --git a/runtime/api/api.h b/runtime/api/api.h index cb9c52c59e..98c2903bb4 100644 --- a/runtime/api/api.h +++ b/runtime/api/api.h @@ -848,6 +848,8 @@ cl_int CL_API_CALL clEnqueueVerifyMemory( size_t sizeOfComparison, cl_uint comparisonMode); +cl_int CL_API_CALL clAddCommentINTEL(const char *comment); + // OpenCL 2.1 cl_int CL_API_CALL clGetDeviceAndHostTimer(cl_device_id device, diff --git a/unit_tests/api/CMakeLists.txt b/unit_tests/api/CMakeLists.txt index 612b566331..4c3e000467 100644 --- a/unit_tests/api/CMakeLists.txt +++ b/unit_tests/api/CMakeLists.txt @@ -9,6 +9,7 @@ set(IGDRCL_SRCS_tests_api ${CMAKE_CURRENT_SOURCE_DIR}/api_tests_wrapper1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/api_tests_wrapper2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/api_tests_wrapper3.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cl_add_comment_to_aub_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/cl_api_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cl_api_tests.h ${CMAKE_CURRENT_SOURCE_DIR}/cl_build_program_tests.inl diff --git a/unit_tests/api/api_tests_wrapper1.cpp b/unit_tests/api/api_tests_wrapper1.cpp index 9e190036fd..976c11319c 100644 --- a/unit_tests/api/api_tests_wrapper1.cpp +++ b/unit_tests/api/api_tests_wrapper1.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "unit_tests/api/cl_add_comment_to_aub_tests.inl" #include "unit_tests/api/cl_build_program_tests.inl" #include "unit_tests/api/cl_clone_kernel_tests.inl" #include "unit_tests/api/cl_compile_program_tests.inl" diff --git a/unit_tests/api/cl_add_comment_to_aub_tests.inl b/unit_tests/api/cl_add_comment_to_aub_tests.inl new file mode 100644 index 0000000000..1d494ed040 --- /dev/null +++ b/unit_tests/api/cl_add_comment_to_aub_tests.inl @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/execution_environment/execution_environment.h" +#include "unit_tests/api/cl_api_tests.h" +#include "unit_tests/mocks/mock_aub_center.h" +#include "unit_tests/mocks/mock_aub_manager.h" + +using namespace NEO; + +namespace ULT { + +TEST(clAddCommentToAubTest, givenNullptrCommentWhenAddCommentToAubThenErrorIsReturned) { + auto retVal = clAddCommentINTEL(nullptr); + EXPECT_EQ(CL_INVALID_VALUE, retVal); +} + +TEST(clAddCommentToAubTest, givenProperCommentAndNullptrAubCenterWhenAddCommentToAubThenErrorIsReturned) { + auto retVal = clAddCommentINTEL("comment"); + EXPECT_EQ(CL_INVALID_VALUE, retVal); +} + +TEST(clAddCommentToAubTest, givenProperCommentAndAubCenterButNullptrAubManagerWhenAddCommentToAubThenErrorIsReturned) { + auto executionEnvironment = platform()->peekExecutionEnvironment(); + executionEnvironment->aubCenter.reset(new MockAubCenter()); + + auto retVal = clAddCommentINTEL("comment"); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + + executionEnvironment->aubCenter.reset(nullptr); +} + +TEST(clAddCommentToAubTest, givenProperCommentAubCenterAndAubManagerWhenAddCommentToAubThenSuccessIsReturned) { + struct AubManagerCommentMock : public MockAubManager { + using MockAubManager::MockAubManager; + void addComment(const char *message) override { + addCommentCalled = true; + EXPECT_STREQ("comment", message); + } + bool addCommentCalled = false; + }; + auto mockAubCenter = new MockAubCenter(); + auto mockAubManager = new AubManagerCommentMock; + mockAubCenter->aubManager.reset(mockAubManager); + auto executionEnvironment = platform()->peekExecutionEnvironment(); + executionEnvironment->aubCenter.reset(mockAubCenter); + + EXPECT_FALSE(mockAubManager->addCommentCalled); + + auto retVal = clAddCommentINTEL("comment"); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_TRUE(mockAubManager->addCommentCalled); + + executionEnvironment->aubCenter.reset(nullptr); +} +} // namespace ULT diff --git a/unit_tests/api/cl_get_extension_function_address_tests.inl b/unit_tests/api/cl_get_extension_function_address_tests.inl index ac888bbb2c..36083e0e1c 100644 --- a/unit_tests/api/cl_get_extension_function_address_tests.inl +++ b/unit_tests/api/cl_get_extension_function_address_tests.inl @@ -47,13 +47,20 @@ TEST_F(clGetExtensionFunctionAddressTests, GivenClCreatePerfCountersCommandQueue auto retVal = clGetExtensionFunctionAddress("clCreatePerfCountersCommandQueueINTEL"); EXPECT_EQ(retVal, reinterpret_cast(clCreatePerfCountersCommandQueueINTEL)); } + TEST_F(clGetExtensionFunctionAddressTests, GivenClSetPerformanceConfigurationINTELWhenGettingExtensionFunctionThenCorrectAddressIsReturned) { auto retVal = clGetExtensionFunctionAddress("clSetPerformanceConfigurationINTEL"); EXPECT_EQ(retVal, reinterpret_cast(clSetPerformanceConfigurationINTEL)); } + TEST_F(clGetExtensionFunctionAddressTests, GivenClCreateBufferWithPropertiesINTELWhenGettingExtensionFunctionThenCorrectAddressIsReturned) { auto functionPointer = clGetExtensionFunctionAddress("clCreateBufferWithPropertiesINTEL"); EXPECT_EQ(functionPointer, reinterpret_cast(clCreateBufferWithPropertiesINTEL)); } +TEST_F(clGetExtensionFunctionAddressTests, givenClAddCommentToAubIntelAsInputWhenFunctionIsCalledThenProperPointerIsReturned) { + auto functionPointer = clGetExtensionFunctionAddress("clAddCommentINTEL"); + EXPECT_EQ(functionPointer, reinterpret_cast(clAddCommentINTEL)); +} + } // namespace ULT