mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 13:33:02 +08:00
Reuse command buffer for immediate cmdlist
Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
e11bcb9882
commit
6073702941
@@ -272,8 +272,9 @@ void CommandContainer::handleCmdBufferAllocations(size_t startIndex) {
|
||||
if (isHandleFenceCompletionRequired) {
|
||||
this->device->getMemoryManager()->handleFenceCompletion(cmdBufferAllocations[i]);
|
||||
}
|
||||
reusableAllocationList->pushFrontOne(*cmdBufferAllocations[i]);
|
||||
|
||||
if (!this->reusableAllocationList->peekContains(*cmdBufferAllocations[i])) {
|
||||
reusableAllocationList->pushFrontOne(*cmdBufferAllocations[i]);
|
||||
}
|
||||
} else {
|
||||
this->device->getMemoryManager()->freeGraphicsMemory(cmdBufferAllocations[i]);
|
||||
}
|
||||
@@ -281,22 +282,14 @@ void CommandContainer::handleCmdBufferAllocations(size_t startIndex) {
|
||||
}
|
||||
|
||||
GraphicsAllocation *CommandContainer::obtainNextCommandBufferAllocation() {
|
||||
size_t alignedSize = alignUp<size_t>(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k);
|
||||
|
||||
GraphicsAllocation *cmdBufferAllocation = nullptr;
|
||||
if (this->reusableAllocationList) {
|
||||
size_t alignedSize = alignUp<size_t>(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k);
|
||||
cmdBufferAllocation = this->reusableAllocationList->detachAllocation(alignedSize, nullptr, nullptr, AllocationType::COMMAND_BUFFER).release();
|
||||
}
|
||||
if (!cmdBufferAllocation) {
|
||||
AllocationProperties properties{device->getRootDeviceIndex(),
|
||||
true /* allocateMemory*/,
|
||||
alignedSize,
|
||||
AllocationType::COMMAND_BUFFER,
|
||||
(device->getNumGenericSubDevices() > 1u) /* multiOsContextCapable */,
|
||||
false,
|
||||
device->getDeviceBitfield()};
|
||||
|
||||
cmdBufferAllocation = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
cmdBufferAllocation = this->allocateCommandBuffer();
|
||||
}
|
||||
|
||||
return cmdBufferAllocation;
|
||||
@@ -308,13 +301,7 @@ void CommandContainer::allocateNextCommandBuffer() {
|
||||
|
||||
cmdBufferAllocations.push_back(cmdBufferAllocation);
|
||||
|
||||
size_t alignedSize = alignUp<size_t>(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k);
|
||||
commandStream->replaceBuffer(cmdBufferAllocation->getUnderlyingBuffer(), alignedSize - cmdBufferReservedSize);
|
||||
commandStream->replaceGraphicsAllocation(cmdBufferAllocation);
|
||||
|
||||
if (!getFlushTaskUsedForImmediate()) {
|
||||
addToResidencyContainer(cmdBufferAllocation);
|
||||
}
|
||||
setCmdBuffer(cmdBufferAllocation);
|
||||
}
|
||||
|
||||
void CommandContainer::closeAndAllocateNextCommandBuffer() {
|
||||
@@ -361,4 +348,41 @@ void CommandContainer::ensureHeapSizePrepared(size_t sshRequiredSize, size_t dsh
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsAllocation *CommandContainer::reuseExistingCmdBuffer() {
|
||||
size_t alignedSize = alignUp<size_t>(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k);
|
||||
auto cmdBufferAllocation = this->reusableAllocationList->detachAllocation(alignedSize, nullptr, this->immediateCmdListCsr, AllocationType::COMMAND_BUFFER).release();
|
||||
return cmdBufferAllocation;
|
||||
}
|
||||
|
||||
void CommandContainer::addCurrentCommandBufferToReusableAllocationList() {
|
||||
auto taskCount = this->immediateCmdListCsr->peekTaskCount() + 1;
|
||||
auto osContextId = this->immediateCmdListCsr->getOsContext().getContextId();
|
||||
commandStream->getGraphicsAllocation()->updateTaskCount(taskCount, osContextId);
|
||||
commandStream->getGraphicsAllocation()->updateResidencyTaskCount(taskCount, osContextId);
|
||||
this->reusableAllocationList->pushTailOne(*this->commandStream->getGraphicsAllocation());
|
||||
}
|
||||
|
||||
void CommandContainer::setCmdBuffer(GraphicsAllocation *cmdBuffer) {
|
||||
size_t alignedSize = alignUp<size_t>(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k);
|
||||
commandStream->replaceBuffer(cmdBuffer->getUnderlyingBuffer(), alignedSize - cmdBufferReservedSize);
|
||||
commandStream->replaceGraphicsAllocation(cmdBuffer);
|
||||
|
||||
if (!getFlushTaskUsedForImmediate()) {
|
||||
addToResidencyContainer(cmdBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsAllocation *CommandContainer::allocateCommandBuffer() {
|
||||
size_t alignedSize = alignUp<size_t>(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k);
|
||||
AllocationProperties properties{device->getRootDeviceIndex(),
|
||||
true /* allocateMemory*/,
|
||||
alignedSize,
|
||||
AllocationType::COMMAND_BUFFER,
|
||||
(device->getNumGenericSubDevices() > 1u) /* multiOsContextCapable */,
|
||||
false,
|
||||
device->getDeviceBitfield()};
|
||||
|
||||
return device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -105,10 +105,17 @@ class CommandContainer : public NonCopyableOrMovableClass {
|
||||
void setImmediateCmdListCsr(CommandStreamReceiver *newValue) {
|
||||
this->immediateCmdListCsr = newValue;
|
||||
}
|
||||
void enableHeapSharing() { heapSharingEnabled = true; }
|
||||
bool immediateCmdListSharedHeap(HeapType heapType) {
|
||||
return (this->immediateCmdListCsr != nullptr && (heapType == HeapType::DYNAMIC_STATE || heapType == HeapType::SURFACE_STATE));
|
||||
return (heapSharingEnabled && (heapType == HeapType::DYNAMIC_STATE || heapType == HeapType::SURFACE_STATE));
|
||||
}
|
||||
void ensureHeapSizePrepared(size_t sshRequiredSize, size_t dshRequiredSize);
|
||||
|
||||
GraphicsAllocation *reuseExistingCmdBuffer();
|
||||
GraphicsAllocation *allocateCommandBuffer();
|
||||
void setCmdBuffer(GraphicsAllocation *cmdBuffer);
|
||||
void addCurrentCommandBufferToReusableAllocationList();
|
||||
|
||||
HeapContainer sshAllocations;
|
||||
uint64_t currentLinearStreamStartOffset = 0u;
|
||||
uint32_t slmSize = std::numeric_limits<uint32_t>::max();
|
||||
@@ -146,6 +153,7 @@ class CommandContainer : public NonCopyableOrMovableClass {
|
||||
|
||||
bool isFlushTaskUsedForImmediate = false;
|
||||
bool isHandleFenceCompletionRequired = false;
|
||||
bool heapSharingEnabled = false;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -827,6 +827,72 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenCloseAndAllocateNextCommandBuf
|
||||
EXPECT_EQ(cmdContainer.getCmdBufferAllocations().size(), 2u);
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerTest, givenCmdContainerWhenSetCmdBufferThenCmdBufferSetCorrectly) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice, nullptr, true);
|
||||
|
||||
AllocationProperties properties{pDevice->getRootDeviceIndex(),
|
||||
true /* allocateMemory*/,
|
||||
2048,
|
||||
AllocationType::COMMAND_BUFFER,
|
||||
(pDevice->getNumGenericSubDevices() > 1u) /* multiOsContextCapable */,
|
||||
false,
|
||||
pDevice->getDeviceBitfield()};
|
||||
|
||||
auto alloc = pDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
cmdContainer.setCmdBuffer(alloc);
|
||||
EXPECT_EQ(cmdContainer.getCommandStream()->getGraphicsAllocation(), alloc);
|
||||
pDevice->getMemoryManager()->freeGraphicsMemory(alloc);
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithoutAnyAllocationInListThenReturnNullptr) {
|
||||
auto cmdContainer = std::make_unique<CommandContainer>();
|
||||
AllocationsList allocList;
|
||||
cmdContainer->initialize(pDevice, &allocList, false);
|
||||
auto csr = pDevice->getDefaultEngine().commandStreamReceiver;
|
||||
cmdContainer->setImmediateCmdListCsr(csr);
|
||||
|
||||
EXPECT_EQ(cmdContainer->reuseExistingCmdBuffer(), nullptr);
|
||||
|
||||
cmdContainer.reset();
|
||||
allocList.freeAllGraphicsAllocations(pDevice);
|
||||
}
|
||||
|
||||
HWTEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithAllocationInListAndCsrTaskCountLowerThanAllocationThenReturnNullptr) {
|
||||
auto cmdContainer = std::make_unique<CommandContainer>();
|
||||
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
||||
*csr.tagAddress = 0u;
|
||||
|
||||
AllocationsList allocList;
|
||||
cmdContainer->initialize(pDevice, &allocList, false);
|
||||
cmdContainer->setImmediateCmdListCsr(&csr);
|
||||
cmdContainer->getCmdBufferAllocations()[0]->updateTaskCount(10, 0);
|
||||
cmdContainer->addCurrentCommandBufferToReusableAllocationList();
|
||||
|
||||
EXPECT_EQ(cmdContainer->reuseExistingCmdBuffer(), nullptr);
|
||||
|
||||
cmdContainer.reset();
|
||||
allocList.freeAllGraphicsAllocations(pDevice);
|
||||
}
|
||||
|
||||
HWTEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithAllocationInListAndCsrTaskCountSameAsAllocationThenReturnAlloc) {
|
||||
auto cmdContainer = std::make_unique<CommandContainer>();
|
||||
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
||||
*csr.tagAddress = 10u;
|
||||
|
||||
AllocationsList allocList;
|
||||
cmdContainer->initialize(pDevice, &allocList, false);
|
||||
cmdContainer->setImmediateCmdListCsr(&csr);
|
||||
|
||||
cmdContainer->getCmdBufferAllocations()[0]->updateTaskCount(10, 0);
|
||||
cmdContainer->addCurrentCommandBufferToReusableAllocationList();
|
||||
|
||||
EXPECT_NE(cmdContainer->reuseExistingCmdBuffer(), nullptr);
|
||||
|
||||
cmdContainer.reset();
|
||||
allocList.freeAllGraphicsAllocations(pDevice);
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerTest, GivenCmdContainerWhenContainerIsInitializedThenSurfaceStateIndirectHeapSizeIsCorrect) {
|
||||
MyMockCommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice, nullptr, true);
|
||||
@@ -837,6 +903,7 @@ TEST_F(CommandContainerTest, GivenCmdContainerWhenContainerIsInitializedThenSurf
|
||||
|
||||
HWTEST_F(CommandContainerTest, givenCmdContainerHasImmediateCsrWhenGettingHeapWithoutEnsuringSpaceThenExpectNullptrReturnedOrUnrecoverable) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.enableHeapSharing();
|
||||
cmdContainer.setImmediateCmdListCsr(pDevice->getDefaultEngine().commandStreamReceiver);
|
||||
cmdContainer.setNumIddPerBlock(1);
|
||||
auto code = cmdContainer.initialize(pDevice, nullptr, true);
|
||||
|
||||
Reference in New Issue
Block a user