feature: allow creating L0 BCS LowPriority Queues

Related-To: NEO-7824

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2024-07-02 14:27:17 +00:00
committed by Compute-Runtime-Automation
parent 5188ab8909
commit 024c015dab
7 changed files with 66 additions and 27 deletions

View File

@@ -142,7 +142,7 @@ struct Device : _ze_device_handle_t {
virtual void setSysmanHandle(SysmanDevice *pSysmanDevice) = 0;
virtual SysmanDevice *getSysmanHandle() = 0;
virtual ze_result_t getCsrForOrdinalAndIndex(NEO::CommandStreamReceiver **csr, uint32_t ordinal, uint32_t index, ze_command_queue_priority_t priority, bool allocateInterrupt) = 0;
virtual ze_result_t getCsrForLowPriority(NEO::CommandStreamReceiver **csr, aub_stream::EngineType engineType) = 0;
virtual ze_result_t getCsrForLowPriority(NEO::CommandStreamReceiver **csr, bool copyOnly) = 0;
virtual NEO::GraphicsAllocation *obtainReusableAllocation(size_t requiredSize, NEO::AllocationType type) = 0;
virtual void storeReusableAllocation(NEO::GraphicsAllocation &alloc) = 0;
virtual ze_result_t getFabricVertex(ze_fabric_vertex_handle_t *phVertex) = 0;

View File

@@ -1682,39 +1682,37 @@ ze_result_t DeviceImp::getCsrForOrdinalAndIndex(NEO::CommandStreamReceiver **csr
auto contextPriority = NEO::EngineUsage::regular;
auto engineGroupType = getEngineGroupTypeForOrdinal(ordinal);
bool copyOnly = NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType);
if (secondaryContextsEnabled && priority == ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH) {
contextPriority = NEO::EngineUsage::highPriority;
} else if (isSuitableForLowPriority(priority, NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType))) {
} else if (isSuitableForLowPriority(priority, copyOnly)) {
contextPriority = NEO::EngineUsage::lowPriority;
}
if (contextPriority == NEO::EngineUsage::lowPriority) {
getCsrForLowPriority(csr, copyOnly);
return ZE_RESULT_SUCCESS;
}
if (ordinal < numEngineGroups) {
auto &engines = engineGroups[ordinal].engines;
if (index >= engines.size()) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
*csr = engines[index].commandStreamReceiver;
auto &osContext = (*csr)->getOsContext();
if (secondaryContextsEnabled && (contextPriority != NEO::EngineUsage::lowPriority)) {
tryAssignSecondaryContext(osContext.getEngineType(), contextPriority, csr, allocateInterrupt);
}
} else {
auto subDeviceOrdinal = ordinal - numEngineGroups;
if (index >= this->subDeviceCopyEngineGroups[subDeviceOrdinal].engines.size()) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
*csr = this->subDeviceCopyEngineGroups[subDeviceOrdinal].engines[index].commandStreamReceiver;
if (secondaryContextsEnabled && (contextPriority != NEO::EngineUsage::lowPriority)) {
tryAssignSecondaryContext((*csr)->getOsContext().getEngineType(), contextPriority, csr, allocateInterrupt);
}
}
if (contextPriority == NEO::EngineUsage::lowPriority) {
getCsrForLowPriority(csr, (*csr)->getOsContext().getEngineType());
auto &osContext = (*csr)->getOsContext();
if (secondaryContextsEnabled) {
tryAssignSecondaryContext(osContext.getEngineType(), contextPriority, csr, allocateInterrupt);
}
return ZE_RESULT_SUCCESS;
@@ -1735,11 +1733,9 @@ bool DeviceImp::tryAssignSecondaryContext(aub_stream::EngineType engineType, NEO
return false;
}
ze_result_t DeviceImp::getCsrForLowPriority(NEO::CommandStreamReceiver **csr, aub_stream::EngineType engineType) {
bool isComputeEngine = NEO::EngineHelpers::isComputeEngine(engineType);
ze_result_t DeviceImp::getCsrForLowPriority(NEO::CommandStreamReceiver **csr, bool copyOnly) {
for (auto &it : getActiveDevice()->getAllEngines()) {
bool engineTypeMatch = NEO::EngineHelpers::isComputeEngine(it.osContext->getEngineType()) && isComputeEngine;
bool engineTypeMatch = NEO::EngineHelpers::isBcs(it.osContext->getEngineType()) == copyOnly;
if (it.osContext->isLowPriority() && engineTypeMatch) {
*csr = it.commandStreamReceiver;
return ZE_RESULT_SUCCESS;
@@ -1753,7 +1749,9 @@ ze_result_t DeviceImp::getCsrForLowPriority(NEO::CommandStreamReceiver **csr, au
}
bool DeviceImp::isSuitableForLowPriority(ze_command_queue_priority_t priority, bool copyOnly) {
return (priority == ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW && !copyOnly && !this->implicitScalingCapable);
bool engineSuitable = copyOnly ? getGfxCoreHelper().getContextGroupContextsCount() > 0 : !this->implicitScalingCapable;
return (priority == ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW && engineSuitable);
}
DebugSession *DeviceImp::getDebugSession(const zet_debug_config_t &config) {

View File

@@ -116,7 +116,7 @@ struct DeviceImp : public Device, NEO::NonCopyableOrMovableClass {
void setSysmanHandle(SysmanDevice *pSysman) override;
SysmanDevice *getSysmanHandle() override;
ze_result_t getCsrForOrdinalAndIndex(NEO::CommandStreamReceiver **csr, uint32_t ordinal, uint32_t index, ze_command_queue_priority_t priority, bool allocateInterrupt) override;
ze_result_t getCsrForLowPriority(NEO::CommandStreamReceiver **csr, aub_stream::EngineType engineType) override;
ze_result_t getCsrForLowPriority(NEO::CommandStreamReceiver **csr, bool copyOnly) override;
bool isSuitableForLowPriority(ze_command_queue_priority_t priority, bool copyOnly);
NEO::GraphicsAllocation *obtainReusableAllocation(size_t requiredSize, NEO::AllocationType type) override;
void storeReusableAllocation(NEO::GraphicsAllocation &alloc) override;

View File

@@ -75,7 +75,7 @@ struct MockDevice : public Device {
ADDMETHOD_NOBASE_VOIDRETURN(setSysmanHandle, (SysmanDevice *));
ADDMETHOD_NOBASE(getSysmanHandle, SysmanDevice *, nullptr, ());
ADDMETHOD_NOBASE(getCsrForOrdinalAndIndex, ze_result_t, ZE_RESULT_SUCCESS, (NEO::CommandStreamReceiver * *csr, uint32_t ordinal, uint32_t index, ze_command_queue_priority_t priority, bool allocateInterrupt));
ADDMETHOD_NOBASE(getCsrForLowPriority, ze_result_t, ZE_RESULT_SUCCESS, (NEO::CommandStreamReceiver * *csr, aub_stream::EngineType engineType));
ADDMETHOD_NOBASE(getCsrForLowPriority, ze_result_t, ZE_RESULT_SUCCESS, (NEO::CommandStreamReceiver * *csr, bool copyOnly));
ADDMETHOD_NOBASE(getDebugProperties, ze_result_t, ZE_RESULT_SUCCESS, (zet_device_debug_properties_t * properties));
ADDMETHOD_NOBASE(getDebugSession, DebugSession *, nullptr, (const zet_debug_config_t &config));
ADDMETHOD_NOBASE_VOIDRETURN(removeDebugSession, ());

View File

@@ -2137,5 +2137,46 @@ TEST(CommandList, givenCopyContextGroupEnabledWhenCreatingImmediateCommandListTh
commandList2->destroy();
}
TEST(CommandList, givenLowPriorityCopyEngineWhenCreatingCmdListThenAssignCorrectEngine) {
HardwareInfo hwInfo = *defaultHwInfo;
DebugManagerStateRestore dbgRestorer;
debugManager.flags.ContextGroupSize.set(5);
hwInfo.featureTable.ftrBcsInfo = 0b111;
hwInfo.capabilityTable.blitterOperationsSupported = true;
auto neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo);
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
auto driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
auto device = static_cast<DeviceImp *>(driverHandle->devices[0]);
auto &engines = device->getNEODevice()->getAllEngines();
auto lpBcsEngine = std::find_if(engines.begin(), engines.end(), [](const auto &engine) {
return ((engine.getEngineUsage() == EngineUsage::lowPriority) && EngineHelpers::isBcs(engine.getEngineType()));
});
if (lpBcsEngine == engines.end()) {
GTEST_SKIP();
}
ze_command_queue_desc_t desc = {};
desc.ordinal = device->getCopyEngineOrdinal();
desc.priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW;
ze_command_list_handle_t commandListHandle;
auto result = device->createCommandListImmediate(&desc, &commandListHandle);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
auto commandList = static_cast<CommandListImp *>(L0::CommandList::fromHandle(commandListHandle));
EXPECT_EQ(commandList->getCsr(false), lpBcsEngine->commandStreamReceiver);
commandList->destroy();
}
} // namespace ult
} // namespace L0

View File

@@ -788,7 +788,7 @@ TEST_F(DeviceCreateCommandQueueTest, givenLowPriorityDescWhenCreateCommandQueueI
EXPECT_NE(commandQueue, nullptr);
EXPECT_TRUE(commandQueue->getCsr()->getOsContext().isLowPriority());
NEO::CommandStreamReceiver *csr = nullptr;
device->getCsrForLowPriority(&csr, device->getNEODevice()->getDefaultEngine().getEngineType());
device->getCsrForLowPriority(&csr, false);
EXPECT_EQ(commandQueue->getCsr(), csr);
commandQueue->destroy();
}
@@ -873,7 +873,7 @@ struct DeferredContextCreationDeviceCreateCommandQueueTest : DeviceCreateCommand
TEST_F(DeferredContextCreationDeviceCreateCommandQueueTest, givenLowPriorityEngineNotInitializedWhenCreateLowPriorityCommandQueueIsCalledThenEngineIsInitialized) {
NEO::CommandStreamReceiver *lowPriorityCsr = nullptr;
device->getCsrForLowPriority(&lowPriorityCsr, device->getNEODevice()->getDefaultEngine().getEngineType());
device->getCsrForLowPriority(&lowPriorityCsr, false);
ASSERT_FALSE(lowPriorityCsr->getOsContext().isInitialized());
ze_command_queue_desc_t desc{};
@@ -906,7 +906,7 @@ TEST_F(DeviceCreateCommandQueueTest, givenLowPriorityDescWhenCreateImmediateComm
EXPECT_NE(commandList, nullptr);
EXPECT_TRUE(commandList->getCsr(false)->getOsContext().isLowPriority());
NEO::CommandStreamReceiver *csr = nullptr;
device->getCsrForLowPriority(&csr, device->getNEODevice()->getDefaultEngine().getEngineType());
device->getCsrForLowPriority(&csr, false);
EXPECT_EQ(commandList->getCsr(false), csr);
commandList->destroy();
}
@@ -1012,7 +1012,7 @@ TEST_F(MultiDeviceCreateCommandQueueTest, givenLowPriorityDescWhenCreateCommandQ
EXPECT_NE(commandQueue, nullptr);
EXPECT_TRUE(commandQueue->getCsr()->getOsContext().isLowPriority());
NEO::CommandStreamReceiver *csr = nullptr;
device->getCsrForLowPriority(&csr, device->getNEODevice()->getDefaultEngine().getEngineType());
device->getCsrForLowPriority(&csr, false);
EXPECT_EQ(commandQueue->getCsr(), csr);
commandQueue->destroy();
}

View File

@@ -4555,7 +4555,7 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingLowPriorityCsrThenCorr
MockDeviceImp deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment());
NEO::CommandStreamReceiver *lowPriorityCsr = nullptr;
auto result = deviceImp.getCsrForLowPriority(&lowPriorityCsr, device->getNEODevice()->getDefaultEngine().getEngineType());
auto result = deviceImp.getCsrForLowPriority(&lowPriorityCsr, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ASSERT_NE(nullptr, lowPriorityCsr);
@@ -5075,7 +5075,7 @@ TEST_F(MultiSubDeviceEnabledImplicitScalingTest, GivenEnabledImplicitScalingWhen
auto &defaultEngine = deviceImp->getActiveDevice()->getDefaultEngine();
NEO::CommandStreamReceiver *csr = nullptr;
EXPECT_ANY_THROW(deviceImp->getCsrForLowPriority(&csr, defaultEngine.getEngineType()));
EXPECT_ANY_THROW(deviceImp->getCsrForLowPriority(&csr, false));
auto ret = deviceImp->getCsrForOrdinalAndIndex(&csr, 0, 0, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW, false);