mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-31 11:26:21 +08:00
Zebin: Use strings section for printf
Resolves: NEO-6143 Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
5d1c3c98a4
commit
06eaef0352
@@ -487,7 +487,7 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeConstantB
|
||||
programInfo.globalConstants.initData = constantSurface.mockGfxAllocation.getUnderlyingBuffer();
|
||||
|
||||
pProgram->setLinkerInput(pClDevice->getRootDeviceIndex(), std::move(programInfo.linkerInput));
|
||||
pProgram->linkBinary(&pClDevice->getDevice(), programInfo.globalConstants.initData, programInfo.globalVariables.initData);
|
||||
pProgram->linkBinary(&pClDevice->getDevice(), programInfo.globalConstants.initData, programInfo.globalVariables.initData, {});
|
||||
uint32_t expectedAddr = static_cast<uint32_t>(constantSurface.getGraphicsAllocation(pClDevice->getRootDeviceIndex())->getGpuAddressToPatch());
|
||||
EXPECT_EQ(expectedAddr, constantSurfaceStorage[0]);
|
||||
EXPECT_EQ(sentinel, constantSurfaceStorage[1]);
|
||||
@@ -533,7 +533,7 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeGlobalPoi
|
||||
programInfo.globalVariables.initData = globalSurface.mockGfxAllocation.getUnderlyingBuffer();
|
||||
|
||||
pProgram->setLinkerInput(pClDevice->getRootDeviceIndex(), std::move(programInfo.linkerInput));
|
||||
pProgram->linkBinary(&pClDevice->getDevice(), programInfo.globalConstants.initData, programInfo.globalVariables.initData);
|
||||
pProgram->linkBinary(&pClDevice->getDevice(), programInfo.globalConstants.initData, programInfo.globalVariables.initData, {});
|
||||
uint32_t expectedAddr = static_cast<uint32_t>(globalSurface.getGraphicsAllocation(pClDevice->getRootDeviceIndex())->getGpuAddressToPatch());
|
||||
EXPECT_EQ(expectedAddr, globalSurfaceStorage[0]);
|
||||
EXPECT_EQ(sentinel, globalSurfaceStorage[1]);
|
||||
@@ -560,7 +560,7 @@ TEST(ProgramLinkBinaryTest, whenLinkerInputEmptyThenLinkSuccessful) {
|
||||
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
|
||||
MockProgram program{nullptr, false, toClDeviceVector(*device)};
|
||||
program.setLinkerInput(device->getRootDeviceIndex(), std::move(linkerInput));
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr);
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr, {});
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ TEST(ProgramLinkBinaryTest, whenLinkerUnresolvedExternalThenLinkFailedAndBuildLo
|
||||
|
||||
std::string buildLog = program.getBuildLog(device->getRootDeviceIndex());
|
||||
EXPECT_TRUE(buildLog.empty());
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr);
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr, {});
|
||||
EXPECT_NE(CL_SUCCESS, ret);
|
||||
program.getKernelInfoArray(rootDeviceIndex).clear();
|
||||
buildLog = program.getBuildLog(rootDeviceIndex);
|
||||
@@ -632,7 +632,7 @@ TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) {
|
||||
buildInfo.globalSurface = new MockGraphicsAllocation(globalVariablesBuffer.data(), globalVariablesBuffer.size());
|
||||
buildInfo.constantSurface = new MockGraphicsAllocation(globalConstantsBuffer.data(), globalConstantsBuffer.size());
|
||||
|
||||
auto ret = program.linkBinary(&pClDevice->getDevice(), globalConstantsInitData.data(), globalVariablesInitData.data());
|
||||
auto ret = program.linkBinary(&pClDevice->getDevice(), globalConstantsInitData.data(), globalVariablesInitData.data(), {});
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
|
||||
linkerInput.reset(static_cast<WhiteBox<LinkerInput> *>(buildInfo.linkerInput.release()));
|
||||
@@ -680,7 +680,7 @@ TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) {
|
||||
buildInfo.globalSurface = new MockGraphicsAllocation(globalVariablesBuffer.data(), globalVariablesBuffer.size());
|
||||
buildInfo.constantSurface = new MockGraphicsAllocation(globalConstantsBuffer.data(), globalConstantsBuffer.size());
|
||||
|
||||
auto ret = program.linkBinary(&pClDevice->getDevice(), globalConstantsInitData.data(), globalVariablesInitData.data());
|
||||
auto ret = program.linkBinary(&pClDevice->getDevice(), globalConstantsInitData.data(), globalVariablesInitData.data(), {});
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
EXPECT_EQ(kernelHeapData, kernelHeap);
|
||||
|
||||
@@ -691,6 +691,49 @@ TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) {
|
||||
buildInfo.constantSurface = nullptr;
|
||||
}
|
||||
|
||||
TEST(ProgramStringSectionTest, WhenConstStringBufferIsPresentThenUseItForLinking) {
|
||||
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
|
||||
auto rootDeviceIndex = device->getRootDeviceIndex();
|
||||
|
||||
MockProgram program{nullptr, false, toClDeviceVector(*device)};
|
||||
|
||||
uint8_t kernelHeapData[64] = {};
|
||||
MockGraphicsAllocation kernelIsa(kernelHeapData, 64);
|
||||
|
||||
KernelInfo kernelInfo = {};
|
||||
kernelInfo.kernelDescriptor.kernelMetadata.kernelName = "onlyKernel";
|
||||
kernelInfo.heapInfo.pKernelHeap = kernelHeapData;
|
||||
kernelInfo.heapInfo.KernelHeapSize = 64;
|
||||
kernelInfo.kernelAllocation = &kernelIsa;
|
||||
|
||||
program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo);
|
||||
|
||||
auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>();
|
||||
linkerInput->relocations.push_back({{".str", 0x8, LinkerInput::RelocationInfo::Type::Address, SegmentType::Instructions}});
|
||||
linkerInput->symbols.insert({".str", {0x0, 0x8, SegmentType::GlobalStrings}});
|
||||
linkerInput->traits.requiresPatchingOfInstructionSegments = true;
|
||||
|
||||
program.setLinkerInput(rootDeviceIndex, std::move(linkerInput));
|
||||
|
||||
auto isaCpuPtr = reinterpret_cast<char *>(kernelInfo.getGraphicsAllocation()->getUnderlyingBuffer());
|
||||
auto patchAddr = ptrOffset(isaCpuPtr, 0x8);
|
||||
|
||||
const char constStringData[] = "Hello World!\n";
|
||||
auto stringsAddr = reinterpret_cast<uintptr_t>(constStringData);
|
||||
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr, {constStringData, sizeof(constStringData)});
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
|
||||
constexpr bool is64Bit = sizeof(void *) == 8;
|
||||
if (is64Bit) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(stringsAddr), *reinterpret_cast<uint64_t *>(patchAddr));
|
||||
} else {
|
||||
EXPECT_EQ(static_cast<uint32_t>(stringsAddr), *reinterpret_cast<uint32_t *>(patchAddr));
|
||||
}
|
||||
|
||||
program.getKernelInfoArray(rootDeviceIndex).clear();
|
||||
}
|
||||
|
||||
TEST(ProgramImplicitArgsTest, whenImplicitRelocationIsPresentThenKernelRequiresImplicitArgs) {
|
||||
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
|
||||
auto rootDeviceIndex = device->getRootDeviceIndex();
|
||||
@@ -708,7 +751,7 @@ TEST(ProgramImplicitArgsTest, whenImplicitRelocationIsPresentThenKernelRequiresI
|
||||
linkerInput->relocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::AddressLow, SegmentType::Instructions}});
|
||||
linkerInput->traits.requiresPatchingOfInstructionSegments = true;
|
||||
program.setLinkerInput(rootDeviceIndex, std::move(linkerInput));
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr);
|
||||
auto ret = program.linkBinary(&device->getDevice(), nullptr, nullptr, {});
|
||||
EXPECT_EQ(CL_SUCCESS, ret);
|
||||
|
||||
EXPECT_TRUE(kernelInfo.kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs);
|
||||
|
||||
Reference in New Issue
Block a user