Skip to content

Commit 06a4d2c

Browse files
Jaime ArteagaCompute-Runtime-Automation
authored andcommitted
Refactor support for L0 scheduling hints (XE_HP and later)
Make sure STATE_COMPUTE_MODE is updated when passing the scheduling hint for a kernel. Signed-off-by: Jaime Arteaga <[email protected]>
1 parent 3b7fbef commit 06a4d2c

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ template <GFXCORE_FAMILY gfxCoreFamily>
7474
void CommandListCoreFamily<gfxCoreFamily>::programThreadArbitrationPolicy(Device *device) {
7575
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
7676
auto &hwHelper = NEO::HwHelper::get(device->getNEODevice()->getHardwareInfo().platform.eRenderCoreFamily);
77-
auto threadArbitrationPolicy = hwHelper.getDefaultThreadArbitrationPolicy();
77+
threadArbitrationPolicy = hwHelper.getDefaultThreadArbitrationPolicy();
7878
if (NEO::DebugManager.flags.OverrideThreadArbitrationPolicy.get() != -1) {
7979
threadArbitrationPolicy = static_cast<uint32_t>(NEO::DebugManager.flags.OverrideThreadArbitrationPolicy.get());
8080
}
@@ -2236,7 +2236,6 @@ void CommandListCoreFamily<gfxCoreFamily>::updateStreamProperties(Kernel &kernel
22362236
using VFE_STATE_TYPE = typename GfxFamily::VFE_STATE_TYPE;
22372237

22382238
auto &hwInfo = device->getHwInfo();
2239-
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
22402239
const auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily);
22412240
auto disableOverdispatch = hwInfoConfig.isDisableOverdispatchAvailable(hwInfo);
22422241

@@ -2257,11 +2256,10 @@ void CommandListCoreFamily<gfxCoreFamily>::updateStreamProperties(Kernel &kernel
22572256

22582257
auto &kernelAttributes = kernel.getKernelDescriptor().kernelAttributes;
22592258
auto &neoDevice = *device->getNEODevice();
2260-
auto threadArbitrationPolicy = hwHelper.getDefaultThreadArbitrationPolicy();
2261-
finalStreamState.stateComputeMode.setProperties(false, kernelAttributes.numGrfRequired, threadArbitrationPolicy);
2259+
finalStreamState.stateComputeMode.setProperties(false, kernelAttributes.numGrfRequired, this->threadArbitrationPolicy);
22622260

22632261
if (finalStreamState.stateComputeMode.isDirty()) {
2264-
clearComputeModePropertiesIfNeeded(false, kernelAttributes.numGrfRequired, threadArbitrationPolicy);
2262+
clearComputeModePropertiesIfNeeded(false, kernelAttributes.numGrfRequired, this->threadArbitrationPolicy);
22652263
NEO::EncodeWA<GfxFamily>::encodeAdditionalPipelineSelect(neoDevice, *commandContainer.getCommandStream(), true);
22662264
NEO::EncodeComputeMode<GfxFamily>::programComputeModeCommand(*commandContainer.getCommandStream(), finalStreamState.stateComputeMode, hwInfo);
22672265
NEO::EncodeWA<GfxFamily>::encodeAdditionalPipelineSelect(neoDevice, *commandContainer.getCommandStream(), false);

level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelWithParams(z
210210
}
211211
}
212212

213+
KernelImp *kernelImp = static_cast<KernelImp *>(kernel);
214+
if (kernelImp->getSchedulingHintExp() != std::numeric_limits<uint32_t>::max()) {
215+
this->threadArbitrationPolicy = kernelImp->getSchedulingHintExp();
216+
}
217+
213218
auto isMultiOsContextCapable = (this->partitionCount > 1) && !isCooperative;
214219
updateStreamProperties(*kernel, isMultiOsContextCapable, isCooperative);
215220

216-
KernelImp *kernelImp = static_cast<KernelImp *>(kernel);
217221
this->containsStatelessUncachedResource |= kernelImp->getKernelRequiresUncachedMocs();
218222
this->requiresQueueUncachedMocs |= kernelImp->getKernelRequiresQueueUncachedMocs();
219-
this->threadArbitrationPolicy = kernelImp->getSchedulingHintExp();
220223

221224
NEO::EncodeDispatchKernelArgs dispatchKernelArgs{
222225
eventAddress, //eventAddress

level_zero/core/source/kernel/kernel_imp.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) {
754754
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
755755
auto &kernelDescriptor = kernelImmData->getDescriptor();
756756

757-
this->schedulingHintExpFlag = hwHelper.getDefaultThreadArbitrationPolicy();
758757
UNRECOVERABLE_IF(!this->kernelImmData->getKernelInfo()->heapInfo.pKernelHeap);
759758

760759
if (isaAllocation->getAllocationType() == NEO::AllocationType::KERNEL_ISA_INTERNAL) {
@@ -1003,7 +1002,14 @@ NEO::GraphicsAllocation *KernelImp::getIsaAllocation() const {
10031002
}
10041003

10051004
ze_result_t KernelImp::setSchedulingHintExp(ze_scheduling_hint_exp_desc_t *pHint) {
1006-
this->schedulingHintExpFlag = pHint->flags;
1005+
1006+
if (pHint->flags == ZE_SCHEDULING_HINT_EXP_FLAG_OLDEST_FIRST) {
1007+
this->schedulingHintExpFlag = NEO::ThreadArbitrationPolicy::AgeBased;
1008+
} else if (pHint->flags == ZE_SCHEDULING_HINT_EXP_FLAG_ROUND_ROBIN) {
1009+
this->schedulingHintExpFlag = NEO::ThreadArbitrationPolicy::RoundRobin;
1010+
} else {
1011+
this->schedulingHintExpFlag = NEO::ThreadArbitrationPolicy::RoundRobinAfterDependency;
1012+
}
10071013
return ZE_RESULT_SUCCESS;
10081014
}
10091015

level_zero/core/source/kernel/kernel_imp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct KernelImp : Kernel {
210210

211211
bool kernelHasIndirectAccess = true;
212212

213-
uint32_t schedulingHintExpFlag = 0u;
213+
uint32_t schedulingHintExpFlag = std::numeric_limits<uint32_t>::max();
214214
std::unique_ptr<NEO::ImplicitArgs> pImplicitArgs;
215215
};
216216

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithIndirectAllocationsNotAll
5757
ASSERT_FALSE(commandList->hasIndirectAllocationsAllowed());
5858
}
5959

60+
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithOldestFirstThreadArbitrationPolicySetUsingSchedulingHintExtensionThenCorrectInternalPolicyIsReturned) {
61+
createKernel();
62+
ze_scheduling_hint_exp_desc_t pHint{};
63+
pHint.flags = ZE_SCHEDULING_HINT_EXP_FLAG_OLDEST_FIRST;
64+
kernel->setSchedulingHintExp(&pHint);
65+
ASSERT_EQ(kernel->getSchedulingHintExp(), NEO::ThreadArbitrationPolicy::AgeBased);
66+
}
67+
68+
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithRRThreadArbitrationPolicySetUsingSchedulingHintExtensionThenCorrectInternalPolicyIsReturned) {
69+
createKernel();
70+
ze_scheduling_hint_exp_desc_t pHint{};
71+
pHint.flags = ZE_SCHEDULING_HINT_EXP_FLAG_ROUND_ROBIN;
72+
kernel->setSchedulingHintExp(&pHint);
73+
ASSERT_EQ(kernel->getSchedulingHintExp(), NEO::ThreadArbitrationPolicy::RoundRobin);
74+
}
75+
76+
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithStallRRThreadArbitrationPolicySetUsingSchedulingHintExtensionThenCorrectInternalPolicyIsReturned) {
77+
createKernel();
78+
ze_scheduling_hint_exp_desc_t pHint{};
79+
pHint.flags = ZE_SCHEDULING_HINT_EXP_FLAG_STALL_BASED_ROUND_ROBIN;
80+
kernel->setSchedulingHintExp(&pHint);
81+
ASSERT_EQ(kernel->getSchedulingHintExp(), NEO::ThreadArbitrationPolicy::RoundRobinAfterDependency);
82+
}
83+
6084
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithThreadArbitrationPolicySetUsingSchedulingHintExtensionTheSameFlagIsUsedToSetCmdListThreadArbitrationPolicy) {
6185
createKernel();
6286
ze_scheduling_hint_exp_desc_t *pHint = new ze_scheduling_hint_exp_desc_t;
@@ -70,7 +94,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithThreadArbitrationPolicySe
7094
auto result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr);
7195

7296
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
73-
ASSERT_EQ(commandList->threadArbitrationPolicy, pHint->flags);
97+
ASSERT_EQ(commandList->threadArbitrationPolicy, NEO::ThreadArbitrationPolicy::RoundRobin);
7498
delete (pHint);
7599
}
76100

0 commit comments

Comments
 (0)