[3/n] Internal 4GB allocator.

-Do not create allocator 32 bit with every DRM memory manager
-This is not needed for apps that do not use this.
-Add allocation of allocator to setForce32BitAddressing

Change-Id: I836b60f6b74eecf678cc9d56851797d0db176107
This commit is contained in:
Mrozek, Michal
2018-02-28 09:27:38 +01:00
committed by sys_ocldev
parent cb37fb97a3
commit 0b6acb4d7a
5 changed files with 45 additions and 3 deletions

View File

@@ -213,6 +213,13 @@ std::unique_ptr<GraphicsAllocation> MemoryManager::obtainReusableAllocation(size
return allocation; return allocation;
} }
void MemoryManager::setForce32BitAllocations(bool newValue) {
if (newValue && !this->allocator32Bit) {
this->allocator32Bit.reset(new Allocator32bit);
}
force32bitAllocations = newValue;
}
void MemoryManager::applyCommonCleanup() { void MemoryManager::applyCommonCleanup() {
if (this->paddingAllocation) { if (this->paddingAllocation) {
this->freeGraphicsMemory(this->paddingAllocation); this->freeGraphicsMemory(this->paddingAllocation);

View File

@@ -171,7 +171,7 @@ class MemoryManager {
virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0; virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0;
bool peekForce32BitAllocations() { return force32bitAllocations; } bool peekForce32BitAllocations() { return force32bitAllocations; }
void setForce32BitAllocations(bool newValue) { force32bitAllocations = newValue; } void setForce32BitAllocations(bool newValue);
GraphicsAllocation *createGraphicsAllocationWithRequiredBitness(size_t size, void *ptr) { GraphicsAllocation *createGraphicsAllocationWithRequiredBitness(size_t size, void *ptr) {
return createGraphicsAllocationWithRequiredBitness(size, ptr, false); return createGraphicsAllocationWithRequiredBitness(size, ptr, false);

View File

@@ -43,7 +43,6 @@ namespace OCLRT {
DrmMemoryManager::DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed) : MemoryManager(false), drm(drm), pinBB(nullptr) { DrmMemoryManager::DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed) : MemoryManager(false), drm(drm), pinBB(nullptr) {
MemoryManager::virtualPaddingAvailable = true; MemoryManager::virtualPaddingAvailable = true;
allocator32Bit = std::unique_ptr<Allocator32bit>(new Allocator32bit);
if (mode != gemCloseWorkerMode::gemCloseWorkerInactive) { if (mode != gemCloseWorkerMode::gemCloseWorkerInactive) {
gemCloseWorker.reset(new DrmGemCloseWorker(*this)); gemCloseWorker.reset(new DrmGemCloseWorker(*this));
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Intel Corporation * Copyright (c) 2017 - 2018, Intel Corporation
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@@ -528,6 +528,21 @@ TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenTagPerfCountAllocatorIsCreated
EXPECT_EQ(UnlimitedPerfCounterCount, allocator->peekMaxTagPoolCount()); EXPECT_EQ(UnlimitedPerfCounterCount, allocator->peekMaxTagPoolCount());
} }
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithTrueMutlipleTimesThenAllocatorIsReused) {
memoryManager->setForce32BitAllocations(true);
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
auto currentAllocator = memoryManager->allocator32Bit.get();
memoryManager->setForce32BitAllocations(true);
EXPECT_EQ(memoryManager->allocator32Bit.get(), currentAllocator);
}
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithFalseThenAllocatorIsNotDeleted) {
memoryManager->setForce32BitAllocations(true);
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
memoryManager->setForce32BitAllocations(false);
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
}
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32bitGraphicsAllocationIsReturned) { TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32bitGraphicsAllocationIsReturned) {
size_t size = 10; size_t size = 10;
auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION);

View File

@@ -597,6 +597,7 @@ TEST_F(DrmMemoryManagerTest, testProfilingAllocatorCleanup) {
TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32BitDrmAllocationIsBeingReturned) { TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32BitDrmAllocationIsBeingReturned) {
mock->ioctl_expected = 3; mock->ioctl_expected = 3;
auto size = 10u; auto size = 10u;
memoryManager->setForce32BitAllocations(true);
auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation);
EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer());
@@ -615,6 +616,24 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }
TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithTrueMutlipleTimesThenAllocatorIsReused) {
mock->ioctl_expected = 0;
EXPECT_EQ(nullptr, memoryManager->allocator32Bit.get());
memoryManager->setForce32BitAllocations(true);
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
auto currentAllocator = memoryManager->allocator32Bit.get();
memoryManager->setForce32BitAllocations(true);
EXPECT_EQ(memoryManager->allocator32Bit.get(), currentAllocator);
}
TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithFalseThenAllocatorIsNotDeleted) {
mock->ioctl_expected = 0;
memoryManager->setForce32BitAllocations(true);
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
memoryManager->setForce32BitAllocations(false);
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
}
TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen32BitBufferIsReturned) { TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen32BitBufferIsReturned) {
DebugManagerStateRestore dbgRestorer; DebugManagerStateRestore dbgRestorer;
{ {
@@ -795,6 +814,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationWithHo
auto size = 10u; auto size = 10u;
void *host_ptr = (void *)0x1000; void *host_ptr = (void *)0x1000;
memoryManager->setForce32BitAllocations(true);
auto allocation = memoryManager->allocate32BitGraphicsMemory(size, host_ptr, MemoryType::EXTERNAL_ALLOCATION); auto allocation = memoryManager->allocate32BitGraphicsMemory(size, host_ptr, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_EQ(nullptr, allocation); EXPECT_EQ(nullptr, allocation);
@@ -807,6 +827,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationAndAll
mock->ioctl_res_ext = &ioctlResExt; mock->ioctl_res_ext = &ioctlResExt;
auto size = 10u; auto size = 10u;
memoryManager->setForce32BitAllocations(true);
auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION);
EXPECT_EQ(nullptr, allocation); EXPECT_EQ(nullptr, allocation);