Skip to content

Commit e7e9804

Browse files
HoppeMateuszCompute-Runtime-Automation
authored andcommittedOct 11, 2024
fix: track shifted contextIds in bitset in bindlessHeapsHelper
- bitset is 64 bit in size, context ids may go beyond that limit when multiple devices are available - this change subtracts contextId of first context for a given root device - tracked state dirty contexts ids are now zero-based Resolves: GSD-10025 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com> Source: 5ae2552
1 parent 8d5c624 commit e7e9804

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed
 

‎level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueue_cmdlist_2.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -885,5 +885,69 @@ HWTEST_F(CommandQueueExecuteCommandListsSimpleTest, GivenRegisterInstructionCach
885885
commandQueue->destroy();
886886
}
887887

888+
using CommandQueueExecuteCommandListsMultiDeviceTest = Test<MultiDeviceFixture>;
889+
890+
HWTEST_F(CommandQueueExecuteCommandListsMultiDeviceTest, GivenDirtyFlagForContextInBindlessHelperWhenExecutingCmdListsThenStateCacheInvalidateIsSent) {
891+
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
892+
ze_command_queue_desc_t queueDesc = {};
893+
ze_result_t returnValue;
894+
auto neoDevice = driverHandle->devices[numRootDevices - 1]->getNEODevice();
895+
auto device = driverHandle->devices[numRootDevices - 1];
896+
897+
auto bindlessHeapsHelper = std::make_unique<MockBindlesHeapsHelper>(neoDevice, neoDevice->getNumGenericSubDevices() > 1);
898+
MockBindlesHeapsHelper *bindlessHeapsHelperPtr = bindlessHeapsHelper.get();
899+
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->bindlessHeapsHelper.reset(bindlessHeapsHelper.release());
900+
901+
queueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS;
902+
auto commandQueue = whiteboxCast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, false, returnValue));
903+
ASSERT_NE(nullptr, commandQueue);
904+
905+
uint32_t contextId = commandQueue->getCsr()->getOsContext().getContextId();
906+
uint32_t contextIdFirst = neoDevice->getMemoryManager()->getFirstContextIdForRootDevice(numRootDevices - 1);
907+
EXPECT_LE(contextIdFirst, contextId);
908+
909+
uint32_t firstDeviceFirstContextId = neoDevice->getMemoryManager()->getFirstContextIdForRootDevice(0);
910+
EXPECT_EQ(0u, firstDeviceFirstContextId);
911+
912+
bindlessHeapsHelperPtr->stateCacheDirtyForContext.set();
913+
914+
auto usedSpaceBefore = commandQueue->commandStream.getUsed();
915+
916+
ze_command_list_handle_t commandLists[] = {
917+
CommandList::create(productFamily, device, NEO::EngineGroupType::renderCompute, 0u, returnValue, false)->toHandle(),
918+
CommandList::create(productFamily, device, NEO::EngineGroupType::renderCompute, 0u, returnValue, false)->toHandle()};
919+
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
920+
CommandList::fromHandle(commandLists[0])->close();
921+
CommandList::fromHandle(commandLists[1])->close();
922+
auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true, nullptr);
923+
924+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
925+
926+
auto usedSpaceAfter = commandQueue->commandStream.getUsed();
927+
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
928+
929+
GenCmdList cmdList;
930+
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(
931+
cmdList, ptrOffset(commandQueue->commandStream.getCpuBase(), 0), usedSpaceAfter));
932+
933+
auto pipeControls = findAll<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
934+
ASSERT_NE(0u, pipeControls.size());
935+
936+
auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(*pipeControls[0]);
937+
EXPECT_TRUE(pipeControl->getCommandStreamerStallEnable());
938+
EXPECT_TRUE(pipeControl->getStateCacheInvalidationEnable());
939+
EXPECT_TRUE(pipeControl->getTextureCacheInvalidationEnable());
940+
EXPECT_TRUE(pipeControl->getRenderTargetCacheFlushEnable());
941+
942+
EXPECT_FALSE(bindlessHeapsHelperPtr->getStateDirtyForContext(commandQueue->getCsr()->getOsContext().getContextId()));
943+
944+
for (auto i = 0u; i < numCommandLists; i++) {
945+
auto commandList = CommandList::fromHandle(commandLists[i]);
946+
commandList->destroy();
947+
}
948+
949+
commandQueue->destroy();
950+
}
951+
888952
} // namespace ult
889953
} // namespace L0

‎shared/source/helpers/bindless_heaps_helper.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ GraphicsAllocation *BindlessHeapsHelper::getHeapAllocation(size_t heapSize, size
7575
void BindlessHeapsHelper::clearStateDirtyForContext(uint32_t osContextId) {
7676
std::lock_guard<std::mutex> autolock(this->mtx);
7777

78-
stateCacheDirtyForContext.reset(osContextId);
78+
uint32_t contextIdShifted = osContextId - memManager->getFirstContextIdForRootDevice(rootDeviceIndex);
79+
DEBUG_BREAK_IF(contextIdShifted >= stateCacheDirtyForContext.size());
80+
81+
stateCacheDirtyForContext.reset(contextIdShifted);
7982
}
8083

8184
bool BindlessHeapsHelper::getStateDirtyForContext(uint32_t osContextId) {
8285
std::lock_guard<std::mutex> autolock(this->mtx);
8386

84-
return stateCacheDirtyForContext.test(osContextId);
87+
uint32_t contextIdShifted = osContextId - memManager->getFirstContextIdForRootDevice(rootDeviceIndex);
88+
DEBUG_BREAK_IF(contextIdShifted >= stateCacheDirtyForContext.size());
89+
90+
return stateCacheDirtyForContext.test(contextIdShifted);
8591
}
8692

8793
SurfaceStateInHeapInfo BindlessHeapsHelper::allocateSSInHeap(size_t ssSize, GraphicsAllocation *surfaceAllocation, BindlesHeapType heapType) {

‎shared/source/memory_manager/memory_manager.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ void MemoryManager::updateLatestContextIdForRootDevice(uint32_t rootDeviceIndex)
368368
}
369369
}
370370

371+
uint32_t MemoryManager::getFirstContextIdForRootDevice(uint32_t rootDeviceIndex) {
372+
auto entry = rootDeviceIndexToContextId.find(rootDeviceIndex);
373+
if (entry != rootDeviceIndexToContextId.end()) {
374+
return entry->second + 1;
375+
}
376+
return 0;
377+
}
378+
371379
OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
372380
const EngineDescriptor &engineDescriptor) {
373381
auto rootDeviceIndex = commandStreamReceiver->getRootDeviceIndex();

‎shared/source/memory_manager/memory_manager.h

+1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ class MemoryManager {
314314

315315
size_t getUsedLocalMemorySize(uint32_t rootDeviceIndex) const { return localMemAllocsSize[rootDeviceIndex]; }
316316
size_t getUsedSystemMemorySize() const { return sysMemAllocsSize; }
317+
uint32_t getFirstContextIdForRootDevice(uint32_t rootDeviceIndex);
317318

318319
protected:
319320
bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo);

0 commit comments

Comments
 (0)