Release split objects when destroy last cmd list with split

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2022-09-19 14:42:42 +00:00
committed by Compute-Runtime-Automation
parent 065406e222
commit 48aab6ce44
4 changed files with 63 additions and 27 deletions

View File

@@ -34,6 +34,10 @@ CommandListAllocatorFn commandListFactory[IGFX_MAX_PRODUCT] = {};
CommandListAllocatorFn commandListFactoryImmediate[IGFX_MAX_PRODUCT] = {};
ze_result_t CommandListImp::destroy() {
if (this->isBcsSplitNeeded) {
static_cast<DeviceImp *>(this->device)->bcsSplit.releaseResources();
}
if (this->cmdListType == CommandListType::TYPE_IMMEDIATE && this->isFlushTaskSubmissionEnabled && !this->isSyncModeQueue) {
auto timeoutMicroseconds = NEO::TimeoutControls::maxTimeout;
this->csr->waitForCompletionWithTimeout(NEO::WaitParams{false, false, timeoutMicroseconds}, this->csr->peekTaskCount());

View File

@@ -11,8 +11,6 @@
#include "level_zero/core/source/device/device_imp.h"
#include <mutex>
namespace L0 {
bool BcsSplit::setupDevice(uint32_t productFamily, bool internalUsage, const ze_command_queue_desc_t *desc, NEO::CommandStreamReceiver *csr) {
@@ -24,8 +22,9 @@ bool BcsSplit::setupDevice(uint32_t productFamily, bool internalUsage, const ze_
return false;
}
static std::mutex bcsSplitInitMutex;
std::lock_guard<std::mutex> lock(bcsSplitInitMutex);
std::lock_guard<std::mutex> lock(this->mtx);
this->clientCount++;
if (!this->cmdQs.empty()) {
return true;
@@ -56,21 +55,20 @@ bool BcsSplit::setupDevice(uint32_t productFamily, bool internalUsage, const ze_
}
void BcsSplit::releaseResources() {
for (auto cmdQ : cmdQs) {
cmdQ->destroy();
std::lock_guard<std::mutex> lock(this->mtx);
this->clientCount--;
if (this->clientCount == 0u) {
for (auto cmdQ : cmdQs) {
cmdQ->destroy();
}
cmdQs.clear();
this->events.releaseResources();
}
}
BcsSplit::Events::~Events() {
for (auto &markerEvent : this->marker) {
markerEvent->destroy();
}
for (auto &subcopyEvent : this->subcopy) {
subcopyEvent->destroy();
}
for (auto &pool : this->pools) {
pool->destroy();
}
this->releaseResources();
}
size_t BcsSplit::Events::obtainForSplit(Context *context, size_t maxEventCountInPool) {
@@ -125,4 +123,18 @@ size_t BcsSplit::Events::allocateNew(Context *context, size_t maxEventCountInPoo
return this->marker.size() - 1;
}
void BcsSplit::Events::releaseResources() {
for (auto &markerEvent : this->marker) {
markerEvent->destroy();
}
marker.clear();
for (auto &subcopyEvent : this->subcopy) {
subcopyEvent->destroy();
}
subcopy.clear();
for (auto &pool : this->pools) {
pool->destroy();
}
pools.clear();
}
} // namespace L0

View File

@@ -16,6 +16,7 @@
#include "level_zero/core/source/event/event.h"
#include <functional>
#include <mutex>
#include <vector>
namespace NEO {
@@ -28,6 +29,9 @@ struct DeviceImp;
struct BcsSplit {
DeviceImp &device;
uint32_t clientCount = 0u;
std::mutex mtx;
struct Events {
BcsSplit &bcsSplit;
@@ -40,6 +44,8 @@ struct BcsSplit {
size_t obtainForSplit(Context *context, size_t maxEventCountInPool);
size_t allocateNew(Context *context, size_t maxEventCountInPool);
void releaseResources();
Events(BcsSplit &bcsSplit) : bcsSplit(bcsSplit){};
~Events();
} events;

View File

@@ -157,6 +157,18 @@ HWTEST2_F(CommandQueueCommandsXeHpc, givenSplitBcsCopyWhenCreateImmediateThenSpl
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, testL0Device.get(), &cmdQueueDesc, false, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList);
EXPECT_NE(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 0u);
std::unique_ptr<L0::CommandList> commandList2(CommandList::createImmediate(productFamily, testL0Device.get(), &cmdQueueDesc, false, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList2);
EXPECT_NE(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 0u);
commandList->destroy();
commandList.release();
EXPECT_NE(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 0u);
commandList2->destroy();
commandList2.release();
EXPECT_EQ(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 0u);
}
HWTEST2_F(CommandQueueCommandsXeHpc, givenSplitBcsCopyAndSplitBcsMaskWhenCreateImmediateThenGivenCountOfSplitCmdQAreCreated, IsXeHpcCore) {
@@ -193,18 +205,20 @@ HWTEST2_F(CommandQueueCommandsXeHpc, givenSplitBcsCopyWhenCreateImmediateThenIni
ze_command_queue_desc_t cmdQueueDesc = {};
cmdQueueDesc.ordinal = static_cast<uint32_t>(testNeoDevice->getEngineGroupIndexFromEngineGroupType(NEO::EngineGroupType::Copy));
{
DebugManager.flags.SplitBcsMask.set(0b11001);
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, testL0Device.get(), &cmdQueueDesc, false, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList);
EXPECT_EQ(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 3u);
}
{
DebugManager.flags.SplitBcsMask.set(0b110);
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, testL0Device.get(), &cmdQueueDesc, false, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList);
EXPECT_EQ(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 3u);
}
DebugManager.flags.SplitBcsMask.set(0b11001);
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, testL0Device.get(), &cmdQueueDesc, false, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList);
EXPECT_EQ(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 3u);
DebugManager.flags.SplitBcsMask.set(0b110);
std::unique_ptr<L0::CommandList> commandList2(CommandList::createImmediate(productFamily, testL0Device.get(), &cmdQueueDesc, false, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList2);
EXPECT_EQ(static_cast<DeviceImp *>(testL0Device.get())->bcsSplit.cmdQs.size(), 3u);
commandList->destroy();
commandList.release();
commandList2->destroy();
commandList2.release();
}
HWTEST2_F(CommandQueueCommandsXeHpc, givenSplitBcsCopyWhenCreateImmediateInternalThenSplitCmdQArenotCreated, IsXeHpcCore) {