diff --git a/opencl/test/unit_test/context/driver_diagnostics_tests.cpp b/opencl/test/unit_test/context/driver_diagnostics_tests.cpp index 9391b6e5cd..3724f6c058 100644 --- a/opencl/test/unit_test/context/driver_diagnostics_tests.cpp +++ b/opencl/test/unit_test/context/driver_diagnostics_tests.cpp @@ -371,18 +371,17 @@ TEST_F(PerformanceHintTest, givenPrintDriverDiagnosticsDebugModeEnabledWhenHintI auto context = Context::create(nullptr, ClDeviceVector(&clDevice, 1), nullptr, nullptr, retVal); testing::internal::CaptureStdout(); - auto buffer = Buffer::create( + auto buffer = std::unique_ptr(Buffer::create( context, CL_MEM_READ_ONLY, 4096, nullptr, - retVal); + retVal)); std::string output = testing::internal::GetCapturedStdout(); EXPECT_NE(0u, output.size()); EXPECT_EQ('\n', output[0]); - buffer->release(); context->release(); } diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index 770610eed3..0f065c86bf 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -1261,10 +1261,41 @@ TEST_F(DeviceGetCapsTest, givenSystemWithNoDriverInfoWhenGettingNameAndVersionTh EXPECT_STREQ(tempName.c_str(), caps.name); EXPECT_STREQ(expectedVersion.c_str(), caps.driverVersion); } - -TEST_F(DeviceGetCapsTest, GivenFlagEnabled64kbPagesWhenSetThenReturnCorrectValue) { +TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryManagerThenReturnCorrectValue) { DebugManagerStateRestore dbgRestore; VariableBackup OsEnabled64kbPagesBackup(&OSInterface::osEnabled64kbPages); + class MockMemoryManager : public MemoryManager { + public: + MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) {} + void addAllocationToHostPtrManager(GraphicsAllocation *memory) override{}; + void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override{}; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override { return nullptr; }; + GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { return nullptr; }; + AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; }; + void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{}; + void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override{}; + uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override { + return 0; + }; + uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override { return 0; }; + AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override { + return {}; + } + void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{}; + GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override { return nullptr; }; + GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override { return nullptr; }; + GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override { return nullptr; }; + GraphicsAllocation *allocateUSMHostGraphicsMemory(const AllocationData &allocationData) override { return nullptr; }; + GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override { return nullptr; }; + GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override { return nullptr; }; + GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; + GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override { return nullptr; }; + + GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr gmm) override { return nullptr; }; + GraphicsAllocation *allocateShareableMemory(const AllocationData &allocationData) override { return nullptr; }; + void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override { return nullptr; }; + void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override{}; + }; MockExecutionEnvironment executionEnvironment; executionEnvironment.prepareRootDeviceEnvironments(1); @@ -1275,21 +1306,48 @@ TEST_F(DeviceGetCapsTest, GivenFlagEnabled64kbPagesWhenSetThenReturnCorrectValue capabilityTable.ftr64KBpages = false; OSInterface::osEnabled64kbPages = false; - memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); + memoryManager.reset(new MockMemoryManager(executionEnvironment)); EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u)); capabilityTable.ftr64KBpages = false; OSInterface::osEnabled64kbPages = true; - memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); + memoryManager.reset(new MockMemoryManager(executionEnvironment)); EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u)); capabilityTable.ftr64KBpages = true; OSInterface::osEnabled64kbPages = false; - memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); + memoryManager.reset(new MockMemoryManager(executionEnvironment)); EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u)); capabilityTable.ftr64KBpages = true; OSInterface::osEnabled64kbPages = true; + memoryManager.reset(new MockMemoryManager(executionEnvironment)); + EXPECT_TRUE(memoryManager->peek64kbPagesEnabled(0u)); + + DebugManager.flags.Enable64kbpages.set(0); // force false + memoryManager.reset(new MockMemoryManager(executionEnvironment)); + EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u)); + + DebugManager.flags.Enable64kbpages.set(1); // force true + memoryManager.reset(new MockMemoryManager(executionEnvironment)); + EXPECT_TRUE(memoryManager->peek64kbPagesEnabled(0u)); +} + +TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorOsAgnosticMemoryManagerThenReturnCorrectValue) { + DebugManagerStateRestore dbgRestore; + + MockExecutionEnvironment executionEnvironment; + executionEnvironment.prepareRootDeviceEnvironments(1); + auto &capabilityTable = executionEnvironment.rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable; + std::unique_ptr memoryManager; + + DebugManager.flags.Enable64kbpages.set(-1); + + capabilityTable.ftr64KBpages = false; + memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); + EXPECT_FALSE(memoryManager->peek64kbPagesEnabled(0u)); + + capabilityTable.ftr64KBpages = true; memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); EXPECT_TRUE(memoryManager->peek64kbPagesEnabled(0u)); diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index e7df04e5e5..d9d246eb5f 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -461,6 +461,9 @@ TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInS struct RenderCompressedBuffersTests : public ::testing::Test { void SetUp() override { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); + for (auto &rootDeviceEnvironment : executionEnvironment->rootDeviceEnvironments) { + rootDeviceEnvironment->initGmm(); + } executionEnvironment->prepareRootDeviceEnvironments(1u); hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo(); device = std::make_unique(MockDevice::create(executionEnvironment, 0u)); @@ -592,6 +595,9 @@ TEST_F(RenderCompressedBuffersTests, givenDebugVariableSetWhenHwFlagIsNotSetThen struct RenderCompressedBuffersSvmTests : public RenderCompressedBuffersTests { void SetUp() override { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); + for (auto &rootDeviceEnvironment : executionEnvironment->rootDeviceEnvironments) { + rootDeviceEnvironment->initGmm(); + } executionEnvironment->prepareRootDeviceEnvironments(1u); hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo(); hwInfo->capabilityTable.gpuAddressSpace = MemoryConstants::max48BitAddress; 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 bf1a4a7960..ed41252752 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -34,6 +34,7 @@ #include "opencl/test/unit_test/fixtures/memory_manager_fixture.h" #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" #include "opencl/test/unit_test/helpers/execution_environment_helper.h" +#include "opencl/test/unit_test/helpers/raii_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_csr.h" @@ -632,6 +633,38 @@ TEST_F(MemoryAllocatorTest, given32BitDeviceWhenPrintfSurfaceIsCreatedThen32BitA DebugManager.flags.Force32bitAddressing.set(false); } } +HWTEST_F(MemoryAllocatorTest, givenSupportFor1MbAligmentWhenAllocateGraphicsMemoryThenAligmentIsSetCorrect) { + class MockHwHelperHw : public HwHelperHw { + public: + using HwHelperHw::HwHelperHw; + bool is1MbAlignmentSupported(const HardwareInfo &hwInfo, bool isRenderCompressed) const override { + return isEnable; + } + bool isEnable = false; + }; + auto raiiFactory = RAIIHwHelperFactory(defaultHwInfo->platform.eRenderCoreFamily); + void *ptr = reinterpret_cast(0x1001); + auto size = MemoryConstants::pageSize; + + raiiFactory.mockHwHelper.isEnable = true; + + auto osAgnosticMemoryManager = std::make_unique>(true, false, *executionEnvironment); + osAgnosticMemoryManager->failInDevicePool = true; + auto allocationWithEnabled1MbAlignment = osAgnosticMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{mockRootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, mockDeviceBitfield}, ptr); + + ASSERT_NE(nullptr, allocationWithEnabled1MbAlignment); + EXPECT_EQ(MemoryConstants::megaByte, osAgnosticMemoryManager->alignAllocationData.alignment); + + osAgnosticMemoryManager->freeGraphicsMemory(allocationWithEnabled1MbAlignment); + + raiiFactory.mockHwHelper.isEnable = false; + auto allocationWithoutEnabled1MbAlignment = osAgnosticMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{mockRootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, mockDeviceBitfield}, ptr); + + ASSERT_NE(nullptr, allocationWithoutEnabled1MbAlignment); + EXPECT_NE(MemoryConstants::megaByte, osAgnosticMemoryManager->alignAllocationData.alignment); + + osAgnosticMemoryManager->freeGraphicsMemory(allocationWithoutEnabled1MbAlignment); +} TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenItIsInitialized) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); @@ -900,6 +933,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.initGmm(); MockMemoryManager memoryManager(false, false, executionEnvironment); void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; @@ -927,6 +961,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryThenMemoryPoolIsSystem64KBPages) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.initGmm(); MemoryManagerCreate memoryManager(true, false, executionEnvironment); auto svmAllocation = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SVM_ZERO_COPY, mockDeviceBitfield}); EXPECT_NE(nullptr, svmAllocation); @@ -936,6 +971,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryThen4KBGraphicsAllocationIsReturned) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.initGmm(); MemoryManagerCreate memoryManager(false, false, executionEnvironment); auto svmAllocation = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SVM_ZERO_COPY, mockDeviceBitfield}); EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool()); @@ -1246,6 +1282,7 @@ TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCre DebugManagerStateRestore dbgRestore; DebugManager.flags.Enable64kbpages.set(true); MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.initGmm(); MemoryManagerCreate memoryManager(true, false, executionEnvironment); GraphicsAllocation *galloc = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, mockDeviceBitfield}); @@ -1432,6 +1469,50 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenGpuAddressIsSetThenAllocatio memoryManager->freeGraphicsMemory(allocation); } +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenOsEnabled64kbPagesFalseThenIs64kbPagesEnabledReturnTrue) { + MockExecutionEnvironment executionEnvironment; + VariableBackup OsEnabled64kbPagesBackup(&OSInterface::osEnabled64kbPages); + OsAgnosticMemoryManager memoryManager(executionEnvironment); + auto hwInfo = *defaultHwInfo; + OSInterface::osEnabled64kbPages = false; + hwInfo.capabilityTable.ftr64KBpages = true; + EXPECT_TRUE(memoryManager.is64kbPagesEnabled(&hwInfo)); + OSInterface::osEnabled64kbPages = true; + EXPECT_TRUE(memoryManager.is64kbPagesEnabled(&hwInfo)); +} + +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenCheckIs64kbPagesEnabledThenOsEnabled64PkbPagesIsNotAffectedReturnedValue) { + MockExecutionEnvironment executionEnvironment; + VariableBackup OsEnabled64kbPagesBackup(&OSInterface::osEnabled64kbPages); + OsAgnosticMemoryManager memoryManager(executionEnvironment); + auto hwInfo = *defaultHwInfo; + OSInterface::osEnabled64kbPages = true; + hwInfo.capabilityTable.ftr64KBpages = true; + EXPECT_TRUE(memoryManager.is64kbPagesEnabled(&hwInfo)); + hwInfo.capabilityTable.ftr64KBpages = false; + EXPECT_FALSE(memoryManager.is64kbPagesEnabled(&hwInfo)); +} + +TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWithFlagEnable64kbpagesWhenCheckIs64kbPagesEnabledThenProperValueIsReturned) { + DebugManagerStateRestore dbgRestore; + + MockExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(executionEnvironment); + auto hwInfo = *defaultHwInfo; + DebugManager.flags.Enable64kbpages.set(true); + hwInfo.capabilityTable.ftr64KBpages = true; + EXPECT_TRUE(memoryManager.is64kbPagesEnabled(&hwInfo)); + DebugManager.flags.Enable64kbpages.set(true); + hwInfo.capabilityTable.ftr64KBpages = false; + EXPECT_FALSE(memoryManager.is64kbPagesEnabled(&hwInfo)); + DebugManager.flags.Enable64kbpages.set(false); + hwInfo.capabilityTable.ftr64KBpages = false; + EXPECT_FALSE(memoryManager.is64kbPagesEnabled(&hwInfo)); + DebugManager.flags.Enable64kbpages.set(false); + hwInfo.capabilityTable.ftr64KBpages = true; + EXPECT_FALSE(memoryManager.is64kbPagesEnabled(&hwInfo)); +} + TEST(MemoryManager, givenSharedResourceCopyWhenAllocatingGraphicsMemoryThenAllocateGraphicsMemoryForImageIsCalled) { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); MockMemoryManager memoryManager(false, true, *executionEnvironment); diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.cpp b/opencl/test/unit_test/mocks/mock_memory_manager.cpp index 0f9685409b..b103142355 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.cpp +++ b/opencl/test/unit_test/mocks/mock_memory_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -63,7 +63,6 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(const Allocati auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemory64kb(allocationData); if (allocation) { - allocation->setDefaultGmm(new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocation->getUnderlyingBuffer(), allocationData.size, false, preferRenderCompressedFlagPassed, true, {})); allocation->getDefaultGmm()->isRenderCompressed = preferRenderCompressedFlagPassed; } return allocation; @@ -94,6 +93,7 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const return nullptr; } allocationCreated = true; + alignAllocationData = allocationData; return OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment(allocationData); } diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.h b/opencl/test/unit_test/mocks/mock_memory_manager.h index 5e9ec74d79..80ddeacb1b 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.h +++ b/opencl/test/unit_test/mocks/mock_memory_manager.h @@ -123,6 +123,7 @@ class MockMemoryManager : public MemoryManagerCreate { uint32_t freeGraphicsMemoryCalled = 0u; uint32_t unlockResourceCalled = 0u; uint32_t lockResourceCalled = 0u; + AllocationData alignAllocationData; std::vector lockResourcePointers; uint32_t handleFenceCompletionCalled = 0u; uint32_t waitForEnginesCompletionCalled = 0u; diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index bb20083a22..f9477d8177 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -58,6 +58,7 @@ class HwHelper { virtual SipKernelType getSipKernelType(bool debuggingActive) const = 0; virtual bool isLocalMemoryEnabled(const HardwareInfo &hwInfo) const = 0; virtual bool isPageTableManagerSupported(const HardwareInfo &hwInfo) const = 0; + virtual bool is1MbAlignmentSupported(const HardwareInfo &hwInfo, bool isRenderCompressed) const = 0; virtual bool isFenceAllocationRequired(const HardwareInfo &hwInfo) const = 0; virtual const AubMemDump::LrcaHelper &getCsTraits(aub_stream::EngineType engineType) const = 0; virtual bool hvAlign4Required() const = 0; @@ -227,6 +228,8 @@ class HwHelperHw : public HwHelper { bool isPageTableManagerSupported(const HardwareInfo &hwInfo) const override; + bool is1MbAlignmentSupported(const HardwareInfo &hwInfo, bool isRenderCompressed) const override; + bool isFenceAllocationRequired(const HardwareInfo &hwInfo) const override; void setRenderSurfaceStateForBuffer(const RootDeviceEnvironment &rootDeviceEnvironment, diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 4c45a7012e..662f982b62 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -172,10 +172,14 @@ bool HwHelperHw::getEnableLocalMemory(const HardwareInfo &hwInfo) const return OSInterface::osEnableLocalMemory && isLocalMemoryEnabled(hwInfo); } +template +bool HwHelperHw::is1MbAlignmentSupported(const HardwareInfo &hwInfo, bool isRenderCompressed) const { + return false; +} + template AuxTranslationMode HwHelperHw::getAuxTranslationMode(const HardwareInfo &hwInfo) { auto mode = HwHelperHw::defaultAuxTranslationMode; - if (DebugManager.flags.ForceAuxTranslationMode.get() != -1) { mode = static_cast(DebugManager.flags.ForceAuxTranslationMode.get()); } diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 58bd60017a..dd3dc558c1 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -46,10 +46,7 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); localMemoryUsageBankSelector.emplace_back(new LocalMemoryUsageBankSelector(HwHelper::getSubDevicesCount(hwInfo))); this->localMemorySupported.push_back(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo)); - this->enable64kbpages.push_back(OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages); - if (DebugManager.flags.Enable64kbpages.get() > -1) { - this->enable64kbpages[rootDeviceIndex] = DebugManager.flags.Enable64kbpages.get() != 0; - } + this->enable64kbpages.push_back(OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages && !!DebugManager.flags.Enable64kbpages.get()); gfxPartitions.push_back(std::make_unique(reservedCpuAddressRange)); diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index 92f40b258b..049cb3ec1b 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -37,6 +37,8 @@ void OsAgnosticMemoryManager::initialize(bool aubUsage) { size_t reservedCpuAddressRangeSize = (4 * 4 + 2 * (aubUsage ? 32 : 4)) * GB; for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) { + auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); + this->enable64kbpages[rootDeviceIndex] = is64kbPagesEnabled(hwInfo); auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace; if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh)) { initialized = false; @@ -49,6 +51,10 @@ void OsAgnosticMemoryManager::initialize(bool aubUsage) { OsAgnosticMemoryManager::~OsAgnosticMemoryManager() = default; +bool OsAgnosticMemoryManager::is64kbPagesEnabled(const HardwareInfo *hwInfo) { + return hwInfo->capabilityTable.ftr64KBpages && !!DebugManager.flags.Enable64kbpages.get(); +} + struct OsHandle { }; @@ -111,12 +117,24 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithGpuVa(con } GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const AllocationData &allocationData) { - AllocationData allocationData64kb = allocationData; - allocationData64kb.size = alignUp(allocationData.size, MemoryConstants::pageSize64k); - allocationData64kb.alignment = MemoryConstants::pageSize64k; - auto memoryAllocation = allocateGraphicsMemoryWithAlignment(allocationData64kb); + AllocationData allocationDataAlign = allocationData; + allocationDataAlign.size = alignUp(allocationData.size, MemoryConstants::pageSize64k); + auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo(); + auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily); + allocationDataAlign.alignment = hwHelper.is1MbAlignmentSupported(*hwInfo, allocationData.flags.preferRenderCompressed) + ? MemoryConstants::megaByte + : MemoryConstants::pageSize64k; + auto memoryAllocation = allocateGraphicsMemoryWithAlignment(allocationDataAlign); if (memoryAllocation) { static_cast(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages); + auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), + allocationData.hostPtr, + allocationDataAlign.alignment, + allocationData.flags.uncacheable, + allocationData.flags.preferRenderCompressed, + allocationData.flags.useSystemMemory, + allocationData.storageInfo); + memoryAllocation->setDefaultGmm(gmm.release()); } return memoryAllocation; } diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.h b/shared/source/memory_manager/os_agnostic_memory_manager.h index 6e9edac31f..306bf038d6 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.h +++ b/shared/source/memory_manager/os_agnostic_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -83,6 +83,7 @@ class OsAgnosticMemoryManager : public MemoryManager { AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override; void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override; + bool is64kbPagesEnabled(const HardwareInfo *hwInfo); protected: GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.h b/shared/source/os_interface/windows/wddm_memory_manager.h index 5f125d0571..9e5b048dbd 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.h +++ b/shared/source/os_interface/windows/wddm_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT *