Refactor: pass root device environment to gmm client context

Related-To: NEO-6853
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-11-25 07:53:05 +00:00
committed by Compute-Runtime-Automation
parent ba9c50694d
commit 27cb39ef25
24 changed files with 150 additions and 156 deletions

View File

@ -283,7 +283,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
DirectSubmissionControllerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct GmmHelperMock : public DestructorCounted<GmmHelper, 6> {
GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, nullptr, hwInfo) {}
GmmHelperMock(uint32_t &destructorId, const RootDeviceEnvironment &rootDeviceEnvironment) : DestructorCounted(destructorId, rootDeviceEnvironment) {}
};
struct OsInterfaceMock : public DestructorCounted<OSInterface, 5> {
OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
@ -304,10 +304,8 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
SourceLevelDebuggerMock(uint32_t &destructorId) : DestructorCounted(destructorId, nullptr) {}
};
auto gmmHelper = new GmmHelperMock(destructorId, defaultHwInfo.get());
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->rootDeviceEnvironments[0]->gmmHelper = std::unique_ptr<GmmHelperMock>(gmmHelper);
executionEnvironment->rootDeviceEnvironments[0]->gmmHelper = std::make_unique<GmmHelperMock>(destructorId, *executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OsInterfaceMock>(destructorId);
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<MemoryOperationsHandlerMock>(destructorId);
executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId, *executionEnvironment);

View File

@ -42,6 +42,7 @@ using namespace ::testing;
namespace NEO {
extern GMM_INIT_IN_ARGS passedInputArgs;
extern GT_SYSTEM_INFO passedGtSystemInfo;
extern SKU_FEATURE_TABLE passedFtrTable;
extern WA_TABLE passedWaTable;
extern bool copyInputArgs;
@ -51,9 +52,11 @@ struct GmmTests : public MockExecutionEnvironmentGmmFixtureTest {
MockExecutionEnvironmentGmmFixture::setUp();
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get();
localPlatformDevice = rootDeviceEnvironment->getMutableHardwareInfo();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
}
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
HardwareInfo *localPlatformDevice = nullptr;
GmmHelper *gmmHelper = nullptr;
};
TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) {
@ -350,11 +353,13 @@ TEST_F(GmmTests, givenNonZeroRowPitchWhenQueryImgFromBufferParamsThenUseUserValu
using GmmCanonizeTests = GmmTests;
TEST_F(GmmCanonizeTests, WhenCanonizingThenCorrectAddressIsReturned) {
auto hwInfo = *defaultHwInfo;
auto &hwInfo = *rootDeviceEnvironment->getMutableHardwareInfo();
// 48 bit - canonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr1 = 0x7777777777777777;
uint64_t goodAddr1 = 0x0000777777777777;
@ -366,18 +371,22 @@ TEST_F(GmmCanonizeTests, WhenCanonizingThenCorrectAddressIsReturned) {
// 36 bit - also canonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
EXPECT_EQ(gmmHelper->canonize(testAddr1), goodAddr1);
EXPECT_EQ(gmmHelper->canonize(testAddr2), goodAddr2);
}
TEST_F(GmmCanonizeTests, WhenDecanonizingThenCorrectAddressIsReturned) {
auto hwInfo = *defaultHwInfo;
auto &hwInfo = *rootDeviceEnvironment->getMutableHardwareInfo();
// 48 bit - decanonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr1 = 0x7777777777777777;
uint64_t goodAddr1 = 0x0000777777777777;
@ -389,18 +398,22 @@ TEST_F(GmmCanonizeTests, WhenDecanonizingThenCorrectAddressIsReturned) {
// 36 bit - also decanonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
EXPECT_EQ(gmmHelper->decanonize(testAddr1), goodAddr1);
EXPECT_EQ(gmmHelper->decanonize(testAddr2), goodAddr2);
}
TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddressesReturnTrue) {
auto hwInfo = *defaultHwInfo;
auto &hwInfo = *rootDeviceEnvironment->getMutableHardwareInfo();
// 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr1 = 0x0000400000000000;
EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr1));
@ -416,7 +429,9 @@ TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddr
// 36 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr5 = 0x0000000400000000;
EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr5));
@ -432,7 +447,9 @@ TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddr
// 57 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57); // 0x01FFFFFFFFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo);
rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr9 = 0x0080000000000000;
EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr9));
@ -1027,31 +1044,31 @@ struct GmmHelperTests : MockExecutionEnvironmentGmmFixtureTest {
};
TEST_F(GmmHelperTests, givenValidGmmFunctionsWhenCreateGmmHelperWithInitializedOsInterfaceThenProperParametersArePassed) {
std::unique_ptr<GmmHelper> gmmHelper;
DeviceFactory::prepareDeviceEnvironments(*executionEnvironment);
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(passedFtrTable)> passedFtrTableBackup(&passedFtrTable);
VariableBackup<decltype(passedGtSystemInfo)> passedGtSystemInfoBackup(&passedGtSystemInfo);
VariableBackup<decltype(passedWaTable)> passedWaTableBackup(&passedWaTable);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
auto hwInfo = defaultHwInfo.get();
auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
SKU_FEATURE_TABLE expectedFtrTable = {};
WA_TABLE expectedWaTable = {};
SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable);
SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable);
gmmHelper.reset(new GmmHelper(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), hwInfo));
auto gmmHelper = std::make_unique<GmmHelper>(*executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM)));
EXPECT_EQ(&hwInfo->gtSystemInfo, passedInputArgs.pGtSysInfo);
EXPECT_EQ(0, memcmp(&hwInfo->gtSystemInfo, &passedGtSystemInfo, sizeof(GT_SYSTEM_INFO)));
EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE)));
EXPECT_EQ(0, memcmp(&expectedWaTable, &passedWaTable, sizeof(WA_TABLE)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
}
TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceThenInitializationDoesntCrashAndProperParametersArePassed) {
std::unique_ptr<GmmHelper> gmmHelper;
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(passedFtrTable)> passedFtrTableBackup(&passedFtrTable);
VariableBackup<decltype(passedGtSystemInfo)> passedGtSystemInfoBackup(&passedGtSystemInfo);
VariableBackup<decltype(passedWaTable)> passedWaTableBackup(&passedWaTable);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
@ -1061,9 +1078,10 @@ TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceT
SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable);
SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable);
gmmHelper.reset(new GmmHelper(nullptr, hwInfo));
MockExecutionEnvironment executionEnvironment{hwInfo};
EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0]->osInterface.get());
EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM)));
EXPECT_EQ(&hwInfo->gtSystemInfo, passedInputArgs.pGtSysInfo);
EXPECT_EQ(0, memcmp(&hwInfo->gtSystemInfo, &passedGtSystemInfo, sizeof(GT_SYSTEM_INFO)));
EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE)));
EXPECT_EQ(0, memcmp(&expectedWaTable, &passedWaTable, sizeof(WA_TABLE)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
@ -1073,9 +1091,8 @@ TEST(GmmHelperTest, givenGmmHelperAndL3CacheDisabledForDebugThenCorrectMOCSIsRet
decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc;
GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>;
std::unique_ptr<GmmHelper> gmmHelper;
auto hwInfo = defaultHwInfo.get();
gmmHelper.reset(new GmmHelper(nullptr, hwInfo));
MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));
@ -1101,9 +1118,8 @@ TEST(GmmHelperTest, givenGmmHelperAndForceAllResourcesUncachedDebugVariableSetTh
decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc;
GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>;
std::unique_ptr<GmmHelper> gmmHelper;
auto hwInfo = defaultHwInfo.get();
gmmHelper.reset(new GmmHelper(nullptr, hwInfo));
MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -45,13 +45,13 @@ TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenFileDescriptorIsSetWi
}
TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedFileDescriptorIsZeroed) {
std::unique_ptr<GmmHelper> gmmHelper;
MockExecutionEnvironment executionEnvironment{};
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
uint32_t expectedFileDescriptor = 0u;
gmmHelper.reset(new GmmHelper(nullptr, defaultHwInfo.get()));
auto gmmHelper = std::make_unique<GmmHelper>(*executionEnvironment.rootDeviceEnvironments[0]);
EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor);
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
}

View File

@ -127,8 +127,9 @@ TEST(GraphicsAllocationTest, WhenAllocationIsCreatedThenItsAddressIsCorrect) {
TEST(GraphicsAllocationTest, GivenNonSharedResourceHandleWhenAllocationIsCreatedThenItsAddressIsCorrect) {
void *cpuPtr = (void *)0x30000;
size_t size = 0x1000;
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper.canonize(castToUint64(cpuPtr));
MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(cpuPtr));
osHandle sharedHandle = Sharing::nonSharedResource;
GraphicsAllocation gfxAllocation(0, AllocationType::UNKNOWN, cpuPtr, size, sharedHandle, MemoryPool::MemoryNull, 0u, canonizedGpuAddress);
uint64_t expectedGpuAddr = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gfxAllocation.getUnderlyingBuffer()));
@ -150,7 +151,8 @@ TEST(GraphicsAllocationTest, WhenGettingAddressesThenAddressesAreCorrect) {
cpuPtr = (void *)65535;
gpuAddr = 1ULL;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddr);
gfxAllocation.setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
@ -340,7 +342,6 @@ TEST_F(MemoryAllocatorTest, WhenPopulatingOsHandleThenOneFragmentIsReturned) {
TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubManagerIsNotAvailableThenFreeMemoryIsNotCalledOnAubManager) {
MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get());
MockMemoryManager mockMemoryManager(mockExecutionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
auto mockAubCenter = new MockAubCenter(*mockExecutionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager.reset(nullptr);
mockExecutionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
@ -360,7 +361,6 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageAndFreeMemoryEnabledWhenOsHandle
const uint32_t rootDeviceIndex = 1u;
MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get(), true, 3);
MockMemoryManager mockMemoryManager(mockExecutionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
auto mockManager0 = new MockAubManager();
auto mockAubCenter0 = new MockAubCenter(*mockExecutionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter0->aubManager.reset(mockManager0);
@ -1598,7 +1598,6 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryEnabledWh
DebugManager.flags.EnableFreeMemory.set(true);
MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager);
@ -1615,7 +1614,6 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryDisabledW
DebugManager.flags.EnableFreeMemory.set(false);
MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager);
@ -2195,8 +2193,9 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation
void *addressWithTrailingBitSet = reinterpret_cast<void *>(address);
uint64_t expectedGpuAddress = 0xf0000000;
osHandle sharedHandle{};
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper.canonize(castToUint64(addressWithTrailingBitSet));
MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(addressWithTrailingBitSet));
GraphicsAllocation graphicsAllocation(0, AllocationType::UNKNOWN, addressWithTrailingBitSet, 1u, sharedHandle, MemoryPool::MemoryNull, 0u, canonizedGpuAddress);
EXPECT_EQ(expectedGpuAddress, graphicsAllocation.getGpuAddress());
}