Use standard64KB heap for linux shareable allocations

Relates-to: NEO-4196

Change-Id: Ica1fd485c14780043f547a752195bf55f80505dd
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2020-03-12 01:25:09 -07:00
committed by sys_ocldev
parent 1aee20050e
commit c0131430d4
4 changed files with 36 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ class DrmGemCloseWorker;
class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> { class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
public: public:
using DrmMemoryManager::acquireGpuRange;
using DrmMemoryManager::allocateGraphicsMemory; using DrmMemoryManager::allocateGraphicsMemory;
using DrmMemoryManager::allocateGraphicsMemory64kb; using DrmMemoryManager::allocateGraphicsMemory64kb;
using DrmMemoryManager::allocateGraphicsMemoryForImage; using DrmMemoryManager::allocateGraphicsMemoryForImage;

View File

@@ -802,7 +802,25 @@ TEST_F(DrmMemoryManagerTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocati
EXPECT_EQ(nullptr, allocation); EXPECT_EQ(nullptr, allocation);
} }
TEST_F(DrmMemoryManagerTest, GivenShareableEnabledWhenAskedToCreateGrahicsAllocationThenValidAllocationIsReturned) { TEST_F(DrmMemoryManagerTest, givenRequiresStandard64KBHeapSetToFalseThenStandardHeapIsUsed) {
const uint32_t rootDeviceIndex = 0;
size_t bufferSize = 4096u;
uint64_t range = memoryManager->acquireGpuRange(bufferSize, false, rootDeviceIndex, false);
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD)), range);
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD)), range);
}
TEST_F(DrmMemoryManagerTest, givenRequiresStandard64KBHeapSetToTrueThenStandard64KBHeapIsUsed) {
const uint32_t rootDeviceIndex = 0;
size_t bufferSize = 4096u;
uint64_t range = memoryManager->acquireGpuRange(bufferSize, false, rootDeviceIndex, true);
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), range);
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), range);
}
TEST_F(DrmMemoryManagerTest, GivenShareableEnabledWhenAskedToCreateGrahicsAllocationThenValidAllocationIsReturnedAndStandard64KBHeapIsUsed) {
mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemCreate = 1; mock->ioctl_expected.gemCreate = 1;
mock->ioctl_expected.gemClose = 1; mock->ioctl_expected.gemClose = 1;
@@ -812,6 +830,10 @@ TEST_F(DrmMemoryManagerTest, GivenShareableEnabledWhenAskedToCreateGrahicsAlloca
auto allocation = memoryManager->allocateShareableMemory(allocationData); auto allocation = memoryManager->allocateShareableMemory(allocationData);
EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation);
EXPECT_NE(0u, allocation->getGpuAddress()); EXPECT_NE(0u, allocation->getGpuAddress());
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(allocation->getRootDeviceIndex())->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), allocation->getGpuAddress());
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(allocation->getRootDeviceIndex())->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), allocation->getGpuAddress());
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }

View File

@@ -125,13 +125,15 @@ uint32_t DrmMemoryManager::unreference(NEO::BufferObject *bo, bool synchronousDe
return r; return r;
} }
uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, bool specificBitness, uint32_t rootDeviceIndex) { uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, bool specificBitness, uint32_t rootDeviceIndex, bool requiresStandard64KBHeap) {
auto gfxPartition = getGfxPartition(rootDeviceIndex); auto gfxPartition = getGfxPartition(rootDeviceIndex);
if (specificBitness && this->force32bitAllocations) { if (specificBitness && this->force32bitAllocations) {
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_EXTERNAL, size)); return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_EXTERNAL, size));
} else {
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD, size));
} }
if (requiresStandard64KBHeap) {
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD64KB, size));
}
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD, size));
} }
void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize, uint32_t rootDeviceIndex) { void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize, uint32_t rootDeviceIndex) {
@@ -204,7 +206,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc
} }
if (isLimitedRange(allocationData.rootDeviceIndex) || svmCpuAllocation) { if (isLimitedRange(allocationData.rootDeviceIndex) || svmCpuAllocation) {
gpuAddress = acquireGpuRange(alignedSize, false, allocationData.rootDeviceIndex); gpuAddress = acquireGpuRange(alignedSize, false, allocationData.rootDeviceIndex, false);
if (!gpuAddress) { if (!gpuAddress) {
bo->close(); bo->close();
delete bo; delete bo;
@@ -247,7 +249,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al
auto realAllocationSize = alignedSize; auto realAllocationSize = alignedSize;
auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr); auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr);
auto gpuVirtualAddress = acquireGpuRange(alignedSize, false, allocationData.rootDeviceIndex); auto gpuVirtualAddress = acquireGpuRange(alignedSize, false, allocationData.rootDeviceIndex, false);
if (!gpuVirtualAddress) { if (!gpuVirtualAddress) {
return nullptr; return nullptr;
} }
@@ -285,7 +287,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory64kb(const AllocationData
GraphicsAllocation *DrmMemoryManager::allocateShareableMemory(const AllocationData &allocationData) { GraphicsAllocation *DrmMemoryManager::allocateShareableMemory(const AllocationData &allocationData) {
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr, allocationData.size, false); auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr, allocationData.size, false);
size_t bufferSize = allocationData.size; size_t bufferSize = allocationData.size;
uint64_t gpuRange = acquireGpuRange(bufferSize, false, allocationData.rootDeviceIndex); uint64_t gpuRange = acquireGpuRange(bufferSize, false, allocationData.rootDeviceIndex, true);
drm_i915_gem_create create = {0, 0, 0}; drm_i915_gem_create create = {0, 0, 0};
create.size = bufferSize; create.size = bufferSize;
@@ -315,7 +317,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
return alloc; return alloc;
} }
uint64_t gpuRange = acquireGpuRange(allocationData.imgInfo->size, false, allocationData.rootDeviceIndex); uint64_t gpuRange = acquireGpuRange(allocationData.imgInfo->size, false, allocationData.rootDeviceIndex, false);
drm_i915_gem_create create = {0, 0, 0}; drm_i915_gem_create create = {0, 0, 0};
create.size = allocationData.imgInfo->size; create.size = allocationData.imgInfo->size;
@@ -427,7 +429,7 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle)
BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness, uint32_t rootDeviceIndex) { BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness, uint32_t rootDeviceIndex) {
uint64_t gpuRange = 0llu; uint64_t gpuRange = 0llu;
gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex); gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex, false);
auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, rootDeviceIndex); auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, rootDeviceIndex);
if (!bo) { if (!bo) {
@@ -501,7 +503,7 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
uint64_t gpuRange = 0llu; uint64_t gpuRange = 0llu;
auto rootDeviceIndex = inputGraphicsAllocation->getRootDeviceIndex(); auto rootDeviceIndex = inputGraphicsAllocation->getRootDeviceIndex();
gpuRange = acquireGpuRange(sizeWithPadding, false, rootDeviceIndex); gpuRange = acquireGpuRange(sizeWithPadding, false, rootDeviceIndex, false);
auto srcPtr = inputGraphicsAllocation->getUnderlyingBuffer(); auto srcPtr = inputGraphicsAllocation->getUnderlyingBuffer();
auto srcSize = inputGraphicsAllocation->getUnderlyingBufferSize(); auto srcSize = inputGraphicsAllocation->getUnderlyingBufferSize();

View File

@@ -62,7 +62,7 @@ class DrmMemoryManager : public MemoryManager {
void pushSharedBufferObject(BufferObject *bo); void pushSharedBufferObject(BufferObject *bo);
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex); BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex);
bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable); bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable);
uint64_t acquireGpuRange(size_t &size, bool requireSpecificBitness, uint32_t rootDeviceIndex); uint64_t acquireGpuRange(size_t &size, bool requireSpecificBitness, uint32_t rootDeviceIndex, bool requiresStandard64KBHeap);
MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex); MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex);
void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const; void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const;
uint32_t getDefaultDrmContextId() const; uint32_t getDefaultDrmContextId() const;