performance: Defer special queue init to first use

Resolves: NEO-12332

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2024-08-22 09:16:39 +00:00
committed by Compute-Runtime-Automation
parent ff4a653c2e
commit 25bb3c87ad
3 changed files with 18 additions and 10 deletions

View File

@@ -158,6 +158,21 @@ uint32_t Context::getMaxRootDeviceIndex() const {
}
CommandQueue *Context::getSpecialQueue(uint32_t rootDeviceIndex) {
if (specialQueues[rootDeviceIndex])
return specialQueues[rootDeviceIndex];
static std::mutex mtx;
std::lock_guard lock(mtx);
if (!specialQueues[rootDeviceIndex]) {
cl_int errcodeRet = CL_SUCCESS;
auto deviceOrdinal = std::distance(this->getRootDeviceIndices().begin(), std::find(this->getRootDeviceIndices().begin(), this->getRootDeviceIndices().end(), rootDeviceIndex));
auto commandQueue = CommandQueue::create(this, this->getDevice(deviceOrdinal), nullptr, true, errcodeRet);
DEBUG_BREAK_IF(commandQueue == nullptr);
DEBUG_BREAK_IF(errcodeRet != CL_SUCCESS);
overrideSpecialQueueAndDecrementRefCount(commandQueue, rootDeviceIndex);
}
return specialQueues[rootDeviceIndex];
}
@@ -179,6 +194,7 @@ bool Context::createImpl(const cl_context_properties *properties,
const ClDeviceVector &inputDevices,
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
void *data, cl_int &errcodeRet) {
errcodeRet = CL_SUCCESS;
auto propertiesCurrent = properties;
bool interopUserSync = false;
@@ -288,14 +304,6 @@ bool Context::createImpl(const cl_context_properties *properties,
}
}
for (auto &device : devices) {
if (!specialQueues[device->getRootDeviceIndex()]) {
auto commandQueue = CommandQueue::create(this, device, nullptr, true, errcodeRet); // NOLINT(clang-analyzer-cplusplus.NewDelete)
DEBUG_BREAK_IF(commandQueue == nullptr);
overrideSpecialQueueAndDecrementRefCount(commandQueue, device->getRootDeviceIndex());
}
}
return true;
}

View File

@@ -120,7 +120,7 @@ TEST_F(ContextTest, WhenCreatingContextThenSpecialQueueIsAvailable) {
TEST_F(ContextTest, WhenSettingSpecialQueueThenQueueIsAvailable) {
MockContext context((ClDevice *)devices[0], true);
auto specialQ = context.getSpecialQueue(0u);
auto specialQ = context.specialQueues[0];
EXPECT_EQ(specialQ, nullptr);
auto cmdQ = new MockCommandQueue(&context, (ClDevice *)devices[0], 0, false);

View File

@@ -435,7 +435,7 @@ TEST_F(GTPinTests, givenInvalidArgumentsThenBufferUnMapFails) {
}
TEST_F(GTPinTests, givenValidRequestForHugeMemoryAllocationThenBufferAllocateFails) {
[[maybe_unused]] auto cmdQ = pContext->getSpecialQueue(0);
DebugManagerStateRestore restorer;
for (auto &allocationInUSMShared : ::testing::Bool()) {
debugManager.flags.GTPinAllocateBufferInSharedMemory.set(allocationInUSMShared);