From e605efb88e209f1e165a6870aa2ab6d168060dc2 Mon Sep 17 00:00:00 2001 From: Maciej Plewka Date: Fri, 21 May 2021 14:08:01 +0000 Subject: [PATCH] Fix pass debugData from kernel descriptor to gtpin Signed-off-by: Maciej Plewka --- opencl/source/gtpin/gtpin_callbacks.cpp | 9 +++- opencl/test/unit_test/gtpin/gtpin_tests.cpp | 54 +++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/opencl/source/gtpin/gtpin_callbacks.cpp b/opencl/source/gtpin/gtpin_callbacks.cpp index f63b66f344..b2974658c8 100644 --- a/opencl/source/gtpin/gtpin_callbacks.cpp +++ b/opencl/source/gtpin/gtpin_callbacks.cpp @@ -95,8 +95,13 @@ void gtpinNotifyKernelCreate(cl_kernel kernel) { paramsIn.igc_hash_id = kernelInfo.shaderHashCode; paramsIn.kernel_name = (char *)kernelInfo.kernelDescriptor.kernelMetadata.kernelName.c_str(); paramsIn.igc_info = kernelInfo.igcInfoForGtpin; - paramsIn.debug_data = pKernel->getProgram()->getDebugData(); - paramsIn.debug_data_size = static_cast(pKernel->getProgram()->getDebugDataSize()); + if (kernelInfo.kernelDescriptor.external.debugData.get()) { + paramsIn.debug_data = kernelInfo.kernelDescriptor.external.debugData->vIsa; + paramsIn.debug_data_size = static_cast(kernelInfo.kernelDescriptor.external.debugData->vIsaSize); + } else { + paramsIn.debug_data = nullptr; + paramsIn.debug_data_size = 0; + } instrument_params_out_t paramsOut = {0}; (*GTPinCallbacks.onKernelCreate)((context_handle_t)(cl_context)context, ¶msIn, ¶msOut); // Substitute ISA of created kernel with instrumented code diff --git a/opencl/test/unit_test/gtpin/gtpin_tests.cpp b/opencl/test/unit_test/gtpin/gtpin_tests.cpp index df5535c38a..731c52fa88 100644 --- a/opencl/test/unit_test/gtpin/gtpin_tests.cpp +++ b/opencl/test/unit_test/gtpin/gtpin_tests.cpp @@ -2459,6 +2459,60 @@ TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenOnKernelCreateIsCalledWithN EXPECT_EQ(prevCreateCount, KernelCreateCallbackCount); } +TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelDoesNotHaveDebugDataThenPassNullPtrToOnKernelCreate) { + static void *debugDataPtr = nullptr; + static size_t debugDataSize = 0; + gtpinCallbacks.onContextCreate = OnContextCreate; + gtpinCallbacks.onContextDestroy = OnContextDestroy; + gtpinCallbacks.onKernelCreate = [](context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) { + paramsOut->inst_kernel_binary = const_cast(paramsIn->orig_kernel_binary); + paramsOut->inst_kernel_size = paramsIn->orig_kernel_size; + paramsOut->kernel_id = paramsIn->igc_hash_id; + debugDataPtr = const_cast(paramsIn->debug_data); + debugDataSize = paramsIn->debug_data_size; + }; + gtpinCallbacks.onKernelSubmit = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {}; + gtpinCallbacks.onCommandBufferCreate = OnCommandBufferCreate; + gtpinCallbacks.onCommandBufferComplete = OnCommandBufferComplete; + retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr); + MockKernelWithInternals mockKernel(*pDevice); + mockKernel.kernelInfo.kernelDescriptor.external.debugData.reset(); + mockKernel.kernelInfo.createKernelAllocation(pDevice->getDevice(), false); + gtpinNotifyKernelCreate(static_cast(mockKernel.mockKernel->getMultiDeviceKernel())); + EXPECT_EQ(debugDataPtr, nullptr); + EXPECT_EQ(debugDataSize, 0u); + pDevice->getMemoryManager()->freeGraphicsMemory(mockKernel.kernelInfo.kernelAllocation); +} + +TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenKernelHasDebugDataThenCorrectDebugDataIsSet) { + static void *debugDataPtr = nullptr; + static size_t debugDataSize = 0; + void *dummyDebugData = reinterpret_cast(0x123456); + size_t dummyDebugDataSize = 0x2245; + gtpinCallbacks.onContextCreate = OnContextCreate; + gtpinCallbacks.onContextDestroy = OnContextDestroy; + gtpinCallbacks.onKernelCreate = [](context_handle_t context, const instrument_params_in_t *paramsIn, instrument_params_out_t *paramsOut) { + paramsOut->inst_kernel_binary = const_cast(paramsIn->orig_kernel_binary); + paramsOut->inst_kernel_size = paramsIn->orig_kernel_size; + paramsOut->kernel_id = paramsIn->igc_hash_id; + debugDataPtr = const_cast(paramsIn->debug_data); + debugDataSize = paramsIn->debug_data_size; + }; + gtpinCallbacks.onKernelSubmit = [](command_buffer_handle_t cb, uint64_t kernelId, uint32_t *entryOffset, resource_handle_t *resource) {}; + gtpinCallbacks.onCommandBufferCreate = OnCommandBufferCreate; + gtpinCallbacks.onCommandBufferComplete = OnCommandBufferComplete; + retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr); + MockKernelWithInternals mockKernel(*pDevice); + mockKernel.kernelInfo.kernelDescriptor.external.debugData.reset(new DebugData()); + mockKernel.kernelInfo.kernelDescriptor.external.debugData->vIsa = reinterpret_cast(dummyDebugData); + mockKernel.kernelInfo.kernelDescriptor.external.debugData->vIsaSize = static_cast(dummyDebugDataSize); + mockKernel.kernelInfo.createKernelAllocation(pDevice->getDevice(), false); + gtpinNotifyKernelCreate(static_cast(mockKernel.mockKernel->getMultiDeviceKernel())); + EXPECT_EQ(debugDataPtr, dummyDebugData); + EXPECT_EQ(debugDataSize, dummyDebugDataSize); + pDevice->getMemoryManager()->freeGraphicsMemory(mockKernel.kernelInfo.kernelAllocation); +} + HWTEST_F(GTPinTests, givenGtPinInitializedWhenSubmittingKernelCommandThenFlushedTaskCountIsNotified) { auto mockCmdQ = std::make_unique>(pContext, pDevice, nullptr);