diff --git a/level_zero/core/source/debugger/debugger_l0.h b/level_zero/core/source/debugger/debugger_l0.h index 0bbda66441..84b55e084c 100644 --- a/level_zero/core/source/debugger/debugger_l0.h +++ b/level_zero/core/source/debugger/debugger_l0.h @@ -71,6 +71,7 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass { void captureStateBaseAddress(NEO::CommandContainer &container, SbaAddresses sba) override; void printTrackedAddresses(uint32_t contextId); + MOCKABLE_VIRTUAL void registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation); virtual size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) = 0; virtual void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) = 0; diff --git a/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp b/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp index e239ced908..d27487deb7 100644 --- a/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp +++ b/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp @@ -7,11 +7,12 @@ #include "shared/source/device/device.h" #include "shared/source/helpers/hw_helper.h" +#include "shared/source/kernel/debug_data.h" +#include "shared/source/os_interface/linux/drm_allocation.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/os_interface.h" #include "level_zero/core/source/debugger/debugger_l0.h" - namespace L0 { bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { if (osInterface != nullptr) { @@ -23,4 +24,12 @@ bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { } return false; } + +void DebuggerL0::registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) { + if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) { + auto drm = device->getRootDeviceEnvironment().osInterface->get()->getDrm(); + auto handle = drm->registerResource(NEO::Drm::ResourceClass::Elf, debugData->vIsa, debugData->vIsaSize); + static_cast(isaAllocation)->linkWithRegisteredHandle(handle); + } +} } // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp b/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp index e66332aeb7..81f513b457 100644 --- a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp +++ b/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp @@ -5,10 +5,19 @@ * */ +#include "shared/source/device/device.h" +#include "shared/source/helpers/hw_helper.h" +#include "shared/source/kernel/debug_data.h" +#include "shared/source/os_interface/linux/os_interface.h" + #include "level_zero/core/source/debugger/debugger_l0.h" namespace L0 { bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { return false; } -} // namespace L0 \ No newline at end of file + +void DebuggerL0::registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) { +} + +} // namespace L0 diff --git a/level_zero/core/source/kernel/kernel.h b/level_zero/core/source/kernel/kernel.h index 113b21e163..6db6f399c9 100644 --- a/level_zero/core/source/kernel/kernel.h +++ b/level_zero/core/source/kernel/kernel.h @@ -33,7 +33,7 @@ struct KernelImmutableData { KernelImmutableData(L0::Device *l0device = nullptr); virtual ~KernelImmutableData(); - void initialize(NEO::KernelInfo *kernelInfo, NEO::MemoryManager &memoryManager, const NEO::Device *device, + void initialize(NEO::KernelInfo *kernelInfo, Device *device, uint32_t computeUnitsUsedForSratch, NEO::GraphicsAllocation *globalConstBuffer, NEO::GraphicsAllocation *globalVarBuffer, bool internalKernel); diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index c213b18ff5..f67b28b20d 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -22,6 +22,7 @@ #include "opencl/source/mem_obj/buffer.h" #include "opencl/source/program/kernel_info.h" +#include "level_zero/core/source/debugger/debugger_l0.h" #include "level_zero/core/source/device/device.h" #include "level_zero/core/source/image/image.h" #include "level_zero/core/source/image/image_format_desc_helper.h" @@ -95,30 +96,37 @@ inline void patchWithImplicitSurface(ArrayRef crossThreadData, ArrayRef } } -void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, NEO::MemoryManager &memoryManager, - const NEO::Device *device, uint32_t computeUnitsUsedForSratch, +void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device, + uint32_t computeUnitsUsedForSratch, NEO::GraphicsAllocation *globalConstBuffer, NEO::GraphicsAllocation *globalVarBuffer, bool internalKernel) { + UNRECOVERABLE_IF(kernelInfo == nullptr); this->kernelDescriptor = &kernelInfo->kernelDescriptor; + auto neoDevice = device->getNEODevice(); + auto memoryManager = device->getNEODevice()->getMemoryManager(); + auto kernelIsaSize = kernelInfo->heapInfo.KernelHeapSize; const auto allocType = internalKernel ? NEO::GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL : NEO::GraphicsAllocation::AllocationType::KERNEL_ISA; - auto allocation = memoryManager.allocateGraphicsMemoryWithProperties( - {device->getRootDeviceIndex(), kernelIsaSize, allocType, device->getDeviceBitfield()}); + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties( + {neoDevice->getRootDeviceIndex(), kernelIsaSize, allocType, neoDevice->getDeviceBitfield()}); UNRECOVERABLE_IF(allocation == nullptr); - auto &hwInfo = device->getHardwareInfo(); + auto &hwInfo = neoDevice->getHardwareInfo(); auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily); if (kernelInfo->heapInfo.pKernelHeap != nullptr) { NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *allocation), - *device, allocation, 0, kernelInfo->heapInfo.pKernelHeap, + *neoDevice, allocation, 0, kernelInfo->heapInfo.pKernelHeap, static_cast(kernelIsaSize)); } isaGraphicsAllocation.reset(allocation); + if (device->getL0Debugger() && kernelInfo->kernelDescriptor.external.debugData.get()) { + device->getL0Debugger()->registerElf(kernelInfo->kernelDescriptor.external.debugData.get(), allocation); + } this->crossThreadDataSize = this->kernelDescriptor->kernelAttributes.crossThreadDataSize; @@ -162,13 +170,13 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, NEO::MemoryMan auto privateSurfaceSize = NEO::KernelHelper::getPrivateSurfaceSize(kernelAttributes.perHwThreadPrivateMemorySize, computeUnitsUsedForSratch); UNRECOVERABLE_IF(privateSurfaceSize == 0); - this->privateMemoryGraphicsAllocation.reset(memoryManager.allocateGraphicsMemoryWithProperties( - {device->getRootDeviceIndex(), privateSurfaceSize, NEO::GraphicsAllocation::AllocationType::PRIVATE_SURFACE, device->getDeviceBitfield()})); + this->privateMemoryGraphicsAllocation.reset(memoryManager->allocateGraphicsMemoryWithProperties( + {neoDevice->getRootDeviceIndex(), privateSurfaceSize, NEO::GraphicsAllocation::AllocationType::PRIVATE_SURFACE, neoDevice->getDeviceBitfield()})); UNRECOVERABLE_IF(this->privateMemoryGraphicsAllocation == nullptr); patchWithImplicitSurface(crossThredDataArrayRef, surfaceStateHeapArrayRef, static_cast(privateMemoryGraphicsAllocation->getGpuAddressToPatch()), - *privateMemoryGraphicsAllocation, kernelDescriptor->payloadMappings.implicitArgs.privateMemoryAddress, *device); + *privateMemoryGraphicsAllocation, kernelDescriptor->payloadMappings.implicitArgs.privateMemoryAddress, *neoDevice); this->residencyContainer.push_back(this->privateMemoryGraphicsAllocation.get()); } @@ -177,7 +185,7 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, NEO::MemoryMan patchWithImplicitSurface(crossThredDataArrayRef, surfaceStateHeapArrayRef, static_cast(globalConstBuffer->getGpuAddressToPatch()), - *globalConstBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalConstantsSurfaceAddress, *device); + *globalConstBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalConstantsSurfaceAddress, *neoDevice); this->residencyContainer.push_back(globalConstBuffer); } else if (nullptr != globalConstBuffer) { this->residencyContainer.push_back(globalConstBuffer); @@ -188,7 +196,7 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, NEO::MemoryMan patchWithImplicitSurface(crossThredDataArrayRef, surfaceStateHeapArrayRef, static_cast(globalVarBuffer->getGpuAddressToPatch()), - *globalVarBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalVariablesSurfaceAddress, *device); + *globalVarBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalVariablesSurfaceAddress, *neoDevice); this->residencyContainer.push_back(globalVarBuffer); } else if (nullptr != globalVarBuffer) { this->residencyContainer.push_back(globalVarBuffer); diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index 9e5a67997e..f3393124e0 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -11,6 +11,7 @@ #include "shared/source/device/device.h" #include "shared/source/device_binary_format/device_binary_formats.h" #include "shared/source/helpers/api_specific_config.h" +#include "shared/source/helpers/constants.h" #include "shared/source/helpers/string.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/unified_memory_manager.h" @@ -61,6 +62,12 @@ ModuleTranslationUnit::~ModuleTranslationUnit() { this->device->getNEODevice()->getExecutionEnvironment()->memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(globalVarBuffer); } } + + if (this->debugData != nullptr) { + for (std::vector::iterator iter = alignedvIsas.begin(); iter != alignedvIsas.end(); ++iter) { + alignedFree(static_cast(*iter)); + } + } } bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions, @@ -278,13 +285,17 @@ void ModuleTranslationUnit::processDebugData() { kernelInfo->kernelDescriptor.external.debugData = std::make_unique(); - kernelInfo->kernelDescriptor.external.debugData->vIsa = kernelDebugData; + char *alignedAlloc = static_cast(alignedMalloc(kernelDebugHeader->SizeVisaDbgInBytes, MemoryConstants::pageSize)); + memcpy_s(static_cast(alignedAlloc), kernelDebugHeader->SizeVisaDbgInBytes, kernelDebugData, kernelDebugHeader->SizeVisaDbgInBytes); + + kernelInfo->kernelDescriptor.external.debugData->vIsa = alignedAlloc; kernelInfo->kernelDescriptor.external.debugData->genIsa = ptrOffset(kernelDebugData, kernelDebugHeader->SizeVisaDbgInBytes); kernelInfo->kernelDescriptor.external.debugData->vIsaSize = kernelDebugHeader->SizeVisaDbgInBytes; kernelInfo->kernelDescriptor.external.debugData->genIsaSize = kernelDebugHeader->SizeGenIsaDbgInBytes; kernelDebugData = ptrOffset(kernelDebugData, static_cast(kernelDebugHeader->SizeVisaDbgInBytes) + kernelDebugHeader->SizeGenIsaDbgInBytes); kernelDebugHeader = reinterpret_cast(kernelDebugData); + alignedvIsas.push_back(alignedAlloc); } } } @@ -324,7 +335,6 @@ bool ModuleImp::initialize(const ze_module_desc_t *desc, NEO::Device *neoDevice) verifyDebugCapabilities(); this->updateBuildLog(neoDevice); - if (debugEnabled) { for (auto kernelInfo : this->translationUnit->programInfo.kernelInfos) { device->getSourceLevelDebugger()->notifyKernelDebugData(kernelInfo->kernelDescriptor.external.debugData.get(), @@ -341,9 +351,7 @@ bool ModuleImp::initialize(const ze_module_desc_t *desc, NEO::Device *neoDevice) kernelImmDatas.reserve(this->translationUnit->programInfo.kernelInfos.size()); for (auto &ki : this->translationUnit->programInfo.kernelInfos) { std::unique_ptr kernelImmData{new KernelImmutableData(this->device)}; - kernelImmData->initialize(ki, *(device->getNEODevice()->getMemoryManager()), - device->getNEODevice(), - device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, + kernelImmData->initialize(ki, device, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, this->translationUnit->globalConstBuffer, this->translationUnit->globalVarBuffer, this->type == ModuleType::Builtin); kernelImmDatas.push_back(std::move(kernelImmData)); diff --git a/level_zero/core/source/module/module_imp.h b/level_zero/core/source/module/module_imp.h index 2f5d1d364e..fcafe87318 100644 --- a/level_zero/core/source/module/module_imp.h +++ b/level_zero/core/source/module/module_imp.h @@ -59,6 +59,7 @@ struct ModuleTranslationUnit { std::unique_ptr debugData; size_t debugDataSize = 0U; + std::vector alignedvIsas; NEO::specConstValuesMap specConstantsValues; }; diff --git a/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp b/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp index 9c284daa38..e885b46804 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp @@ -6,8 +6,10 @@ */ #include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/kernel/debug_data.h" #include "shared/source/os_interface/linux/os_interface.h" +#include "opencl/test/unit_test/mocks/linux/mock_drm_allocation.h" #include "opencl/test/unit_test/os_interface/linux/drm_mock.h" #include "test.h" @@ -130,5 +132,49 @@ TEST(L0DebuggerLinux, givenPerContextVmNotEnabledWhenInitializingDebuggingInOsTh EXPECT_FALSE(drmMock->registerClassesCalled); } +TEST_F(L0DebuggerLinuxTest, whenRegisterElfisCalledThenItRegistersBindExtHandles) { + NEO::DebugData debugData; + debugData.vIsa = "01234567890"; + debugData.vIsaSize = 10; + MockDrmAllocation isaAllocation(GraphicsAllocation::AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); + MockBufferObject bo(drmMock, 0, 0, 1); + isaAllocation.bufferObjects[0] = &bo; + device->getL0Debugger()->registerElf(&debugData, &isaAllocation); + + EXPECT_EQ(static_cast(10), drmMock->registeredDataSize); + + auto &bos = isaAllocation.getBOs(); + for (auto bo : bos) { + if (bo) { + auto extBindHandles = bo->getBindExtHandles(); + EXPECT_NE(static_cast(0), extBindHandles.size()); + } + } +} + +TEST_F(L0DebuggerLinuxTest, whenRegisterElfisCalledInAllocationWithNoBOThenItRegistersBindExtHandles) { + NEO::DebugData debugData; + debugData.vIsa = "01234567890"; + debugData.vIsaSize = 10; + MockDrmAllocation isaAllocation(GraphicsAllocation::AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); + device->getL0Debugger()->registerElf(&debugData, &isaAllocation); + + EXPECT_EQ(static_cast(10u), drmMock->registeredDataSize); +} + +TEST_F(L0DebuggerLinuxTest, givenNoOSInterfaceThenRegisterElfDoesNothing) { + NEO::OSInterface *OSInterface_tmp = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.release(); + NEO::DebugData debugData; + debugData.vIsa = "01234567890"; + debugData.vIsaSize = 10; + drmMock->registeredDataSize = 0; + MockDrmAllocation isaAllocation(GraphicsAllocation::AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); + + device->getL0Debugger()->registerElf(&debugData, &isaAllocation); + + EXPECT_EQ(static_cast(0u), drmMock->registeredDataSize); + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.reset(OSInterface_tmp); +} + } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp index 8ed7bc92cc..9d5b6e07b8 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp @@ -15,6 +15,7 @@ #include "opencl/source/program/kernel_info_from_patchtokens.h" #include "test.h" +#include "level_zero/core/source/debugger/debugger_l0.h" #include "level_zero/core/source/image/image_format_desc_helper.h" #include "level_zero/core/source/image/image_hw.h" #include "level_zero/core/source/kernel/kernel_hw.h" @@ -262,7 +263,7 @@ HWTEST_F(KernelPropertiesTests, whenInitializingThenCalculatesProperPrivateSurfa kernelAttributes.simdSize = 8; KernelImmutableData kernelImmutableData(device); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), computeUnitsUsedForSratch, nullptr, nullptr, false); + kernelImmutableData.initialize(&kernelInfo, device, computeUnitsUsedForSratch, nullptr, nullptr, false); size_t expectedSize = static_cast(kernelAttributes.perHwThreadPrivateMemorySize) * computeUnitsUsedForSratch; EXPECT_GE(expectedSize, kernelImmutableData.getPrivateMemoryGraphicsAllocation()->getUnderlyingBufferSize()); @@ -453,7 +454,7 @@ struct KernelIsaTests : Test { if (createBcsEngine) { auto &engine = device->getNEODevice()->getEngine(0); - bcsOsContext.reset(OsContext::create(nullptr, 1, device->getNEODevice()->getDeviceBitfield(), aub_stream::ENGINE_BCS, PreemptionMode::Disabled, + bcsOsContext.reset(OsContext::create(nullptr, 0, device->getNEODevice()->getDeviceBitfield(), aub_stream::ENGINE_BCS, PreemptionMode::Disabled, false, false, false)); engine.osContext = bcsOsContext.get(); engine.commandStreamReceiver->setupContext(*bcsOsContext); @@ -478,7 +479,7 @@ TEST_F(KernelIsaTests, givenKernelAllocationInLocalMemoryWhenCreatingWithoutAllo auto bcsCsr = device->getNEODevice()->getEngine(aub_stream::EngineType::ENGINE_BCS, false, false).commandStreamReceiver; auto initialTaskCount = bcsCsr->peekTaskCount(); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), 0, nullptr, nullptr, false); + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false); if (kernelImmutableData.getIsaGraphicsAllocation()->isAllocatedInLocalMemoryPool()) { EXPECT_EQ(initialTaskCount + 1, bcsCsr->peekTaskCount()); @@ -504,7 +505,7 @@ TEST_F(KernelIsaTests, givenKernelAllocationInLocalMemoryWhenCreatingWithAllowed auto bcsCsr = device->getNEODevice()->getEngine(aub_stream::EngineType::ENGINE_BCS, false, false).commandStreamReceiver; auto initialTaskCount = bcsCsr->peekTaskCount(); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), 0, nullptr, nullptr, false); + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false); EXPECT_EQ(initialTaskCount, bcsCsr->peekTaskCount()); @@ -528,7 +529,7 @@ TEST_F(KernelIsaTests, givenKernelAllocationInLocalMemoryWhenCreatingWithDisallo auto bcsCsr = device->getNEODevice()->getEngine(aub_stream::EngineType::ENGINE_BCS, false, false).commandStreamReceiver; auto initialTaskCount = bcsCsr->peekTaskCount(); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), 0, nullptr, nullptr, false); + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false); EXPECT_EQ(initialTaskCount, bcsCsr->peekTaskCount()); @@ -543,7 +544,7 @@ TEST_F(KernelIsaTests, givenKernelInfoWhenInitializingImmutableDataWithInternalI KernelImmutableData kernelImmutableData(device); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), 0, nullptr, nullptr, true); + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, true); EXPECT_EQ(NEO::GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, kernelImmutableData.getIsaGraphicsAllocation()->getAllocationType()); } @@ -555,7 +556,7 @@ TEST_F(KernelIsaTests, givenKernelInfoWhenInitializingImmutableDataWithNonIntern KernelImmutableData kernelImmutableData(device); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), 0, nullptr, nullptr, false); + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false); EXPECT_EQ(NEO::GraphicsAllocation::AllocationType::KERNEL_ISA, kernelImmutableData.getIsaGraphicsAllocation()->getAllocationType()); } @@ -573,13 +574,39 @@ TEST_F(KernelIsaTests, givenGlobalBuffersWhenCreatingKernelImmutableDataThenBuff NEO::MockGraphicsAllocation globalVarBuffer(buffer, gpuAddress, size); NEO::MockGraphicsAllocation globalConstBuffer(buffer, gpuAddress, size); - kernelImmutableData.initialize(&kernelInfo, *device->getNEODevice()->getMemoryManager(), device->getNEODevice(), 0, + kernelImmutableData.initialize(&kernelInfo, device, 0, &globalConstBuffer, &globalVarBuffer, false); auto &resCont = kernelImmutableData.getResidencyContainer(); EXPECT_EQ(1, std::count(resCont.begin(), resCont.end(), &globalVarBuffer)); EXPECT_EQ(1, std::count(resCont.begin(), resCont.end(), &globalConstBuffer)); } +TEST_F(KernelIsaTests, givenDebugONAndKernelDegugInfoWhenInitializingImmutableDataThenRegisterElf) { + uint32_t kernelHeap = 0; + KernelInfo kernelInfo; + kernelInfo.heapInfo.KernelHeapSize = 1; + kernelInfo.heapInfo.pKernelHeap = &kernelHeap; + auto debugData = new DebugData; + kernelInfo.kernelDescriptor.external.debugData.reset(debugData); + class MockDebugger : public DebuggerL0 { + public: + MockDebugger(NEO::Device *neodev) : DebuggerL0(neodev) { + } + void registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) override { + debugData->vIsaSize = 123; + }; + size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) override { return static_cast(0); }; + void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) override{}; + }; + MockDebugger *debugger = new MockDebugger(neoDevice); + + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(static_cast(debugger)); + KernelImmutableData kernelImmutableData(device); + + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false); + EXPECT_EQ(kernelInfo.kernelDescriptor.external.debugData->vIsaSize, static_cast(123)); +} + using KernelImpPatchBindlessTest = Test; TEST_F(KernelImpPatchBindlessTest, GivenKernelImpWhenPatchBindlessOffsetCalledThenOffsetPatchedCorrectly) { diff --git a/opencl/test/unit_test/os_interface/linux/drm_mock.h b/opencl/test/unit_test/os_interface/linux/drm_mock.h index ed996c3286..cba07ebc72 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_mock.h +++ b/opencl/test/unit_test/os_interface/linux/drm_mock.h @@ -237,7 +237,7 @@ class DrmMockResources : public DrmMock { return true; } - uint32_t registerResource(ResourceClass classType, void *data, size_t size) override { + uint32_t registerResource(ResourceClass classType, const void *data, size_t size) override { registeredClass = classType; memcpy_s(registeredData, sizeof(registeredData), data, size); registeredDataSize = size; diff --git a/shared/source/debugger/debugger.cpp b/shared/source/debugger/debugger.cpp index 24c9f3f5e0..a5bec21ee8 100644 --- a/shared/source/debugger/debugger.cpp +++ b/shared/source/debugger/debugger.cpp @@ -12,7 +12,6 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/source_level_debugger/source_level_debugger.h" - namespace NEO { std::unique_ptr Debugger::create(HardwareInfo *hwInfo) { std::unique_ptr sourceLevelDebugger; diff --git a/shared/source/debugger/debugger.h b/shared/source/debugger/debugger.h index 161556cc45..f724176bd2 100644 --- a/shared/source/debugger/debugger.h +++ b/shared/source/debugger/debugger.h @@ -11,6 +11,8 @@ namespace NEO { struct HardwareInfo; class CommandContainer; class IndirectHeap; +struct DebugData; +class GraphicsAllocation; class Debugger { public: @@ -28,7 +30,6 @@ class Debugger { virtual ~Debugger() = default; bool isLegacy() const { return isLegacyMode; } virtual void captureStateBaseAddress(CommandContainer &container, SbaAddresses sba) = 0; - void *getDebugSurfaceReservedSurfaceState(IndirectHeap &ssh); inline static bool isDebugEnabled(bool internalUsage) { diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 29af515068..5998426687 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -112,6 +112,15 @@ void DrmAllocation::registerBOBindExtHandle(Drm *drm) { } } +void DrmAllocation::linkWithRegisteredHandle(uint32_t handle) { + auto &bos = getBOs(); + for (auto bo : bos) { + if (bo) { + bo->addBindExtHandle(handle); + } + } +} + void DrmAllocation::freeRegisteredBOBindExtHandles(Drm *drm) { for (auto &i : registeredBoBindHandles) { drm->unregisterResource(i); diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index bbffd430dc..df2e753f0e 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -73,6 +73,7 @@ class DrmAllocation : public GraphicsAllocation { void bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector *bufferObjects, bool bind); MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm); void freeRegisteredBOBindExtHandles(Drm *drm); + void linkWithRegisteredHandle(uint32_t handle); protected: BufferObjects bufferObjects{}; diff --git a/shared/source/os_interface/linux/drm_debug.cpp b/shared/source/os_interface/linux/drm_debug.cpp index e01f0b0eaa..3c9113798a 100644 --- a/shared/source/os_interface/linux/drm_debug.cpp +++ b/shared/source/os_interface/linux/drm_debug.cpp @@ -13,7 +13,7 @@ bool Drm::registerResourceClasses() { return false; } -uint32_t Drm::registerResource(ResourceClass classType, void *data, size_t size) { +uint32_t Drm::registerResource(ResourceClass classType, const void *data, size_t size) { return 0; } @@ -23,4 +23,4 @@ uint32_t Drm::registerIsaCookie(uint32_t isaHandle) { void Drm::unregisterResource(uint32_t handle) { } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index 552de9329e..489b8c630f 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -122,7 +122,7 @@ class Drm { MOCKABLE_VIRTUAL bool isVmBindAvailable(); MOCKABLE_VIRTUAL bool registerResourceClasses(); - MOCKABLE_VIRTUAL uint32_t registerResource(ResourceClass classType, void *data, size_t size); + MOCKABLE_VIRTUAL uint32_t registerResource(ResourceClass classType, const void *data, size_t size); MOCKABLE_VIRTUAL void unregisterResource(uint32_t handle); MOCKABLE_VIRTUAL uint32_t registerIsaCookie(uint32_t isaHandle);