Skip to content

Commit 5cf3eeb

Browse files
fix: use lowest priority level as default for primary context
calculate the lowest and highest software priority in one place Related-To: HSD-18043767497 Signed-off-by: Katarzyna Cencelewska <[email protected]>
1 parent 0d4aa66 commit 5cf3eeb

File tree

14 files changed

+68
-51
lines changed

14 files changed

+68
-51
lines changed

level_zero/core/source/device/device_imp.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,11 +1586,8 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool
15861586
device->populateSubDeviceCopyEngineGroups();
15871587
auto &productHelper = device->getProductHelper();
15881588
device->calculationForDisablingEuFusionWithDpasNeeded = productHelper.isCalculationForDisablingEuFusionWithDpasNeeded(hwInfo);
1589-
1590-
auto numPriorities = static_cast<int32_t>(device->getNEODevice()->getGfxCoreHelper().getQueuePriorityLevels());
1591-
1592-
device->queuePriorityHigh = -(numPriorities + 1) / 2 + 1;
1593-
device->queuePriorityLow = (numPriorities) / 2;
1589+
device->queuePriorityHigh = gfxCoreHelper.getHighestQueuePriorityLevel();
1590+
device->queuePriorityLow = gfxCoreHelper.getLowestQueuePriorityLevel();
15941591

15951592
return device;
15961593
}
@@ -1839,7 +1836,7 @@ ze_result_t DeviceImp::getCsrForOrdinalAndIndex(NEO::CommandStreamReceiver **csr
18391836
if (priorityLevel.has_value()) {
18401837
if (priorityLevel.value() <= 0) {
18411838
priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH;
1842-
} else if (priorityLevel.value() > 0) {
1839+
} else {
18431840
priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL;
18441841
}
18451842
}

level_zero/core/test/unit_tests/mocks/mock_device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ struct MockDeviceImp : public L0::DeviceImp {
112112
using Base::inOrderTimestampAllocator;
113113
using Base::neoDevice;
114114
using Base::queryPeerAccess;
115-
using Base::queuePriorityHigh;
116-
using Base::queuePriorityLow;
117115
using Base::subDeviceCopyEngineGroups;
118116
using Base::syncDispatchTokenAllocation;
119117

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,11 +3406,11 @@ HWTEST2_F(ContextGroupStateBaseAddressGlobalStatelessTest,
34063406
NEO::EngineTypeUsage engineTypeUsage;
34073407
engineTypeUsage.first = hwInfo.capabilityTable.defaultEngineType;
34083408
engineTypeUsage.second = NEO::EngineUsage::regular;
3409-
auto primaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, 0, false)->commandStreamReceiver;
3409+
auto primaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, std::nullopt, false)->commandStreamReceiver;
34103410
EXPECT_EQ(nullptr, primaryCsr->getOsContext().getPrimaryContext());
34113411
EXPECT_TRUE(primaryCsr->getOsContext().isPartOfContextGroup());
34123412

3413-
auto secondaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, 0, false)->commandStreamReceiver;
3413+
auto secondaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, std::nullopt, false)->commandStreamReceiver;
34143414

34153415
ze_command_queue_desc_t desc = {};
34163416
auto otherCommandQueue = new MockCommandQueueHw<FamilyType::gfxCoreFamily>(device, secondaryCsr, &desc);
@@ -3457,11 +3457,11 @@ HWTEST2_F(ContextGroupStateBaseAddressGlobalStatelessTest,
34573457
NEO::EngineTypeUsage engineTypeUsage;
34583458
engineTypeUsage.first = hwInfo.capabilityTable.defaultEngineType;
34593459
engineTypeUsage.second = NEO::EngineUsage::regular;
3460-
auto primaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, 0, false)->commandStreamReceiver;
3460+
auto primaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, std::nullopt, false)->commandStreamReceiver;
34613461
EXPECT_EQ(nullptr, primaryCsr->getOsContext().getPrimaryContext());
34623462
EXPECT_TRUE(primaryCsr->getOsContext().isPartOfContextGroup());
34633463

3464-
[[maybe_unused]] auto secondaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, 0, false)->commandStreamReceiver;
3464+
[[maybe_unused]] auto secondaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage, std::nullopt, false)->commandStreamReceiver;
34653465

34663466
ze_command_queue_desc_t queueDesc{ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC};
34673467
queueDesc.ordinal = 0u;

level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,7 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor
42264226
{
42274227
MockExecutionEnvironment *executionEnvironment = new MockExecutionEnvironment{&hwInfo};
42284228
auto *neoMockDevice = NEO::MockDevice::createWithExecutionEnvironment<NEO::MockDevice>(&hwInfo, executionEnvironment, rootDeviceIndex);
4229+
auto highestPriorityLevel = mockExecutionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHelper<GfxCoreHelper>().getHighestQueuePriorityLevel();
42294230
MockDeviceImp deviceImp(neoMockDevice);
42304231

42314232
NEO::CommandStreamReceiver *highPriorityCsr = nullptr;
@@ -4249,7 +4250,7 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor
42494250
ASSERT_TRUE(engineGroups[ordinalCopy].engineGroupType == NEO::EngineGroupType::copy);
42504251

42514252
uint32_t index = 1;
4252-
auto result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, deviceImp.queuePriorityHigh, false);
4253+
auto result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, highestPriorityLevel, false);
42534254
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
42544255
ASSERT_NE(nullptr, highPriorityCsr);
42554256

@@ -4266,7 +4267,7 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor
42664267
EXPECT_TRUE(highPriorityCsr->getOsContext().isPartOfContextGroup());
42674268
EXPECT_NE(nullptr, highPriorityCsr->getOsContext().getPrimaryContext());
42684269

4269-
result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr2, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, deviceImp.queuePriorityHigh, false);
4270+
result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr2, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, highestPriorityLevel, false);
42704271
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
42714272
ASSERT_NE(nullptr, highPriorityCsr2);
42724273
EXPECT_NE(highPriorityCsr, highPriorityCsr2);
@@ -4275,19 +4276,19 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor
42754276
EXPECT_TRUE(highPriorityCsr2->getOsContext().isPartOfContextGroup());
42764277

42774278
index = 100;
4278-
result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, deviceImp.queuePriorityHigh, false);
4279+
result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, highestPriorityLevel, false);
42794280
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
42804281

42814282
index = 0;
42824283
ordinal = 100;
4283-
result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, deviceImp.queuePriorityHigh, false);
4284+
result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, highestPriorityLevel, false);
42844285
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
42854286

42864287
// When no HP copy engine, then hp csr from group is returned
42874288
NEO::CommandStreamReceiver *bcsEngine = nullptr, *bcsEngine2 = nullptr;
42884289
EXPECT_EQ(nullptr, neoMockDevice->getHpCopyEngine());
42894290

4290-
result = deviceImp.getCsrForOrdinalAndIndex(&bcsEngine, ordinalCopy, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, deviceImp.queuePriorityHigh, false);
4291+
result = deviceImp.getCsrForOrdinalAndIndex(&bcsEngine, ordinalCopy, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, highestPriorityLevel, false);
42914292
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
42924293
ASSERT_NE(nullptr, bcsEngine);
42934294
EXPECT_TRUE(bcsEngine->getOsContext().isHighPriority());
@@ -4395,7 +4396,7 @@ HWTEST2_F(DeviceTest, givenHpCopyEngineWhenGettingHighPriorityCsrThenCorrectCsrA
43954396
ordinal = i;
43964397

43974398
uint32_t index = 0;
4398-
auto result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, 0, false);
4399+
auto result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, std::nullopt, false);
43994400
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
44004401
ASSERT_NE(nullptr, highPriorityCsr);
44014402

opencl/source/command_queue/command_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ CommandQueue::~CommandQueue() {
178178
}
179179

180180
void tryAssignSecondaryEngine(Device &device, EngineControl *&engineControl, EngineTypeUsage engineTypeUsage) {
181-
auto newEngine = device.getSecondaryEngineCsr(engineTypeUsage, 0, false);
181+
auto newEngine = device.getSecondaryEngineCsr(engineTypeUsage, std::nullopt, false);
182182
if (newEngine) {
183183
engineControl = newEngine;
184184
}

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, PrintL0MetricLogs, 0, "L0 Metrics logs mask. 0 -
377377
DECLARE_DEBUG_VARIABLE(bool, PrintL0SetKernelArg, false, "Print L0 Set Kernel Arg data")
378378
DECLARE_DEBUG_VARIABLE(bool, LogIndirectDetectionKernelDetails, false, "Log information for indirect detection for each kernel")
379379
DECLARE_DEBUG_VARIABLE(bool, PrintMclData, false, "Print all parameters used for MCL");
380+
DECLARE_DEBUG_VARIABLE(bool, PrintSecondaryContextEngineInfo, false, "Print info about used secondary contexts engine");
380381

381382
/*PERFORMANCE FLAGS*/
382383
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForBuffers, false, "When active all buffer allocations will not share memory with CPU.")

shared/source/device/device.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,6 @@ bool Device::createEngines() {
393393

394394
auto highPriorityContextCount = gfxCoreHelper.getContextGroupHpContextsCount(engineGroupType, hpEngineAvailable);
395395

396-
if (debugManager.flags.OverrideNumHighPriorityContexts.get() != -1) {
397-
highPriorityContextCount = static_cast<uint32_t>(debugManager.flags.OverrideNumHighPriorityContexts.get());
398-
}
399-
400396
if (getRootDeviceEnvironment().osInterface && getRootDeviceEnvironment().osInterface->getAggregatedProcessCount() > 1) {
401397
const auto numProcesses = getRootDeviceEnvironment().osInterface->getAggregatedProcessCount();
402398

@@ -413,6 +409,10 @@ bool Device::createEngines() {
413409
gfxCoreHelper.adjustCopyEngineRegularContextCount(engineGroup->engines.size(), contextCount);
414410
}
415411
}
412+
413+
if (debugManager.flags.OverrideNumHighPriorityContexts.get() != -1) {
414+
highPriorityContextCount = static_cast<uint32_t>(debugManager.flags.OverrideNumHighPriorityContexts.get());
415+
}
416416
for (uint32_t engineIndex = 0; engineIndex < static_cast<uint32_t>(engineGroup->engines.size()); engineIndex++) {
417417
auto engineType = engineGroup->engines[engineIndex].getEngineType();
418418

@@ -565,7 +565,9 @@ bool Device::createEngine(EngineTypeUsage engineTypeUsage) {
565565
osContext->setContextGroupCount(useContextGroup ? gfxCoreHelper.getContextGroupContextsCount() : 0);
566566
osContext->setIsPrimaryEngine(isPrimaryEngine);
567567
osContext->setIsDefaultEngine(isDefaultEngine);
568-
568+
if (isPrimaryEngine) {
569+
osContext->overridePriority(gfxCoreHelper.getLowestQueuePriorityLevel());
570+
}
569571
DEBUG_BREAK_IF(getDeviceBitfield().count() > 1 && !osContext->isRootDevice());
570572

571573
commandStreamReceiver->setupContext(*osContext);
@@ -1336,11 +1338,14 @@ EngineControl *SecondaryContexts::getEngine(EngineUsage usage, std::optional<int
13361338
}
13371339
if (priorityLevel.has_value()) {
13381340
engines[secondaryEngineIndex].osContext->overridePriority(priorityLevel.value());
1341+
} else {
1342+
int32_t lowestPriorityLevel = engines[secondaryEngineIndex].commandStreamReceiver->getGfxCoreHelper().getLowestQueuePriorityLevel();
1343+
engines[secondaryEngineIndex].osContext->overridePriority(lowestPriorityLevel);
13391344
}
1345+
PRINT_DEBUG_STRING(debugManager.flags.PrintSecondaryContextEngineInfo.get(), stdout, "SecondaryContexts::getEngine-> engineUsage: %d index %d priorityLevel: %d \n", EngineHelpers::engineUsageToString(usage).c_str(), secondaryEngineIndex, engines[secondaryEngineIndex].osContext->getPriorityLevel());
13401346

13411347
return &engines[secondaryEngineIndex];
13421348
}
1343-
13441349
void Device::stopDirectSubmissionForCopyEngine() {
13451350
auto internalBcsEngine = getInternalCopyEngine();
13461351
if (internalBcsEngine == nullptr || getHardwareInfo().featureTable.ftrBcsInfo.count() > 1) {

shared/source/helpers/gfx_core_helper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "shared/source/helpers/gfx_core_helper.h"
99

1010
#include "shared/source/debug_settings/debug_settings_manager.h"
11+
#include "shared/source/helpers/basic_math.h"
1112
#include "shared/source/helpers/constants.h"
1213
#include "shared/source/helpers/hw_info.h"
1314
#include "shared/source/os_interface/product_helper.h"
@@ -153,4 +154,12 @@ bool GfxCoreHelper::isWorkaroundRequired(uint32_t lowestSteppingWithBug, uint32_
153154
return (lowestHwRevIdWithBug <= hwInfo.platform.usRevId && hwInfo.platform.usRevId < hwRevIdWithFix);
154155
}
155156

157+
int32_t GfxCoreHelper::getHighestQueuePriorityLevel() const {
158+
return -(static_cast<int32_t>(Math::divideAndRoundUp(getQueuePriorityLevels(), 2))) + 1;
159+
}
160+
161+
int32_t GfxCoreHelper::getLowestQueuePriorityLevel() const {
162+
return getQueuePriorityLevels() / 2;
163+
}
164+
156165
} // namespace NEO

shared/source/helpers/gfx_core_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class GfxCoreHelper {
218218

219219
virtual bool isExtendedUsmPoolSizeEnabled() const = 0;
220220
virtual bool crossEngineCacheFlushRequired() const = 0;
221+
int32_t getHighestQueuePriorityLevel() const;
222+
int32_t getLowestQueuePriorityLevel() const;
221223

222224
virtual ~GfxCoreHelper() = default;
223225

shared/source/os_interface/os_context.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
4343
}
4444

4545
bool hasPriorityLevel() const { return priorityLevel.has_value(); }
46-
int getPriorityLevel() const { return priorityLevel.value_or(0); }
46+
int getPriorityLevel() const {
47+
UNRECOVERABLE_IF(!priorityLevel.has_value());
48+
return priorityLevel.value();
49+
}
4750
bool isRegular() const { return engineUsage == EngineUsage::regular; }
4851
bool isLowPriority() const { return engineUsage == EngineUsage::lowPriority; }
4952
bool isHighPriority() const { return engineUsage == EngineUsage::highPriority; }
@@ -126,7 +129,7 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
126129
const uint32_t numSupportedDevices;
127130
aub_stream::EngineType engineType = aub_stream::ENGINE_RCS;
128131
EngineUsage engineUsage;
129-
std::optional<int> priorityLevel;
132+
std::optional<int> priorityLevel = std::nullopt;
130133
const bool rootDevice = false;
131134
bool defaultContext = false;
132135
bool directSubmissionActive = false;

0 commit comments

Comments
 (0)