L0: Pass debug zebin to SLD

Added passing debug zebin to SLD.
Added support for .const.data.strings section in debug zebin creation.
Refactored debug zebin creation code.

Resolves: NEO-6246
Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
Krystian Chmielewski
2021-10-28 15:54:45 +00:00
committed by Compute-Runtime-Automation
parent a787931b1d
commit 8e57e48695
9 changed files with 294 additions and 82 deletions

View File

@@ -15,6 +15,7 @@
#include "shared/test/common/mocks/mock_compilers.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/unit_test/device_binary_format/zebin_tests.h"
#include "level_zero/core/source/module/module.h"
#include "level_zero/core/source/module/module_imp.h"
@@ -288,6 +289,88 @@ struct MultiDeviceModuleFixture : public MultiDeviceFixture {
std::unique_ptr<WhiteBox<::L0::Kernel>> kernel;
};
struct ModuleWithZebinFixture : public DeviceFixture {
struct MockImmutableData : public KernelImmutableData {
using KernelImmutableData::device;
using KernelImmutableData::isaGraphicsAllocation;
using KernelImmutableData::kernelDescriptor;
MockImmutableData(L0::Device *device) {
auto mockKernelDescriptor = new NEO::KernelDescriptor;
mockKernelDescriptor->kernelMetadata.kernelName = "kernel";
kernelDescriptor = mockKernelDescriptor;
this->device = device;
isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0,
NEO::GraphicsAllocation::AllocationType::KERNEL_ISA,
reinterpret_cast<void *>(0x1234),
0x1000,
0,
sizeof(uint32_t),
MemoryPool::System4KBPages));
}
~MockImmutableData() {
delete kernelDescriptor;
}
};
struct MockModuleWithZebin : public L0::ModuleImp {
using ModuleImp::getZebinSegments;
using ModuleImp::kernelImmDatas;
using ModuleImp::passDebugData;
using ModuleImp::translationUnit;
MockModuleWithZebin(L0::Device *device) : ModuleImp(device, nullptr, ModuleType::User) {}
void addSegments() {
kernelImmDatas.push_back(std::make_unique<MockImmutableData>(device));
translationUnit->globalVarBuffer = new NEO::MockGraphicsAllocation(0,
NEO::GraphicsAllocation::AllocationType::GLOBAL_SURFACE,
reinterpret_cast<void *>(0x1234),
0x1000,
0,
sizeof(uint32_t),
MemoryPool::System4KBPages);
translationUnit->globalConstBuffer = new NEO::MockGraphicsAllocation(0,
NEO::GraphicsAllocation::AllocationType::GLOBAL_SURFACE,
reinterpret_cast<void *>(0x1234),
0x1000,
0,
sizeof(uint32_t),
MemoryPool::System4KBPages);
translationUnit->programInfo.globalStrings.initData = &strings;
translationUnit->programInfo.globalStrings.size = sizeof(strings);
}
void addKernelSegment() {
}
void addEmptyZebin() {
auto zebin = ZebinTestData::ValidEmptyProgram();
translationUnit->unpackedDeviceBinarySize = zebin.storage.size();
translationUnit->unpackedDeviceBinary.reset(new char[zebin.storage.size()]);
memcpy_s(translationUnit->unpackedDeviceBinary.get(), translationUnit->unpackedDeviceBinarySize,
zebin.storage.data(), zebin.storage.size());
}
~MockModuleWithZebin() {
}
const char strings[12] = "Hello olleH";
};
void SetUp() {
NEO::MockCompilerEnableGuard mock(true);
DeviceFixture::SetUp();
module = std::make_unique<MockModuleWithZebin>(device);
}
void TearDown() {
DeviceFixture::TearDown();
}
std::unique_ptr<MockModuleWithZebin> module;
};
struct ImportHostPointerModuleFixture : public ModuleFixture {
void SetUp() {
DebugManager.flags.EnableHostPointerImport.set(1);

View File

@@ -297,6 +297,16 @@ TEST_F(ModuleWithSLDTest, GivenDebugDataWithMultipleRelocationsWhenInitializingM
EXPECT_NE(nullptr, kernelInfo->kernelDescriptor.external.relocatedDebugData);
}
using ModuleWithZebinAndSLDTest = Test<ModuleWithZebinFixture>;
TEST_F(ModuleWithZebinAndSLDTest, GivenZebinThenCreateDebugZebinAndPassToSLD) {
module->addEmptyZebin();
auto debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);
module->passDebugData();
EXPECT_TRUE(module->translationUnit->debugData);
}
using KernelDebugSurfaceTest = Test<ModuleFixture>;
HWTEST_F(KernelDebugSurfaceTest, givenDebuggerAndBindfulKernelWhenAppendingKernelToCommandListThenBindfulSurfaceStateForDebugSurfaceIsProgrammed) {

View File

@@ -5,6 +5,7 @@
*
*/
#include "shared/source/device_binary_format/debug_zebin.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/kernel/implicit_args.h"
@@ -1958,5 +1959,39 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationWhenLinkingModuleThenSegmentIsPat
EXPECT_TRUE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs);
}
using ModuleWithZebinTest = Test<ModuleWithZebinFixture>;
TEST_F(ModuleWithZebinTest, givenNoZebinThenSegmentsAreEmpty) {
auto segments = module->getZebinSegments();
EXPECT_EQ(std::numeric_limits<uintptr_t>::max(), segments.constData.address);
EXPECT_TRUE(segments.constData.data.empty());
EXPECT_EQ(std::numeric_limits<uintptr_t>::max(), segments.varData.address);
EXPECT_TRUE(segments.varData.data.empty());
EXPECT_EQ(std::numeric_limits<uintptr_t>::max(), segments.stringData.address);
EXPECT_TRUE(segments.stringData.data.empty());
EXPECT_TRUE(segments.nameToSegMap.empty());
}
TEST_F(ModuleWithZebinTest, givenZebinSegmentsThenSegmentsArePopulated) {
module->addSegments();
auto segments = module->getZebinSegments();
auto checkGPUSeg = [](NEO::GraphicsAllocation *alloc, NEO::Debug::Segments::Segment segment) {
EXPECT_EQ(static_cast<uintptr_t>(alloc->getGpuAddressToPatch()), segment.address);
EXPECT_EQ(reinterpret_cast<uint8_t *>(alloc->getUnderlyingBuffer()), segment.data.begin());
EXPECT_EQ(static_cast<size_t>(alloc->getUnderlyingBufferSize()), segment.data.size());
};
checkGPUSeg(module->translationUnit->globalConstBuffer, segments.constData);
checkGPUSeg(module->translationUnit->globalConstBuffer, segments.varData);
checkGPUSeg(module->kernelImmDatas[0]->getIsaGraphicsAllocation(), segments.nameToSegMap["kernel"]);
EXPECT_EQ(reinterpret_cast<uintptr_t>(module->translationUnit->programInfo.globalStrings.initData), segments.stringData.address);
EXPECT_EQ(reinterpret_cast<const uint8_t *>(module->translationUnit->programInfo.globalStrings.initData), segments.stringData.data.begin());
EXPECT_EQ(module->translationUnit->programInfo.globalStrings.size, segments.stringData.data.size());
}
} // namespace ult
} // namespace L0