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 f43f1175a5..7440b0e730 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 @@ -2178,7 +2178,7 @@ kernels: EXPECT_NE(nullptr, moduleTuValid.programInfo.linkerInput.get()); } -TEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryAndGlobalsAreExportedThenTheirAllocationTypeIsUSMDevice) { +TEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryAndGlobalsAreExportedThenTheirAllocationTypeIsSVM) { std::string zeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name : kernel @@ -2217,14 +2217,8 @@ kernels: zebin.data(), zebin.size()); auto retVal = moduleTu.processUnpackedBinary(); EXPECT_TRUE(retVal); - EXPECT_EQ(AllocationType::BUFFER, moduleTu.globalConstBuffer->getAllocationType()); - EXPECT_EQ(AllocationType::BUFFER, moduleTu.globalVarBuffer->getAllocationType()); - - auto svmAllocsManager = device->getDriverHandle()->getSvmAllocsManager(); - auto globalConstBufferAllocType = svmAllocsManager->getSVMAlloc(reinterpret_cast(moduleTu.globalConstBuffer->getGpuAddress()))->memoryType; - auto globalVarBufferAllocType = svmAllocsManager->getSVMAlloc(reinterpret_cast(moduleTu.globalVarBuffer->getGpuAddress()))->memoryType; - EXPECT_EQ(DEVICE_UNIFIED_MEMORY, globalConstBufferAllocType); - EXPECT_EQ(DEVICE_UNIFIED_MEMORY, globalVarBufferAllocType); + EXPECT_EQ(AllocationType::SVM_ZERO_COPY, moduleTu.globalConstBuffer->getAllocationType()); + EXPECT_EQ(AllocationType::SVM_ZERO_COPY, moduleTu.globalVarBuffer->getAllocationType()); } HWTEST_F(ModuleTranslationUnitTest, WhenBuildOptionsAreNullThenReuseExistingOptions) { diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 65048f4aac..9957353dfa 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1229,7 +1229,7 @@ uint64_t DrmMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t } bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) { - if (graphicsAllocation->getUnderlyingBuffer()) { + if (graphicsAllocation->getUnderlyingBuffer() || !isLocalMemorySupported(graphicsAllocation->getRootDeviceIndex())) { return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy); } return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, maxNBitValue(graphicsAllocation->storageInfo.getNumBanks())); diff --git a/shared/source/program/program_initialization.cpp b/shared/source/program/program_initialization.cpp index c80ec47534..57d56e7feb 100644 --- a/shared/source/program/program_initialization.cpp +++ b/shared/source/program/program_initialization.cpp @@ -39,16 +39,14 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc rootDeviceIndices.push_back(rootDeviceIndex); std::map subDeviceBitfields; subDeviceBitfields.insert({rootDeviceIndex, deviceBitfield}); - NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, subDeviceBitfields); - unifiedMemoryProperties.device = &device; - auto ptr = svmAllocManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); + auto ptr = svmAllocManager->createSVMAlloc(size, svmProps, rootDeviceIndices, subDeviceBitfields); DEBUG_BREAK_IF(ptr == nullptr); if (ptr == nullptr) { return nullptr; } - auto usmAlloc = svmAllocManager->getSVMAlloc(ptr); - UNRECOVERABLE_IF(usmAlloc == nullptr); - gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); + auto svmAlloc = svmAllocManager->getSVMAlloc(ptr); + UNRECOVERABLE_IF(svmAlloc == nullptr); + gpuAllocation = svmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); } else { auto allocationType = constant ? AllocationType::CONSTANT_SURFACE : AllocationType::GLOBAL_SURFACE; gpuAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, diff --git a/shared/test/common/mocks/mock_graphics_allocation.h b/shared/test/common/mocks/mock_graphics_allocation.h index fad91e2d31..f4234ff702 100644 --- a/shared/test/common/mocks/mock_graphics_allocation.h +++ b/shared/test/common/mocks/mock_graphics_allocation.h @@ -20,7 +20,6 @@ class MockGraphicsAllocation : public MemoryAllocation { using MemoryAllocation::allocationOffset; using MemoryAllocation::allocationType; using MemoryAllocation::aubInfo; - using MemoryAllocation::cpuPtr; using MemoryAllocation::gpuAddress; using MemoryAllocation::MemoryAllocation; using MemoryAllocation::memoryPool; diff --git a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp index 2f5d76beb1..7f831e628e 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -5,7 +5,6 @@ * */ -#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "gtest/gtest.h" @@ -20,15 +19,3 @@ TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivat EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(AllocationType::LINEAR_STREAM)); EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(AllocationType::INTERNAL_HEAP)); } - -TEST(MemoryManagerTest, givenAllocationWithNullCpuPtrThenMemoryCopyToAllocationReturnsFalse) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - MockMemoryManager memoryManager(false, false, executionEnvironment); - constexpr uint8_t allocationSize = 10; - uint8_t allocationStorage[allocationSize] = {0}; - MockGraphicsAllocation allocation{allocationStorage, allocationSize}; - allocation.cpuPtr = nullptr; - constexpr size_t offset = 0; - - EXPECT_FALSE(memoryManager.copyMemoryToAllocation(&allocation, offset, nullptr, 0)); -} diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index 7d37480e82..ed762ba078 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -1495,7 +1495,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh size_t sourceAllocationSize = MemoryConstants::pageSize; size_t destinationAllocationSize = sourceAllocationSize + offset; - DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize); + DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, destinationAllocationSize); std::vector dataToCopy(sourceAllocationSize, 1u); AllocationData allocData; @@ -1507,19 +1507,19 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh allocData.storageInfo.memoryBanks.set(0, true); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; - auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status); + auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status); ASSERT_NE(nullptr, allocation); - auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size()); + auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size()); EXPECT_TRUE(ret); - EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManager.lockedLocalMemory[0].get(), offset), dataToCopy.data(), dataToCopy.size())); + EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[0].get(), offset), dataToCopy.data(), dataToCopy.size())); - drmMemoryManager.freeGraphicsMemory(allocation); + drmMemoryManger.freeGraphicsMemory(allocation); } TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationFailsToLockResourceThenItReturnsFalse) { - DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, 0); + DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, 0); std::vector dataToCopy(MemoryConstants::pageSize, 1u); AllocationData allocData; @@ -1530,13 +1530,13 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh allocData.rootDeviceIndex = rootDeviceIndex; allocData.storageInfo.memoryBanks.set(0, true); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; - auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status); + auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status); ASSERT_NE(nullptr, allocation); - auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size()); + auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size()); EXPECT_FALSE(ret); - drmMemoryManager.freeGraphicsMemory(allocation); + drmMemoryManger.freeGraphicsMemory(allocation); } TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationWithCpuPtrThenAllocationIsFilledWithCorrectData) { @@ -1544,18 +1544,18 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh size_t sourceAllocationSize = MemoryConstants::pageSize; size_t destinationAllocationSize = sourceAllocationSize + offset; - DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, false, 0); + DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, false, 0); std::vector dataToCopy(sourceAllocationSize, 1u); - auto allocation = drmMemoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, destinationAllocationSize, AllocationType::KERNEL_ISA, mockDeviceBitfield}); + auto allocation = drmMemoryManger.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, destinationAllocationSize, AllocationType::KERNEL_ISA, mockDeviceBitfield}); ASSERT_NE(nullptr, allocation); - auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size()); + auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size()); EXPECT_TRUE(ret); EXPECT_EQ(0, memcmp(ptrOffset(allocation->getUnderlyingBuffer(), offset), dataToCopy.data(), dataToCopy.size())); - drmMemoryManager.freeGraphicsMemory(allocation); + drmMemoryManger.freeGraphicsMemory(allocation); } TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationOnAllMemoryBanksReturnsSuccessThenAllocationIsFilledWithCorrectData) { @@ -1563,7 +1563,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh size_t sourceAllocationSize = MemoryConstants::pageSize; size_t destinationAllocationSize = sourceAllocationSize + offset; - DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize); + DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, destinationAllocationSize); std::vector dataToCopy(sourceAllocationSize, 1u); AllocationData allocData; @@ -1574,17 +1574,17 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh allocData.storageInfo.memoryBanks = maxNBitValue(MemoryBanks::getBankForLocalMemory(3)); allocData.rootDeviceIndex = rootDeviceIndex; MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; - auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status); + auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status); ASSERT_NE(nullptr, allocation); - auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size()); + auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size()); EXPECT_TRUE(ret); for (auto index = 0u; index < 3; index++) { - EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManager.lockedLocalMemory[index].get(), offset), dataToCopy.data(), dataToCopy.size())); + EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[index].get(), offset), dataToCopy.data(), dataToCopy.size())); } - drmMemoryManager.freeGraphicsMemory(allocation); + drmMemoryManger.freeGraphicsMemory(allocation); } typedef Test DrmMemoryManagerTestPrelim; diff --git a/shared/test/unit_test/program/program_initialization_tests.cpp b/shared/test/unit_test/program/program_initialization_tests.cpp index cd605616be..0b184bbf06 100644 --- a/shared/test/unit_test/program/program_initialization_tests.cpp +++ b/shared/test/unit_test/program/program_initialization_tests.cpp @@ -62,7 +62,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh device.getMemoryManager()->freeGraphicsMemory(alloc); } -TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsUsmDeviceAllocation) { +TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsSvmAllocation) { MockDevice device{}; REQUIRE_SVM_OR_SKIP(&device); MockMemoryManager memoryManager; @@ -77,11 +77,10 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize()); + ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); ASSERT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); - EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast(alloc->getGpuAddress()))->memoryType); + EXPECT_FALSE(alloc->isMemObjectsAllocationWithWritableFlags()); svmAllocsManager.freeSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress()))); alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalVariables, initData.data()); @@ -100,11 +99,10 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize()); + ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); EXPECT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast(alloc->getGpuAddress()))->memoryType); svmAllocsManager.freeSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress()))); } @@ -183,6 +181,26 @@ TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreNotExportedAndAllocationFailsThenG EXPECT_EQ(nullptr, alloc); } +TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreExportedAndAllocationFailsThenGracefullyReturnsNullptr) { + MockDevice device{}; + MockMemoryManager memoryManager{*device.getExecutionEnvironment()}; + MockSVMAllocsManager svmAllocsManager(&memoryManager, false); + memoryManager.failInAllocateWithSizeAndAlignment = true; + WhiteBox linkerInputExportGlobalVariables; + WhiteBox linkerInputExportGlobalConstants; + linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true; + linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true; + std::vector initData; + initData.resize(64, 7U); + GraphicsAllocation *alloc = nullptr; + + alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data()); + EXPECT_EQ(nullptr, alloc); + + alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data()); + EXPECT_EQ(nullptr, alloc); +} + TEST(AllocateGlobalSurfaceTest, GivenAllocationInLocalMemoryWhichRequiresBlitterWhenAllocatingNonSvmAllocationThenBlitterIsUsed) { REQUIRE_SVM_OR_SKIP(defaultHwInfo.get()); DebugManagerStateRestore restorer;