Allow to allocate shareable graphics allocation
Change-Id: I284b03b001e5b67c344d46f34048803ef9a57314 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
parent
f6757c02a4
commit
1e011f9a08
|
@ -16,19 +16,19 @@ bool GraphicsAllocation::isL3Capable() {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, uint32_t osContextCount, bool isShareable) : gpuBaseAddress(baseAddress),
|
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, uint32_t osContextCount, bool shareable) : gpuBaseAddress(baseAddress),
|
||||||
size(sizeIn),
|
size(sizeIn),
|
||||||
cpuPtr(cpuPtrIn),
|
cpuPtr(cpuPtrIn),
|
||||||
gpuAddress(gpuAddress),
|
gpuAddress(gpuAddress),
|
||||||
isShareable(isShareable) {
|
shareable(shareable) {
|
||||||
usageInfos.resize(maxOsContextCount);
|
usageInfos.resize(maxOsContextCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, uint32_t osContextCount, bool isShareable) : size(sizeIn),
|
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, uint32_t osContextCount, bool shareable) : size(sizeIn),
|
||||||
cpuPtr(cpuPtrIn),
|
cpuPtr(cpuPtrIn),
|
||||||
gpuAddress(castToUint64(cpuPtrIn)),
|
gpuAddress(castToUint64(cpuPtrIn)),
|
||||||
sharedHandle(sharedHandleIn),
|
sharedHandle(sharedHandleIn),
|
||||||
isShareable(isShareable) {
|
shareable(shareable) {
|
||||||
usageInfos.resize(maxOsContextCount);
|
usageInfos.resize(maxOsContextCount);
|
||||||
}
|
}
|
||||||
GraphicsAllocation::~GraphicsAllocation() = default;
|
GraphicsAllocation::~GraphicsAllocation() = default;
|
||||||
|
|
|
@ -133,6 +133,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||||
void resetResidencyTaskCount(uint32_t contextId) { updateResidencyTaskCount(objectNotResident, contextId); }
|
void resetResidencyTaskCount(uint32_t contextId) { updateResidencyTaskCount(objectNotResident, contextId); }
|
||||||
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
||||||
|
|
||||||
|
bool isShareable() const { return shareable; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
constexpr static uint32_t objectNotResident = (uint32_t)-1;
|
constexpr static uint32_t objectNotResident = (uint32_t)-1;
|
||||||
constexpr static uint32_t objectNotUsed = (uint32_t)-1;
|
constexpr static uint32_t objectNotUsed = (uint32_t)-1;
|
||||||
|
@ -160,6 +162,6 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||||
bool memObjectsAllocationWithWritableFlags = false;
|
bool memObjectsAllocationWithWritableFlags = false;
|
||||||
std::vector<UsageInfo> usageInfos;
|
std::vector<UsageInfo> usageInfos;
|
||||||
std::atomic<uint32_t> registeredContextsNum{0};
|
std::atomic<uint32_t> registeredContextsNum{0};
|
||||||
bool isShareable = false;
|
bool shareable = false;
|
||||||
};
|
};
|
||||||
} // namespace OCLRT
|
} // namespace OCLRT
|
||||||
|
|
|
@ -193,6 +193,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||||
bool forcePin = properties.flags.forcePin;
|
bool forcePin = properties.flags.forcePin;
|
||||||
bool uncacheable = properties.flags.uncacheable;
|
bool uncacheable = properties.flags.uncacheable;
|
||||||
bool mustBeZeroCopy = false;
|
bool mustBeZeroCopy = false;
|
||||||
|
bool shareable = properties.flags.shareable;
|
||||||
|
|
||||||
switch (properties.allocationType) {
|
switch (properties.allocationType) {
|
||||||
case GraphicsAllocation::AllocationType::BUFFER:
|
case GraphicsAllocation::AllocationType::BUFFER:
|
||||||
|
@ -254,6 +255,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||||
allocationData.flags.uncacheable = uncacheable;
|
allocationData.flags.uncacheable = uncacheable;
|
||||||
allocationData.flags.flushL3 = properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite;
|
allocationData.flags.flushL3 = properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite;
|
||||||
allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == properties.allocationType;
|
allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == properties.allocationType;
|
||||||
|
allocationData.flags.shareable = shareable;
|
||||||
|
|
||||||
if (allocationData.flags.mustBeZeroCopy) {
|
if (allocationData.flags.mustBeZeroCopy) {
|
||||||
allocationData.flags.useSystemMemory = true;
|
allocationData.flags.useSystemMemory = true;
|
||||||
|
|
|
@ -45,7 +45,8 @@ struct AllocationProperties {
|
||||||
uint32_t flushL3RequiredForWrite : 1;
|
uint32_t flushL3RequiredForWrite : 1;
|
||||||
uint32_t forcePin : 1;
|
uint32_t forcePin : 1;
|
||||||
uint32_t uncacheable : 1;
|
uint32_t uncacheable : 1;
|
||||||
uint32_t reserved : 27;
|
uint32_t shareable : 1;
|
||||||
|
uint32_t reserved : 26;
|
||||||
} flags;
|
} flags;
|
||||||
uint32_t allFlags = 0;
|
uint32_t allFlags = 0;
|
||||||
};
|
};
|
||||||
|
@ -201,7 +202,8 @@ class MemoryManager {
|
||||||
uint32_t uncacheable : 1;
|
uint32_t uncacheable : 1;
|
||||||
uint32_t flushL3 : 1;
|
uint32_t flushL3 : 1;
|
||||||
uint32_t preferRenderCompressed : 1;
|
uint32_t preferRenderCompressed : 1;
|
||||||
uint32_t reserved : 23;
|
uint32_t shareable : 1;
|
||||||
|
uint32_t reserved : 22;
|
||||||
} flags;
|
} flags;
|
||||||
uint32_t allFlags = 0;
|
uint32_t allFlags = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
|
||||||
|
|
||||||
if (fakeBigAllocations && allocationData.size > bigAllocation) {
|
if (fakeBigAllocations && allocationData.size > bigAllocation) {
|
||||||
memoryAllocation = new MemoryAllocation(nullptr, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), allocationData.size, counter,
|
memoryAllocation = new MemoryAllocation(nullptr, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), allocationData.size, counter,
|
||||||
MemoryPool::System4KBPages, this->getOsContextCount(), false);
|
MemoryPool::System4KBPages, this->getOsContextCount(), allocationData.flags.shareable);
|
||||||
counter++;
|
counter++;
|
||||||
memoryAllocation->uncacheable = allocationData.flags.uncacheable;
|
memoryAllocation->uncacheable = allocationData.flags.uncacheable;
|
||||||
return memoryAllocation;
|
return memoryAllocation;
|
||||||
|
@ -45,7 +45,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
|
||||||
auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
|
auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
|
||||||
if (ptr != nullptr) {
|
if (ptr != nullptr) {
|
||||||
memoryAllocation = new MemoryAllocation(ptr, ptr, reinterpret_cast<uint64_t>(ptr), allocationData.size, counter, MemoryPool::System4KBPages,
|
memoryAllocation = new MemoryAllocation(ptr, ptr, reinterpret_cast<uint64_t>(ptr), allocationData.size, counter, MemoryPool::System4KBPages,
|
||||||
this->getOsContextCount(), false);
|
this->getOsContextCount(), allocationData.flags.shareable);
|
||||||
if (!memoryAllocation) {
|
if (!memoryAllocation) {
|
||||||
alignedFreeWrapper(ptr);
|
alignedFreeWrapper(ptr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -228,7 +228,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc
|
||||||
if (forcePinEnabled && pinBB != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) {
|
if (forcePinEnabled && pinBB != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) {
|
||||||
pinBB->pin(&bo, 1, getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId());
|
pinBB->pin(&bo, 1, getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId());
|
||||||
}
|
}
|
||||||
return new DrmAllocation(bo, res, cSize, MemoryPool::System4KBPages, getOsContextCount(), false);
|
return new DrmAllocation(bo, res, cSize, MemoryPool::System4KBPages, getOsContextCount(), allocationData.flags.shareable);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) {
|
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(AllocationData
|
||||||
size_t sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize64k);
|
size_t sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize64k);
|
||||||
Gmm *gmm = nullptr;
|
Gmm *gmm = nullptr;
|
||||||
|
|
||||||
auto wddmAllocation = std::make_unique<WddmAllocation>(nullptr, sizeAligned, nullptr, MemoryPool::System64KBPages, getOsContextCount(), false);
|
auto wddmAllocation = std::make_unique<WddmAllocation>(nullptr, sizeAligned, nullptr, MemoryPool::System64KBPages, getOsContextCount(), !!allocationData.flags.shareable);
|
||||||
|
|
||||||
gmm = new Gmm(nullptr, sizeAligned, false, allocationData.flags.preferRenderCompressed, true);
|
gmm = new Gmm(nullptr, sizeAligned, false, allocationData.flags.preferRenderCompressed, true);
|
||||||
wddmAllocation->gmm = gmm;
|
wddmAllocation->gmm = gmm;
|
||||||
|
@ -98,7 +98,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto wddmAllocation = std::make_unique<WddmAllocation>(pSysMem, sizeAligned, nullptr, MemoryPool::System4KBPages, getOsContextCount(), false);
|
auto wddmAllocation = std::make_unique<WddmAllocation>(pSysMem, sizeAligned, nullptr, MemoryPool::System4KBPages, getOsContextCount(), allocationData.flags.shareable);
|
||||||
wddmAllocation->driverAllocatedCpuPointer = pSysMem;
|
wddmAllocation->driverAllocatedCpuPointer = pSysMem;
|
||||||
|
|
||||||
gmm = new Gmm(pSysMem, sizeAligned, allocationData.flags.uncacheable);
|
gmm = new Gmm(pSysMem, sizeAligned, allocationData.flags.uncacheable);
|
||||||
|
|
|
@ -377,3 +377,31 @@ TEST(MemoryManagerTest, givenTimestampTagBufferTypeWhenGetAllocationDataIsCalled
|
||||||
MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER}, 0, nullptr);
|
MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER}, 0, nullptr);
|
||||||
EXPECT_TRUE(allocData.flags.useSystemMemory);
|
EXPECT_TRUE(allocData.flags.useSystemMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
|
||||||
|
MockMemoryManager memoryManager(false);
|
||||||
|
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
|
||||||
|
properties.flags.shareable = true;
|
||||||
|
|
||||||
|
AllocationData allocData;
|
||||||
|
MockMemoryManager::getAllocationData(allocData, properties, 0, nullptr);
|
||||||
|
EXPECT_TRUE(allocData.flags.shareable);
|
||||||
|
|
||||||
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties);
|
||||||
|
EXPECT_TRUE(allocation->isShareable());
|
||||||
|
memoryManager.freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
|
||||||
|
MockMemoryManager memoryManager(false);
|
||||||
|
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
|
||||||
|
properties.flags.shareable = false;
|
||||||
|
|
||||||
|
AllocationData allocData;
|
||||||
|
MockMemoryManager::getAllocationData(allocData, properties, 0, nullptr);
|
||||||
|
EXPECT_FALSE(allocData.flags.shareable);
|
||||||
|
|
||||||
|
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties);
|
||||||
|
EXPECT_FALSE(allocation->isShareable());
|
||||||
|
memoryManager.freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,9 @@ void *MockMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) {
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) {
|
||||||
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties({redundancyRatio * properties.size, properties.allocationType});
|
AllocationProperties adjustedProperties(properties);
|
||||||
|
adjustedProperties.size = redundancyRatio * properties.size;
|
||||||
|
return OsAgnosticMemoryManager::allocateGraphicsMemoryWithProperties(adjustedProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, const void *hostPtr) {
|
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, const void *hostPtr) {
|
||||||
|
|
|
@ -651,6 +651,26 @@ TEST_F(DrmMemoryManagerTest, GivenNoInputsWhenOsHandleIsCreatedThenAllBoHandlesA
|
||||||
EXPECT_EQ(nullptr, boHandle2->bo);
|
EXPECT_EQ(nullptr, boHandle2->bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DrmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
|
||||||
|
mock->ioctl_expected.total = -1;
|
||||||
|
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
|
||||||
|
properties.flags.shareable = true;
|
||||||
|
|
||||||
|
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
|
||||||
|
EXPECT_TRUE(allocation->isShareable());
|
||||||
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DrmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
|
||||||
|
mock->ioctl_expected.total = -1;
|
||||||
|
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
|
||||||
|
properties.flags.shareable = false;
|
||||||
|
|
||||||
|
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
|
||||||
|
EXPECT_FALSE(allocation->isShareable());
|
||||||
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DrmMemoryManagerTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
|
TEST_F(DrmMemoryManagerTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
|
||||||
OsHandleStorage handleStorage;
|
OsHandleStorage handleStorage;
|
||||||
auto ptr = reinterpret_cast<void *>(0x1000);
|
auto ptr = reinterpret_cast<void *>(0x1000);
|
||||||
|
|
|
@ -228,6 +228,24 @@ TEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtualPa
|
||||||
EXPECT_FALSE(memoryManager->peekVirtualPaddingSupport());
|
EXPECT_FALSE(memoryManager->peekVirtualPaddingSupport());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(WddmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagEnabledWhenAllocateMemoryThenAllocationIsShareable) {
|
||||||
|
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
|
||||||
|
properties.flags.shareable = true;
|
||||||
|
|
||||||
|
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
|
||||||
|
EXPECT_TRUE(allocation->isShareable());
|
||||||
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(WddmMemoryManagerTest, givenAllocationPropertiesWithShareableFlagDisabledWhenAllocateMemoryThenAllocationIsNotShareable) {
|
||||||
|
AllocationProperties properties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER};
|
||||||
|
properties.flags.shareable = false;
|
||||||
|
|
||||||
|
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
|
||||||
|
EXPECT_FALSE(allocation->isShareable());
|
||||||
|
memoryManager->freeGraphicsMemory(allocation);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(WddmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
|
TEST_F(WddmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
|
||||||
void *cpuPtr = (void *)0x30000;
|
void *cpuPtr = (void *)0x30000;
|
||||||
size_t size = 0x1000;
|
size_t size = 0x1000;
|
||||||
|
|
Loading…
Reference in New Issue