mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
[29/n] Internal 4GB allocator.
- Internal allocations may now coexists with non internal on reusable list. - Caller now specifies if internal allocation is needed. - If criteria are not met , then allocation is not returned. Change-Id: I7da3a4f944768b7c8a873e44fd47248f1d76bf9e
This commit is contained in:
@ -281,7 +281,7 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) {
|
||||
|
||||
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
|
||||
|
||||
GraphicsAllocation *allocation = memoryManager->obtainReusableAllocation(requiredSize).release();
|
||||
GraphicsAllocation *allocation = memoryManager->obtainReusableAllocation(requiredSize, false).release();
|
||||
|
||||
if (!allocation) {
|
||||
allocation = memoryManager->allocateGraphicsMemory(requiredSize, MemoryConstants::pageSize);
|
||||
@ -640,7 +640,7 @@ void CommandQueue::allocateHeapMemory(IndirectHeap::Type heapType,
|
||||
|
||||
finalHeapSize = alignUp(std::max(finalHeapSize, minRequiredSize), MemoryConstants::pageSize);
|
||||
|
||||
auto heapMemory = memoryManager->obtainReusableAllocation(finalHeapSize).release();
|
||||
auto heapMemory = memoryManager->obtainReusableAllocation(finalHeapSize, false).release();
|
||||
|
||||
if (!heapMemory) {
|
||||
heapMemory = memoryManager->allocateGraphicsMemory(finalHeapSize, MemoryConstants::pageSize);
|
||||
|
@ -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
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@ -240,7 +240,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
|
||||
DEBUG_BREAK_IF(nullptr == memoryManager);
|
||||
|
||||
TakeOwnershipWrapper<Device> deviceOwnership(getDevice());
|
||||
auto patternAllocation = memoryManager->obtainReusableAllocation(patternSize).release();
|
||||
auto patternAllocation = memoryManager->obtainReusableAllocation(patternSize, false).release();
|
||||
deviceOwnership.unlock();
|
||||
|
||||
if (!patternAllocation) {
|
||||
|
@ -143,7 +143,7 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
|
||||
|
||||
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
|
||||
|
||||
auto allocation = memoryManager->obtainReusableAllocation(requiredSize).release();
|
||||
auto allocation = memoryManager->obtainReusableAllocation(requiredSize, false).release();
|
||||
if (!allocation) {
|
||||
allocation = memoryManager->allocateGraphicsMemory(requiredSize, MemoryConstants::pageSize);
|
||||
}
|
||||
|
@ -41,12 +41,14 @@ namespace OCLRT {
|
||||
struct ReusableAllocationRequirements {
|
||||
size_t requiredMinimalSize;
|
||||
volatile uint32_t *csrTagAddress;
|
||||
bool internalAllocationRequired;
|
||||
};
|
||||
|
||||
std::unique_ptr<GraphicsAllocation> AllocationsList::detachAllocation(size_t requiredMinimalSize, volatile uint32_t *csrTagAddress) {
|
||||
std::unique_ptr<GraphicsAllocation> AllocationsList::detachAllocation(size_t requiredMinimalSize, volatile uint32_t *csrTagAddress, bool internalAllocationRequired) {
|
||||
ReusableAllocationRequirements req;
|
||||
req.requiredMinimalSize = requiredMinimalSize;
|
||||
req.csrTagAddress = csrTagAddress;
|
||||
req.internalAllocationRequired = internalAllocationRequired;
|
||||
GraphicsAllocation *a = nullptr;
|
||||
GraphicsAllocation *retAlloc = processLocked<AllocationsList, &AllocationsList::detachAllocationImpl>(a, static_cast<void *>(&req));
|
||||
return std::unique_ptr<GraphicsAllocation>(retAlloc);
|
||||
@ -57,7 +59,9 @@ GraphicsAllocation *AllocationsList::detachAllocationImpl(GraphicsAllocation *,
|
||||
auto *curr = head;
|
||||
while (curr != nullptr) {
|
||||
auto currentTagValue = req->csrTagAddress ? *req->csrTagAddress : -1;
|
||||
if ((curr->getUnderlyingBufferSize() >= req->requiredMinimalSize) && ((currentTagValue > curr->taskCount) || (curr->taskCount == 0))) {
|
||||
if ((req->internalAllocationRequired == curr->is32BitAllocation) &&
|
||||
(curr->getUnderlyingBufferSize() >= req->requiredMinimalSize) &&
|
||||
((currentTagValue > curr->taskCount) || (curr->taskCount == 0))) {
|
||||
return removeOneImpl(curr, nullptr);
|
||||
}
|
||||
curr = curr->next;
|
||||
@ -207,9 +211,9 @@ void MemoryManager::storeAllocation(std::unique_ptr<GraphicsAllocation> gfxAlloc
|
||||
allocationsList.pushTailOne(*gfxAllocation.release());
|
||||
}
|
||||
|
||||
std::unique_ptr<GraphicsAllocation> MemoryManager::obtainReusableAllocation(size_t requiredSize) {
|
||||
std::unique_ptr<GraphicsAllocation> MemoryManager::obtainReusableAllocation(size_t requiredSize, bool internalAllocation) {
|
||||
std::lock_guard<decltype(mtx)> lock(mtx);
|
||||
auto allocation = allocationsForReuse.detachAllocation(requiredSize, csr ? csr->getTagAddress() : nullptr);
|
||||
auto allocation = allocationsForReuse.detachAllocation(requiredSize, csr ? csr->getTagAddress() : nullptr, internalAllocation);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ constexpr size_t paddingBufferSize = 2 * MemoryConstants::megaByte;
|
||||
|
||||
class AllocationsList : public IDList<GraphicsAllocation, true, true> {
|
||||
public:
|
||||
std::unique_ptr<GraphicsAllocation> detachAllocation(size_t requiredMinimalSize, volatile uint32_t *csrTagAddress = nullptr);
|
||||
std::unique_ptr<GraphicsAllocation> detachAllocation(size_t requiredMinimalSize, volatile uint32_t *csrTagAddress, bool internalAllocationRequired);
|
||||
|
||||
private:
|
||||
GraphicsAllocation *detachAllocationImpl(GraphicsAllocation *, void *);
|
||||
@ -164,7 +164,7 @@ class MemoryManager {
|
||||
TagAllocator<HwTimeStamps> *getEventTsAllocator();
|
||||
TagAllocator<HwPerfCounter> *getEventPerfCountAllocator();
|
||||
|
||||
std::unique_ptr<GraphicsAllocation> obtainReusableAllocation(size_t requiredSize);
|
||||
std::unique_ptr<GraphicsAllocation> obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired);
|
||||
|
||||
//intrusive list of allocation
|
||||
AllocationsList graphicsAllocations;
|
||||
|
@ -1775,7 +1775,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, InForced32BitAllocationsModeDoNotS
|
||||
auto newScratchAllocation = commandStreamReceiver->getScratchAllocation();
|
||||
EXPECT_NE(scratchAllocation, newScratchAllocation); // Allocation changed
|
||||
|
||||
std::unique_ptr<GraphicsAllocation> allocationReusable = pDevice->getMemoryManager()->obtainReusableAllocation(4096);
|
||||
std::unique_ptr<GraphicsAllocation> allocationReusable = pDevice->getMemoryManager()->obtainReusableAllocation(4096, false);
|
||||
|
||||
if (allocationReusable.get() != nullptr) {
|
||||
if (is64bit) {
|
||||
@ -1809,7 +1809,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, InForced32BitAllocationsModeStore3
|
||||
auto newScratchAllocation = commandStreamReceiver->getScratchAllocation();
|
||||
EXPECT_NE(scratchAllocation, newScratchAllocation); // Allocation changed
|
||||
|
||||
std::unique_ptr<GraphicsAllocation> allocationTemporary = pDevice->getMemoryManager()->graphicsAllocations.detachAllocation(0, nullptr);
|
||||
std::unique_ptr<GraphicsAllocation> allocationTemporary = pDevice->getMemoryManager()->graphicsAllocations.detachAllocation(0, nullptr, true);
|
||||
|
||||
EXPECT_EQ(scratchAllocation, allocationTemporary.get());
|
||||
pDevice->getMemoryManager()->freeGraphicsMemory(allocationTemporary.release());
|
||||
|
@ -211,7 +211,7 @@ HWTEST_F(CommandStreamReceiverTest, dontReuseSurfaceIfStillInUse) {
|
||||
|
||||
*hwTag = 1;
|
||||
|
||||
auto newAllocation = memoryManager->obtainReusableAllocation(1);
|
||||
auto newAllocation = memoryManager->obtainReusableAllocation(1, false);
|
||||
|
||||
EXPECT_EQ(nullptr, newAllocation);
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ TEST_F(MemoryAllocatorTest, obtainAllocationFromEmptyReuseListReturnNullPtr) {
|
||||
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
|
||||
|
||||
auto allocation2 = memoryManager->obtainReusableAllocation(1);
|
||||
auto allocation2 = memoryManager->obtainReusableAllocation(1, false);
|
||||
EXPECT_EQ(nullptr, allocation2);
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
@ -345,7 +345,7 @@ TEST_F(MemoryAllocatorTest, obtainAllocationFromReusableList) {
|
||||
|
||||
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
||||
|
||||
auto allocation2 = memoryManager->obtainReusableAllocation(1);
|
||||
auto allocation2 = memoryManager->obtainReusableAllocation(1, false);
|
||||
EXPECT_EQ(allocation, allocation2.get());
|
||||
|
||||
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
@ -380,7 +380,7 @@ TEST_F(MemoryAllocatorTest, obtainAllocationFromMidlleOfReusableList) {
|
||||
EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation2));
|
||||
EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation3));
|
||||
|
||||
auto reusableAllocation = memoryManager->obtainReusableAllocation(10000);
|
||||
auto reusableAllocation = memoryManager->obtainReusableAllocation(10000, false);
|
||||
|
||||
EXPECT_EQ(nullptr, reusableAllocation->next);
|
||||
EXPECT_EQ(nullptr, reusableAllocation->prev);
|
||||
@ -393,6 +393,48 @@ TEST_F(MemoryAllocatorTest, obtainAllocationFromMidlleOfReusableList) {
|
||||
memoryManager->freeGraphicsMemory(reusableAllocation.release());
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenNonInternalAllocationWhenItIsPutOnReusableListWhenInternalAllocationIsRequestedThenNullIsReturned) {
|
||||
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(4096, 4096);
|
||||
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
||||
|
||||
EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
auto internalAllocation = memoryManager->obtainReusableAllocation(1, true);
|
||||
EXPECT_EQ(nullptr, internalAllocation);
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenInternalAllocationWhenItIsPutOnReusableListWhenNonInternalAllocationIsRequestedThenNullIsReturned) {
|
||||
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(4096, 4096);
|
||||
allocation->is32BitAllocation = true;
|
||||
|
||||
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
||||
|
||||
EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
auto internalAllocation = memoryManager->obtainReusableAllocation(1, false);
|
||||
EXPECT_EQ(nullptr, internalAllocation);
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenInternalAllocationWhenItIsPutOnReusableListWhenInternalAllocationIsRequestedThenItIsReturned) {
|
||||
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(4096, 4096);
|
||||
allocation->is32BitAllocation = true;
|
||||
|
||||
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
||||
|
||||
EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
auto internalAllocation = memoryManager->obtainReusableAllocation(1, true);
|
||||
EXPECT_EQ(allocation, internalAllocation.get());
|
||||
internalAllocation.release();
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, AlignedHostPtrWithAlignedSizeWhenAskedForGraphicsAllocationReturnsNullStorageFromHostPtrManager) {
|
||||
auto ptr = (void *)0x1000;
|
||||
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, ptr);
|
||||
|
Reference in New Issue
Block a user