Skip to content

Commit fc770ca

Browse files
feature: enable dispatch primary batch buffer from immediate
Related-To: NEO-10356 Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent 8ede026 commit fc770ca

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::initialize(Device *device, NEO
246246
this->l1CachePolicyData.init(productHelper);
247247
this->cmdListHeapAddressModel = L0GfxCoreHelper::getHeapAddressModel(rootDeviceEnvironment);
248248
this->dummyBlitWa.rootDeviceEnvironment = &(neoDevice->getRootDeviceEnvironmentRef());
249-
this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !isImmediateType());
249+
this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !(this->internalUsage && isImmediateType()));
250250
this->useOnlyGlobalTimestamps = gfxCoreHelper.useOnlyGlobalTimestamps();
251251
this->maxFillPaternSizeForCopyEngine = productHelper.getMaxFillPaternSizeForCopyEngine();
252252
this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled();

level_zero/core/source/cmdqueue/cmdqueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ze_result_t CommandQueueImp::initialize(bool copyOnly, bool isInternal, bool imm
9898
auto &productHelper = rootDeviceEnvironment.getHelper<NEO::ProductHelper>();
9999
this->doubleSbaWa = productHelper.isAdditionalStateBaseAddressWARequired(hwInfo);
100100
this->cmdListHeapAddressModel = L0GfxCoreHelper::getHeapAddressModel(rootDeviceEnvironment);
101-
this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !immediateCmdListQueue);
101+
this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !(internalUsage && immediateCmdListQueue));
102102
auto &compilerProductHelper = rootDeviceEnvironment.getHelper<NEO::CompilerProductHelper>();
103103
this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled();
104104
this->heaplessStateInitEnabled = compilerProductHelper.isHeaplessStateInitEnabled(this->heaplessModeEnabled);

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,14 +1729,14 @@ HWTEST2_F(CommandListCreateTests, givenPlatformNotSupportsSharedHeapsWhenImmedia
17291729

17301730
using PrimaryBatchBufferCmdListTest = Test<PrimaryBatchBufferCmdListFixture>;
17311731

1732-
HWTEST_F(PrimaryBatchBufferCmdListTest, givenForcedPrimaryBatchBufferWhenRegularAndImmediateObjectCreatedThenRegularSetPrimaryFlagAndImmediateNot) {
1732+
HWTEST_F(PrimaryBatchBufferCmdListTest, givenForcedPrimaryBatchBufferWhenRegularAndImmediateObjectCreatedThenRegularAndImmediateSetPrimaryFlag) {
17331733
EXPECT_TRUE(commandList->dispatchCmdListBatchBufferAsPrimary);
17341734
EXPECT_TRUE(commandQueue->dispatchCmdListBatchBufferAsPrimary);
17351735

1736-
EXPECT_FALSE(commandListImmediate->dispatchCmdListBatchBufferAsPrimary);
1736+
EXPECT_TRUE(commandListImmediate->dispatchCmdListBatchBufferAsPrimary);
17371737
ASSERT_NE(nullptr, commandListImmediate->cmdQImmediate);
17381738
auto immediateCmdQueue = static_cast<L0::ult::CommandQueue *>(commandListImmediate->cmdQImmediate);
1739-
EXPECT_FALSE(immediateCmdQueue->dispatchCmdListBatchBufferAsPrimary);
1739+
EXPECT_TRUE(immediateCmdQueue->dispatchCmdListBatchBufferAsPrimary);
17401740
}
17411741

17421742
HWTEST_F(PrimaryBatchBufferCmdListTest, givenPrimaryBatchBufferWhenAppendingKernelAndClosingCommandListThenExpectAlignedSpaceForBatchBufferStart) {
@@ -1851,6 +1851,46 @@ HWTEST_F(PrimaryBatchBufferCmdListTest, givenRegularCmdListWhenFlushingThenPassS
18511851
EXPECT_TRUE(ultCsr->latestFlushedBatchBuffer.hasStallingCmds);
18521852
}
18531853

1854+
HWTEST_F(PrimaryBatchBufferCmdListTest, givenRegularCmdListWhenNoPreambleExpectedAndForceBbStartThenDispatchBbStart) {
1855+
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START;
1856+
1857+
ze_group_count_t groupCount{1, 1, 1};
1858+
CmdListKernelLaunchParams launchParams = {};
1859+
auto result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
1860+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
1861+
result = commandList->close();
1862+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
1863+
auto cmdListHandle = commandList->toHandle();
1864+
1865+
auto regularCmdBufferAllocation = commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation();
1866+
1867+
// 1st dispatch can carry state preamble
1868+
result = commandQueue->executeCommandLists(1, &cmdListHandle, nullptr, true, nullptr);
1869+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
1870+
1871+
auto &queueStream = commandQueue->commandStream;
1872+
1873+
auto offsetBefore = queueStream.getUsed();
1874+
commandQueue->triggerBbStartJump();
1875+
result = commandQueue->executeCommandLists(1, &cmdListHandle, nullptr, true, nullptr);
1876+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
1877+
auto offsetAfter = queueStream.getUsed();
1878+
1879+
GenCmdList cmdList;
1880+
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(
1881+
cmdList,
1882+
ptrOffset(queueStream.getCpuBase(), offsetBefore),
1883+
offsetAfter - offsetBefore));
1884+
ASSERT_NE(0u, cmdList.size());
1885+
1886+
auto firstCmdIt = cmdList.begin();
1887+
auto bbStartCmd = genCmdCast<MI_BATCH_BUFFER_START *>(*firstCmdIt);
1888+
ASSERT_NE(nullptr, bbStartCmd);
1889+
1890+
EXPECT_EQ(regularCmdBufferAllocation->getGpuAddress(), bbStartCmd->getBatchBufferStartAddress());
1891+
EXPECT_EQ(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER::SECOND_LEVEL_BATCH_BUFFER_FIRST_LEVEL_BATCH, bbStartCmd->getSecondLevelBatchBuffer());
1892+
}
1893+
18541894
HWTEST2_F(PrimaryBatchBufferCmdListTest, givenRelaxedOrderingAndRegularCmdListAndSubmittedToImmediateWhenFlushingThenPassStallingCmdsInfo, IsAtLeastXeHpcCore) {
18551895
DebugManagerStateRestore restore;
18561896
debugManager.flags.DirectSubmissionRelaxedOrdering.set(1);

0 commit comments

Comments
 (0)