performance: Defer special queue init to first use

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2024-08-23 10:54:56 +00:00
committed by Compute-Runtime-Automation
parent 42ee377b78
commit 9152b6ac04
3 changed files with 21 additions and 10 deletions

View File

@@ -158,6 +158,24 @@ 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 device = std::find_if(this->getDevices().begin(), this->getDevices().end(), [rootDeviceIndex](const auto &device) {
return device->getRootDeviceIndex() == rootDeviceIndex;
});
auto commandQueue = CommandQueue::create(this, *device, nullptr, true, errcodeRet);
DEBUG_BREAK_IF(commandQueue == nullptr);
DEBUG_BREAK_IF(errcodeRet != CL_SUCCESS);
overrideSpecialQueueAndDecrementRefCount(commandQueue, rootDeviceIndex);
}
return specialQueues[rootDeviceIndex];
}
@@ -179,6 +197,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 +307,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;
}