Relocate debug data

Related-To: NEO-4769

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-02-09 14:57:16 +00:00
committed by Compute-Runtime-Automation
parent a0d3e8b352
commit 6dd0f0c728
17 changed files with 579 additions and 51 deletions

View File

@@ -21,6 +21,7 @@ namespace ult {
template <>
struct WhiteBox<::L0::KernelImmutableData> : public ::L0::KernelImmutableData {
using BaseClass = ::L0::KernelImmutableData;
using ::L0::KernelImmutableData::createRelocatedDebugData;
using ::L0::KernelImmutableData::crossThreadDataSize;
using ::L0::KernelImmutableData::crossThreadDataTemplate;
using ::L0::KernelImmutableData::device;

View File

@@ -65,6 +65,8 @@ struct MockModuleTranslationUnit : public L0::ModuleTranslationUnit {
struct MockModule : public L0::ModuleImp {
using ModuleImp::debugEnabled;
using ModuleImp::kernelImmDatas;
using ModuleImp::translationUnit;
MockModule(L0::Device *device,
L0::ModuleBuildLog *moduleBuildLog,
@@ -77,6 +79,7 @@ struct MockModule : public L0::ModuleImp {
const KernelImmutableData *getKernelImmutableData(const char *functionName) const override {
return kernelImmData;
}
KernelImmutableData *kernelImmData = nullptr;
};

View File

@@ -7,6 +7,7 @@
#include "shared/source/device_binary_format/patchtokens_decoder.h"
#include "shared/source/kernel/kernel_descriptor_from_patchtokens.h"
#include "shared/test/common/mocks/mock_elf.h"
#include "opencl/source/program/kernel_info.h"
#include "opencl/source/program/kernel_info_from_patchtokens.h"
@@ -106,6 +107,140 @@ TEST_F(DeviceWithDebuggerEnabledTest, GivenNonDebuggeableKernelWhenModuleIsIniti
EXPECT_FALSE(module->isDebugEnabled());
}
using ModuleWithSLDTest = Test<ModuleFixture>;
TEST_F(ModuleWithSLDTest, GivenNoDebugDataWhenInitializingModuleThenRelocatedDebugDataIsNotCreated) {
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->compilerInterface.reset(cip);
auto debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);
uint8_t binary[10];
ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
moduleDesc.pInputModule = binary;
moduleDesc.inputSize = 10;
ModuleBuildLog *moduleBuildLog = nullptr;
std::unique_ptr<MockModule> module = std::make_unique<MockModule>(device,
moduleBuildLog,
ModuleType::User);
module->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
uint32_t kernelHeap = 0;
auto kernelInfo = new KernelInfo();
kernelInfo->heapInfo.KernelHeapSize = 1;
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;
Mock<::L0::Kernel> kernel;
kernel.module = module.get();
kernel.immutableData.kernelInfo = kernelInfo;
kernel.immutableData.surfaceStateHeapSize = 64;
kernel.immutableData.surfaceStateHeapTemplate.reset(new uint8_t[64]);
kernelInfo->kernelDescriptor.payloadMappings.implicitArgs.systemThreadSurfaceAddress.bindful = 0;
module->kernelImmData = &kernel.immutableData;
module->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
EXPECT_EQ(nullptr, module->translationUnit->debugData.get());
auto result = module->initialize(&moduleDesc, neoDevice);
EXPECT_TRUE(result);
EXPECT_EQ(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData);
}
TEST_F(ModuleWithSLDTest, GivenDebugDataWithSingleRelocationWhenInitializingModuleThenRelocatedDebugDataIsNotCreated) {
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->compilerInterface.reset(cip);
auto debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);
createKernel();
uint8_t binary[10];
ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
moduleDesc.pInputModule = binary;
moduleDesc.inputSize = 10;
ModuleBuildLog *moduleBuildLog = nullptr;
std::unique_ptr<MockModule> moduleMock = std::make_unique<MockModule>(device, moduleBuildLog, ModuleType::User);
moduleMock->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
uint32_t kernelHeap = 0;
auto kernelInfo = new KernelInfo();
kernelInfo->heapInfo.KernelHeapSize = 1;
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;
Mock<::L0::Kernel> kernelMock;
kernelMock.module = moduleMock.get();
kernelMock.immutableData.kernelInfo = kernelInfo;
kernelMock.immutableData.surfaceStateHeapSize = 64;
kernelMock.immutableData.surfaceStateHeapTemplate.reset(new uint8_t[64]);
kernelInfo->kernelDescriptor.payloadMappings.implicitArgs.systemThreadSurfaceAddress.bindful = 0;
moduleMock->kernelImmData = &kernelMock.immutableData;
moduleMock->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
kernelInfo->kernelDescriptor.external.debugData = std::make_unique<NEO::DebugData>();
kernelInfo->kernelDescriptor.external.debugData->vIsa = kernel->getKernelDescriptor().external.debugData->vIsa;
kernelInfo->kernelDescriptor.external.debugData->vIsaSize = kernel->getKernelDescriptor().external.debugData->vIsaSize;
kernelInfo->kernelDescriptor.external.debugData->genIsa = nullptr;
kernelInfo->kernelDescriptor.external.debugData->genIsaSize = 0;
auto result = moduleMock->initialize(&moduleDesc, neoDevice);
EXPECT_TRUE(result);
EXPECT_EQ(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData);
}
TEST_F(ModuleWithSLDTest, GivenDebugDataWithMultipleRelocationsWhenInitializingModuleThenRelocatedDebugDataIsCreated) {
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->compilerInterface.reset(cip);
auto debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);
uint8_t binary[10];
ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
moduleDesc.pInputModule = binary;
moduleDesc.inputSize = 10;
ModuleBuildLog *moduleBuildLog = nullptr;
std::unique_ptr<MockModule> moduleMock = std::make_unique<MockModule>(device, moduleBuildLog, ModuleType::User);
moduleMock->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
uint32_t kernelHeap = 0;
auto kernelInfo = new KernelInfo();
kernelInfo->heapInfo.KernelHeapSize = 1;
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;
Mock<::L0::Kernel> kernelMock;
kernelMock.module = moduleMock.get();
kernelMock.immutableData.kernelInfo = kernelInfo;
kernelInfo->kernelDescriptor.payloadMappings.implicitArgs.systemThreadSurfaceAddress.bindful = 0;
moduleMock->kernelImmData = &kernelMock.immutableData;
moduleMock->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
kernelInfo->kernelDescriptor.external.debugData = std::make_unique<NEO::DebugData>();
auto debugData = MockElfEncoder<>::createRelocateableDebugDataElf();
kernelInfo->kernelDescriptor.external.debugData->vIsaSize = static_cast<uint32_t>(debugData.size());
kernelInfo->kernelDescriptor.external.debugData->vIsa = reinterpret_cast<char *>(debugData.data());
kernelInfo->kernelDescriptor.external.debugData->genIsa = nullptr;
kernelInfo->kernelDescriptor.external.debugData->genIsaSize = 0;
EXPECT_EQ(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData);
auto result = moduleMock->initialize(&moduleDesc, neoDevice);
EXPECT_TRUE(result);
EXPECT_NE(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData);
}
using KernelDebugSurfaceTest = Test<ModuleFixture>;
HWTEST_F(KernelDebugSurfaceTest, givenDebuggerAndBindfulKernelWhenAppendingKernelToCommandListThenBindfulSurfaceStateForDebugSurfaceIsProgrammed) {

View File

@@ -8,6 +8,7 @@
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_elf.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/unit_test/compiler_interface/linker_mock.h"
#include "shared/test/unit_test/device_binary_format/zebin_tests.h"
@@ -857,5 +858,56 @@ TEST_F(ModuleTest, givenInternalOptionsWhenBindlessDisabledThenBindlesOptionsNot
EXPECT_FALSE(NEO::CompilerOptions::contains(internalBuildOptions, NEO::CompilerOptions::bindlessMode));
}
using ModuleDebugDataTest = Test<DeviceFixture>;
TEST_F(ModuleDebugDataTest, GivenDebugDataWithRelocationsWhenCreatingRelocatedDebugDataThenRelocationsAreApplied) {
auto cip = new NEO::MockCompilerInterfaceCaptureBuildOptions();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->compilerInterface.reset(cip);
uint8_t binary[10];
ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
moduleDesc.pInputModule = binary;
moduleDesc.inputSize = 10;
ModuleBuildLog *moduleBuildLog = nullptr;
std::unique_ptr<MockModule> module = std::make_unique<MockModule>(device,
moduleBuildLog,
ModuleType::User);
module->translationUnit = std::make_unique<MockModuleTranslationUnit>(device);
module->translationUnit->globalVarBuffer = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
{device->getRootDeviceIndex(), MemoryConstants::pageSize, NEO::GraphicsAllocation::AllocationType::BUFFER, neoDevice->getDeviceBitfield()});
module->translationUnit->globalConstBuffer = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
{device->getRootDeviceIndex(), MemoryConstants::pageSize, NEO::GraphicsAllocation::AllocationType::BUFFER, neoDevice->getDeviceBitfield()});
uint32_t kernelHeap = 0;
auto kernelInfo = new KernelInfo();
kernelInfo->heapInfo.KernelHeapSize = 1;
kernelInfo->heapInfo.pKernelHeap = &kernelHeap;
kernelInfo->kernelDescriptor.payloadMappings.implicitArgs.systemThreadSurfaceAddress.bindful = 0;
kernelInfo->kernelDescriptor.external.debugData = std::make_unique<NEO::DebugData>();
auto debugData = MockElfEncoder<>::createRelocateableDebugDataElf();
kernelInfo->kernelDescriptor.external.debugData->vIsaSize = static_cast<uint32_t>(debugData.size());
kernelInfo->kernelDescriptor.external.debugData->vIsa = reinterpret_cast<char *>(debugData.data());
// pass kernelInfo ownership to programInfo
module->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
std::unique_ptr<WhiteBox<::L0::KernelImmutableData>> kernelImmData{new WhiteBox<::L0::KernelImmutableData>(this->device)};
kernelImmData->initialize(kernelInfo, device, 0, module->translationUnit->globalConstBuffer, module->translationUnit->globalVarBuffer, false);
kernelImmData->createRelocatedDebugData(module->translationUnit->globalConstBuffer, module->translationUnit->globalVarBuffer);
module->kernelImmDatas.push_back(std::move(kernelImmData));
EXPECT_NE(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData);
uint64_t *relocAddress = reinterpret_cast<uint64_t *>(kernelInfo->kernelDescriptor.external.relocatedDebugData.get() + 600);
auto expectedValue = module->kernelImmDatas[0]->getIsaGraphicsAllocation()->getGpuAddress() + 0x1a8;
EXPECT_EQ(expectedValue, *relocAddress);
}
} // namespace ult
} // namespace L0