diff --git a/level_zero/core/test/unit_tests/fixtures/module_fixture.cpp b/level_zero/core/test/unit_tests/fixtures/module_fixture.cpp index c33c579373..ff8fddf6c9 100644 --- a/level_zero/core/test/unit_tests/fixtures/module_fixture.cpp +++ b/level_zero/core/test/unit_tests/fixtures/module_fixture.cpp @@ -8,7 +8,6 @@ #include "level_zero/core/test/unit_tests/fixtures/module_fixture.h" #include "shared/source/command_container/implicit_scaling.h" -#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "gtest/gtest.h" @@ -18,33 +17,7 @@ namespace ult { ModuleImmutableDataFixture::MockImmutableMemoryManager::MockImmutableMemoryManager(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast(executionEnvironment)) {} -ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize) { - mockKernelDescriptor = new NEO::KernelDescriptor; - mockKernelDescriptor->kernelAttributes.perHwThreadPrivateMemorySize = perHwThreadPrivateMemorySize; - kernelDescriptor = mockKernelDescriptor; - - mockKernelInfo = new NEO::KernelInfo; - mockKernelInfo->heapInfo.pKernelHeap = kernelHeap; - mockKernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize; - kernelInfo = mockKernelInfo; - - if (getIsaGraphicsAllocation() != nullptr) { - device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation); - isaGraphicsAllocation.release(); - } - auto ptr = reinterpret_cast(0x1234); - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0, - NEO::AllocationType::KERNEL_ISA, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress)); - kernelInfo->kernelAllocation = isaGraphicsAllocation.get(); -} +ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize) : MockImmutableData(perHwThreadPrivateMemorySize, 0, 0) {} ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize, uint32_t perThreadScratchSize, uint32_t perThreaddPrivateScratchSize) { mockKernelDescriptor = new NEO::KernelDescriptor; mockKernelDescriptor->kernelAttributes.perHwThreadPrivateMemorySize = perHwThreadPrivateMemorySize; @@ -57,13 +30,7 @@ ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwT mockKernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize; kernelInfo = mockKernelInfo; - if (getIsaGraphicsAllocation() != nullptr) { - device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation); - isaGraphicsAllocation.release(); - } auto ptr = reinterpret_cast(0x1234); - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0, NEO::AllocationType::KERNEL_ISA, ptr, @@ -71,7 +38,7 @@ ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwT 0u, MemoryPool::System4KBPages, MemoryManager::maxOsContextCount, - canonizedGpuAddress)); + castToUint64(ptr))); kernelInfo->kernelAllocation = isaGraphicsAllocation.get(); } @@ -247,8 +214,6 @@ ModuleWithZebinFixture::MockImmutableData::MockImmutableData(L0::Device *device) kernelDescriptor = mockKernelDescriptor; this->device = device; auto ptr = reinterpret_cast(0x1234); - auto gmmHelper = device->getNEODevice()->getGmmHelper(); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0, NEO::AllocationType::KERNEL_ISA, ptr, @@ -256,7 +221,7 @@ ModuleWithZebinFixture::MockImmutableData::MockImmutableData(L0::Device *device) 0u, MemoryPool::System4KBPages, MemoryManager::maxOsContextCount, - canonizedGpuAddress)); + castToUint64(ptr))); } ModuleWithZebinFixture::MockImmutableData::~MockImmutableData() { @@ -269,8 +234,7 @@ ModuleWithZebinFixture::MockModuleWithZebin::MockModuleWithZebin(L0::Device *dev void ModuleWithZebinFixture::MockModuleWithZebin::addSegments() { kernelImmDatas.push_back(std::make_unique(device)); auto ptr = reinterpret_cast(0x1234); - auto gmmHelper = device->getNEODevice()->getGmmHelper(); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto canonizedGpuAddress = castToUint64(ptr); translationUnit->globalVarBuffer = new NEO::MockGraphicsAllocation(0, NEO::AllocationType::GLOBAL_SURFACE, ptr, diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 4b56c2c010..32416db926 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -283,7 +283,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe DirectSubmissionControllerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; struct GmmHelperMock : public DestructorCounted { - 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 { 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(); - executionEnvironment->rootDeviceEnvironments[0]->gmmHelper = std::unique_ptr(gmmHelper); + executionEnvironment->rootDeviceEnvironments[0]->gmmHelper = std::make_unique(destructorId, *executionEnvironment->rootDeviceEnvironments[0]); executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(destructorId); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId, *executionEnvironment); diff --git a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp index fcaece1d52..f855702067 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -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(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(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(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(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(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(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(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; DeviceFactory::prepareDeviceEnvironments(*executionEnvironment); VariableBackup passedInputArgsBackup(&passedInputArgs); VariableBackup passedFtrTableBackup(&passedFtrTable); + VariableBackup passedGtSystemInfoBackup(&passedGtSystemInfo); VariableBackup passedWaTableBackup(&passedWaTable); VariableBackup copyInputArgsBackup(©InputArgs, 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(*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; VariableBackup passedInputArgsBackup(&passedInputArgs); VariableBackup passedFtrTableBackup(&passedFtrTable); + VariableBackup passedGtSystemInfoBackup(&passedGtSystemInfo); VariableBackup passedWaTableBackup(&passedWaTable); VariableBackup copyInputArgsBackup(©InputArgs, 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; - std::unique_ptr 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; - std::unique_ptr 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)); diff --git a/opencl/test/unit_test/linux/os_interface_linux_tests.cpp b/opencl/test/unit_test/linux/os_interface_linux_tests.cpp index 9cebcea1f1..3f25b18b2e 100644 --- a/opencl/test/unit_test/linux/os_interface_linux_tests.cpp +++ b/opencl/test/unit_test/linux/os_interface_linux_tests.cpp @@ -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; + MockExecutionEnvironment executionEnvironment{}; VariableBackup passedInputArgsBackup(&passedInputArgs); VariableBackup copyInputArgsBackup(©InputArgs, true); uint32_t expectedFileDescriptor = 0u; - gmmHelper.reset(new GmmHelper(nullptr, defaultHwInfo.get())); + auto gmmHelper = std::make_unique(*executionEnvironment.rootDeviceEnvironments[0]); EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); } diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 112f0c6c92..6b367f06ad 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -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(reinterpret_cast(gfxAllocation.getUnderlyingBuffer())); @@ -150,7 +151,8 @@ TEST(GraphicsAllocationTest, WhenGettingAddressesThenAddressesAreCorrect) { cpuPtr = (void *)65535; gpuAddr = 1ULL; - auto gmmHelper = std::make_unique(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(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(mockManager); @@ -2195,8 +2193,9 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation void *addressWithTrailingBitSet = reinterpret_cast(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()); } diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index 3b7f775f8a..ff199519c8 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -110,7 +110,7 @@ bool RootDeviceEnvironment::initAilConfiguration() { void RootDeviceEnvironment::initGmm() { if (!gmmHelper) { - gmmHelper.reset(new GmmHelper(osInterface.get(), getHardwareInfo())); + gmmHelper.reset(new GmmHelper(*this)); } } diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.cpp b/shared/source/gmm_helper/client_context/gmm_client_context.cpp index 552f6b8110..7fdc5aa3aa 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context.cpp @@ -7,6 +7,8 @@ #include "shared/source/gmm_helper/client_context/gmm_client_context.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" #include "shared/source/gmm_helper/gmm_interface.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/hw_info.h" @@ -14,21 +16,23 @@ #include "shared/source/sku_info/operations/sku_info_transfer.h" namespace NEO { -GmmClientContext::GmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo) : hardwareInfo(hwInfo) { +GmmClientContext::GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment) : hardwareInfo(rootDeviceEnvironment.getHardwareInfo()) { _SKU_FEATURE_TABLE gmmFtrTable = {}; _WA_TABLE gmmWaTable = {}; - SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, &hwInfo->featureTable); - SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, &hwInfo->workaroundTable); + SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, &hardwareInfo->featureTable); + SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, &hardwareInfo->workaroundTable); GMM_INIT_IN_ARGS inArgs{}; GMM_INIT_OUT_ARGS outArgs{}; + auto gtSystemInfo = hardwareInfo->gtSystemInfo; inArgs.ClientType = GMM_CLIENT::GMM_OCL_VISTA; - inArgs.pGtSysInfo = &hwInfo->gtSystemInfo; + inArgs.pGtSysInfo = >SystemInfo; inArgs.pSkuTable = &gmmFtrTable; inArgs.pWaTable = &gmmWaTable; - inArgs.Platform = hwInfo->platform; + inArgs.Platform = hardwareInfo->platform; + auto osInterface = rootDeviceEnvironment.osInterface.get(); if (osInterface && osInterface->getDriverModel()) { osInterface->getDriverModel()->setGmmInputArgs(&inArgs); } @@ -86,5 +90,8 @@ uint32_t GmmClientContext::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResource return patIndex; } +void GmmClientContext::setHandleAllocator(std::unique_ptr allocator) { + this->handleAllocator = std::move(allocator); +} } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.h b/shared/source/gmm_helper/client_context/gmm_client_context.h index 9d00ad4e05..9a4c0ebe53 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.h +++ b/shared/source/gmm_helper/client_context/gmm_client_context.h @@ -6,19 +6,19 @@ */ #pragma once -#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" #include "shared/source/gmm_helper/gmm_lib.h" #include namespace NEO { class GmmClientContext; -class OSInterface; +struct RootDeviceEnvironment; struct HardwareInfo; +class GmmHandleAllocator; class GmmClientContext { public: - GmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo); + GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment); MOCKABLE_VIRTUAL ~GmmClientContext(); MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage); @@ -29,8 +29,8 @@ class GmmClientContext { MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo); GMM_CLIENT_CONTEXT *getHandle() const; template - static std::unique_ptr create(OSInterface *osInterface, HardwareInfo *hwInfo) { - return std::make_unique(osInterface, hwInfo); + static std::unique_ptr create(const RootDeviceEnvironment &rootDeviceEnvironment) { + return std::make_unique(rootDeviceEnvironment); } const HardwareInfo *getHardwareInfo() { @@ -40,9 +40,7 @@ class GmmClientContext { MOCKABLE_VIRTUAL uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); MOCKABLE_VIRTUAL uint8_t getMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); - void setHandleAllocator(std::unique_ptr allocator) { - this->handleAllocator = std::move(allocator); - } + void setHandleAllocator(std::unique_ptr allocator); MOCKABLE_VIRTUAL void setGmmDeviceInfo(GMM_DEVICE_INFO *deviceInfo); @@ -51,7 +49,7 @@ class GmmClientContext { } protected: - HardwareInfo *hardwareInfo = nullptr; + const HardwareInfo *hardwareInfo = nullptr; GMM_CLIENT_CONTEXT *clientContext; std::unique_ptr handleAllocator; }; diff --git a/shared/source/gmm_helper/client_context/gmm_handle_allocator.h b/shared/source/gmm_helper/client_context/gmm_handle_allocator.h index 036ac3460e..0a08ba1a5d 100644 --- a/shared/source/gmm_helper/client_context/gmm_handle_allocator.h +++ b/shared/source/gmm_helper/client_context/gmm_handle_allocator.h @@ -7,7 +7,7 @@ #pragma once -#include "shared/source/gmm_helper/gmm.h" +#include "shared/source/gmm_helper/gmm_lib.h" #include @@ -30,4 +30,4 @@ class GmmHandleAllocator { } }; -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/gmm_helper/gmm_helper.cpp b/shared/source/gmm_helper/gmm_helper.cpp index b4aa915f7d..65e190a0b6 100644 --- a/shared/source/gmm_helper/gmm_helper.cpp +++ b/shared/source/gmm_helper/gmm_helper.cpp @@ -8,6 +8,7 @@ #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/hw_helper.h" @@ -42,11 +43,11 @@ void GmmHelper::applyMocsEncryptionBit(uint32_t &index) { } } -GmmHelper::GmmHelper(OSInterface *osInterface, const HardwareInfo *pHwInfo) : hwInfo(pHwInfo) { +GmmHelper::GmmHelper(const RootDeviceEnvironment &rootDeviceEnvironment) : hwInfo(rootDeviceEnvironment.getHardwareInfo()) { auto hwInfoAddressWidth = Math::log2(hwInfo->capabilityTable.gpuAddressSpace + 1); addressWidth = std::max(hwInfoAddressWidth, 48u); - gmmClientContext = GmmHelper::createGmmContextWrapperFunc(osInterface, const_cast(pHwInfo)); + gmmClientContext = GmmHelper::createGmmContextWrapperFunc(rootDeviceEnvironment); UNRECOVERABLE_IF(!gmmClientContext); } diff --git a/shared/source/gmm_helper/gmm_helper.h b/shared/source/gmm_helper/gmm_helper.h index 38cddb5b0d..1efaf0f56d 100644 --- a/shared/source/gmm_helper/gmm_helper.h +++ b/shared/source/gmm_helper/gmm_helper.h @@ -11,13 +11,13 @@ namespace NEO { class GmmClientContext; -class OSInterface; struct HardwareInfo; +struct RootDeviceEnvironment; class GmmHelper { public: GmmHelper() = delete; - GmmHelper(OSInterface *osInterface, const HardwareInfo *hwInfo); + GmmHelper(const RootDeviceEnvironment &rootDeviceEnvironment); MOCKABLE_VIRTUAL ~GmmHelper(); const HardwareInfo *getHardwareInfo(); @@ -37,7 +37,7 @@ class GmmHelper { GmmClientContext *getClientContext() const; - static std::unique_ptr (*createGmmContextWrapperFunc)(OSInterface *, HardwareInfo *); + static std::unique_ptr (*createGmmContextWrapperFunc)(const RootDeviceEnvironment &); protected: uint32_t addressWidth; diff --git a/shared/source/gmm_helper/resource_info_impl.cpp b/shared/source/gmm_helper/resource_info_impl.cpp index b846891902..877897a14e 100644 --- a/shared/source/gmm_helper/resource_info_impl.cpp +++ b/shared/source/gmm_helper/resource_info_impl.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/gmm_helper/client_context/gmm_client_context.h" +#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h" #include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/debug_helpers.h" diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index fb5a4bba42..7e481fec6a 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -5,7 +5,7 @@ * */ -#include "drm_neo.h" +#include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/command_stream/submission_status.h" #include "shared/source/debug_settings/debug_settings_manager.h" @@ -13,6 +13,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h" +#include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/constants.h" #include "shared/source/helpers/debug_helpers.h" diff --git a/shared/test/common/mock_gmm/mock_gmm.cpp b/shared/test/common/mock_gmm/mock_gmm.cpp index 16401e92a6..f901f5c84b 100644 --- a/shared/test/common/mock_gmm/mock_gmm.cpp +++ b/shared/test/common/mock_gmm/mock_gmm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,7 @@ namespace NEO { GMM_INIT_IN_ARGS passedInputArgs = {}; +GT_SYSTEM_INFO passedGtSystemInfo = {}; SKU_FEATURE_TABLE passedFtrTable = {}; WA_TABLE passedWaTable = {}; bool copyInputArgs = false; @@ -23,6 +24,7 @@ GMM_STATUS initialize(GMM_INIT_IN_ARGS *pInArgs, GMM_INIT_OUT_ARGS *pOutArgs) { } if (copyInputArgs) { passedInputArgs = *pInArgs; + passedGtSystemInfo = *reinterpret_cast(pInArgs->pGtSysInfo); passedFtrTable = *reinterpret_cast(pInArgs->pSkuTable); passedWaTable = *reinterpret_cast(pInArgs->pWaTable); } diff --git a/shared/test/common/mocks/mock_gmm_client_context.cpp b/shared/test/common/mocks/mock_gmm_client_context.cpp index 5123a8bb31..0b83622f49 100644 --- a/shared/test/common/mocks/mock_gmm_client_context.cpp +++ b/shared/test/common/mocks/mock_gmm_client_context.cpp @@ -8,8 +8,6 @@ #include "mock_gmm_client_context.h" namespace NEO { -MockGmmClientContext::MockGmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo) : MockGmmClientContextBase(osInterface, hwInfo) { -} MEMORY_OBJECT_CONTROL_STATE MockGmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { MEMORY_OBJECT_CONTROL_STATE retVal = {}; diff --git a/shared/test/common/mocks/mock_gmm_client_context.h b/shared/test/common/mocks/mock_gmm_client_context.h index 29d7e30fc2..d18c5da342 100644 --- a/shared/test/common/mocks/mock_gmm_client_context.h +++ b/shared/test/common/mocks/mock_gmm_client_context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,6 @@ namespace NEO { class MockGmmClientContext : public MockGmmClientContextBase { public: - MockGmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo); + using MockGmmClientContextBase::MockGmmClientContextBase; }; } // namespace NEO diff --git a/shared/test/common/os_interface/linux/drm_command_stream_fixture.h b/shared/test/common/os_interface/linux/drm_command_stream_fixture.h index 660e9b2988..e9bab7b48c 100644 --- a/shared/test/common/os_interface/linux/drm_command_stream_fixture.h +++ b/shared/test/common/os_interface/linux/drm_command_stream_fixture.h @@ -46,6 +46,7 @@ class DrmCommandStreamTest : public ::testing::Test { executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); executionEnvironment.rootDeviceEnvironments[0]->initGmm(); + gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo)); osContext = std::make_unique(*mock, 0, 0u, @@ -95,6 +96,7 @@ class DrmCommandStreamTest : public ::testing::Test { DebugManagerStateRestore dbgState; MockExecutionEnvironment executionEnvironment; std::unique_ptr osContext; + GmmHelper *gmmHelper = nullptr; }; template diff --git a/shared/test/unit_test/command_stream/linear_stream_tests.cpp b/shared/test/unit_test/command_stream/linear_stream_tests.cpp index 73de6701aa..da0da71e3a 100644 --- a/shared/test/unit_test/command_stream/linear_stream_tests.cpp +++ b/shared/test/unit_test/command_stream/linear_stream_tests.cpp @@ -10,6 +10,7 @@ #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/fixtures/linear_stream_fixture.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" using namespace NEO; @@ -42,7 +43,8 @@ TEST(LinearStreamSimpleTest, givenLinearStreamWithoutGraphicsAllocationWhenGetti TEST(LinearStreamSimpleTest, givenLinearStreamWithGraphicsAllocationWhenGettingGpuBaseThenGpuAddressFromGraphicsAllocationIsReturned) { MockGraphicsAllocation gfxAllocation; - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); + auto executionEnvironment = MockExecutionEnvironment{}; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); auto canonizedGpuAddress = gmmHelper->canonize(0x5555000); gfxAllocation.setCpuPtrAndGpuAddress(nullptr, canonizedGpuAddress); diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp index 7dde6d2a9e..7472a7f79c 100644 --- a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp @@ -10,11 +10,12 @@ #include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/constants.h" #include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_gmm_client_context.h" #include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/test_macros/hw_test.h" -extern PRODUCT_FAMILY productFamily; +using namespace NEO; struct MockGmmHandleAllocator : NEO::GmmHandleAllocator { void *createHandle(const GMM_RESOURCE_INFO *gmmResourceInfo) override { @@ -40,9 +41,9 @@ struct MockGmmHandleAllocator : NEO::GmmHandleAllocator { }; TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreatingGmmResourceInfoHandles) { - NEO::HardwareInfo hwInfo; - hwInfo.platform.eProductFamily = productFamily; - NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; + auto hwInfo = *defaultHwInfo; + MockExecutionEnvironment executionEnvironment{&hwInfo}; + NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]}; gmmClientCtx.setHandleAllocator(std::make_unique()); auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); @@ -73,9 +74,9 @@ TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreating } TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenDecodingResourceInfoThenExistingHandleIsOpened) { - NEO::HardwareInfo hwInfo; - hwInfo.platform.eProductFamily = productFamily; - NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; + auto hwInfo = *defaultHwInfo; + MockExecutionEnvironment executionEnvironment{&hwInfo}; + NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]}; gmmClientCtx.setHandleAllocator(std::make_unique()); auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); @@ -131,9 +132,9 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD } TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) { - NEO::HardwareInfo hwInfo; - hwInfo.platform.eProductFamily = productFamily; - NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; + auto hwInfo = *defaultHwInfo; + MockExecutionEnvironment executionEnvironment{&hwInfo}; + NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]}; gmmClientCtx.setHandleAllocator(std::make_unique()); auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); @@ -206,23 +207,28 @@ TEST(GmmResourceInfo, GivenEmptyHandleWhenUsingBaseHandleAllocatorThenOpenHandle } TEST(GmmHelperTests, WhenInitializingGmmHelperThenCorrectAddressWidthIsSet) { - auto hwInfo = *NEO::defaultHwInfo; + auto hwInfo = *defaultHwInfo; + { + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); + MockExecutionEnvironment executionEnvironment{&hwInfo}; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); - hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); - auto gmmHelper = std::make_unique(nullptr, &hwInfo); + auto addressWidth = gmmHelper->getAddressWidth(); + EXPECT_EQ(48u, addressWidth); + } + { + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); + MockExecutionEnvironment executionEnvironment{&hwInfo}; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); - auto addressWidth = gmmHelper->getAddressWidth(); - EXPECT_EQ(48u, addressWidth); - - hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); - gmmHelper = std::make_unique(nullptr, &hwInfo); - - addressWidth = gmmHelper->getAddressWidth(); - EXPECT_EQ(48u, addressWidth); - - hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57); - gmmHelper = std::make_unique(nullptr, &hwInfo); - - addressWidth = gmmHelper->getAddressWidth(); - EXPECT_EQ(57u, addressWidth); -} \ No newline at end of file + auto addressWidth = gmmHelper->getAddressWidth(); + EXPECT_EQ(48u, addressWidth); + } + { + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57); + MockExecutionEnvironment executionEnvironment{&hwInfo}; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); + auto addressWidth = gmmHelper->getAddressWidth(); + EXPECT_EQ(57u, addressWidth); + } +} diff --git a/shared/test/unit_test/helpers/dirty_state_helpers_tests.cpp b/shared/test/unit_test/helpers/dirty_state_helpers_tests.cpp index 33454e3a09..7d1ad0a16a 100644 --- a/shared/test/unit_test/helpers/dirty_state_helpers_tests.cpp +++ b/shared/test/unit_test/helpers/dirty_state_helpers_tests.cpp @@ -11,6 +11,7 @@ #include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "gtest/gtest.h" @@ -66,7 +67,8 @@ TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenAddressChangedThenReturnDirty auto newBuffer = ptrOffset(buffer, MemoryConstants::pageSize + 1); auto graphicsAllocation = stream->getGraphicsAllocation(); - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); + MockExecutionEnvironment executionEnvironment{}; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer)); graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, canonizedGpuAddress); @@ -106,7 +108,8 @@ TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenSizeAndBufferChangedThenRetur auto newBuffer = ptrOffset(buffer, 1); auto newBufferSize = bufferSize + MemoryConstants::pageSize; auto graphicsAllocation = stream->getGraphicsAllocation(); - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); + MockExecutionEnvironment executionEnvironment{}; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer)); graphicsAllocation->setSize(newBufferSize); diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp index 65ef67f795..bac34dde9c 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp @@ -232,8 +232,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTest, GivenInvalidAddressWhenFlushingThenSucc char *commandBuffer = new (std::nothrow) char[1024]; ASSERT_NE(nullptr, commandBuffer); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) - GmmHelper gmmHelper(nullptr, defaultHwInfo.get()); - auto canonizedGpuAddress = gmmHelper.canonize(castToUint64(commandBuffer)); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(commandBuffer)); DrmAllocation commandBufferAllocation(0, AllocationType::COMMAND_BUFFER, nullptr, commandBuffer, 1024, static_cast(1u), MemoryPool::MemoryNull, canonizedGpuAddress); LinearStream cs(&commandBufferAllocation); @@ -1067,4 +1066,4 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenPrintBOsForSubmitAndFailur std::string output = testing::internal::GetCapturedStdout(); EXPECT_TRUE(output.empty()); -} \ No newline at end of file +} diff --git a/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp b/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp index 6bb337d666..f4a8bd978f 100644 --- a/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp @@ -28,7 +28,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages); - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); + auto gmmHelper = executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(); auto canonizedGpuAddress = gmmHelper->canonize(0x12345); allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress); @@ -79,7 +79,7 @@ TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInstead DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages); - auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); + auto gmmHelper = executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(); auto canonizedGpuAddress = gmmHelper->canonize(0x12345); allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress); diff --git a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp index b6d8ab77a7..0fa199b9f4 100644 --- a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp +++ b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp @@ -201,21 +201,20 @@ NTSTATUS __stdcall getDeviceStateMock(D3DKMT_GETDEVICESTATE *arg) { struct WddmLinuxTest : public ::testing::Test { void SetUp() override { - mockRootDeviceEnvironment = std::make_unique(mockExecEnv); osEnvironment = std::make_unique(); osEnvironment->gdi->closeAdapter = closeAdapterMock; auto hwDeviceIdIn = std::make_unique(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique()); this->hwDeviceId = hwDeviceIdIn.get(); - - auto wddm = std::make_unique(std::move(hwDeviceIdIn), *mockRootDeviceEnvironment.get()); + auto &rootDeviceEnvironment = *mockExecEnv.rootDeviceEnvironments[0]; + auto wddm = std::make_unique(std::move(hwDeviceIdIn), rootDeviceEnvironment); this->wddm = wddm.get(); - mockGmmClientContext = NEO::GmmClientContext::create(nullptr, NEO::defaultHwInfo.get()); - wddm->gmmMemory = std::make_unique(mockGmmClientContext.get()); + auto gmmHelper = rootDeviceEnvironment.getGmmHelper(); + + wddm->gmmMemory = std::make_unique(gmmHelper->getClientContext()); *wddm->gfxPlatform = NEO::defaultHwInfo->platform; - mockExecEnv.rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface); - mockExecEnv.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(wddm)); - mockExecEnv.rootDeviceEnvironments[0]->gmmHelper.reset(new NEO::GmmHelper(mockExecEnv.rootDeviceEnvironments[0]->osInterface.get(), mockExecEnv.rootDeviceEnvironments[0]->getHardwareInfo())); + rootDeviceEnvironment.osInterface.reset(new NEO::OSInterface); + rootDeviceEnvironment.osInterface->setDriverModel(std::move(wddm)); } size_t getMaxSvmSize() const { @@ -231,10 +230,8 @@ struct WddmLinuxTest : public ::testing::Test { std::unique_ptr osEnvironment; NEO::MockExecutionEnvironment mockExecEnv; - std::unique_ptr mockRootDeviceEnvironment; MockWddmLinux *wddm = nullptr; WddmLinuxMockHwDeviceIdWddm *hwDeviceId = nullptr; - std::unique_ptr mockGmmClientContext; }; using GmmTestsDG2 = WddmLinuxTest; diff --git a/shared/test/unit_test/os_interface/windows/gmm_helper_tests_win.cpp b/shared/test/unit_test/os_interface/windows/gmm_helper_tests_win.cpp index c7cd4477f7..701e68cf20 100644 --- a/shared/test/unit_test/os_interface/windows/gmm_helper_tests_win.cpp +++ b/shared/test/unit_test/os_interface/windows/gmm_helper_tests_win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,7 @@ #include "shared/source/gmm_helper/gmm_lib.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/variable_backup.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "gtest/gtest.h" @@ -18,13 +19,12 @@ extern GMM_INIT_IN_ARGS passedInputArgs; extern bool copyInputArgs; TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedAdapterBDFIsZeroed) { - std::unique_ptr gmmHelper; VariableBackup passedInputArgsBackup(&passedInputArgs); VariableBackup copyInputArgsBackup(©InputArgs, true); ADAPTER_BDF expectedAdapterBDF{}; - gmmHelper.reset(new GmmHelper(nullptr, defaultHwInfo.get())); + MockExecutionEnvironment executionEnvironment{}; EXPECT_EQ(0, memcmp(&expectedAdapterBDF, &passedInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF))); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); }