1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/*
* Copyright (C) 2022-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/memory_manager/prefetch_manager.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/memory_manager/mock_prefetch_manager.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_svm_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(PrefetchManagerTests, givenPrefetchManagerWhenCallingInterfaceFunctionsThenUpdateAllocationsInPrefetchContext) {
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
auto device = deviceFactory->rootDevices[0];
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto prefetchManager = std::make_unique<MockPrefetchManager>();
PrefetchContext prefetchContext;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, nullptr);
ASSERT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
EXPECT_EQ(0u, prefetchContext.allocations.size());
prefetchManager->insertAllocation(prefetchContext, ptr, *svmData);
EXPECT_EQ(1u, prefetchContext.allocations.size());
prefetchManager->migrateAllocationsToGpu(prefetchContext, *svmManager.get(), *device, *csr.get());
EXPECT_EQ(1u, prefetchContext.allocations.size());
prefetchManager->removeAllocations(prefetchContext);
EXPECT_EQ(0u, prefetchContext.allocations.size());
svmManager->freeSVMAlloc(ptr);
}
TEST(PrefetchManagerTests, givenPrefetchManagerWhenCallingMigrateAllocationsToGpuThenPrefetchMemoryForValidSVMAllocPtrs) {
DebugManagerStateRestore restore;
debugManager.flags.UseKmdMigration.set(1);
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
auto device = deviceFactory->rootDevices[0];
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto prefetchManager = std::make_unique<MockPrefetchManager>();
PrefetchContext prefetchContext;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, nullptr);
ASSERT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
prefetchManager->insertAllocation(prefetchContext, ptr, *svmData);
EXPECT_FALSE(prefetchManager->migrateAllocationsToGpuCalled);
EXPECT_FALSE(svmManager->prefetchMemoryCalled);
prefetchManager->migrateAllocationsToGpu(prefetchContext, *svmManager.get(), *device, *csr.get());
EXPECT_TRUE(prefetchManager->migrateAllocationsToGpuCalled);
EXPECT_TRUE(svmManager->prefetchMemoryCalled);
svmManager->freeSVMAlloc(ptr);
prefetchManager->migrateAllocationsToGpuCalled = false;
svmManager->prefetchMemoryCalled = false;
prefetchManager->migrateAllocationsToGpu(prefetchContext, *svmManager.get(), *device, *csr.get());
EXPECT_TRUE(prefetchManager->migrateAllocationsToGpuCalled);
EXPECT_FALSE(svmManager->prefetchMemoryCalled);
}
|