From 410e3c0ced975d627db2941a9504a04f3342d107 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 8 Oct 2020 14:31:53 +0200 Subject: [PATCH] Add ULT for Linker::patchDataSegments Verify blitter usage. Change-Id: Ic6dc10df967b8b22a86c29dee6a8df0d357ddf65 Signed-off-by: Filip Hazubski --- .../compiler_interface/linker_tests.cpp | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/shared/test/unit_test/compiler_interface/linker_tests.cpp b/shared/test/unit_test/compiler_interface/linker_tests.cpp index 9786d5e458..e9e0f265ea 100644 --- a/shared/test/unit_test/compiler_interface/linker_tests.cpp +++ b/shared/test/unit_test/compiler_interface/linker_tests.cpp @@ -7,10 +7,13 @@ #include "shared/source/helpers/ptr_math.h" #include "shared/source/memory_manager/graphics_allocation.h" +#include "shared/source/program/program_initialization.h" +#include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/default_hw_info.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_graphics_allocation.h" +#include "opencl/test/unit_test/mocks/mock_svm_manager.h" #include "RelocationInfo.h" #include "gmock/gmock.h" @@ -959,6 +962,86 @@ TEST(LinkerTests, givenInvalidRelocationOffsetThenPatchingOfDataSegmentsFails) { EXPECT_EQ(0U, unresolvedExternals.size()); } +TEST(LinkerTests, GivenAllocationInLocalMemoryWhichRequiresBlitterWhenPatchingDataSegmentsAllocationThenBlitterIsUsed) { + DebugManagerStateRestore restorer; + + auto hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = true; + + uint32_t blitsCounter = 0; + uint32_t expectedBlitsCount = 0; + auto mockBlitMemoryToAllocation = [&blitsCounter](const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr, + Vec3 size) -> BlitOperationResult { + blitsCounter++; + return BlitOperationResult::Success; + }; + VariableBackup blitMemoryToAllocationFuncBackup{ + &BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation}; + + LocalMemoryAccessMode localMemoryAccessModes[] = { + LocalMemoryAccessMode::Default, + LocalMemoryAccessMode::CpuAccessAllowed, + LocalMemoryAccessMode::CpuAccessDisallowed}; + + std::vector initData; + initData.resize(64, 7U); + + for (auto localMemoryAccessMode : localMemoryAccessModes) { + DebugManager.flags.ForceLocalMemoryAccessMode.set(static_cast(localMemoryAccessMode)); + for (auto isLocalMemorySupported : ::testing::Bool()) { + DebugManager.flags.EnableLocalMemory.set(isLocalMemorySupported); + auto pDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + MockSVMAllocsManager svmAllocsManager(pDevice->getMemoryManager()); + + WhiteBox linkerInput; + NEO::Linker linker(linkerInput); + + NEO::Linker::SegmentInfo emptySegmentInfo; + NEO::Linker::UnresolvedExternals unresolvedExternals; + + std::vector nonEmptypatchableSegmentData; + nonEmptypatchableSegmentData.resize(64, 8U); + auto pNonEmptypatchableSegment = allocateGlobalsSurface(&svmAllocsManager, *pDevice, nonEmptypatchableSegmentData.size(), + true /* constant */, nullptr /* linker input */, + nonEmptypatchableSegmentData.data()); + + NEO::LinkerInput::RelocationInfo relocInfo; + relocInfo.offset = 0U; + relocInfo.symbolName = "aaa"; + relocInfo.type = NEO::LinkerInput::RelocationInfo::Type::Address; + linkerInput.dataRelocations.push_back(relocInfo); + linkerInput.dataRelocations[0].relocationSegment = NEO::SegmentType::GlobalVariables; + linkerInput.dataRelocations[0].symbolSegment = NEO::SegmentType::GlobalVariables; + linkerInput.traits.requiresPatchingOfGlobalVariablesBuffer = true; + uint64_t initData = 0x1234; + + auto linkResult = linker.link(emptySegmentInfo, emptySegmentInfo, emptySegmentInfo, + pNonEmptypatchableSegment, pNonEmptypatchableSegment, {}, + unresolvedExternals, pDevice.get(), &initData, &initData); + + EXPECT_EQ(NEO::LinkingStatus::LinkedFully, linkResult); + EXPECT_EQ(0U, unresolvedExternals.size()); + + linkerInput.dataRelocations[0].type = NEO::LinkerInput::RelocationInfo::Type::AddressLow; + linkResult = linker.link(emptySegmentInfo, emptySegmentInfo, emptySegmentInfo, + pNonEmptypatchableSegment, pNonEmptypatchableSegment, {}, + unresolvedExternals, pDevice.get(), &initData, &initData); + + EXPECT_EQ(NEO::LinkingStatus::LinkedFully, linkResult); + EXPECT_EQ(0U, unresolvedExternals.size()); + + if (pNonEmptypatchableSegment->isAllocatedInLocalMemoryPool() && + (localMemoryAccessMode == LocalMemoryAccessMode::CpuAccessDisallowed)) { + auto blitsOnAllocationInitialization = 1; + auto blitsOnPatchingDataSegments = 2; + expectedBlitsCount += blitsOnAllocationInitialization + blitsOnPatchingDataSegments; + } + EXPECT_EQ(expectedBlitsCount, blitsCounter); + pDevice->getMemoryManager()->freeGraphicsMemory(pNonEmptypatchableSegment); + } + } +} + TEST(LinkerErrorMessageTests, whenListOfUnresolvedExternalsIsEmptyThenErrorTypeDefaultsToInternalError) { NEO::Linker::UnresolvedExternals unresolvedExternals; std::vector segmentsNames{"kernel1", "kernel2"};