mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Allowing the creation of overlapping buffers
Related-To: NEO-5871 Signed-off-by: Andrzej Koska <andrzej.koska@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
33a2f49b21
commit
94c97fc14c
@ -42,6 +42,14 @@ class TestedMemoryManager : public OsAgnosticMemoryManager {
|
||||
}
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithHostPtr(properties);
|
||||
}
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &properties) override {
|
||||
EXPECT_NE(0u, HPExpectedSize);
|
||||
if (HPExpectedSize == properties.size) {
|
||||
EXPECT_TRUE(properties.flags.forcePin);
|
||||
HPAllocCount++;
|
||||
}
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(properties);
|
||||
}
|
||||
|
||||
size_t expectedSize = 0;
|
||||
uint32_t allocCount = 0;
|
||||
|
@ -479,7 +479,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHo
|
||||
|
||||
auto allocation = memoryManager.allocateGraphicsMemory(allocData);
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
EXPECT_EQ(1u, allocation->fragmentsStorage.fragmentCount);
|
||||
EXPECT_EQ((executionEnvironment.rootDeviceEnvironments[0u]->getHardwareInfo()->capabilityTable.hostPtrTrackingEnabled || is32bit), allocation->fragmentsStorage.fragmentCount);
|
||||
EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool());
|
||||
|
||||
memoryManager.freeGraphicsMemory(allocation);
|
||||
|
@ -1418,10 +1418,11 @@ TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCre
|
||||
galloc = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, mockDeviceBitfield});
|
||||
EXPECT_NE(nullptr, galloc);
|
||||
EXPECT_NE(nullptr, galloc->getUnderlyingBuffer());
|
||||
EXPECT_EQ(0u, (uintptr_t)galloc->getUnderlyingBuffer() % MemoryConstants::pageSize64k);
|
||||
size_t size = (executionEnvironment.rootDeviceEnvironments[0u]->getHardwareInfo()->capabilityTable.hostPtrTrackingEnabled) ? MemoryConstants::pageSize64k : MemoryConstants::pageSize;
|
||||
EXPECT_EQ(0u, (uintptr_t)galloc->getUnderlyingBuffer() % size);
|
||||
|
||||
EXPECT_NE(0u, galloc->getGpuAddress());
|
||||
EXPECT_EQ(0u, (uintptr_t)galloc->getGpuAddress() % MemoryConstants::pageSize64k);
|
||||
EXPECT_EQ(0u, (uintptr_t)galloc->getGpuAddress() % size);
|
||||
memoryManager.freeGraphicsMemory(galloc);
|
||||
}
|
||||
|
||||
@ -1697,6 +1698,49 @@ TEST(MemoryManager, givenBufferAndLimitedGPUWhenAllocatingGraphicsMemoryThenAllo
|
||||
EXPECT_TRUE(memoryManager.allocate32BitGraphicsMemoryImplCalled);
|
||||
memoryManager.freeGraphicsMemory(bufferAllocation);
|
||||
}
|
||||
|
||||
TEST(MemoryManager, givenBufferHostMemoryAndHostPtrTrackingDisabledWhenAllocatingGraphicsMemoryThenAllocateGraphicsMemoryForNonSvmHostPtrIsCalled) {
|
||||
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
|
||||
HardwareInfo hwInfoLocal = *defaultHwInfo;
|
||||
hwInfoLocal.capabilityTable.hostPtrTrackingEnabled = false;
|
||||
executionEnvironment->rootDeviceEnvironments[0u]->setHwInfo(&hwInfoLocal);
|
||||
|
||||
MockMemoryManager memoryManager(false, true, *executionEnvironment);
|
||||
char bufferData[4096]{};
|
||||
AllocationData allocationData{};
|
||||
allocationData.hostPtr = bufferData;
|
||||
allocationData.size = 4096u;
|
||||
allocationData.type = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
|
||||
|
||||
auto bufferAllocation = memoryManager.allocateGraphicsMemory(allocationData);
|
||||
EXPECT_NE(nullptr, bufferAllocation);
|
||||
EXPECT_FALSE(memoryManager.allocateForImageCalled);
|
||||
if (!is32bit) {
|
||||
EXPECT_TRUE(memoryManager.allocateGraphicsMemoryForNonSvmHostPtrCalled);
|
||||
}
|
||||
memoryManager.freeGraphicsMemory(bufferAllocation);
|
||||
}
|
||||
|
||||
TEST(MemoryManager, givenBufferHostMemoryAndHostPtrTrackingDisabledAndForce32bitAllocationsWhenAllocatingGraphicsMemoryThenAllocateGraphicsMemoryForNonSvmHostPtrIsNotCalled) {
|
||||
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
|
||||
HardwareInfo hwInfoLocal = *defaultHwInfo;
|
||||
hwInfoLocal.capabilityTable.hostPtrTrackingEnabled = false;
|
||||
executionEnvironment->rootDeviceEnvironments[0u]->setHwInfo(&hwInfoLocal);
|
||||
|
||||
MockMemoryManager memoryManager(false, true, *executionEnvironment);
|
||||
memoryManager.setForce32BitAllocations(true);
|
||||
char bufferData[4096]{};
|
||||
AllocationData allocationData{};
|
||||
allocationData.hostPtr = bufferData;
|
||||
allocationData.size = 4096u;
|
||||
allocationData.type = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
|
||||
|
||||
auto bufferAllocation = memoryManager.allocateGraphicsMemory(allocationData);
|
||||
EXPECT_NE(nullptr, bufferAllocation);
|
||||
EXPECT_FALSE(memoryManager.allocateGraphicsMemoryForNonSvmHostPtrCalled);
|
||||
memoryManager.freeGraphicsMemory(bufferAllocation);
|
||||
}
|
||||
|
||||
TEST(MemoryManager, givenShareableWhenAllocatingGraphicsMemoryThenAllocateShareableIsCalled) {
|
||||
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
|
||||
MockMemoryManager memoryManager(false, true, *executionEnvironment);
|
||||
@ -2698,6 +2742,24 @@ HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenHostPtrTrackingModeThenNonSv
|
||||
EXPECT_EQ(false, result);
|
||||
}
|
||||
|
||||
HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenHostPtrTrackingModeThenNonSvmBufferIsNotSet) {
|
||||
HardwareInfo hwInfoLocal = *defaultHwInfo;
|
||||
hwInfoLocal.capabilityTable.hostPtrTrackingEnabled = true;
|
||||
memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[0u]->setHwInfo(&hwInfoLocal);
|
||||
int buffer = 0;
|
||||
EXPECT_FALSE(memoryManager->isNonSvmBuffer(&buffer, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, 0u));
|
||||
EXPECT_FALSE(memoryManager->isNonSvmBuffer(&buffer, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, 0u));
|
||||
}
|
||||
|
||||
HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenHostPtrTrackingDisabledAnd64bitsThenNonSvmBufferIsSetForBufferHostMemory) {
|
||||
HardwareInfo hwInfoLocal = *defaultHwInfo;
|
||||
hwInfoLocal.capabilityTable.hostPtrTrackingEnabled = false;
|
||||
memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[0u]->setHwInfo(&hwInfoLocal);
|
||||
int buffer = 0;
|
||||
EXPECT_FALSE(memoryManager->isNonSvmBuffer(&buffer, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, 0u));
|
||||
EXPECT_EQ(!is32bit, memoryManager->isNonSvmBuffer(&buffer, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, 0u));
|
||||
}
|
||||
|
||||
HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenHostPtrTrackingEnabledThenNonSvmHostPtrUsageDependsOnFullRangeSvm) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.EnableHostPtrTracking.set(1);
|
||||
|
@ -133,6 +133,11 @@ GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(uint32_t root
|
||||
return allocate32BitGraphicsMemoryImpl(allocationData, useLocalMemory);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) {
|
||||
allocateGraphicsMemoryForNonSvmHostPtrCalled = true;
|
||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) {
|
||||
allocate32BitGraphicsMemoryImplCalled = true;
|
||||
if (failAllocate32Bit) {
|
||||
|
@ -31,7 +31,6 @@ class MemoryManagerCreate : public T {
|
||||
|
||||
class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
public:
|
||||
using MemoryManager::allocateGraphicsMemoryForNonSvmHostPtr;
|
||||
using MemoryManager::allocateGraphicsMemoryInPreferredPool;
|
||||
using MemoryManager::allocateGraphicsMemoryWithAlignment;
|
||||
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
||||
@ -42,6 +41,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
using MemoryManager::getAllocationData;
|
||||
using MemoryManager::gfxPartitions;
|
||||
using MemoryManager::internalLocalMemoryUsageBankSelector;
|
||||
using MemoryManager::isNonSvmBuffer;
|
||||
using MemoryManager::multiContextResourceDestructor;
|
||||
using MemoryManager::overrideAllocationData;
|
||||
using MemoryManager::pageFaultManager;
|
||||
@ -134,6 +134,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType);
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
||||
|
||||
bool isLimitedGPU(uint32_t rootDeviceIndex) override {
|
||||
return limitedGPU;
|
||||
@ -161,6 +162,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
bool preferRenderCompressedFlagPassed = false;
|
||||
bool allocateForImageCalled = false;
|
||||
bool allocate32BitGraphicsMemoryImplCalled = false;
|
||||
bool allocateGraphicsMemoryForNonSvmHostPtrCalled = false;
|
||||
bool allocateForShareableCalled = false;
|
||||
bool failReserveAddress = false;
|
||||
bool failAllocateSystemMemory = false;
|
||||
@ -234,6 +236,7 @@ class FailMemoryManager : public MockMemoryManager {
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &
|
||||
if (allocationData.flags.shareable) {
|
||||
return allocateShareableMemory(allocationData);
|
||||
}
|
||||
if (useNonSvmHostPtrAlloc(allocationData.type, allocationData.rootDeviceIndex)) {
|
||||
if (useNonSvmHostPtrAlloc(allocationData.type, allocationData.rootDeviceIndex) || isNonSvmBuffer(allocationData.hostPtr, allocationData.type, allocationData.rootDeviceIndex)) {
|
||||
auto allocation = allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
|
||||
if (allocation) {
|
||||
allocation->setFlushL3Required(allocationData.flags.flushL3);
|
||||
|
@ -214,6 +214,9 @@ class MemoryManager {
|
||||
LocalMemoryUsageBankSelector *getLocalMemoryUsageBankSelector(GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex);
|
||||
|
||||
bool isLocalMemoryUsedForIsa(uint32_t rootDeviceIndex);
|
||||
MOCKABLE_VIRTUAL bool isNonSvmBuffer(const void *hostPtr, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex) {
|
||||
return !force32bitAllocations && hostPtr && !isHostPointerTrackingEnabled(rootDeviceIndex) && (allocationType == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo);
|
||||
|
Reference in New Issue
Block a user