Allow to allocate shareable graphics allocation

Change-Id: I284b03b001e5b67c344d46f34048803ef9a57314
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2018-12-20 07:43:57 +00:00 committed by sys_ocldev
parent f6757c02a4
commit 1e011f9a08
11 changed files with 93 additions and 19 deletions

View File

@ -16,19 +16,19 @@ bool GraphicsAllocation::isL3Capable() {
}
return false;
}
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, uint32_t osContextCount, bool isShareable) : gpuBaseAddress(baseAddress),
size(sizeIn),
cpuPtr(cpuPtrIn),
gpuAddress(gpuAddress),
isShareable(isShareable) {
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, uint32_t osContextCount, bool shareable) : gpuBaseAddress(baseAddress),
size(sizeIn),
cpuPtr(cpuPtrIn),
gpuAddress(gpuAddress),
shareable(shareable) {
usageInfos.resize(maxOsContextCount);
}
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, uint32_t osContextCount, bool isShareable) : size(sizeIn),
cpuPtr(cpuPtrIn),
gpuAddress(castToUint64(cpuPtrIn)),
sharedHandle(sharedHandleIn),
isShareable(isShareable) {
GraphicsAllocation::GraphicsAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, uint32_t osContextCount, bool shareable) : size(sizeIn),
cpuPtr(cpuPtrIn),
gpuAddress(castToUint64(cpuPtrIn)),
sharedHandle(sharedHandleIn),
shareable(shareable) {
usageInfos.resize(maxOsContextCount);
}
GraphicsAllocation::~GraphicsAllocation() = default;

View File

@ -133,6 +133,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
void resetResidencyTaskCount(uint32_t contextId) { updateResidencyTaskCount(objectNotResident, contextId); }
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
bool isShareable() const { return shareable; }
protected:
constexpr static uint32_t objectNotResident = (uint32_t)-1;
constexpr static uint32_t objectNotUsed = (uint32_t)-1;
@ -160,6 +162,6 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
bool memObjectsAllocationWithWritableFlags = false;
std::vector<UsageInfo> usageInfos;
std::atomic<uint32_t> registeredContextsNum{0};
bool isShareable = false;
bool shareable = false;
};
} // namespace OCLRT

View File

@ -193,6 +193,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
bool forcePin = properties.flags.forcePin;
bool uncacheable = properties.flags.uncacheable;
bool mustBeZeroCopy = false;
bool shareable = properties.flags.shareable;
switch (properties.allocationType) {
case GraphicsAllocation::AllocationType::BUFFER:
@ -254,6 +255,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
allocationData.flags.uncacheable = uncacheable;
allocationData.flags.flushL3 = properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite;
allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == properties.allocationType;
allocationData.flags.shareable = shareable;
if (allocationData.flags.mustBeZeroCopy) {
allocationData.flags.useSystemMemory = true;

View File

@ -45,7 +45,8 @@ struct AllocationProperties {
uint32_t flushL3RequiredForWrite : 1;
uint32_t forcePin : 1;
uint32_t uncacheable : 1;
uint32_t reserved : 27;
uint32_t shareable : 1;
uint32_t reserved : 26;
} flags;
uint32_t allFlags = 0;
};
@ -201,7 +202,8 @@ class MemoryManager {
uint32_t uncacheable : 1;
uint32_t flushL3 : 1;
uint32_t preferRenderCompressed : 1;
uint32_t reserved : 23;
uint32_t shareable : 1;
uint32_t reserved : 22;
} flags;
uint32_t allFlags = 0;
};

View File

@ -37,7 +37,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
if (fakeBigAllocations && allocationData.size > bigAllocation) {
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++;
memoryAllocation->uncacheable = allocationData.flags.uncacheable;
return memoryAllocation;
@ -45,7 +45,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
if (ptr != nullptr) {
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) {
alignedFreeWrapper(ptr);
return nullptr;

View File

@ -228,7 +228,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc
if (forcePinEnabled && pinBB != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) {
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) {

View File

@ -67,7 +67,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(AllocationData
size_t sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize64k);
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);
wddmAllocation->gmm = gmm;
@ -98,7 +98,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const
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;
gmm = new Gmm(pSysMem, sizeAligned, allocationData.flags.uncacheable);

View File

@ -377,3 +377,31 @@ TEST(MemoryManagerTest, givenTimestampTagBufferTypeWhenGetAllocationDataIsCalled
MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::TIMESTAMP_TAG_BUFFER}, 0, nullptr);
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);
}

View File

@ -30,7 +30,9 @@ void *MockMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
}
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) {

View File

@ -651,6 +651,26 @@ TEST_F(DrmMemoryManagerTest, GivenNoInputsWhenOsHandleIsCreatedThenAllBoHandlesA
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) {
OsHandleStorage handleStorage;
auto ptr = reinterpret_cast<void *>(0x1000);

View File

@ -228,6 +228,24 @@ TEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtualPa
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) {
void *cpuPtr = (void *)0x30000;
size_t size = 0x1000;