Skip to content

Commit dbeb263

Browse files
Fix CFE programming when usm transfer required
Resolves: NEO-6288 Signed-off-by: Szymon Morek <[email protected]>
1 parent f1e839b commit dbeb263

File tree

2 files changed

+87
-11
lines changed

2 files changed

+87
-11
lines changed

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
151151

152152
size_t totalCmdBuffers = 0;
153153
uint32_t perThreadScratchSpaceSize = 0;
154+
NEO::PageFaultManager *pageFaultManager = nullptr;
155+
if (performMigration) {
156+
pageFaultManager = device->getDriverHandle()->getMemoryManager()->getPageFaultManager();
157+
if (pageFaultManager == nullptr) {
158+
performMigration = false;
159+
}
160+
}
154161
for (auto i = 0u; i < numCommandLists; i++) {
155162
auto commandList = CommandList::fromHandle(phCommandLists[i]);
156163

@@ -189,6 +196,8 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
189196
}
190197

191198
partitionCount = std::max(partitionCount, commandList->partitionCount);
199+
commandList->csr = csr;
200+
commandList->makeResidentAndMigrate(performMigration);
192201
}
193202

194203
size_t linearStreamSizeEstimate = totalCmdBuffers * sizeof(MI_BATCH_BUFFER_START);
@@ -337,14 +346,6 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
337346
}
338347
}
339348

340-
NEO::PageFaultManager *pageFaultManager = nullptr;
341-
if (performMigration) {
342-
pageFaultManager = device->getDriverHandle()->getMemoryManager()->getPageFaultManager();
343-
if (pageFaultManager == nullptr) {
344-
performMigration = false;
345-
}
346-
}
347-
348349
for (auto i = 0u; i < numCommandLists; ++i) {
349350
auto commandList = CommandList::fromHandle(phCommandLists[i]);
350351
auto cmdBufferAllocations = commandList->commandContainer.getCmdBufferAllocations();
@@ -399,9 +400,6 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
399400
printfFunctionContainer.insert(printfFunctionContainer.end(),
400401
commandList->getPrintfFunctionContainer().begin(),
401402
commandList->getPrintfFunctionContainer().end());
402-
403-
commandList->csr = csr;
404-
commandList->makeResidentAndMigrate(performMigration);
405403
}
406404

407405
if (performMigration) {

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
2121
#include "shared/test/common/mocks/mock_graphics_allocation.h"
2222
#include "shared/test/common/mocks/mock_memory_manager.h"
23+
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
2324
#include "shared/test/common/mocks/ult_device_factory.h"
2425

2526
#include "test.h"
@@ -2030,5 +2031,82 @@ TEST_F(CommandQueueCreate, givenOverrideCmdQueueSyncModeToSynchronousWhenCommand
20302031

20312032
commandQueue->destroy();
20322033
}
2034+
2035+
struct DeviceWithDualStorage : Test<DeviceFixture> {
2036+
void SetUp() override {
2037+
NEO::MockCompilerEnableGuard mock(true);
2038+
DebugManager.flags.EnableLocalMemory.set(1);
2039+
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(1);
2040+
DeviceFixture::SetUp();
2041+
}
2042+
void TearDown() override {
2043+
DeviceFixture::TearDown();
2044+
}
2045+
DebugManagerStateRestore restorer;
2046+
};
2047+
2048+
HWTEST2_F(DeviceWithDualStorage, givenCmdListWithAppendedKernelAndUsmTransferAndBlitterDisabledWhenExecuteCmdListThenCfeStateOnceProgrammed, IsAtLeastXeHpCore) {
2049+
using CFE_STATE = typename FamilyType::CFE_STATE;
2050+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<MockMemoryOperationsHandler>();
2051+
ze_result_t res = ZE_RESULT_SUCCESS;
2052+
2053+
const ze_command_queue_desc_t desc = {};
2054+
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily,
2055+
device,
2056+
neoDevice->getInternalEngine().commandStreamReceiver,
2057+
&desc,
2058+
false,
2059+
false,
2060+
res));
2061+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
2062+
ASSERT_NE(nullptr, commandQueue);
2063+
2064+
auto commandList = std::unique_ptr<CommandList>(whitebox_cast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, res)));
2065+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
2066+
ASSERT_NE(nullptr, commandList);
2067+
Mock<Kernel> kernel;
2068+
kernel.immutableData.device = device;
2069+
size_t size = 10;
2070+
size_t alignment = 1u;
2071+
void *ptr = nullptr;
2072+
ze_device_mem_alloc_desc_t deviceDesc = {};
2073+
ze_host_mem_alloc_desc_t hostDesc = {};
2074+
res = context->allocSharedMem(device->toHandle(),
2075+
&deviceDesc,
2076+
&hostDesc,
2077+
size, alignment, &ptr);
2078+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
2079+
auto gpuAlloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
2080+
kernel.residencyContainer.push_back(gpuAlloc);
2081+
2082+
ze_group_count_t dispatchFunctionArguments{1, 1, 1};
2083+
commandList->appendLaunchKernel(kernel.toHandle(), &dispatchFunctionArguments, nullptr, 0, nullptr);
2084+
auto deviceImp = static_cast<DeviceImp *>(device);
2085+
auto pageFaultCmdQueue = whitebox_cast(deviceImp->pageFaultCommandList->cmdQImmediate);
2086+
2087+
auto sizeBefore = commandQueue->commandStream->getUsed();
2088+
auto pageFaultSizeBefore = pageFaultCmdQueue->commandStream->getUsed();
2089+
auto handle = commandList->toHandle();
2090+
commandQueue->executeCommandLists(1, &handle, nullptr, true);
2091+
auto sizeAfter = commandQueue->commandStream->getUsed();
2092+
auto pageFaultSizeAfter = pageFaultCmdQueue->commandStream->getUsed();
2093+
EXPECT_LT(sizeBefore, sizeAfter);
2094+
EXPECT_LT(pageFaultSizeBefore, pageFaultSizeAfter);
2095+
2096+
GenCmdList commands;
2097+
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(commandQueue->commandStream->getCpuBase(), 0),
2098+
sizeAfter);
2099+
auto count = findAll<CFE_STATE *>(commands.begin(), commands.end()).size();
2100+
EXPECT_EQ(0u, count);
2101+
2102+
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(pageFaultCmdQueue->commandStream->getCpuBase(), 0),
2103+
pageFaultSizeAfter);
2104+
count = findAll<CFE_STATE *>(commands.begin(), commands.end()).size();
2105+
EXPECT_EQ(1u, count);
2106+
2107+
res = context->freeMem(ptr);
2108+
ASSERT_EQ(ZE_RESULT_SUCCESS, res);
2109+
commandQueue->destroy();
2110+
}
20332111
} // namespace ult
20342112
} // namespace L0

0 commit comments

Comments
 (0)