Skip to content

Commit 3ca77a6

Browse files
Program sba for global bindless heaps
Signed-off-by: Maciej Plewka <[email protected]>
1 parent b9aee10 commit 3ca77a6

24 files changed

+570
-86
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -11,6 +11,7 @@
1111
#include "shared/source/command_stream/linear_stream.h"
1212
#include "shared/source/command_stream/preemption.h"
1313
#include "shared/source/device/device.h"
14+
#include "shared/source/helpers/api_specific_config.h"
1415
#include "shared/source/helpers/blit_commands_helper.h"
1516
#include "shared/source/helpers/heap_helper.h"
1617
#include "shared/source/helpers/hw_helper.h"
@@ -70,7 +71,10 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::reset() {
7071
containsStatelessUncachedResource = false;
7172

7273
if (!isCopyOnly()) {
73-
programStateBaseAddress(commandContainer, true);
74+
if (!NEO::ApiSpecificConfig::getBindlessConfiguration()) {
75+
programStateBaseAddress(commandContainer, false);
76+
}
77+
commandContainer.setDirtyStateForAllHeaps(false);
7478
programThreadArbitrationPolicy(device);
7579
}
7680

@@ -89,7 +93,10 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::initialize(Device *device, NEO
8993
ze_result_t returnType = parseErrorCode(returnValue);
9094
if (returnType == ZE_RESULT_SUCCESS) {
9195
if (!isCopyOnly()) {
92-
programStateBaseAddress(commandContainer, false);
96+
if (!NEO::ApiSpecificConfig::getBindlessConfiguration()) {
97+
programStateBaseAddress(commandContainer, false);
98+
}
99+
commandContainer.setDirtyStateForAllHeaps(false);
93100
programThreadArbitrationPolicy(device);
94101
}
95102
}
@@ -1701,7 +1708,6 @@ void CommandListCoreFamily<gfxCoreFamily>::programStateBaseAddress(NEO::CommandC
17011708

17021709
device->getL0Debugger()->captureStateBaseAddress(commandContainer, sbaAddresses);
17031710
}
1704-
commandContainer.setDirtyStateForAllHeaps(false);
17051711
}
17061712

17071713
} // namespace L0

level_zero/core/source/cmdqueue/cmdqueue_hw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -35,7 +35,7 @@ struct CommandQueueHw : public CommandQueueImp {
3535

3636
void dispatchTaskCountWrite(NEO::LinearStream &commandStream, bool flushDataCache) override;
3737

38-
void programGeneralStateBaseAddress(uint64_t gsba, bool useLocalMemoryForIndirectHeap, NEO::LinearStream &commandStream);
38+
void programStateBaseAddress(uint64_t gsba, bool useLocalMemoryForIndirectHeap, NEO::LinearStream &commandStream);
3939
size_t estimateStateBaseAddressCmdSize();
4040
MOCKABLE_VIRTUAL void programFrontEnd(uint64_t scratchAddress, NEO::LinearStream &commandStream);
4141

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -227,7 +227,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
227227
}
228228
if (gsbaStateDirty) {
229229
auto indirectHeap = CommandList::fromHandle(phCommandLists[0])->commandContainer.getIndirectHeap(NEO::HeapType::INDIRECT_OBJECT);
230-
programGeneralStateBaseAddress(scratchSpaceController->calculateNewGSH(), indirectHeap->getGraphicsAllocation()->isAllocatedInLocalMemoryPool(), child);
230+
programStateBaseAddress(scratchSpaceController->calculateNewGSH(), indirectHeap->getGraphicsAllocation()->isAllocatedInLocalMemoryPool(), child);
231231
}
232232

233233
if (commandQueuePreemptionMode == NEO::PreemptionMode::Initial) {

level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -11,6 +11,7 @@
1111
#include "shared/source/command_stream/csr_definitions.h"
1212
#include "shared/source/command_stream/linear_stream.h"
1313
#include "shared/source/device/device.h"
14+
#include "shared/source/helpers/api_specific_config.h"
1415
#include "shared/source/helpers/hw_info.h"
1516
#include "shared/source/helpers/interlocked_max.h"
1617
#include "shared/source/helpers/preamble.h"
@@ -28,7 +29,7 @@
2829
namespace L0 {
2930

3031
template <GFXCORE_FAMILY gfxCoreFamily>
31-
void CommandQueueHw<gfxCoreFamily>::programGeneralStateBaseAddress(uint64_t gsba, bool useLocalMemoryForIndirectHeap, NEO::LinearStream &commandStream) {
32+
void CommandQueueHw<gfxCoreFamily>::programStateBaseAddress(uint64_t gsba, bool useLocalMemoryForIndirectHeap, NEO::LinearStream &commandStream) {
3233
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
3334
using STATE_BASE_ADDRESS = typename GfxFamily::STATE_BASE_ADDRESS;
3435
using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL;
@@ -51,6 +52,12 @@ void CommandQueueHw<gfxCoreFamily>::programGeneralStateBaseAddress(uint64_t gsba
5152
auto pSbaCmd = static_cast<STATE_BASE_ADDRESS *>(commandStream.getSpace(sizeof(STATE_BASE_ADDRESS)));
5253
STATE_BASE_ADDRESS sbaCmd;
5354

55+
bool useGlobalSshAndDsh = NEO::ApiSpecificConfig::getBindlessConfiguration();
56+
uint64_t globalHeapsBase = 0;
57+
if (useGlobalSshAndDsh) {
58+
globalHeapsBase = neoDevice->getBindlessHeapsHelper()->getGlobalHeapsBase();
59+
}
60+
5461
NEO::StateBaseAddressHelper<GfxFamily>::programStateBaseAddress(&sbaCmd,
5562
nullptr,
5663
nullptr,
@@ -60,7 +67,9 @@ void CommandQueueHw<gfxCoreFamily>::programGeneralStateBaseAddress(uint64_t gsba
6067
(device->getMOCS(true, false) >> 1),
6168
neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap),
6269
neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), !hwHelper.useSystemMemoryPlacementForISA(hwInfo)),
70+
globalHeapsBase,
6371
true,
72+
useGlobalSshAndDsh,
6473
neoDevice->getGmmHelper(),
6574
false,
6675
NEO::MemoryCompressionState::NotApplicable);

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -315,6 +315,8 @@ TEST_F(CommandListCreate, givenInvalidProductFamilyThenReturnsNullPointer) {
315315
}
316316

317317
HWCMDTEST_F(IGFX_GEN8_CORE, CommandListCreate, whenCommandListIsCreatedThenPCAndStateBaseAddressCmdsAreAddedAndCorrectlyProgrammed) {
318+
DebugManagerStateRestore dbgRestorer;
319+
DebugManager.flags.UseBindlessMode.set(0);
318320
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
319321
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
320322

@@ -368,6 +370,33 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandListCreate, whenCommandListIsCreatedThenPCAnd
368370
EXPECT_EQ(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER), cmdSba->getStatelessDataPortAccessMemoryObjectControlState());
369371
}
370372

373+
HWCMDTEST_F(IGFX_GEN8_CORE, CommandListCreate, whenBindlessModeEnabledWhenCommandListIsCreatedThenStateBaseAddressCmdsIsNotAdded) {
374+
DebugManagerStateRestore dbgRestorer;
375+
DebugManager.flags.UseBindlessMode.set(1);
376+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
377+
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
378+
379+
ze_result_t returnValue;
380+
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
381+
auto &commandContainer = commandList->commandContainer;
382+
383+
ASSERT_NE(nullptr, commandContainer.getCommandStream());
384+
auto usedSpaceBefore = commandContainer.getCommandStream()->getUsed();
385+
386+
auto result = commandList->close();
387+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
388+
389+
auto usedSpaceAfter = commandContainer.getCommandStream()->getUsed();
390+
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
391+
392+
GenCmdList cmdList;
393+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
394+
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), usedSpaceAfter));
395+
396+
auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
397+
ASSERT_EQ(cmdList.end(), itor);
398+
}
399+
371400
HWTEST_F(CommandListCreate, givenCommandListWithCopyOnlyWhenCreatedThenStateBaseAddressCmdIsNotProgrammed) {
372401
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
373402

@@ -411,6 +440,47 @@ HWTEST_F(CommandListCreate, whenCommandListIsResetThenContainsStatelessUncachedR
411440
EXPECT_FALSE(commandList->getContainsStatelessUncachedResource());
412441
}
413442

443+
HWTEST_F(CommandListCreate, givenBindlessModeEnabledWhenCommandListsResetThenSbaNotReloaded) {
444+
DebugManagerStateRestore dbgRestorer;
445+
DebugManager.flags.UseBindlessMode.set(1);
446+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
447+
ze_result_t returnValue;
448+
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily,
449+
device,
450+
NEO::EngineGroupType::Compute,
451+
returnValue));
452+
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
453+
returnValue = commandList->reset();
454+
auto usedAfter = commandList->commandContainer.getCommandStream()->getUsed();
455+
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
456+
GenCmdList cmdList;
457+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
458+
cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), usedAfter));
459+
460+
auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
461+
ASSERT_EQ(cmdList.end(), itor);
462+
}
463+
HWTEST_F(CommandListCreate, givenBindlessModeDisabledWhenCommandListsResetThenSbaReloaded) {
464+
DebugManagerStateRestore dbgRestorer;
465+
DebugManager.flags.UseBindlessMode.set(0);
466+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
467+
ze_result_t returnValue;
468+
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily,
469+
device,
470+
NEO::EngineGroupType::Compute,
471+
returnValue));
472+
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
473+
returnValue = commandList->reset();
474+
auto usedAfter = commandList->commandContainer.getCommandStream()->getUsed();
475+
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
476+
GenCmdList cmdList;
477+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
478+
cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), usedAfter));
479+
480+
auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
481+
ASSERT_NE(cmdList.end(), itor);
482+
}
483+
414484
HWTEST_F(CommandListCreate, givenCommandListWithCopyOnlyWhenResetThenStateBaseAddressNotProgrammed) {
415485
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
416486

level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -10,10 +10,13 @@
1010
#include "shared/source/gmm_helper/gmm_helper.h"
1111
#include "shared/source/helpers/state_base_address.h"
1212
#include "shared/source/os_interface/device_factory.h"
13+
#include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h"
1314
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
1415
#include "shared/test/unit_test/helpers/default_hw_info.h"
1516
#include "shared/test/unit_test/helpers/variable_backup.h"
17+
#include "shared/test/unit_test/mocks/mock_bindless_heaps_helper.h"
1618
#include "shared/test/unit_test/mocks/mock_command_stream_receiver.h"
19+
#include "shared/test/unit_test/mocks/mock_graphics_allocation.h"
1720

1821
#include "opencl/test/unit_test/libult/ult_command_stream_receiver.h"
1922
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
@@ -301,7 +304,7 @@ HWTEST2_F(CommandQueueProgramSBATest, whenCreatingCommandQueueThenItIsInitialize
301304
.Times(1); // instruction heap
302305
}
303306

304-
commandQueue->programGeneralStateBaseAddress(0u, true, child);
307+
commandQueue->programStateBaseAddress(0u, true, child);
305308

306309
if (isaInLocalMemory) {
307310
EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false))
@@ -317,7 +320,7 @@ HWTEST2_F(CommandQueueProgramSBATest, whenCreatingCommandQueueThenItIsInitialize
317320
.Times(2);
318321
}
319322

320-
commandQueue->programGeneralStateBaseAddress(0u, false, child);
323+
commandQueue->programStateBaseAddress(0u, false, child);
321324

322325
commandQueue->destroy();
323326
}
@@ -333,7 +336,7 @@ HWTEST2_F(CommandQueueProgramSBATest,
333336
uint32_t alignedSize = 4096u;
334337
NEO::LinearStream child(commandQueue->commandStream->getSpace(alignedSize), alignedSize);
335338

336-
commandQueue->programGeneralStateBaseAddress(0u, true, child);
339+
commandQueue->programStateBaseAddress(0u, true, child);
337340
auto pSbaCmd = static_cast<STATE_BASE_ADDRESS *>(commandQueue->commandStream->getSpace(sizeof(STATE_BASE_ADDRESS)));
338341
uint32_t statelessMocsIndex = pSbaCmd->getStatelessDataPortAccessMemoryObjectControlState();
339342

@@ -344,6 +347,82 @@ HWTEST2_F(CommandQueueProgramSBATest,
344347
commandQueue->destroy();
345348
}
346349

350+
using BindlessCommandQueueSBASupport = IsAtLeastProduct<IGFX_SKYLAKE>;
351+
352+
HWTEST2_F(CommandQueueProgramSBATest,
353+
givenBindlessModeEnabledWhenProgrammingStateBaseAddressThenBindlessBaseAddressIsPassed, BindlessCommandQueueSBASupport) {
354+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
355+
DebugManagerStateRestore dbgRestorer;
356+
DebugManager.flags.UseBindlessMode.set(1);
357+
auto bindlessHeapsHelper = std::make_unique<MockBindlesHeapsHelper>(neoDevice->getMemoryManager(), neoDevice->getNumAvailableDevices() > 1, neoDevice->getRootDeviceIndex());
358+
MockBindlesHeapsHelper *bindlessHeapsHelperPtr = bindlessHeapsHelper.get();
359+
neoDevice->bindlessHeapHelper.reset(bindlessHeapsHelper.release());
360+
NEO::MockGraphicsAllocation baseAllocation;
361+
bindlessHeapsHelperPtr->surfaceStateHeaps[NEO::BindlessHeapsHelper::GLOBAL_SSH].reset(new IndirectHeap(&baseAllocation, true));
362+
baseAllocation.setGpuBaseAddress(0x123000);
363+
ze_command_queue_desc_t desc = {};
364+
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
365+
auto commandQueue = new MockCommandQueueHw<gfxCoreFamily>(device, csr.get(), &desc);
366+
commandQueue->initialize(false, false);
367+
368+
uint32_t alignedSize = 4096u;
369+
NEO::LinearStream child(commandQueue->commandStream->getSpace(alignedSize), alignedSize);
370+
371+
commandQueue->programStateBaseAddress(0u, true, child);
372+
373+
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
374+
375+
GenCmdList cmdList;
376+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
377+
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
378+
379+
auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
380+
ASSERT_NE(cmdList.end(), itor);
381+
382+
auto cmdSba = genCmdCast<STATE_BASE_ADDRESS *>(*itor);
383+
EXPECT_EQ(cmdSba->getBindlessSurfaceStateBaseAddressModifyEnable(), true);
384+
EXPECT_EQ(cmdSba->getBindlessSurfaceStateBaseAddress(), neoDevice->bindlessHeapHelper->getGlobalHeapsBase());
385+
EXPECT_EQ(cmdSba->getBindlessSurfaceStateSize(), MemoryConstants::sizeOf4GBinPageEntities);
386+
387+
commandQueue->destroy();
388+
}
389+
390+
HWTEST2_F(CommandQueueProgramSBATest,
391+
givenBindlessModeDisabledWhenProgrammingStateBaseAddressThenBindlessBaseAddressNotPassed, CommandQueueSBASupport) {
392+
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
393+
DebugManagerStateRestore dbgRestorer;
394+
DebugManager.flags.UseBindlessMode.set(0);
395+
auto bindlessHeapsHelper = std::make_unique<MockBindlesHeapsHelper>(neoDevice->getMemoryManager(), neoDevice->getNumAvailableDevices() > 1, neoDevice->getRootDeviceIndex());
396+
MockBindlesHeapsHelper *bindlessHeapsHelperPtr = bindlessHeapsHelper.get();
397+
neoDevice->bindlessHeapHelper.reset(bindlessHeapsHelper.release());
398+
NEO::MockGraphicsAllocation baseAllocation;
399+
bindlessHeapsHelperPtr->surfaceStateHeaps[NEO::BindlessHeapsHelper::GLOBAL_SSH].reset(new IndirectHeap(&baseAllocation, true));
400+
baseAllocation.setGpuBaseAddress(0x123000);
401+
ze_command_queue_desc_t desc = {};
402+
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
403+
auto commandQueue = new MockCommandQueueHw<gfxCoreFamily>(device, csr.get(), &desc);
404+
commandQueue->initialize(false, false);
405+
406+
uint32_t alignedSize = 4096u;
407+
NEO::LinearStream child(commandQueue->commandStream->getSpace(alignedSize), alignedSize);
408+
409+
commandQueue->programStateBaseAddress(0u, true, child);
410+
411+
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
412+
413+
GenCmdList cmdList;
414+
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
415+
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
416+
417+
auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
418+
ASSERT_NE(cmdList.end(), itor);
419+
420+
auto cmdSba = genCmdCast<STATE_BASE_ADDRESS *>(*itor);
421+
EXPECT_NE(cmdSba->getBindlessSurfaceStateBaseAddress(), neoDevice->bindlessHeapHelper->getGlobalHeapsBase());
422+
423+
commandQueue->destroy();
424+
}
425+
347426
TEST_F(CommandQueueCreate, givenCmdQueueWithBlitCopyWhenExecutingNonCopyBlitCommandListThenWrongCommandListStatusReturned) {
348427
const ze_command_queue_desc_t desc = {};
349428
ze_result_t returnValue;

0 commit comments

Comments
 (0)