Skip to content

Commit 601ace6

Browse files
Add unit test for append memory prefetch for regular command list
Related-To: NEO-6740 Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent 3de620a commit 601ace6

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "level_zero/core/source/event/event.h"
1515
#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h"
1616
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
17+
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
1718
#include "level_zero/core/test/unit_tests/mocks/mock_module.h"
1819

1920
namespace L0 {
@@ -317,6 +318,74 @@ HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigr
317318
commandList->destroy();
318319
}
319320

321+
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiIsCalledOnUnifiedSharedMemoryThenCallMigrateAllocationsToGpu, IsXeHpcCore) {
322+
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
323+
using POSTSYNC_DATA = typename FamilyType::POSTSYNC_DATA;
324+
using WALKER_TYPE = typename FamilyType::WALKER_TYPE;
325+
326+
DebugManagerStateRestore restore;
327+
DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1);
328+
DebugManager.flags.UseKmdMigration.set(1);
329+
330+
neoDevice->deviceBitfield = 0b1000;
331+
332+
auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager());
333+
memoryManager->prefetchManager.reset(new MockPrefetchManager());
334+
335+
createKernel();
336+
ze_result_t returnValue;
337+
ze_command_queue_desc_t queueDesc = {};
338+
339+
ze_command_list_handle_t commandListHandle = CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle();
340+
auto commandList = CommandList::fromHandle(commandListHandle);
341+
auto commandQueue = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue);
342+
343+
ze_event_pool_desc_t eventPoolDesc = {};
344+
eventPoolDesc.count = 1;
345+
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
346+
347+
ze_event_desc_t eventDesc = {};
348+
eventDesc.index = 0;
349+
350+
auto eventPool = std::unique_ptr<EventPool>(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, returnValue));
351+
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
352+
auto event = std::unique_ptr<Event>(Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
353+
354+
size_t size = 10;
355+
size_t alignment = 1u;
356+
void *ptr = nullptr;
357+
358+
ze_device_mem_alloc_desc_t deviceDesc = {};
359+
ze_host_mem_alloc_desc_t hostDesc = {};
360+
auto result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr);
361+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
362+
EXPECT_NE(nullptr, ptr);
363+
364+
result = commandList->appendMemoryPrefetch(ptr, size);
365+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
366+
367+
auto prefetchManager = static_cast<MockPrefetchManager *>(memoryManager->prefetchManager.get());
368+
EXPECT_EQ(1u, prefetchManager->allocations.size());
369+
370+
ze_group_count_t groupCount{1, 1, 1};
371+
CmdListKernelLaunchParams launchParams = {};
372+
result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, event->toHandle(), 0, nullptr, launchParams);
373+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
374+
375+
result = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, true);
376+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
377+
378+
EXPECT_TRUE(memoryManager->setMemPrefetchCalled);
379+
EXPECT_EQ(3u, memoryManager->memPrefetchSubDeviceId);
380+
381+
EXPECT_TRUE(prefetchManager->migrateAllocationsToGpuCalled);
382+
EXPECT_EQ(0u, prefetchManager->allocations.size());
383+
384+
context->freeMem(ptr);
385+
commandList->destroy();
386+
commandQueue->destroy();
387+
}
388+
320389
using CommandListEventFenceTestsXeHpcCore = Test<ModuleFixture>;
321390

322391
HWTEST2_F(CommandListEventFenceTestsXeHpcCore, givenCommandListWithProfilingEventAfterCommandWhenRevId03ThenMiFenceIsAdded, IsXeHpcCore) {

shared/source/memory_manager/prefetch_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PrefetchManager : public NonCopyableOrMovableClass {
2727

2828
void insertAllocation(SvmAllocationData &svmData);
2929

30-
void migrateAllocationsToGpu(SVMAllocsManager &unifiedMemoryManager, Device &device);
30+
MOCKABLE_VIRTUAL void migrateAllocationsToGpu(SVMAllocsManager &unifiedMemoryManager, Device &device);
3131

3232
protected:
3333
std::vector<SvmAllocationData> allocations;

shared/test/unit_test/memory_manager/mock_prefetch_manager.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
#pragma once
99

1010
#include "shared/source/memory_manager/prefetch_manager.h"
11+
#include "shared/source/memory_manager/unified_memory_manager.h"
1112

1213
using namespace NEO;
1314

1415
class MockPrefetchManager : public PrefetchManager {
1516
public:
1617
using PrefetchManager::allocations;
18+
19+
void migrateAllocationsToGpu(SVMAllocsManager &unifiedMemoryManager, Device &device) override {
20+
PrefetchManager::migrateAllocationsToGpu(unifiedMemoryManager, device);
21+
migrateAllocationsToGpuCalled = true;
22+
}
23+
24+
bool migrateAllocationsToGpuCalled = false;
1725
};

0 commit comments

Comments
 (0)