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 7440b0e730..f43f1175a5 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, WhenCreatingFromZeBinaryAndGlobalsAreExportedThenTheirAllocationTypeIsSVM) { +TEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryAndGlobalsAreExportedThenTheirAllocationTypeIsUSMDevice) { std::string zeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name : kernel @@ -2217,8 +2217,14 @@ kernels: zebin.data(), zebin.size()); auto retVal = moduleTu.processUnpackedBinary(); EXPECT_TRUE(retVal); - EXPECT_EQ(AllocationType::SVM_ZERO_COPY, moduleTu.globalConstBuffer->getAllocationType()); - EXPECT_EQ(AllocationType::SVM_ZERO_COPY, moduleTu.globalVarBuffer->getAllocationType()); + 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); } HWTEST_F(ModuleTranslationUnitTest, WhenBuildOptionsAreNullThenReuseExistingOptions) { diff --git a/shared/source/program/program_initialization.cpp b/shared/source/program/program_initialization.cpp index 57d56e7feb..c80ec47534 100644 --- a/shared/source/program/program_initialization.cpp +++ b/shared/source/program/program_initialization.cpp @@ -39,14 +39,16 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc rootDeviceIndices.push_back(rootDeviceIndex); std::map subDeviceBitfields; subDeviceBitfields.insert({rootDeviceIndex, deviceBitfield}); - auto ptr = svmAllocManager->createSVMAlloc(size, svmProps, rootDeviceIndices, subDeviceBitfields); + NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, subDeviceBitfields); + unifiedMemoryProperties.device = &device; + auto ptr = svmAllocManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); DEBUG_BREAK_IF(ptr == nullptr); if (ptr == nullptr) { return nullptr; } - auto svmAlloc = svmAllocManager->getSVMAlloc(ptr); - UNRECOVERABLE_IF(svmAlloc == nullptr); - gpuAllocation = svmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); + auto usmAlloc = svmAllocManager->getSVMAlloc(ptr); + UNRECOVERABLE_IF(usmAlloc == nullptr); + gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); } else { auto allocationType = constant ? AllocationType::CONSTANT_SURFACE : AllocationType::GLOBAL_SURFACE; gpuAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, diff --git a/shared/test/unit_test/program/program_initialization_tests.cpp b/shared/test/unit_test/program/program_initialization_tests.cpp index 0b184bbf06..cd605616be 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, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsSvmAllocation) { +TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsUsmDeviceAllocation) { MockDevice device{}; REQUIRE_SVM_OR_SKIP(&device); MockMemoryManager memoryManager; @@ -77,10 +77,11 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize()); EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); ASSERT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); - EXPECT_FALSE(alloc->isMemObjectsAllocationWithWritableFlags()); + EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags()); + EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast(alloc->getGpuAddress()))->memoryType); svmAllocsManager.freeSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress()))); alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalVariables, initData.data()); @@ -99,10 +100,11 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data()); ASSERT_NE(nullptr, alloc); - ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize()); + ASSERT_EQ(MemoryConstants::pageSize64k, 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()))); } @@ -181,26 +183,6 @@ 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;