Add shareable allocation for Windows

Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich
2021-08-11 10:36:04 +00:00
committed by Compute-Runtime-Automation
parent c7ff2bacd3
commit 4390590831
22 changed files with 111 additions and 36 deletions

View File

@@ -1388,7 +1388,7 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override { return nullptr; };
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override { return nullptr; };
GraphicsAllocation *allocateShareableMemory(const AllocationData &allocationData) override { return nullptr; };
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override { return nullptr; };
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override { return nullptr; };
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override{};
};

View File

@@ -593,7 +593,6 @@ TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenSharedUnifiedM
TEST_F(UnifiedMemoryManagerPropertiesTest, givenDeviceBitfieldWithSingleBitSetWhenSharedUnifiedMemoryAllocationIsCreatedThenProperPropertiesArePassedToMemoryManager) {
MockCommandQueue cmdQ;
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0x8)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
@@ -608,17 +607,19 @@ TEST_F(UnifiedMemoryManagerPropertiesTest, givenDeviceBitfieldWithSingleBitSetWh
}
TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenMultiOsContextFlagTrueThenProperPropertiesArePassedToMemoryManager) {
MockCommandQueue cmdQ;
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(4);
MockExecutionEnvironment executionEnvironment;
auto memoryManager = std::make_unique<MemoryManagerPropertiesCheck>(false, true, executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
memoryManager->pageFaultManager = std::make_unique<MockPageFaultManager>();
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0xf)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
svmManager->multiOsContextSupport = true;
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_FALSE(memoryManager->multiOsContextCapablePassed);
EXPECT_TRUE(memoryManager->multiStorageResourcePassed);
@@ -628,6 +629,7 @@ TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenMultiOsContext
}
TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenMultiOsContextFlagFalseThenLowestSubDevicePassedToMemoryManager) {
MockCommandQueue cmdQ;
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(4);
DebugManager.flags.OverrideLeastOccupiedBank.set(1);
@@ -635,12 +637,13 @@ TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenMultiOsContext
MockExecutionEnvironment executionEnvironment;
auto memoryManager = std::make_unique<MemoryManagerPropertiesCheck>(false, true, executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
memoryManager->pageFaultManager = std::make_unique<MockPageFaultManager>();
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0xE)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
svmManager->multiOsContextSupport = false;
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, &cmdQ);
auto expectedSubDevices = unifiedMemoryProperties.subdeviceBitfields.at(mockRootDeviceIndex);
expectedSubDevices.reset();
@@ -653,18 +656,64 @@ TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenMultiOsContext
svmManager->freeSVMAlloc(ptr);
}
TEST(UnifiedMemoryTest, givenDeviceBitfieldWithSingleBitsSetWhenMultiOsContextFlagTrueThenProperPropertiesArePassedToMemoryManager) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(1);
TEST(UnifiedMemoryTest, givenDeviceBitfieldWithMultipleBitsSetWhenMultiOsContextFlagTrueAndDeviceMemoryThenProperPropertiesArePassedToMemoryManager) {
MockContext mockContext;
auto device = mockContext.getDevice(0u);
MockExecutionEnvironment executionEnvironment;
auto memoryManager = std::make_unique<MemoryManagerPropertiesCheck>(false, true, executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0xf)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = &device->getDevice();
svmManager->multiOsContextSupport = true;
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
EXPECT_FALSE(memoryManager->multiOsContextCapablePassed);
EXPECT_TRUE(memoryManager->multiStorageResourcePassed);
EXPECT_EQ(unifiedMemoryProperties.subdeviceBitfields.at(mockRootDeviceIndex), memoryManager->subDevicesBitfieldPassed);
svmManager->freeSVMAlloc(ptr);
}
TEST(UnifiedMemoryTest, givenDeviceBitfieldWithTwoBitsSetWhenMultiOsContextFlagTrueAndDeviceMemoryThenProperPropertiesArePassedToMemoryManager) {
MockContext mockContext;
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
MockExecutionEnvironment executionEnvironment;
auto memoryManager = std::make_unique<MemoryManagerPropertiesCheck>(false, true, executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0x6)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
auto device = mockContext.getDevice(0u);
unifiedMemoryProperties.device = &device->getDevice();
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
EXPECT_FALSE(memoryManager->multiOsContextCapablePassed);
EXPECT_FALSE(memoryManager->multiStorageResourcePassed);
auto expectedSubDevices = unifiedMemoryProperties.subdeviceBitfields.at(mockRootDeviceIndex);
expectedSubDevices.reset();
expectedSubDevices.set(1);
EXPECT_EQ(expectedSubDevices, memoryManager->subDevicesBitfieldPassed);
svmManager->freeSVMAlloc(ptr);
}
TEST(UnifiedMemoryTest, givenDeviceBitfieldWithSingleBitsSetWhenMultiOsContextFlagTrueThenProperPropertiesArePassedToMemoryManager) {
MockCommandQueue cmdQ;
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(1);
MockExecutionEnvironment executionEnvironment;
auto memoryManager = std::make_unique<MemoryManagerPropertiesCheck>(false, true, executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
memoryManager->pageFaultManager = std::make_unique<MockPageFaultManager>();
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0x1)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
svmManager->multiOsContextSupport = true;
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_FALSE(memoryManager->multiOsContextCapablePassed);
EXPECT_FALSE(memoryManager->multiStorageResourcePassed);
@@ -674,11 +723,12 @@ TEST(UnifiedMemoryTest, givenDeviceBitfieldWithSingleBitsSetWhenMultiOsContextFl
}
TEST_F(UnifiedMemoryManagerPropertiesTest, givenDeviceBitfieldWithSingleBitSetWhenDeviceUnifiedMemoryAllocationIsCreatedThenProperPropertiesArePassedToMemoryManager) {
MockCommandQueue cmdQ;
std::set<uint32_t> rootDeviceIndices{mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, DeviceBitfield(0x8)}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_FALSE(memoryManager->multiOsContextCapablePassed);
EXPECT_FALSE(memoryManager->multiStorageResourcePassed);

View File

@@ -33,6 +33,11 @@ void *MockMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
if (failAllocateSystemMemory) {
return nullptr;
}
if (fakeBigAllocations && size > bigAllocation) {
size = MemoryConstants::pageSize64k;
}
return OsAgnosticMemoryManager::allocateSystemMemory(redundancyRatio * size, alignment);
}
@@ -74,9 +79,9 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(const Allo
return allocation;
}
GraphicsAllocation *MockMemoryManager::allocateShareableMemory(const AllocationData &allocationData) {
GraphicsAllocation *MockMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
allocateForShareableCalled = true;
return OsAgnosticMemoryManager::allocateShareableMemory(allocationData);
return OsAgnosticMemoryManager::allocateMemoryByKMD(allocationData);
}
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(const AllocationData &allocationData) {

View File

@@ -73,7 +73,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
void setDeferredDeleter(DeferredDeleter *deleter);
void overrideAsyncDeleterFlag(bool newValue);
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override;
GraphicsAllocation *allocateShareableMemory(const AllocationData &allocationData) override;
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override;
int redundancyRatio = 1;
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
@@ -262,7 +262,7 @@ class FailMemoryManager : public MockMemoryManager {
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override {
return nullptr;
}
GraphicsAllocation *allocateShareableMemory(const AllocationData &allocationData) override {
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override {
return nullptr;
}
int32_t failedAllocationsCount = 0;

View File

@@ -1096,7 +1096,7 @@ TEST_F(DrmMemoryManagerTest, GivenShareableEnabledWhenAskedToCreateGraphicsAlloc
allocationData.size = MemoryConstants::pageSize;
allocationData.flags.shareable = true;
auto allocation = memoryManager->allocateShareableMemory(allocationData);
auto allocation = memoryManager->allocateMemoryByKMD(allocationData);
EXPECT_NE(nullptr, allocation);
EXPECT_NE(0u, allocation->getGpuAddress());

View File

@@ -23,7 +23,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
using BaseClass::allocateGraphicsMemoryWithAlignment;
using BaseClass::allocateGraphicsMemoryWithGpuVa;
using BaseClass::allocateGraphicsMemoryWithProperties;
using BaseClass::allocateShareableMemory;
using BaseClass::allocateMemoryByKMD;
using BaseClass::createGraphicsAllocation;
using BaseClass::createWddmAllocation;
using BaseClass::getWddm;

View File

@@ -157,6 +157,22 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
memoryManager->freeGraphicsMemory(allocation);
}
class MockCreateWddmAllocationMemoryManager : public MockWddmMemoryManager {
public:
MockCreateWddmAllocationMemoryManager(NEO::ExecutionEnvironment &execEnv) : MockWddmMemoryManager(execEnv) {}
bool createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr) override {
return false;
}
};
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryFailedThenNullptrFromAllocateMemoryByKMDIsReturned) {
memoryManager.reset(new MockCreateWddmAllocationMemoryManager(*executionEnvironment));
AllocationData allocationData;
allocationData.size = MemoryConstants::pageSize;
auto allocation = memoryManager->allocateMemoryByKMD(allocationData);
EXPECT_EQ(nullptr, allocation);
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
AllocationData allocationData;
@@ -353,7 +369,7 @@ TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndSmallSizeWhenAskedTo
AllocationData allocationData;
allocationData.size = 4096u;
allocationData.flags.shareable = true;
auto allocation = memoryManager->allocateShareableMemory(allocationData);
auto allocation = memoryManager->allocateMemoryByKMD(allocationData);
EXPECT_NE(nullptr, allocation);
EXPECT_FALSE(memoryManager->allocateHugeGraphicsMemoryCalled);
memoryManager->freeGraphicsMemory(allocation);
@@ -365,7 +381,7 @@ TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndHugeSizeWhenAskedToC
AllocationData allocationData;
allocationData.size = 2ULL * MemoryConstants::pageSize64k;
allocationData.flags.shareable = true;
auto allocation = memoryManager->allocateShareableMemory(allocationData);
auto allocation = memoryManager->allocateMemoryByKMD(allocationData);
EXPECT_NE(nullptr, allocation);
EXPECT_TRUE(memoryManager->allocateHugeGraphicsMemoryCalled);
memoryManager->freeGraphicsMemory(allocation);