Reuse command buffers in L0 command queue
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
parent
dd3c59f46d
commit
b2f286fc4a
|
@ -178,8 +178,18 @@ ze_result_t CommandQueueImp::CommandBufferManager::initialize(Device *device, si
|
|||
false,
|
||||
device->getNEODevice()->getDeviceBitfield()};
|
||||
|
||||
buffers[BUFFER_ALLOCATION::FIRST] = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
buffers[BUFFER_ALLOCATION::SECOND] = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
auto firstBuffer = device->obtainReusableAllocation(alignedSize, NEO::GraphicsAllocation::AllocationType::COMMAND_BUFFER);
|
||||
if (!firstBuffer) {
|
||||
firstBuffer = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
}
|
||||
|
||||
auto secondBuffer = device->obtainReusableAllocation(alignedSize, NEO::GraphicsAllocation::AllocationType::COMMAND_BUFFER);
|
||||
if (!secondBuffer) {
|
||||
secondBuffer = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
||||
}
|
||||
|
||||
buffers[BUFFER_ALLOCATION::FIRST] = firstBuffer;
|
||||
buffers[BUFFER_ALLOCATION::SECOND] = secondBuffer;
|
||||
|
||||
if (!buffers[BUFFER_ALLOCATION::FIRST] || !buffers[BUFFER_ALLOCATION::SECOND]) {
|
||||
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
|
||||
|
@ -192,13 +202,13 @@ ze_result_t CommandQueueImp::CommandBufferManager::initialize(Device *device, si
|
|||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void CommandQueueImp::CommandBufferManager::destroy(NEO::MemoryManager *memoryManager) {
|
||||
void CommandQueueImp::CommandBufferManager::destroy(Device *device) {
|
||||
if (buffers[BUFFER_ALLOCATION::FIRST]) {
|
||||
memoryManager->freeGraphicsMemory(buffers[BUFFER_ALLOCATION::FIRST]);
|
||||
device->storeReusableAllocation(*buffers[BUFFER_ALLOCATION::FIRST]);
|
||||
buffers[BUFFER_ALLOCATION::FIRST] = nullptr;
|
||||
}
|
||||
if (buffers[BUFFER_ALLOCATION::SECOND]) {
|
||||
memoryManager->freeGraphicsMemory(buffers[BUFFER_ALLOCATION::SECOND]);
|
||||
device->storeReusableAllocation(*buffers[BUFFER_ALLOCATION::SECOND]);
|
||||
buffers[BUFFER_ALLOCATION::SECOND] = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::destroy() {
|
|||
delete commandStream;
|
||||
commandStream = nullptr;
|
||||
}
|
||||
buffers.destroy(this->getDevice()->getNEODevice()->getMemoryManager());
|
||||
buffers.destroy(this->getDevice());
|
||||
delete this;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ struct CommandQueueImp : public CommandQueue {
|
|||
};
|
||||
|
||||
ze_result_t initialize(Device *device, size_t sizeRequested);
|
||||
void destroy(NEO::MemoryManager *memoryManager);
|
||||
void destroy(Device *device);
|
||||
void switchBuffers(NEO::CommandStreamReceiver *csr);
|
||||
|
||||
NEO::GraphicsAllocation *getCurrentBufferAllocation() {
|
||||
|
|
|
@ -506,6 +506,22 @@ TEST_F(CommandQueueInitTests, givenMultipleSubDevicesWhenInitializingThenAllocat
|
|||
commandQueue->destroy();
|
||||
}
|
||||
|
||||
TEST_F(CommandQueueInitTests, whenDestroyCommandQueueThenStoreCommandBuffersAsReusableAllocations) {
|
||||
ze_command_queue_desc_t desc = {};
|
||||
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
|
||||
csr->setupContext(*neoDevice->getDefaultEngine().osContext);
|
||||
|
||||
ze_result_t returnValue;
|
||||
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily, device, csr.get(), &desc, false, false, returnValue);
|
||||
EXPECT_NE(nullptr, commandQueue);
|
||||
auto deviceImp = static_cast<DeviceImp *>(device);
|
||||
EXPECT_TRUE(deviceImp->allocationsForReuse.peekIsEmpty());
|
||||
|
||||
commandQueue->destroy();
|
||||
|
||||
EXPECT_FALSE(deviceImp->allocationsForReuse.peekIsEmpty());
|
||||
}
|
||||
|
||||
struct DeviceWithDualStorage : Test<DeviceFixture> {
|
||||
void SetUp() override {
|
||||
NEO::MockCompilerEnableGuard mock(true);
|
||||
|
|
Loading…
Reference in New Issue