diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index e31447d887..7a9128509c 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -100,23 +100,8 @@ void ModuleTranslationUnit::freeGlobalBufferAllocation(const std::unique_ptr(globalBuffer->getGpuAddress()); - - if (auto usmPool = device->getNEODevice()->getUsmConstantSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - [[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false); - DEBUG_BREAK_IF(!ret); - return; - } - - if (auto usmPool = device->getNEODevice()->getUsmGlobalSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - [[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false); - DEBUG_BREAK_IF(!ret); - return; - } - auto svmAllocsManager = device->getDriverHandle()->getSvmAllocsManager(); + auto gpuAddress = reinterpret_cast(globalBuffer->getGpuAddress()); if (svmAllocsManager->getSVMAlloc(gpuAddress)) { svmAllocsManager->freeSVMAlloc(gpuAddress); diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 28ad03631b..4323bba0b2 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -36,8 +36,6 @@ #include "shared/test/common/mocks/mock_l0_debugger.h" #include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/mocks/mock_modules_zebin.h" -#include "shared/test/common/mocks/mock_product_helper.h" -#include "shared/test/common/mocks/mock_usm_memory_pool.h" #include "shared/test/common/mocks/mock_zebin_wrapper.h" #include "shared/test/common/test_macros/hw_test.h" @@ -3590,143 +3588,6 @@ kernels: EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, globalVarBufferAllocType); } -TEST_F(ModuleTranslationUnitTest, GivenUsmPoolsAnd2MBLocalMemAlignmentEnabledWhenProcessingZebinThenGlobalBuffersAreTakenFromPoolAndFreedOnModuleTranslationUnitDestroy) { - auto usmConstantSurfaceAllocPool = new MockUsmMemAllocPool; - auto usmGlobalSurfaceAllocPool = new MockUsmMemAllocPool; - - neoDevice->resetUsmConstantSurfaceAllocPool(usmConstantSurfaceAllocPool); - neoDevice->resetUsmGlobalSurfaceAllocPool(usmGlobalSurfaceAllocPool); - - auto mockProductHelper = new MockProductHelper; - neoDevice->getRootDeviceEnvironmentRef().productHelper.reset(mockProductHelper); - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - std::string zeInfo = std::string("version :\'") + versionToString(NEO::Zebin::ZeInfo::zeInfoDecoderVersion) + R"===(' -kernels: - - name : kernel - execution_env : - simd_size : 8 -)==="; - MockElfEncoder<> elfEncoder; - elfEncoder.getElfFileHeader().type = NEO::Zebin::Elf::ET_ZEBIN_EXE; - elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::textPrefix.str() + "kernel", std::string{}); - elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::dataConst, std::string{"12345678"}); - auto dataConstSectionIndex = elfEncoder.getLastSectionHeaderIndex(); - elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::dataGlobal, std::string{"12345678"}); - auto dataGlobalSectionIndex = elfEncoder.getLastSectionHeaderIndex(); - - NEO::Elf::ElfSymbolEntry symbolTable[2] = {}; - symbolTable[0].name = decltype(symbolTable[0].name)(elfEncoder.appendSectionName("const.data")); - symbolTable[0].info = NEO::Elf::SymbolTableType::STT_OBJECT | NEO::Elf::SymbolTableBind::STB_GLOBAL << 4; - symbolTable[0].shndx = decltype(symbolTable[0].shndx)(dataConstSectionIndex); - symbolTable[0].size = 4; - symbolTable[0].value = 0; - - symbolTable[1].name = decltype(symbolTable[1].name)(elfEncoder.appendSectionName("global.data")); - symbolTable[1].info = NEO::Elf::SymbolTableType::STT_OBJECT | NEO::Elf::SymbolTableBind::STB_GLOBAL << 4; - symbolTable[1].shndx = decltype(symbolTable[1].shndx)(dataGlobalSectionIndex); - symbolTable[1].size = 4; - symbolTable[1].value = 0; - elfEncoder.appendSection(NEO::Elf::SHT_SYMTAB, NEO::Zebin::Elf::SectionNames::symtab, - ArrayRef(reinterpret_cast(symbolTable), sizeof(symbolTable))); - elfEncoder.appendSection(NEO::Zebin::Elf::SHT_ZEBIN_ZEINFO, NEO::Zebin::Elf::SectionNames::zeInfo, zeInfo); - auto zebin = elfEncoder.encode(); - - { - L0::ModuleTranslationUnit moduleTu(this->device); - moduleTu.unpackedDeviceBinarySize = zebin.size(); - moduleTu.unpackedDeviceBinary = std::make_unique(moduleTu.unpackedDeviceBinarySize); - memcpy_s(moduleTu.unpackedDeviceBinary.get(), moduleTu.unpackedDeviceBinarySize, - zebin.data(), zebin.size()); - auto retVal = moduleTu.processUnpackedBinary(); - EXPECT_EQ(retVal, ZE_RESULT_SUCCESS); - EXPECT_EQ(AllocationType::constantSurface, moduleTu.globalConstBuffer->getGraphicsAllocation()->getAllocationType()); - EXPECT_EQ(AllocationType::globalSurface, moduleTu.globalVarBuffer->getGraphicsAllocation()->getAllocationType()); - - EXPECT_TRUE(neoDevice->getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(moduleTu.globalConstBuffer->getGpuAddress()))); - EXPECT_TRUE(neoDevice->getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(moduleTu.globalVarBuffer->getGpuAddress()))); - } - - EXPECT_EQ(1u, usmConstantSurfaceAllocPool->freeSVMAllocCalled); - EXPECT_EQ(1u, usmGlobalSurfaceAllocPool->freeSVMAllocCalled); -} - -TEST_F(ModuleTranslationUnitTest, GivenUsmPoolEnabledWhenTwoModuleTranslationUnitsAreCreatedWithTheSameDeviceThenTheyShareUnderlyingGlobalSurfacePoolAllocations) { - auto usmConstantSurfaceAllocPool = new MockUsmMemAllocPool; - auto usmGlobalSurfaceAllocPool = new MockUsmMemAllocPool; - - neoDevice->resetUsmConstantSurfaceAllocPool(usmConstantSurfaceAllocPool); - neoDevice->resetUsmGlobalSurfaceAllocPool(usmGlobalSurfaceAllocPool); - - auto mockProductHelper = new MockProductHelper; - neoDevice->getRootDeviceEnvironmentRef().productHelper.reset(mockProductHelper); - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - std::string zeInfo = std::string("version :\'") + versionToString(NEO::Zebin::ZeInfo::zeInfoDecoderVersion) + R"===(' -kernels: - - name : kernel - execution_env : - simd_size : 8 -)==="; - MockElfEncoder<> elfEncoder; - elfEncoder.getElfFileHeader().type = NEO::Zebin::Elf::ET_ZEBIN_EXE; - elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::textPrefix.str() + "kernel", std::string{}); - elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::dataConst, std::string{"12345678"}); - auto dataConstSectionIndex = elfEncoder.getLastSectionHeaderIndex(); - elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::dataGlobal, std::string{"12345678"}); - auto dataGlobalSectionIndex = elfEncoder.getLastSectionHeaderIndex(); - - NEO::Elf::ElfSymbolEntry symbolTable[2] = {}; - symbolTable[0].name = decltype(symbolTable[0].name)(elfEncoder.appendSectionName("const.data")); - symbolTable[0].info = NEO::Elf::SymbolTableType::STT_OBJECT | NEO::Elf::SymbolTableBind::STB_GLOBAL << 4; - symbolTable[0].shndx = decltype(symbolTable[0].shndx)(dataConstSectionIndex); - symbolTable[0].size = 4; - symbolTable[0].value = 0; - - symbolTable[1].name = decltype(symbolTable[1].name)(elfEncoder.appendSectionName("global.data")); - symbolTable[1].info = NEO::Elf::SymbolTableType::STT_OBJECT | NEO::Elf::SymbolTableBind::STB_GLOBAL << 4; - symbolTable[1].shndx = decltype(symbolTable[1].shndx)(dataGlobalSectionIndex); - symbolTable[1].size = 4; - symbolTable[1].value = 0; - elfEncoder.appendSection(NEO::Elf::SHT_SYMTAB, NEO::Zebin::Elf::SectionNames::symtab, - ArrayRef(reinterpret_cast(symbolTable), sizeof(symbolTable))); - elfEncoder.appendSection(NEO::Zebin::Elf::SHT_ZEBIN_ZEINFO, NEO::Zebin::Elf::SectionNames::zeInfo, zeInfo); - auto zebin = elfEncoder.encode(); - - { - L0::ModuleTranslationUnit moduleTu(this->device); - moduleTu.unpackedDeviceBinarySize = zebin.size(); - moduleTu.unpackedDeviceBinary = std::make_unique(moduleTu.unpackedDeviceBinarySize); - memcpy_s(moduleTu.unpackedDeviceBinary.get(), moduleTu.unpackedDeviceBinarySize, - zebin.data(), zebin.size()); - auto retVal = moduleTu.processUnpackedBinary(); - EXPECT_EQ(retVal, ZE_RESULT_SUCCESS); - - EXPECT_TRUE(neoDevice->getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(moduleTu.globalConstBuffer->getGpuAddress()))); - EXPECT_TRUE(neoDevice->getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(moduleTu.globalVarBuffer->getGpuAddress()))); - - L0::ModuleTranslationUnit moduleTu2(this->device); - moduleTu2.unpackedDeviceBinarySize = zebin.size(); - moduleTu2.unpackedDeviceBinary = std::make_unique(moduleTu2.unpackedDeviceBinarySize); - memcpy_s(moduleTu2.unpackedDeviceBinary.get(), moduleTu2.unpackedDeviceBinarySize, - zebin.data(), zebin.size()); - retVal = moduleTu2.processUnpackedBinary(); - EXPECT_EQ(retVal, ZE_RESULT_SUCCESS); - - EXPECT_TRUE(neoDevice->getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(moduleTu2.globalConstBuffer->getGpuAddress()))); - EXPECT_TRUE(neoDevice->getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(moduleTu2.globalVarBuffer->getGpuAddress()))); - - EXPECT_EQ(moduleTu.globalConstBuffer->getGraphicsAllocation(), moduleTu2.globalConstBuffer->getGraphicsAllocation()); - EXPECT_EQ(moduleTu.globalVarBuffer->getGraphicsAllocation(), moduleTu2.globalVarBuffer->getGraphicsAllocation()); - - EXPECT_NE(moduleTu.globalConstBuffer->getGpuAddress(), moduleTu2.globalConstBuffer->getGpuAddress()); - EXPECT_NE(moduleTu.globalVarBuffer->getGpuAddress(), moduleTu2.globalVarBuffer->getGpuAddress()); - } - - EXPECT_EQ(2u, usmConstantSurfaceAllocPool->freeSVMAllocCalled); - EXPECT_EQ(2u, usmGlobalSurfaceAllocPool->freeSVMAllocCalled); -} - HWTEST_F(ModuleTranslationUnitTest, WithNoCompilerWhenCallingBuildFromSpirvThenFailureReturned) { auto &rootDeviceEnvironment = this->neoDevice->executionEnvironment->rootDeviceEnvironments[this->neoDevice->getRootDeviceIndex()]; rootDeviceEnvironment->compilerInterface.reset(nullptr); diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 4f830d2572..4c9b421480 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -50,11 +50,10 @@ Platform::~Platform() { if (isInitialized()) { delete stagingBufferManager; svmAllocsManager->cleanupUSMAllocCaches(); - } - devicesCleanup(false); - if (isInitialized()) { delete svmAllocsManager; } + devicesCleanup(false); + gtpinNotifyPlatformShutdown(); executionEnvironment.decRefInternal(); } diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 65ef9cfa0e..fbf5cb8721 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -218,25 +218,11 @@ cl_int Program::processGenBinary(const ClDevice &clDevice) { auto &buildInfo = buildInfos[rootDeviceIndex]; if (buildInfo.constantSurface) { - auto gpuAddress = reinterpret_cast(buildInfo.constantSurface->getGpuAddress()); - if (auto usmPool = clDevice.getDevice().getUsmConstantSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - [[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false); - DEBUG_BREAK_IF(!ret); - } else { - clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.constantSurface->getGraphicsAllocation()); - } + clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.constantSurface->getGraphicsAllocation()); buildInfo.constantSurface.reset(); } if (buildInfo.globalSurface) { - auto gpuAddress = reinterpret_cast(buildInfo.globalSurface->getGpuAddress()); - if (auto usmPool = clDevice.getDevice().getUsmGlobalSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - [[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false); - DEBUG_BREAK_IF(!ret); - } else { - clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.globalSurface->getGraphicsAllocation()); - } + clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.globalSurface->getGraphicsAllocation()); buildInfo.globalSurface.reset(); } diff --git a/opencl/source/program/program.cpp b/opencl/source/program/program.cpp index f6bc283f72..40bfccb643 100644 --- a/opencl/source/program/program.cpp +++ b/opencl/source/program/program.cpp @@ -124,8 +124,21 @@ Program::~Program() { } for (const auto &buildInfo : buildInfos) { - freeGlobalBufferAllocation(buildInfo.constantSurface); - freeGlobalBufferAllocation(buildInfo.globalSurface); + if (auto &constantSurface = buildInfo.constantSurface; constantSurface) { + if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(constantSurface->getGpuAddress())))) { + context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(constantSurface->getGpuAddress())); + } else { + this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(constantSurface->getGraphicsAllocation()); + } + } + + if (auto &globalSurface = buildInfo.globalSurface; globalSurface) { + if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(globalSurface->getGpuAddress())))) { + context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(globalSurface->getGpuAddress())); + } else { + this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(globalSurface->getGraphicsAllocation()); + } + } } notifyModuleDestroy(); @@ -135,41 +148,6 @@ Program::~Program() { } } -void Program::freeGlobalBufferAllocation(const std::unique_ptr &globalBuffer) { - if (!globalBuffer) { - return; - } - - auto graphicsAllocation = globalBuffer->getGraphicsAllocation(); - if (!graphicsAllocation) { - return; - } - - auto gpuAddress = reinterpret_cast(globalBuffer->getGpuAddress()); - - for (const auto &device : clDevices) { - if (auto usmPool = device->getDevice().getUsmConstantSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - [[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false); - DEBUG_BREAK_IF(!ret); - return; - } - - if (auto usmPool = device->getDevice().getUsmGlobalSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - [[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false); - DEBUG_BREAK_IF(!ret); - return; - } - } - - if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(globalBuffer->getGpuAddress())))) { - context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(globalBuffer->getGpuAddress())); - } else { - this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(globalBuffer->getGraphicsAllocation()); - } -} - cl_int Program::createProgramFromBinary( const void *pBinary, size_t binarySize, ClDevice &clDevice) { diff --git a/opencl/source/program/program.h b/opencl/source/program/program.h index faba7d93e9..e3699983c2 100644 --- a/opencl/source/program/program.h +++ b/opencl/source/program/program.h @@ -188,8 +188,6 @@ class Program : public BaseObject<_cl_program> { return isSpirV; } - void freeGlobalBufferAllocation(const std::unique_ptr &buffer); - NEO::SharedPoolAllocation *getConstantSurface(uint32_t rootDeviceIndex) const; NEO::GraphicsAllocation *getConstantSurfaceGA(uint32_t rootDeviceIndex) const; NEO::SharedPoolAllocation *getGlobalSurface(uint32_t rootDeviceIndex) const; diff --git a/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp index 8be8d6a7d2..499f3e971b 100644 --- a/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/cl_memory_manager_tests.cpp @@ -366,8 +366,6 @@ TEST_F(ClMemoryManagerMultiRootDeviceTests, WhenAllocatingGlobalSurfaceThenItHas context->svmAllocsManager = nullptr; } - deviceFactory->cleanupPlatformOnDestruction = false; - std::vector initData(1024, 0x5B); WhiteBox linkerInput; linkerInput.traits.exportsGlobalConstants = true; @@ -379,16 +377,10 @@ TEST_F(ClMemoryManagerMultiRootDeviceTests, WhenAllocatingGlobalSurfaceThenItHas ASSERT_NE(nullptr, allocation); EXPECT_EQ(expectedRootDeviceIndex, allocation->getRootDeviceIndex()); - auto gpuAddress = reinterpret_cast(surface->getGpuAddress()); - if (auto usmPool = device1->getDevice().getUsmGlobalSurfaceAllocPool(); - usmPool && usmPool->isInPool(gpuAddress)) { - usmPool->freeSVMAlloc(gpuAddress, false); + if (device1->getMemoryManager()->isLimitedRange(expectedRootDeviceIndex)) { + device1->getMemoryManager()->freeGraphicsMemory(allocation); } else { - if (device1->getMemoryManager()->isLimitedRange(expectedRootDeviceIndex)) { - device1->getMemoryManager()->freeGraphicsMemory(allocation); - } else { - context->getSVMAllocsManager()->freeSVMAlloc(gpuAddress); - } + context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(surface->getGpuAddress())); } } diff --git a/opencl/test/unit_test/program/program_data_tests.cpp b/opencl/test/unit_test/program/program_data_tests.cpp index 062419afb1..8529f973ec 100644 --- a/opencl/test/unit_test/program/program_data_tests.cpp +++ b/opencl/test/unit_test/program/program_data_tests.cpp @@ -20,8 +20,6 @@ #include "shared/test/common/mocks/mock_csr.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_memory_manager.h" -#include "shared/test/common/mocks/mock_product_helper.h" -#include "shared/test/common/mocks/mock_usm_memory_pool.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test.h" @@ -229,50 +227,6 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreExportedThenAllocateSurfacesAsSvm) EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(surface->getGpuAddress()))); } -TEST_F(ProgramDataTest, GivenUsmPoolAnd2MBAlignmentEnabledWhenGlobalsExportedThenAllocateSurfacesFromUsmPoolAndFreeOnProgramDestroy) { - ASSERT_NE(nullptr, this->pContext->getSVMAllocsManager()); - auto usmConstantSurfaceAllocPool = new MockUsmMemAllocPool; - auto usmGlobalSurfaceAllocPool = new MockUsmMemAllocPool; - - pClDevice->getDevice().resetUsmConstantSurfaceAllocPool(usmConstantSurfaceAllocPool); - pClDevice->getDevice().resetUsmGlobalSurfaceAllocPool(usmGlobalSurfaceAllocPool); - - auto mockProductHelper = new MockProductHelper; - pClDevice->getDevice().getRootDeviceEnvironmentRef().productHelper.reset(mockProductHelper); - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - char globalData[128] = {}; - ProgramInfo programInfo; - programInfo.globalConstants.initData = globalData; - programInfo.globalConstants.size = sizeof(globalData); - programInfo.globalVariables.initData = globalData; - programInfo.globalVariables.size = sizeof(globalData); - std::unique_ptr> mockLinkerInput = std::make_unique>(); - mockLinkerInput->traits.exportsGlobalConstants = true; - mockLinkerInput->traits.exportsGlobalVariables = true; - programInfo.linkerInput = std::move(mockLinkerInput); - this->pProgram->processProgramInfo(programInfo, *pClDevice); - - auto constantSurface = pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex()); - ASSERT_NE(nullptr, constantSurface); - ASSERT_NE(nullptr, constantSurface->getGraphicsAllocation()); - EXPECT_TRUE(pClDevice->getDevice().getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(constantSurface->getGpuAddress()))); - - auto globalSurface = pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex()); - ASSERT_NE(nullptr, globalSurface); - ASSERT_NE(nullptr, globalSurface->getGraphicsAllocation()); - EXPECT_TRUE(pClDevice->getDevice().getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - - EXPECT_EQ(0u, usmConstantSurfaceAllocPool->freeSVMAllocCalled); - EXPECT_EQ(0u, usmGlobalSurfaceAllocPool->freeSVMAllocCalled); - - delete this->pProgram; - this->pProgram = nullptr; - - EXPECT_EQ(1u, usmConstantSurfaceAllocPool->freeSVMAllocCalled); - EXPECT_EQ(1u, usmGlobalSurfaceAllocPool->freeSVMAllocCalled); -} - TEST_F(ProgramDataTest, whenGlobalConstantsAreNotExportedThenAllocateSurfacesAsNonSvm) { if (this->pContext->getSVMAllocsManager() == nullptr) { return; diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index e315f45746..b26bfa83ab 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -27,9 +27,7 @@ #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/surface.h" #include "shared/source/os_interface/os_context.h" -#include "shared/source/program/program_initialization.h" #include "shared/source/utilities/arrayref.h" -#include "shared/test/common/compiler_interface/linker_mock.h" #include "shared/test/common/device_binary_format/patchtokens_tests.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/gtest_helpers.h" @@ -44,8 +42,6 @@ #include "shared/test/common/mocks/mock_elf.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_modules_zebin.h" -#include "shared/test/common/mocks/mock_product_helper.h" -#include "shared/test/common/mocks/mock_usm_memory_pool.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/utilities/base_object_utils.h" @@ -540,49 +536,6 @@ TEST_F(ProgramFromBinaryTest, whenProgramIsBeingRebuildThenOutdatedGlobalBuffers EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface.get()); } -TEST_F(ProgramFromBinaryTest, GivenUsmPoolAnd2MBAlignmentEnabledWhenProgramIsBeingRebuildThenOutdatedGlobalBuffersAreFreedFromUsmPool) { - ASSERT_NE(nullptr, this->pContext->getSVMAllocsManager()); - - pProgram->build(pProgram->getDevices(), nullptr); - EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface); - EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface); - - auto usmConstantSurfaceAllocPool = new MockUsmMemAllocPool; - auto usmGlobalSurfaceAllocPool = new MockUsmMemAllocPool; - - pClDevice->getDevice().resetUsmConstantSurfaceAllocPool(usmConstantSurfaceAllocPool); - pClDevice->getDevice().resetUsmGlobalSurfaceAllocPool(usmGlobalSurfaceAllocPool); - - auto mockProductHelper = new MockProductHelper; - pClDevice->getDevice().getRootDeviceEnvironmentRef().productHelper.reset(mockProductHelper); - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - std::vector initData(1024, 0x5B); - WhiteBox linkerInput; - linkerInput.traits.exportsGlobalConstants = true; - linkerInput.traits.exportsGlobalVariables = true; - - pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface.reset(allocateGlobalsSurface(pContext->getSVMAllocsManager(), pClDevice->getDevice(), initData.size(), 0u, true, &linkerInput, initData.data())); - auto &constantSurface = pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface; - EXPECT_TRUE(pClDevice->getDevice().getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(constantSurface->getGpuAddress()))); - pProgram->processGenBinary(*pClDevice); - EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface.get()); - EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface.get()); - - EXPECT_EQ(1u, usmConstantSurfaceAllocPool->freeSVMAllocCalled); - EXPECT_EQ(0u, usmGlobalSurfaceAllocPool->freeSVMAllocCalled); - - pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface.reset(allocateGlobalsSurface(pContext->getSVMAllocsManager(), pClDevice->getDevice(), initData.size(), 0u, false, &linkerInput, initData.data())); - auto &globalSurface = pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface; - EXPECT_TRUE(pClDevice->getDevice().getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - pProgram->processGenBinary(*pClDevice); - EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface.get()); - EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface.get()); - - EXPECT_EQ(1u, usmConstantSurfaceAllocPool->freeSVMAllocCalled); - EXPECT_EQ(1u, usmGlobalSurfaceAllocPool->freeSVMAllocCalled); -} - TEST_F(ProgramFromBinaryTest, givenProgramWhenCleanKernelInfoIsCalledThenKernelAllocationIsFreed) { pProgram->build(pProgram->getDevices(), nullptr); EXPECT_EQ(1u, pProgram->getNumKernels()); diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index dc5bffb1fc..771bea6c99 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -77,13 +77,6 @@ Device::~Device() { if (deviceUsmMemAllocPoolsManager) { deviceUsmMemAllocPoolsManager->cleanup(); } - if (usmConstantSurfaceAllocPool) { - usmConstantSurfaceAllocPool->cleanup(); - } - if (usmGlobalSurfaceAllocPool) { - usmGlobalSurfaceAllocPool->cleanup(); - } - secondaryCsrs.clear(); executionEnvironment->memoryManager->releaseSecondaryOsContexts(this->getRootDeviceIndex()); commandStreamReceivers.clear(); @@ -229,10 +222,6 @@ bool Device::initializeCommonResources() { deviceBitfields.emplace(getRootDeviceIndex(), getDeviceBitfield()); deviceUsmMemAllocPoolsManager.reset(new UsmMemAllocPoolsManager(getMemoryManager(), rootDeviceIndices, deviceBitfields, this, InternalMemoryType::deviceUnifiedMemory)); } - - this->resetUsmConstantSurfaceAllocPool(new UsmMemAllocPool); - this->resetUsmGlobalSurfaceAllocPool(new UsmMemAllocPool); - return true; } @@ -278,14 +267,6 @@ void Device::cleanupUsmAllocationPool() { } } -void Device::resetUsmConstantSurfaceAllocPool(UsmMemAllocPool *usmMemAllocPool) { - this->usmConstantSurfaceAllocPool.reset(usmMemAllocPool); -} - -void Device::resetUsmGlobalSurfaceAllocPool(UsmMemAllocPool *usmMemAllocPool) { - this->usmGlobalSurfaceAllocPool.reset(usmMemAllocPool); -} - bool Device::initDeviceFully() { if (!getRootDeviceEnvironment().isExposeSingleDeviceMode()) { diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 2318307446..c12246520d 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -213,12 +213,6 @@ class Device : public ReferenceTrackedObject, NEO::NonCopyableAndNonMova UsmMemAllocPool *getUsmMemAllocPool() { return usmMemAllocPool.get(); } - UsmMemAllocPool *getUsmConstantSurfaceAllocPool() { - return usmConstantSurfaceAllocPool.get(); - } - UsmMemAllocPool *getUsmGlobalSurfaceAllocPool() { - return usmGlobalSurfaceAllocPool.get(); - } MOCKABLE_VIRTUAL void stopDirectSubmissionAndWaitForCompletion(); MOCKABLE_VIRTUAL void pollForCompletion(); bool isAnyDirectSubmissionEnabled() const; @@ -268,9 +262,6 @@ class Device : public ReferenceTrackedObject, NEO::NonCopyableAndNonMova void resetUsmAllocationPool(UsmMemAllocPool *usmMemAllocPool); void cleanupUsmAllocationPool(); - void resetUsmConstantSurfaceAllocPool(UsmMemAllocPool *usmMemAllocPool); - void resetUsmGlobalSurfaceAllocPool(UsmMemAllocPool *usmMemAllocPool); - std::unordered_map crossAccessEnabledDevices; bool canAccessPeer(QueryPeerAccessFunc queryPeerAccess, Device *peerDevice, bool &canAccess); static void initializePeerAccessForDevices(QueryPeerAccessFunc queryPeerAccess, const std::vector &devices); @@ -362,8 +353,6 @@ class Device : public ReferenceTrackedObject, NEO::NonCopyableAndNonMova TimestampPoolAllocator deviceTimestampPoolAllocator; std::unique_ptr deviceUsmMemAllocPoolsManager; std::unique_ptr usmMemAllocPool; - std::unique_ptr usmConstantSurfaceAllocPool; - std::unique_ptr usmGlobalSurfaceAllocPool; std::atomic_uint32_t bufferPoolCount = 0u; uint32_t maxBufferPoolCount = 0u; diff --git a/shared/source/memory_manager/unified_memory_pooling.h b/shared/source/memory_manager/unified_memory_pooling.h index c9e32a33c8..6b94071067 100644 --- a/shared/source/memory_manager/unified_memory_pooling.h +++ b/shared/source/memory_manager/unified_memory_pooling.h @@ -27,7 +27,7 @@ class UsmMemAllocPool { UsmMemAllocPool() = default; virtual ~UsmMemAllocPool() = default; - MOCKABLE_VIRTUAL bool initialize(SVMAllocsManager *svmMemoryManager, const UnifiedMemoryProperties &memoryProperties, size_t poolSize, size_t minServicedSize, size_t maxServicedSize); + bool initialize(SVMAllocsManager *svmMemoryManager, const UnifiedMemoryProperties &memoryProperties, size_t poolSize, size_t minServicedSize, size_t maxServicedSize); bool initialize(SVMAllocsManager *svmMemoryManager, void *ptr, SvmAllocationData *svmData, size_t minServicedSize, size_t maxServicedSize); bool isInitialized() const; size_t getPoolSize() const; @@ -37,10 +37,10 @@ class UsmMemAllocPool { static double getPercentOfFreeMemoryForRecycling(InternalMemoryType memoryType); bool sizeIsAllowed(size_t size); bool canBePooled(size_t size, const UnifiedMemoryProperties &memoryProperties); - MOCKABLE_VIRTUAL void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties); + void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties); bool isInPool(const void *ptr) const; bool isEmpty(); - MOCKABLE_VIRTUAL bool freeSVMAlloc(const void *ptr, bool blocking); + bool freeSVMAlloc(const void *ptr, bool blocking); size_t getPooledAllocationSize(const void *ptr); void *getPooledAllocationBasePtr(const void *ptr); size_t getOffsetInPool(const void *ptr) const; diff --git a/shared/source/program/program_initialization.cpp b/shared/source/program/program_initialization.cpp index 4621b48d65..12ae491adb 100644 --- a/shared/source/program/program_initialization.cpp +++ b/shared/source/program/program_initialization.cpp @@ -42,67 +42,27 @@ SharedPoolAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAll unifiedMemoryProperties.device = &device; unifiedMemoryProperties.requestedAllocationType = allocationType; unifiedMemoryProperties.isInternalAllocation = true; - - UsmMemAllocPool *allocPool = nullptr; - if (allocationType == AllocationType::constantSurface) { - allocPool = device.getUsmConstantSurfaceAllocPool(); - } else { - allocPool = device.getUsmGlobalSurfaceAllocPool(); - } - - if (allocPool && device.getProductHelper().is2MBLocalMemAlignmentEnabled()) { - if (!allocPool->isInitialized()) { - constexpr size_t alignment = MemoryConstants::pageSize2M; - constexpr size_t poolSize = MemoryConstants::pageSize2M; - constexpr size_t minServicedSize = 0u; - constexpr size_t maxServicedSize = 2 * MemoryConstants::megaByte; - - NEO::SVMAllocsManager::UnifiedMemoryProperties poolMemoryProperties(InternalMemoryType::deviceUnifiedMemory, alignment, rootDeviceIndices, subDeviceBitfields); - poolMemoryProperties.device = &device; - poolMemoryProperties.requestedAllocationType = allocationType; - poolMemoryProperties.isInternalAllocation = true; - - allocPool->initialize(svmAllocManager, poolMemoryProperties, poolSize, minServicedSize, maxServicedSize); - } - - if (allocPool->isInitialized()) { - unifiedMemoryProperties.alignment = MemoryConstants::pageSize; - auto pooledPtr = allocPool->createUnifiedMemoryAllocation(totalSize, unifiedMemoryProperties); - if (pooledPtr) { - allocationOffset = allocPool->getOffsetInPool(pooledPtr); - allocatedSize = allocPool->getPooledAllocationSize(pooledPtr); - auto usmAlloc = svmAllocManager->getSVMAlloc(reinterpret_cast(allocPool->getPoolAddress())); - UNRECOVERABLE_IF(usmAlloc == nullptr); - gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); - } - } - } - - if (!gpuAllocation) { - auto ptr = svmAllocManager->createUnifiedMemoryAllocation(totalSize, unifiedMemoryProperties); - DEBUG_BREAK_IF(ptr == nullptr); - if (ptr == nullptr) { - return nullptr; - } - auto usmAlloc = svmAllocManager->getSVMAlloc(ptr); - UNRECOVERABLE_IF(usmAlloc == nullptr); - gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); - allocationOffset = 0u; - allocatedSize = gpuAllocation->getUnderlyingBufferSize(); + auto ptr = svmAllocManager->createUnifiedMemoryAllocation(totalSize, unifiedMemoryProperties); + DEBUG_BREAK_IF(ptr == nullptr); + if (ptr == nullptr) { + return nullptr; } + auto usmAlloc = svmAllocManager->getSVMAlloc(ptr); + UNRECOVERABLE_IF(usmAlloc == nullptr); + gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); } else { gpuAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, true, // allocateMemory totalSize, allocationType, false, // isMultiStorageAllocation deviceBitfield}); - if (nullptr == gpuAllocation) { - return nullptr; - } - allocationOffset = 0u; - allocatedSize = gpuAllocation->getUnderlyingBufferSize(); } + if (!gpuAllocation) { + return nullptr; + } + allocatedSize = gpuAllocation->getUnderlyingBufferSize(); + auto &rootDeviceEnvironment = device.getRootDeviceEnvironment(); auto &productHelper = device.getProductHelper(); diff --git a/shared/test/common/mocks/mock_usm_memory_pool.h b/shared/test/common/mocks/mock_usm_memory_pool.h index a6d7e82f10..df1471561d 100644 --- a/shared/test/common/mocks/mock_usm_memory_pool.h +++ b/shared/test/common/mocks/mock_usm_memory_pool.h @@ -19,24 +19,6 @@ class MockUsmMemAllocPool : public UsmMemAllocPool { using UsmMemAllocPool::poolMemoryType; using UsmMemAllocPool::poolSize; - bool initialize(SVMAllocsManager *svmMemoryManager, const UnifiedMemoryProperties &memoryProperties, size_t poolSize, size_t minServicedSize, size_t maxServicedSize) override { - if (callBaseInitialize) { - return UsmMemAllocPool::initialize(svmMemoryManager, memoryProperties, poolSize, minServicedSize, maxServicedSize); - } - return initializeResult; - } - bool callBaseInitialize = true; - bool initializeResult = false; - - void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties) override { - if (callBaseCreateUnifiedMemoryAllocation) { - return UsmMemAllocPool::createUnifiedMemoryAllocation(size, memoryProperties); - } - return createUnifiedMemoryAllocationResult; - } - bool callBaseCreateUnifiedMemoryAllocation = true; - void *createUnifiedMemoryAllocationResult = nullptr; - void cleanup() override { ++cleanupCalled; if (callBaseCleanup) { @@ -45,12 +27,6 @@ class MockUsmMemAllocPool : public UsmMemAllocPool { } uint32_t cleanupCalled = 0u; bool callBaseCleanup = true; - - bool freeSVMAlloc(const void *ptr, bool blocking) override { - ++freeSVMAllocCalled; - return UsmMemAllocPool::freeSVMAlloc(ptr, blocking); - }; - uint32_t freeSVMAllocCalled = 0u; }; class MockUsmMemAllocPoolsManager : public UsmMemAllocPoolsManager { diff --git a/shared/test/unit_test/program/program_initialization_tests.cpp b/shared/test/unit_test/program/program_initialization_tests.cpp index c8e050fe33..9f13d15f3d 100644 --- a/shared/test/unit_test/program/program_initialization_tests.cpp +++ b/shared/test/unit_test/program/program_initialization_tests.cpp @@ -10,15 +10,12 @@ #include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/blit_helper.h" #include "shared/source/helpers/local_memory_access_modes.h" -#include "shared/source/memory_manager/unified_memory_pooling.h" #include "shared/source/program/program_initialization.h" #include "shared/test/common/compiler_interface/linker_mock.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_memory_manager.h" -#include "shared/test/common/mocks/mock_product_helper.h" #include "shared/test/common/mocks/mock_svm_manager.h" -#include "shared/test/common/mocks/mock_usm_memory_pool.h" #include "gtest/gtest.h" @@ -316,175 +313,3 @@ TEST(AllocateGlobalSurfaceTest, whenAllocatingGlobalSurfaceWithZeroInitSizeGreat device.getMemoryManager()->freeGraphicsMemory(alloc); } - -struct AllocateGlobalSurfaceWithUsmPoolTest : public ::testing::Test { - void SetUp() override { - device.injectMemoryManager(new MockMemoryManager()); - device.resetUsmConstantSurfaceAllocPool(new UsmMemAllocPool); - device.resetUsmGlobalSurfaceAllocPool(new UsmMemAllocPool); - - mockProductHelper = new MockProductHelper; - device.getRootDeviceEnvironmentRef().productHelper.reset(mockProductHelper); - - svmAllocsManager = std::make_unique(device.getMemoryManager()); - } - - MockProductHelper *mockProductHelper{nullptr}; - std::unique_ptr svmAllocsManager; - WhiteBox linkerInputExportGlobalVariables; - WhiteBox linkerInputExportGlobalConstants; - MockDevice device{}; - - DebugManagerStateRestore restore; -}; - -TEST_F(AllocateGlobalSurfaceWithUsmPoolTest, GivenUsmAllocPoolAnd2MBLocalMemAlignmentDisabledThenGlobalSurfaceAllocationNotTakenFromUsmPool) { - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = false; - - linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true; - linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true; - std::vector initData; - initData.resize(64, 7U); - std::unique_ptr globalSurface; - - globalSurface.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data())); - ASSERT_NE(nullptr, globalSurface); - EXPECT_FALSE(device.getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - EXPECT_EQ(globalSurface->getGraphicsAllocation()->getUnderlyingBufferSize(), globalSurface->getSize()); - EXPECT_EQ(0u, globalSurface->getOffset()); - svmAllocsManager->freeSVMAlloc(reinterpret_cast(static_cast(globalSurface->getGpuAddress()))); - - globalSurface.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalVariables, initData.data())); - ASSERT_NE(nullptr, globalSurface); - EXPECT_FALSE(device.getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - EXPECT_EQ(globalSurface->getGraphicsAllocation()->getUnderlyingBufferSize(), globalSurface->getSize()); - EXPECT_EQ(0u, globalSurface->getOffset()); - svmAllocsManager->freeSVMAlloc(reinterpret_cast(static_cast(globalSurface->getGpuAddress()))); -} - -TEST_F(AllocateGlobalSurfaceWithUsmPoolTest, GivenUsmAllocPoolAnd2MBLocalMemAlignmentEnabledThenGlobalSurfaceAllocationTakenFromUsmPool) { - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true; - linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true; - std::vector initData; - initData.resize(64, 7U); - - { - std::unique_ptr constantSurface1; - std::unique_ptr constantSurface2; - - constantSurface1.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data())); - ASSERT_NE(nullptr, constantSurface1); - EXPECT_TRUE(device.getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(constantSurface1->getGpuAddress()))); - EXPECT_NE(constantSurface1->getGraphicsAllocation()->getUnderlyingBufferSize(), constantSurface1->getSize()); - EXPECT_EQ(0, memcmp(constantSurface1->getUnderlyingBuffer(), initData.data(), initData.size())); - EXPECT_TRUE(constantSurface1->getGraphicsAllocation()->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(AllocationType::constantSurface, constantSurface1->getGraphicsAllocation()->getAllocationType()); - - constantSurface2.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data())); - ASSERT_NE(nullptr, constantSurface2); - EXPECT_TRUE(device.getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(constantSurface2->getGpuAddress()))); - EXPECT_NE(constantSurface2->getGraphicsAllocation()->getUnderlyingBufferSize(), constantSurface2->getSize()); - EXPECT_EQ(0, memcmp(constantSurface2->getUnderlyingBuffer(), initData.data(), initData.size())); - EXPECT_TRUE(constantSurface2->getGraphicsAllocation()->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(AllocationType::constantSurface, constantSurface2->getGraphicsAllocation()->getAllocationType()); - - EXPECT_EQ(constantSurface1->getGraphicsAllocation(), constantSurface2->getGraphicsAllocation()); - EXPECT_EQ(constantSurface1->getSize(), constantSurface2->getSize()); - EXPECT_NE(constantSurface1->getGpuAddress(), constantSurface2->getGpuAddress()); - EXPECT_NE(constantSurface1->getOffset(), constantSurface2->getOffset()); - } - - { - std::unique_ptr globalSurface1; - std::unique_ptr globalSurface2; - - globalSurface1.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalVariables, initData.data())); - ASSERT_NE(nullptr, globalSurface1); - EXPECT_TRUE(device.getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface1->getGpuAddress()))); - EXPECT_NE(globalSurface1->getGraphicsAllocation()->getUnderlyingBufferSize(), globalSurface1->getSize()); - EXPECT_EQ(0, memcmp(globalSurface1->getUnderlyingBuffer(), initData.data(), initData.size())); - EXPECT_TRUE(globalSurface1->getGraphicsAllocation()->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(AllocationType::globalSurface, globalSurface1->getGraphicsAllocation()->getAllocationType()); - - globalSurface2.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalVariables, initData.data())); - ASSERT_NE(nullptr, globalSurface2); - EXPECT_TRUE(device.getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface2->getGpuAddress()))); - EXPECT_NE(globalSurface2->getGraphicsAllocation()->getUnderlyingBufferSize(), globalSurface2->getSize()); - EXPECT_EQ(0, memcmp(globalSurface2->getUnderlyingBuffer(), initData.data(), initData.size())); - EXPECT_TRUE(globalSurface2->getGraphicsAllocation()->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(AllocationType::globalSurface, globalSurface2->getGraphicsAllocation()->getAllocationType()); - - EXPECT_EQ(globalSurface1->getGraphicsAllocation(), globalSurface2->getGraphicsAllocation()); - EXPECT_EQ(globalSurface1->getSize(), globalSurface2->getSize()); - EXPECT_NE(globalSurface1->getGpuAddress(), globalSurface2->getGpuAddress()); - EXPECT_NE(globalSurface1->getOffset(), globalSurface2->getOffset()); - } -} - -TEST_F(AllocateGlobalSurfaceWithUsmPoolTest, Given2MBLocalMemAlignmentEnabledButUsmPoolInitializeFailsThenDoNotUseUsmPool) { - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - auto usmConstantSurfaceAllocPool = new MockUsmMemAllocPool; - auto usmGlobalSurfaceAllocPool = new MockUsmMemAllocPool; - - device.resetUsmConstantSurfaceAllocPool(usmConstantSurfaceAllocPool); - device.resetUsmGlobalSurfaceAllocPool(usmGlobalSurfaceAllocPool); - - usmConstantSurfaceAllocPool->callBaseInitialize = false; - usmConstantSurfaceAllocPool->initializeResult = false; - - usmGlobalSurfaceAllocPool->callBaseInitialize = false; - usmGlobalSurfaceAllocPool->initializeResult = false; - - linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true; - linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true; - std::vector initData; - initData.resize(64, 7U); - - std::unique_ptr globalSurface; - - globalSurface.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data())); - ASSERT_NE(nullptr, globalSurface); - EXPECT_FALSE(device.getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - svmAllocsManager->freeSVMAlloc(reinterpret_cast(static_cast(globalSurface->getGpuAddress()))); - - globalSurface.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalVariables, initData.data())); - ASSERT_NE(nullptr, globalSurface); - EXPECT_FALSE(device.getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - svmAllocsManager->freeSVMAlloc(reinterpret_cast(static_cast(globalSurface->getGpuAddress()))); -} - -TEST_F(AllocateGlobalSurfaceWithUsmPoolTest, Given2MBLocalMemAlignmentEnabledButAllocatingFromUsmPoolFailsThenDoNotUseUsmPool) { - mockProductHelper->is2MBLocalMemAlignmentEnabledResult = true; - - auto usmConstantSurfaceAllocPool = new MockUsmMemAllocPool; - auto usmGlobalSurfaceAllocPool = new MockUsmMemAllocPool; - - device.resetUsmConstantSurfaceAllocPool(usmConstantSurfaceAllocPool); - device.resetUsmGlobalSurfaceAllocPool(usmGlobalSurfaceAllocPool); - - usmConstantSurfaceAllocPool->callBaseCreateUnifiedMemoryAllocation = false; - usmConstantSurfaceAllocPool->createUnifiedMemoryAllocationResult = nullptr; - - usmGlobalSurfaceAllocPool->callBaseCreateUnifiedMemoryAllocation = false; - usmGlobalSurfaceAllocPool->createUnifiedMemoryAllocationResult = nullptr; - - linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true; - linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true; - std::vector initData; - initData.resize(64, 7U); - - std::unique_ptr globalSurface; - - globalSurface.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalConstants, initData.data())); - ASSERT_NE(nullptr, globalSurface); - EXPECT_FALSE(device.getUsmConstantSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - svmAllocsManager->freeSVMAlloc(reinterpret_cast(static_cast(globalSurface->getGpuAddress()))); - - globalSurface.reset(allocateGlobalsSurface(svmAllocsManager.get(), device, initData.size(), 0u, false /* constant */, &linkerInputExportGlobalVariables, initData.data())); - ASSERT_NE(nullptr, globalSurface); - EXPECT_FALSE(device.getUsmGlobalSurfaceAllocPool()->isInPool(reinterpret_cast(globalSurface->getGpuAddress()))); - svmAllocsManager->freeSVMAlloc(reinterpret_cast(static_cast(globalSurface->getGpuAddress()))); -} \ No newline at end of file