diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index b9d93a5f17..593581b01c 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -171,7 +171,12 @@ ze_result_t CommandQueueHw::executeCommandLists( bool indirectAllocationsAllowed = commandList->hasIndirectAllocationsAllowed(); if (indirectAllocationsAllowed) { auto svmAllocsManager = device->getDriverHandle()->getSvmAllocsManager(); - if (NEO::DebugManager.flags.MakeIndirectAllocationsResidentAsPack.get() == 1) { + auto submitAsPack = device->getDriverHandle()->getMemoryManager()->allowIndirectAllocationsAsPack(neoDevice->getRootDeviceIndex()); + if (NEO::DebugManager.flags.MakeIndirectAllocationsResidentAsPack.get() != -1) { + submitAsPack = !!NEO::DebugManager.flags.MakeIndirectAllocationsResidentAsPack.get(); + } + + if (submitAsPack) { svmAllocsManager->makeIndirectAllocationsResident(*csr, csr->peekTaskCount() + 1u); } else { UnifiedMemoryControls unifiedMemoryControls = commandList->getUnifiedMemoryControls(); diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp index f008d3ac9d..891bbd82d3 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp @@ -874,6 +874,66 @@ HWTEST_F(CommandQueueIndirectAllocations, givenDebugModeToTreatIndirectAllocatio commandQueue->destroy(); } +HWTEST_F(CommandQueueIndirectAllocations, givenDeviceThatSupportsSubmittingIndirectAllocationsAsPackWhenIndirectAccessIsUsedThenWholePackIsMadeResident) { + const ze_command_queue_desc_t desc = {}; + + MockCsrHw2 csr(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); + csr.initializeTagAllocation(); + csr.setupContext(*neoDevice->getDefaultEngine().osContext); + + ze_result_t returnValue; + L0::CommandQueue *commandQueue = CommandQueue::create(productFamily, + device, + &csr, + &desc, + true, + false, + returnValue); + ASSERT_NE(nullptr, commandQueue); + + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, 0u, returnValue)); + + void *deviceAlloc = nullptr; + ze_device_mem_alloc_desc_t deviceDesc = {}; + auto result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &deviceAlloc); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + auto gpuAlloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(deviceAlloc)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); + ASSERT_NE(nullptr, gpuAlloc); + + createKernel(true); + kernel->unifiedMemoryControls.indirectDeviceAllocationsAllowed = true; + EXPECT_TRUE(kernel->getUnifiedMemoryControls().indirectDeviceAllocationsAllowed); + + ze_group_count_t groupCount{1, 1, 1}; + result = commandList->appendLaunchKernel(kernel->toHandle(), + &groupCount, + nullptr, + 0, + nullptr); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + auto itorEvent = std::find(std::begin(commandList->commandContainer.getResidencyContainer()), + std::end(commandList->commandContainer.getResidencyContainer()), + gpuAlloc); + EXPECT_EQ(itorEvent, std::end(commandList->commandContainer.getResidencyContainer())); + + auto commandListHandle = commandList->toHandle(); + + EXPECT_FALSE(gpuAlloc->isResident(csr.getOsContext().getContextId())); + + static_cast(driverHandle.get()->getMemoryManager())->overrideAllocateAsPackReturn = 1u; + + result = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + EXPECT_TRUE(gpuAlloc->isResident(csr.getOsContext().getContextId())); + EXPECT_EQ(GraphicsAllocation::objectAlwaysResident, gpuAlloc->getResidencyTaskCount(csr.getOsContext().getContextId())); + + device->getDriverHandle()->getSvmAllocsManager()->freeSVMAlloc(deviceAlloc); + commandQueue->destroy(); +} + using DeviceCreateCommandQueueTest = Test; TEST_F(DeviceCreateCommandQueueTest, givenLowPriorityDescWhenCreateCommandQueueIsCalledThenLowPriorityCsrIsAssigned) { ze_command_queue_desc_t desc{}; diff --git a/shared/test/common/mocks/mock_memory_manager.h b/shared/test/common/mocks/mock_memory_manager.h index 104f639a5d..837bafdfe8 100644 --- a/shared/test/common/mocks/mock_memory_manager.h +++ b/shared/test/common/mocks/mock_memory_manager.h @@ -183,6 +183,13 @@ class MockMemoryManager : public MemoryManagerCreate { } return allocateGraphicsMemoryForNonSvmHostPtrResult; } + bool allowIndirectAllocationsAsPack(uint32_t rootDeviceIndex) override { + if (overrideAllocateAsPackReturn != -1) { + return !!overrideAllocateAsPackReturn; + } else { + return MemoryManager::allowIndirectAllocationsAsPack(rootDeviceIndex); + } + } uint32_t copyMemoryToAllocationBanksCalled = 0u; uint32_t populateOsHandlesCalled = 0u; @@ -191,6 +198,7 @@ class MockMemoryManager : public MemoryManagerCreate { uint32_t unlockResourceCalled = 0u; uint32_t lockResourceCalled = 0u; uint32_t createGraphicsAllocationFromExistingStorageCalled = 0u; + int32_t overrideAllocateAsPackReturn = -1; std::vector allocationsFromExistingStorage{}; AllocationData alignAllocationData; uint32_t successAllocatedGraphicsMemoryIndex = 0u;