diff --git a/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp b/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp index 813a53732d..c1c090b3b8 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp @@ -140,7 +140,7 @@ TEST_F(L0DebuggerLinuxTest, whenRegisterElfisCalledThenItRegistersBindExtHandles debugData.vIsa = "01234567890"; debugData.vIsaSize = 10; MockDrmAllocation isaAllocation(AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); - MockBufferObject bo(drmMock, 0, 0, 1); + MockBufferObject bo(drmMock, 3, 0, 0, 1); isaAllocation.bufferObjects[0] = &bo; device->getL0Debugger()->registerElf(&debugData, &isaAllocation); @@ -181,11 +181,11 @@ TEST_F(L0DebuggerLinuxTest, givenNoOSInterfaceThenRegisterElfDoesNothing) { TEST_F(L0DebuggerLinuxTest, givenAllocationsWhenAttachingZebinModuleThenAllAllocationsHaveRegisteredHandle) { MockDrmAllocation isaAllocation(AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); - MockBufferObject bo(drmMock, 0, 0, 1); + MockBufferObject bo(drmMock, 3, 0, 0, 1); isaAllocation.bufferObjects[0] = &bo; MockDrmAllocation isaAllocation2(AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); - MockBufferObject bo2(drmMock, 0, 0, 1); + MockBufferObject bo2(drmMock, 3, 0, 0, 1); isaAllocation2.bufferObjects[0] = &bo2; uint32_t handle = 0; diff --git a/opencl/test/unit_test/linux/main_linux_dll.cpp b/opencl/test/unit_test/linux/main_linux_dll.cpp index 3cb56a5386..a412ca6523 100644 --- a/opencl/test/unit_test/linux/main_linux_dll.cpp +++ b/opencl/test/unit_test/linux/main_linux_dll.cpp @@ -666,12 +666,16 @@ TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenEx } TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCreated) { + DebugManagerStateRestore restorer; + DebugManager.flags.OverridePatIndex.set(0); + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]); drm->setupIoctlHelper(defaultHwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment); EXPECT_NE(nullptr, drmMemoryManager.get()); executionEnvironment.memoryManager = std::move(drmMemoryManager); @@ -681,6 +685,7 @@ TEST(DrmMemoryManagerCreate, givenEnableHostPtrValidationSetToZeroWhenCreateDrmM DebugManagerStateRestore restorer; DebugManager.flags.EnableHostPtrValidation.set(0); DebugManager.flags.EnableGemCloseWorker.set(0); + DebugManager.flags.OverridePatIndex.set(0); VariableBackup backup(&ultHwConfig); ultHwConfig.forceOsAgnosticMemoryManager = false; @@ -691,6 +696,7 @@ TEST(DrmMemoryManagerCreate, givenEnableHostPtrValidationSetToZeroWhenCreateDrmM drm->setupIoctlHelper(defaultHwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment); EXPECT_NE(nullptr, drmMemoryManager.get()); EXPECT_FALSE(static_cast(drmMemoryManager.get())->isValidateHostMemoryEnabled()); diff --git a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp index c6e16e24d8..41539fa3be 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp @@ -244,7 +244,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned TEST(DrmBufferObjectSimpleTest, givenBufferObjectWhenConstructedWithASizeThenTheSizeIsInitialized) { MockExecutionEnvironment executionEnvironment; std::unique_ptr drmMock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0])); - std::unique_ptr bo(new BufferObject(drmMock.get(), 1, 0x1000, 1)); + std::unique_ptr bo(new BufferObject(drmMock.get(), 3, 1, 0x1000, 1)); EXPECT_EQ(0x1000u, bo->peekSize()); } @@ -322,7 +322,7 @@ TEST_F(DrmBufferObjectTest, givenDeleterWhenBufferObjectIsCreatedAndDeletedThenC mock->ioctl_expected.reset(); { - std::unique_ptr bo(new BufferObject(mock.get(), 1, 0x1000, 1)); + std::unique_ptr bo(new BufferObject(mock.get(), 3, 1, 0x1000, 1)); } EXPECT_EQ(1, mock->ioctl_cnt.gemClose); @@ -337,7 +337,7 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoCreatedThenBindInfoIsInitia DrmMock drm(*(device->getExecutionEnvironment()->rootDeviceEnvironments[0].get())); EXPECT_TRUE(drm.isPerContextVMRequired()); auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount(); - MockBufferObject bo(&drm, 0, 0, osContextCount); + MockBufferObject bo(&drm, 3, 0, 0, osContextCount); EXPECT_EQ(osContextCount, bo.bindInfo.size()); @@ -364,7 +364,7 @@ TEST(DrmBufferObject, givenDrmIoctlReturnsErrorNotSupportedThenBufferObjectRetur std::unique_ptr device(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0)); auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount(); - MockBufferObject bo(drm, 0, 0, osContextCount); + MockBufferObject bo(drm, 3, 0, 0, osContextCount); std::unique_ptr osContext; osContext.reset(new OsContextLinux(*drm, 0u, EngineDescriptorHelper::getDefaultDescriptor())); @@ -391,7 +391,7 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectB std::unique_ptr device(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0)); auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount(); - MockBufferObject bo(drm, 0, 0, osContextCount); + MockBufferObject bo(drm, 3, 0, 0, osContextCount); EXPECT_EQ(osContextCount, bo.bindInfo.size()); @@ -432,7 +432,7 @@ TEST(DrmBufferObject, givenPrintBOBindingResultWhenBOBindAndUnbindSucceedsThenPr std::unique_ptr device(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0)); auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount(); - MockBufferObject bo(drm, 0, 0, osContextCount); + MockBufferObject bo(drm, 3, 0, 0, osContextCount); EXPECT_EQ(osContextCount, bo.bindInfo.size()); @@ -484,7 +484,7 @@ TEST(DrmBufferObject, givenPrintBOBindingResultWhenBOBindAndUnbindFailsThenPrint std::unique_ptr device(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0)); auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount(); - MockBufferObject bo(drm, 0, 0, osContextCount); + MockBufferObject bo(drm, 3, 0, 0, osContextCount); EXPECT_EQ(osContextCount, bo.bindInfo.size()); @@ -515,7 +515,7 @@ TEST(DrmBufferObject, whenBindExtHandleAddedThenItIsStored) { executionEnvironment->prepareRootDeviceEnvironments(1); DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.addBindExtHandle(4); EXPECT_EQ(1u, bo.bindExtHandles.size()); @@ -530,7 +530,7 @@ TEST(DrmBufferObject, whenMarkForCapturedCalledThenIsMarkedForCaptureReturnsTrue executionEnvironment->prepareRootDeviceEnvironments(1); DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); EXPECT_FALSE(bo.isMarkedForCapture()); bo.markForCapture(); @@ -570,21 +570,21 @@ TEST_F(DrmBufferObjectTest, given47bitAddressWhenSetThenIsAddressNotCanonized) { uint64_t address = maxNBitValue(47) - maxNBitValue(5); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.setAddress(address); auto boAddress = bo.peekAddress(); EXPECT_EQ(boAddress, address); } TEST_F(DrmBufferObjectTest, given48bitAddressWhenSetThenAddressIsCanonized) { - VariableBackup backup(&MockGmmHelper::addressWidth, 48); - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get())); + VariableBackup backup(&MockGmmHelper::addressWidth, 48); + uint64_t address = maxNBitValue(48) - maxNBitValue(5); uint64_t expectedAddress = std::numeric_limits::max() - maxNBitValue(5); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.setAddress(address); auto boAddress = bo.peekAddress(); EXPECT_EQ(boAddress, expectedAddress); @@ -596,7 +596,7 @@ TEST_F(DrmBufferObjectTest, givenBoIsCreatedWhenPageFaultIsSupportedThenExplicit for (auto isPageFaultSupported : {false, true}) { drm.pageFaultSupported = isPageFaultSupported; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); EXPECT_EQ(isPageFaultSupported, bo.isExplicitResidencyRequired()); } } @@ -604,7 +604,7 @@ TEST_F(DrmBufferObjectTest, givenBoIsCreatedWhenPageFaultIsSupportedThenExplicit TEST_F(DrmBufferObjectTest, whenBoRequiresExplicitResidencyThenTheCorrespondingQueryReturnsCorrectValue) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get())); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); for (auto required : {false, true}) { bo.requireExplicitResidency(required); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_mm_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_mm_tests.cpp index b5fa6ab88b..01fd6a84d3 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_mm_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_mm_tests.cpp @@ -45,6 +45,7 @@ HWTEST_F(DrmCommandStreamMMTest, GivenForcePinThenMemoryManagerCreatesPinBb) { executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); DrmCommandStreamReceiver csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive); @@ -64,6 +65,7 @@ HWTEST_F(DrmCommandStreamMMTest, givenForcePinDisabledWhenMemoryManagerIsCreated executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); DrmCommandStreamReceiver csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive); auto memoryManager = new TestedDrmMemoryManager(false, true, false, executionEnvironment); @@ -83,6 +85,7 @@ HWTEST_F(DrmCommandStreamMMTest, givenExecutionEnvironmentWithMoreThanOneRootDev auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]); executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(drm)); executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); } auto memoryManager = new TestedDrmMemoryManager(false, true, false, executionEnvironment); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_prelim_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_prelim_tests.cpp index f621a9bc78..a703881021 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_prelim_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_xehp_and_later_prelim_tests.cpp @@ -292,6 +292,7 @@ class DrmCommandStreamForceTileTest : public ::testing::Test { executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo)); osContext = std::make_unique(*mock, rootDeviceIndex, @@ -401,9 +402,11 @@ struct DrmImplicitScalingCommandStreamTest : ::testing::Test { drm = new DrmMock(mockFd, *executionEnvironment->rootDeviceEnvironments[0]); drm->setupIoctlHelper(hwInfo->platform.eProductFamily); drm->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo.get())); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(hwInfo.get()); executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); osContext = std::make_unique(*drm, 0u, EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], @@ -439,15 +442,15 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DrmImplicitScalingCommandStreamTest, givenTwoTilesW auto csr = createCsr(); auto size = 1024u; - auto multiStorageBo0 = new BufferObject(drm, 30, 0, 1); - auto multiStorageBo1 = new BufferObject(drm, 31, 0, 1); + auto multiStorageBo0 = new BufferObject(drm, 3, 30, 0, 1); + auto multiStorageBo1 = new BufferObject(drm, 3, 31, 0, 1); BufferObjects multiStorageBos{multiStorageBo0, multiStorageBo1}; auto multiStorageAllocation = new DrmAllocation(0, AllocationType::UNKNOWN, multiStorageBos, nullptr, 0u, size, MemoryPool::LocalMemory); multiStorageAllocation->storageInfo.memoryBanks = 0b11; csr->CommandStreamReceiver::makeResident(*multiStorageAllocation); - auto tileInstancedBo0 = new BufferObject(drm, 40, 0, 1); - auto tileInstancedBo1 = new BufferObject(drm, 41, 0, 1); + auto tileInstancedBo0 = new BufferObject(drm, 3, 40, 0, 1); + auto tileInstancedBo1 = new BufferObject(drm, 3, 41, 0, 1); BufferObjects tileInstancedBos{tileInstancedBo0, tileInstancedBo1}; auto tileInstancedAllocation = new DrmAllocation(0, AllocationType::UNKNOWN, tileInstancedBos, nullptr, 0u, size, MemoryPool::LocalMemory); tileInstancedAllocation->storageInfo.memoryBanks = 0b11; @@ -510,10 +513,10 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DrmImplicitScalingCommandStreamTest, whenForceExecu gemCloseWorkerMode::gemCloseWorkerActive); csr->setupContext(*osContext); - auto tileInstancedBo0 = new BufferObject(drm, 40, 0, 1); - auto tileInstancedBo1 = new BufferObject(drm, 41, 0, 1); - auto tileInstancedBo2 = new BufferObject(drm, 42, 0, 1); - auto tileInstancedBo3 = new BufferObject(drm, 43, 0, 1); + auto tileInstancedBo0 = new BufferObject(drm, 3, 40, 0, 1); + auto tileInstancedBo1 = new BufferObject(drm, 3, 41, 0, 1); + auto tileInstancedBo2 = new BufferObject(drm, 3, 42, 0, 1); + auto tileInstancedBo3 = new BufferObject(drm, 3, 43, 0, 1); BufferObjects tileInstancedBos{tileInstancedBo0, tileInstancedBo1, tileInstancedBo2, tileInstancedBo3}; auto tileInstancedAllocation = new DrmAllocation(0, AllocationType::UNKNOWN, tileInstancedBos, nullptr, 0u, 1024u, MemoryPool::LocalMemory); tileInstancedAllocation->storageInfo.memoryBanks = 0b11; @@ -553,10 +556,10 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DrmImplicitScalingCommandStreamTest, whenForceExecu gemCloseWorkerMode::gemCloseWorkerActive); csr->setupContext(*osContext); - auto tileInstancedBo0 = new BufferObject(drm, 40, 0, 1); - auto tileInstancedBo1 = new BufferObject(drm, 41, 0, 1); - auto tileInstancedBo2 = new BufferObject(drm, 42, 0, 1); - auto tileInstancedBo3 = new BufferObject(drm, 43, 0, 1); + auto tileInstancedBo0 = new BufferObject(drm, 3, 40, 0, 1); + auto tileInstancedBo1 = new BufferObject(drm, 3, 41, 0, 1); + auto tileInstancedBo2 = new BufferObject(drm, 3, 42, 0, 1); + auto tileInstancedBo3 = new BufferObject(drm, 3, 43, 0, 1); BufferObjects tileInstancedBos{tileInstancedBo0, tileInstancedBo1, tileInstancedBo2, tileInstancedBo3}; auto tileInstancedAllocation = new DrmAllocation(0, AllocationType::UNKNOWN, tileInstancedBos, nullptr, 0u, 1024u, MemoryPool::LocalMemory); tileInstancedAllocation->storageInfo.memoryBanks = 0b11; @@ -598,7 +601,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DrmImplicitScalingCommandStreamTest, givenUseSingle csr->setupContext(*osContext); const auto size = 1024u; - BufferObject *bufferObject = new BufferObject(drm, 30, 0, 1); + BufferObject *bufferObject = new BufferObject(drm, 3, 30, 0, 1); BufferObjects bufferObjects{bufferObject}; auto allocation = new DrmAllocation(0, AllocationType::UNKNOWN, bufferObjects, nullptr, 0u, size, MemoryPool::LocalMemory); csr->CommandStreamReceiver::makeResident(*allocation); @@ -638,7 +641,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DrmImplicitScalingCommandStreamTest, givenDisabledI csr->setupContext(*osContext); const auto size = 1024u; - BufferObject *bufferObject = new BufferObject(drm, 30, 0, 1); + BufferObject *bufferObject = new BufferObject(drm, 3, 30, 0, 1); BufferObjects bufferObjects{bufferObject}; auto allocation = new DrmAllocation(0, AllocationType::UNKNOWN, bufferObjects, nullptr, 0u, size, MemoryPool::LocalMemory); csr->CommandStreamReceiver::makeResident(*allocation); @@ -671,7 +674,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DrmImplicitScalingCommandStreamTest, givenMultiTile csr->setupContext(*osContext); const auto size = 1024u; - BufferObject *bufferObject = new BufferObject(drm, 30, 0, 1); + BufferObject *bufferObject = new BufferObject(drm, 3, 30, 0, 1); BufferObjects bufferObjects{bufferObject}; auto allocation = new DrmAllocation(0, AllocationType::UNKNOWN, bufferObjects, nullptr, 0u, size, MemoryPool::LocalMemory); csr->CommandStreamReceiver::makeResident(*allocation); diff --git a/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp index 2a333e2f76..675f5f92d7 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -108,7 +108,7 @@ TEST_F(DrmGemCloseWorkerTests, WhenClosingGemThenSucceeds) { this->drmMock->gem_close_expected = 1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObject(this->drmMock, 1, 0, 1); + auto bo = new BufferObject(this->drmMock, 3, 1, 0, 1); worker->push(bo); @@ -119,7 +119,7 @@ TEST_F(DrmGemCloseWorkerTests, GivenMultipleThreadsWhenClosingGemThenSucceeds) { this->drmMock->gem_close_expected = -1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObject(this->drmMock, 1, 0, 1); + auto bo = new BufferObject(this->drmMock, 3, 1, 0, 1); worker->push(bo); @@ -139,7 +139,7 @@ TEST_F(DrmGemCloseWorkerTests, GivenMultipleThreadsAndCloseFalseWhenClosingGemTh this->drmMock->gem_close_expected = -1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObject(this->drmMock, 1, 0, 1); + auto bo = new BufferObject(this->drmMock, 3, 1, 0, 1); worker->push(bo); worker->close(false); @@ -157,7 +157,7 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl this->drmMock->gem_close_expected = 1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObject(this->drmMock, 1, 0, 1); + auto bo = new BufferObject(this->drmMock, 3, 1, 0, 1); bo->reference(); worker->push(bo); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index aca9da04f4..0946c49226 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -25,7 +25,7 @@ #include "gtest/gtest.h" TEST_F(DrmMemoryManagerLocalMemoryWithCustomPrelimMockTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnBufferObjectThenReturnPtr) { - BufferObject bo(mock, 1, 1024, 1); + BufferObject bo(mock, 3, 1, 1024, 1); DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_EQ(&bo, drmAllocation.getBO()); @@ -50,7 +50,13 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenDrmMemoryManagerWithPrelimSup auto gpuAddress = 0x1234u; auto size = MemoryConstants::pageSize64k; - auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, (1 << (MemoryBanks::getBankForLocalMemory(0) - 1)), 1)); + auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), + nullptr, + AllocationType::BUFFER, + gpuAddress, + size, + (1 << (MemoryBanks::getBankForLocalMemory(0) - 1)), + 1)); ASSERT_NE(nullptr, bo); EXPECT_EQ(1u, mock->ioctlCallsCount); @@ -93,6 +99,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); rootDeviceIndices.push_back(i); } @@ -142,6 +149,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); rootDeviceIndices.push_back(i); } @@ -210,6 +218,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); rootDeviceIndices.push_back(i); } @@ -1215,7 +1224,13 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenPrintBOCreateDestroyResultFla mock->queryEngineInfo(); testing::internal::CaptureStdout(); - auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, (1 << (MemoryBanks::getBankForLocalMemory(0) - 1)), 1)); + auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), + nullptr, + AllocationType::BUFFER, + gpuAddress, + size, + (1 << (MemoryBanks::getBankForLocalMemory(0) - 1)), + 1)); EXPECT_NE(nullptr, bo); std::string output = testing::internal::GetCapturedStdout(); @@ -1540,7 +1555,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerWhenLockUnlockIsCalledOn this->ioctlResExt = {mock->ioctl_cnt.total, -1}; mock->ioctl_res_ext = &ioctlResExt; - BufferObject bo(mock, 1, 0, 1); + BufferObject bo(mock, 3, 1, 0, 1); DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_NE(nullptr, drmAllocation.getBO()); @@ -1555,7 +1570,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerWhenLockUnlockIsCalledOn mock->ioctl_expected.gemMmapOffset = 2; mock->failOnMmapOffset = true; - BufferObject bo(mock, 1, 0, 1); + BufferObject bo(mock, 3, 1, 0, 1); DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_NE(nullptr, drmAllocation.getBO()); @@ -1888,7 +1903,8 @@ TEST(AllocationInfoLogging, givenDrmGraphicsAllocationWithMultipleBOsWhenGetting executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - BufferObject bo0(&drm, 0, 0, 1), bo1(&drm, 1, 0, 1), bo2(&drm, 2, 0, 1), bo3(&drm, 3, 0, 1); + BufferObject bo0(&drm, 3, 0, 0, 1), bo1(&drm, 3, 1, 0, 1), + bo2(&drm, 3, 2, 0, 1), bo3(&drm, 3, 3, 0, 1); BufferObjects bos{&bo0, &bo1, &bo2, &bo3}; DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, bos, nullptr, 0u, 0u, MemoryPool::LocalMemory); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp index 7a35de7ff8..c6b969e10e 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp @@ -28,7 +28,7 @@ namespace NEO { -BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount); +BufferObject *createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount); class DrmMemoryManagerLocalMemoryTest : public ::testing::Test { public: @@ -94,6 +94,8 @@ HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBuffer auto size = MemoryConstants::pageSize64k; auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), + nullptr, + AllocationType::BUFFER, gpuAddress, size, (1 << (MemoryBanks::getBankForLocalMemory(0) - 1)), @@ -132,6 +134,7 @@ HWTEST2_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndMem executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); rootDeviceIndices.push_back(i); } @@ -178,6 +181,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndMemory executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); rootDeviceIndices.push_back(i); } @@ -269,6 +273,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndNoMemo executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); rootDeviceIndices.push_back(i); } @@ -409,6 +414,8 @@ class DrmMemoryManagerLocalMemoryMemoryBankMock : public TestedDrmMemoryManager } BufferObject *createBufferObjectInMemoryRegion(Drm *drm, + Gmm *gmm, + AllocationType allocationType, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, @@ -604,7 +611,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhen } TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnBufferObjectThenReturnPtr) { - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_EQ(&bo, drmAllocation.getBO()); @@ -808,7 +815,7 @@ TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAl this->ioctlResExt = {mockExp->ioctl_cnt.total, -1}; mockExp->ioctl_res_ext = &ioctlResExt; - BufferObject bo(mockExp, 1, 0, 0); + BufferObject bo(mockExp, 3, 1, 0, 0); DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_NE(nullptr, drmAllocation.getBO()); @@ -824,7 +831,7 @@ TEST_F(DrmMemoryManagerTestImpl, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAl mockExp->returnIoctlExtraErrorValue = true; mockExp->failOnMmapOffset = true; - BufferObject bo(mockExp, 1, 0, 0); + BufferObject bo(mockExp, 3, 1, 0, 0); DrmAllocation drmAllocation(0, AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_NE(nullptr, drmAllocation.getBO()); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 35abbe5e2a..e7d6a64295 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -2677,7 +2677,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledButFails DrmMockCustom drmMock(*executionEnvironment->rootDeviceEnvironments[0]); struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) {} }; BufferObjectMock bo(&drmMock); DrmAllocation drmAllocation(rootDeviceIndex, AllocationType::UNKNOWN, &bo, nullptr, 0u, static_cast(0u), MemoryPool::MemoryNull); @@ -2710,7 +2710,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenUnlockResourceIsCalledOnAl DrmMockCustom drmMock(*executionEnvironment->rootDeviceEnvironments[0]); struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) {} }; auto bo = new BufferObjectMock(&drmMock); auto drmAllocation = new DrmAllocation(rootDeviceIndex, AllocationType::UNKNOWN, bo, nullptr, 0u, static_cast(0u), MemoryPool::LocalMemory); @@ -2737,7 +2737,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledButFai DrmMockCustom drmMock(*executionEnvironment->rootDeviceEnvironments[0]); struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) {} }; BufferObjectMock bo(&drmMock); DrmAllocation drmAllocation(rootDeviceIndex, AllocationType::UNKNOWN, &bo, nullptr, 0u, static_cast(0u), MemoryPool::MemoryNull); @@ -2753,7 +2753,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledOnAllo DrmMockCustom drmMock(*executionEnvironment->rootDeviceEnvironments[0]); struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) {} }; BufferObjectMock bo(&drmMock); DrmAllocation drmAllocation(rootDeviceIndex, AllocationType::UNKNOWN, &bo, nullptr, 0u, static_cast(0u), MemoryPool::MemoryNull); @@ -3354,7 +3354,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna class PinBufferObject : public BufferObject { public: - PinBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) { + PinBufferObject(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) { } int validateHostPtr(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) override { @@ -3957,7 +3957,18 @@ TEST_F(DrmMemoryManagerTest, givenDebugModuleAreaTypeWhenCreatingAllocationThen3 memoryManager->freeGraphicsMemory(moduleDebugArea); } -TEST(DrmAllocationTest, givenAllocationTypeWhenPassedToDrmAllocationConstructorThenAllocationTypeIsStored) { +struct DrmAllocationTests : public ::testing::Test { + void SetUp() override { + executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); + } + + std::unique_ptr executionEnvironment; +}; + +TEST_F(DrmAllocationTests, givenAllocationTypeWhenPassedToDrmAllocationConstructorThenAllocationTypeIsStored) { DrmAllocation allocation{0, AllocationType::COMMAND_BUFFER, nullptr, nullptr, static_cast(0), 0u, MemoryPool::MemoryNull}; EXPECT_EQ(AllocationType::COMMAND_BUFFER, allocation.getAllocationType()); @@ -3965,7 +3976,7 @@ TEST(DrmAllocationTest, givenAllocationTypeWhenPassedToDrmAllocationConstructorT EXPECT_EQ(AllocationType::UNKNOWN, allocation2.getAllocationType()); } -TEST(DrmAllocationTest, givenMemoryPoolWhenPassedToDrmAllocationConstructorThenMemoryPoolIsStored) { +TEST_F(DrmAllocationTests, givenMemoryPoolWhenPassedToDrmAllocationConstructorThenMemoryPoolIsStored) { DrmAllocation allocation{0, AllocationType::COMMAND_BUFFER, nullptr, nullptr, static_cast(0), 0u, MemoryPool::System64KBPages}; EXPECT_EQ(MemoryPool::System64KBPages, allocation.getMemoryPool()); @@ -4087,6 +4098,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); TestedDrmMemoryManager memoryManger(executionEnvironment); AllocationProperties properties{mockRootDeviceIndex, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield}; @@ -4110,6 +4122,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]); executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(drm)); executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); TestedDrmMemoryManager memoryManger(executionEnvironment); osHandle handle = 1u; @@ -4142,10 +4155,7 @@ TEST(DrmMemoryMangerTest, givenMultipleRootDeviceWhenMemoryManagerGetsDrmThenDrm EXPECT_EQ(CommonConstants::unspecifiedDeviceIndex, drmMemoryManager.getRootDeviceIndex(nullptr)); } -TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShouldBeRegisteredThenBoHasBindExtHandleAdded) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenAllocationTypeShouldBeRegisteredThenBoHasBindExtHandleAdded) { DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); for (uint32_t i = 3; i < 3 + static_cast(Drm::ResourceClass::MaxSize); i++) { @@ -4153,7 +4163,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould } { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::DEBUG_CONTEXT_SAVE_AREA, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4163,7 +4173,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould drm.registeredClass = Drm::ResourceClass::MaxSize; { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::DEBUG_SBA_TRACKING_BUFFER, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4173,7 +4183,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould drm.registeredClass = Drm::ResourceClass::MaxSize; { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4183,7 +4193,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould drm.registeredClass = Drm::ResourceClass::MaxSize; { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::DEBUG_MODULE_AREA, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4194,7 +4204,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould drm.registeredClass = Drm::ResourceClass::MaxSize; { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER_HOST_MEMORY, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4203,10 +4213,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould } } -TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShouldNotBeRegisteredThenNoBindHandleCreated) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenAllocationTypeShouldNotBeRegisteredThenNoBindHandleCreated) { DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); drm.registeredClass = Drm::ResourceClass::MaxSize; @@ -4216,7 +4223,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould } { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::KERNEL_ISA_INTERNAL, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4225,13 +4232,11 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould EXPECT_EQ(Drm::ResourceClass::MaxSize, drm.registeredClass); } -TEST(DrmAllocationTest, givenResourceRegistrationNotEnabledWhenRegisteringBindExtHandleThenHandleIsNotAddedToBo) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); +TEST_F(DrmAllocationTests, givenResourceRegistrationNotEnabledWhenRegisteringBindExtHandleThenHandleIsNotAddedToBo) { DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); EXPECT_EQ(0u, drm.classHandles.size()); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::DEBUG_CONTEXT_SAVE_AREA, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4272,7 +4277,7 @@ TEST(DrmMemoryManager, givenResourceRegistrationEnabledAndAllocTypeToCaptureWhen // mock resource registration enabling by storing class handles mockDrm->classHandles.push_back(1); - MockBufferObject bo(mockDrm, 0, 0, 1); + MockBufferObject bo(mockDrm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::SCRATCH_SURFACE, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; memoryManager->registerAllocationInOs(&allocation); @@ -4293,6 +4298,7 @@ TEST(DrmMemoryManager, givenTrackedAllocationTypeWhenAllocatingThenAllocationIsR auto mockDrm = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]); executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mockDrm)); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); auto memoryManager = std::make_unique(false, false, false, *executionEnvironment); for (uint32_t i = 3; i < 3 + static_cast(Drm::ResourceClass::MaxSize); i++) { @@ -4323,6 +4329,7 @@ TEST(DrmMemoryManager, givenTrackedAllocationTypeWhenFreeingThenRegisteredHandle auto mockDrm = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]); executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mockDrm)); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); auto memoryManager = std::make_unique(false, false, false, *executionEnvironment); for (uint32_t i = 3; i < 3 + static_cast(Drm::ResourceClass::MaxSize); i++) { @@ -4365,15 +4372,12 @@ TEST(DrmMemoryManager, givenNullBoWhenRegisteringBindExtHandleThenEarlyReturn) { gfxAllocation.freeRegisteredBOBindExtHandles(mockDrm.get()); } -TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationIsRegisteredThenBosAreMarkedForCaptureAndRequireImmediateBinding) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenAllocationIsRegisteredThenBosAreMarkedForCaptureAndRequireImmediateBinding) { DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); // mock resource registration enabling by storing class handles drm.classHandles.push_back(1); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::DEBUG_CONTEXT_SAVE_AREA, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4382,10 +4386,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationIsRegister EXPECT_TRUE(bo.isImmediateBindingRequired()); } -TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenCookieIsAddedToBoHandle) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenCookieIsAddedToBoHandle) { DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); for (uint32_t i = 3; i < 3 + static_cast(Drm::ResourceClass::MaxSize); i++) { @@ -4394,7 +4395,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC drm.registeredClass = Drm::ResourceClass::MaxSize; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::KERNEL_ISA, MemoryPool::System4KBPages); allocation.bufferObjects[0] = &bo; allocation.registerBOBindExtHandle(&drm); @@ -4407,10 +4408,7 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC EXPECT_EQ(2u, drm.unregisterCalledCount); } -TEST(DrmAllocationTest, givenDrmAllocationWhenSetCacheRegionIsCalledForDefaultRegionThenReturnTrue) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenSetCacheRegionIsCalledForDefaultRegionThenReturnTrue) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); @@ -4418,10 +4416,7 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenSetCacheRegionIsCalledForDefaultRe EXPECT_TRUE(allocation.setCacheRegion(&drm, CacheRegion::Default)); } -TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRegionIsNotSet) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRegionIsNotSet) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); @@ -4429,10 +4424,7 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRe EXPECT_FALSE(allocation.setCacheRegion(&drm, CacheRegion::Region1)); } -TEST(DrmAllocationTest, givenDrmAllocationWhenDefaultCacheInfoIsAvailableThenCacheRegionIsNotSet) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenDefaultCacheInfoIsAvailableThenCacheRegionIsNotSet) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); drm.setupCacheInfo(*defaultHwInfo.get()); @@ -4441,10 +4433,7 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenDefaultCacheInfoIsAvailableThenCac EXPECT_FALSE(allocation.setCacheRegion(&drm, CacheRegion::Region1)); } -TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); drm.cacheInfo.reset(new MockCacheInfo(drm, 32 * MemoryConstants::kiloByte, 2, 32)); @@ -4453,45 +4442,46 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse EXPECT_FALSE(allocation.setCacheAdvice(&drm, 1024, CacheRegion::None)); } -TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenReturnTrue) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenReturnTrue) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); drm.cacheInfo.reset(new MockCacheInfo(drm, 32 * MemoryConstants::kiloByte, 2, 32)); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); - EXPECT_TRUE(allocation.setCacheAdvice(&drm, 1024, CacheRegion::Region1)); + if ((HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getNumCacheRegions() == 0) && + HwInfoConfig::get(defaultHwInfo->platform.eProductFamily)->isVmBindPatIndexProgrammingSupported()) { + EXPECT_ANY_THROW(allocation.setCacheAdvice(&drm, 1024, CacheRegion::Region1)); + } else { + EXPECT_TRUE(allocation.setCacheAdvice(&drm, 1024, CacheRegion::Region1)); + } } -TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSetRegionInBufferObject) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSetRegionInBufferObject) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); drm.cacheInfo.reset(new MockCacheInfo(drm, 32 * MemoryConstants::kiloByte, 2, 32)); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; - EXPECT_TRUE(allocation.setCacheAdvice(&drm, 1024, CacheRegion::Region1)); + if ((HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getNumCacheRegions() == 0) && + HwInfoConfig::get(defaultHwInfo->platform.eProductFamily)->isVmBindPatIndexProgrammingSupported()) { + EXPECT_ANY_THROW(allocation.setCacheAdvice(&drm, 1024, CacheRegion::Region1)); + } else { + EXPECT_TRUE(allocation.setCacheAdvice(&drm, 1024, CacheRegion::Region1)); - for (auto bo : allocation.bufferObjects) { - if (bo != nullptr) { - EXPECT_EQ(CacheRegion::Region1, bo->peekCacheRegion()); + for (auto bo : allocation.bufferObjects) { + if (bo != nullptr) { + EXPECT_EQ(CacheRegion::Region1, bo->peekCacheRegion()); + } } } } -TEST(DrmAllocationTest, givenDrmAllocationWhenBufferObjectIsCreatedThenApplyDefaultCachePolicy) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenBufferObjectIsCreatedThenApplyDefaultCachePolicy) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -4502,13 +4492,10 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenBufferObjectIsCreatedThenApplyDefa } } -TEST(DrmAllocationTest, givenDrmAllocationWhenSetCachePolicyIsCalledThenUpdatePolicyInBufferObject) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenSetCachePolicyIsCalledThenUpdatePolicyInBufferObject) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -4521,13 +4508,10 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenSetCachePolicyIsCalledThenUpdatePo } } -TEST(DrmAllocationTest, givenDrmAllocationWhenSetMemAdviseWithCachePolicyIsCalledThenUpdatePolicyInBufferObject) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenDrmAllocationWhenSetMemAdviseWithCachePolicyIsCalledThenUpdatePolicyInBufferObject) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -4547,13 +4531,10 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenSetMemAdviseWithCachePolicyIsCalle } } -TEST(DrmAllocationTest, givenBoWhenMarkingForCaptureThenBosAreMarked) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->prepareRootDeviceEnvironments(1); - +TEST_F(DrmAllocationTests, givenBoWhenMarkingForCaptureThenBosAreMarked) { DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::SCRATCH_SURFACE, MemoryPool::System4KBPages); allocation.markForCapture(); @@ -4564,6 +4545,9 @@ TEST(DrmAllocationTest, givenBoWhenMarkingForCaptureThenBosAreMarked) { } TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithCacheRegionThenSetRegionInBufferObject) { + if (HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getNumCacheRegions() == 0) { + GTEST_SKIP(); + } mock->ioctl_expected.total = -1; auto drm = static_cast(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->as()); drm->cacheInfo.reset(new MockCacheInfo(*drm, 32 * MemoryConstants::kiloByte, 2, 32)); @@ -4727,7 +4711,7 @@ struct DrmMemoryManagerToTestLockInLocalMemory : public TestedDrmMemoryManager { TEST_F(DrmMemoryManagerTest, givenDrmManagerWithLocalMemoryWhenLockResourceIsCalledOnWriteCombinedAllocationThenReturnPtrAlignedTo64Kb) { DrmMemoryManagerToTestLockInLocalMemory memoryManager(*executionEnvironment); - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); DrmAllocation drmAllocation(0, AllocationType::WRITE_COMBINED, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_EQ(&bo, drmAllocation.getBO()); @@ -4743,7 +4727,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmManagerWithLocalMemoryWhenLockResourceIsCal TEST_F(DrmMemoryManagerTest, givenDrmManagerWithoutLocalMemoryWhenLockResourceIsCalledOnWriteCombinedAllocationThenReturnNullptr) { TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment); - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); DrmAllocation drmAllocation(0, AllocationType::WRITE_COMBINED, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_EQ(&bo, drmAllocation.getBO()); @@ -4926,7 +4910,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThen TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemAdviseIsCalledThenUpdateCachePolicyInBufferObject) { TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment); - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); DrmAllocation drmAllocation(0, AllocationType::UNIFIED_SHARED_MEMORY, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_EQ(&bo, drmAllocation.getBO()); @@ -4942,7 +4926,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemAdviseIsCalledThenUp TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchIsCalledThenReturnTrue) { TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment); - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); DrmAllocation drmAllocation(0, AllocationType::UNIFIED_SHARED_MEMORY, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); EXPECT_EQ(&bo, drmAllocation.getBO()); @@ -4963,7 +4947,7 @@ TEST_F(DrmMemoryManagerTest, givenPageFaultIsUnSupportedWhenCallingBindBoOnBuffe osContext.ensureContextInitialized(); uint32_t vmHandleId = 0; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -4996,7 +4980,7 @@ TEST_F(DrmMemoryManagerTest, givenPageFaultIsSupportedWhenCallingBindBoOnAllocat }; for (auto shouldAllocationPageFault : {false, true}) { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocationToTestPageFault allocation; allocation.bufferObjects[0] = &bo; allocation.shouldPageFault = shouldAllocationPageFault; @@ -5015,7 +4999,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenDrmMemor auto gpuAddress = 0x1234u; auto size = MemoryConstants::pageSize; - auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1)); + auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), nullptr, AllocationType::BUFFER, gpuAddress, size, MemoryBanks::MainBank, 1)); EXPECT_EQ(nullptr, bo); } @@ -5023,7 +5007,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenDrmMemor auto gpuAddress = 0x1234u; auto size = 0u; - auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1)); + auto bo = std::unique_ptr(memoryManager->createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), nullptr, AllocationType::BUFFER, gpuAddress, size, MemoryBanks::MainBank, 1)); EXPECT_EQ(nullptr, bo); } @@ -5480,6 +5464,33 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenNotSetUs memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenPatIndexProgrammingAllowedWhenCreatingAllocationThenSetValidPatIndex) { + MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; + AllocationData allocData; + allocData.allFlags = 0; + allocData.size = MemoryConstants::pageSize; + allocData.flags.allocateMemory = true; + allocData.type = AllocationType::BUFFER; + allocData.rootDeviceIndex = rootDeviceIndex; + + auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status); + EXPECT_NE(nullptr, allocation); + + auto drmAllocation = static_cast(allocation); + ASSERT_NE(nullptr, drmAllocation->getBO()); + + if (HwInfoConfig::get(defaultHwInfo->platform.eProductFamily)->isVmBindPatIndexProgrammingSupported()) { + auto expectedIndex = mock->getPatIndex(allocation->getDefaultGmm(), allocation->getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false); + + EXPECT_NE(CommonConstants::unsupportedPatIndex, drmAllocation->getBO()->peekPatIndex()); + EXPECT_EQ(expectedIndex, drmAllocation->getBO()->peekPatIndex()); + } else { + EXPECT_EQ(CommonConstants::unsupportedPatIndex, drmAllocation->getBO()->peekPatIndex()); + } + + memoryManager->freeGraphicsMemory(allocation); +} + TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedForImageThenLocalMemoryAllocationIsReturnedFromStandard64KbHeap) { ImageDescriptor imgDesc = {}; imgDesc.imageType = ImageType::Image2D; @@ -5662,7 +5673,7 @@ TEST(DrmMemoryManagerCopyMemoryToAllocationBanksTest, givenDrmMemoryManagerWhenC for (auto index = 0u; index < 4; index++) { drmMemoryManger.lockedLocalMemory[index].reset(); - mockAllocation.bufferObjects.push_back(new BufferObject(drm, index, sourceAllocationSize, 3)); + mockAllocation.bufferObjects.push_back(new BufferObject(drm, 3, index, sourceAllocationSize, 3)); } auto ret = drmMemoryManger.copyMemoryToAllocationBanks(&mockAllocation, offset, dataToCopy.data(), dataToCopy.size(), memoryBanksToCopy); @@ -5682,7 +5693,7 @@ TEST(DrmMemoryManagerCopyMemoryToAllocationBanksTest, givenDrmMemoryManagerWhenC TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectSucceedsThenReturnTrueAndCorrectOffset) { mock->ioctl_expected.gemMmapOffset = 1; - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); mock->mmapOffsetExpected = 21; uint64_t offset = 0; @@ -5694,7 +5705,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBuf TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectFailsThenReturnFalse) { mock->ioctl_expected.gemMmapOffset = 2; - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); mock->failOnMmapOffset = true; uint64_t offset = 0; @@ -5705,7 +5716,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBuf TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledForLocalMemoryThenApplyCorrectFlags) { mock->ioctl_expected.gemMmapOffset = 5; - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); uint64_t offset = 0; auto ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, 0, offset); @@ -5725,7 +5736,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBuf TEST_F(DrmMemoryManagerTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledForSystemMemoryThenApplyCorrectFlags) { mock->ioctl_expected.gemMmapOffset = 4; - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); uint64_t offset = 0; bool ret = false; @@ -5763,7 +5774,7 @@ TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithMmapPtrThenMmapCalled) mock->ioctl_expected.gemMmap = 1; mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.gemClose = 1; - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); void *cpuPtr = (void *)0x30000; size_t size = 0x1000; @@ -5780,7 +5791,7 @@ TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithMmapPtrAndFailedMmapCal mock->ioctl_expected.gemMmap = 1; mock->ioctl_res = -1; - BufferObject bo(mock, 1, 1024, 0); + BufferObject bo(mock, 3, 1, 1024, 0); void *cpuPtr = (void *)0x30000; size_t size = 0x1000; diff --git a/opencl/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp index 242feb8f33..03d7ad7fda 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp @@ -69,6 +69,7 @@ struct DrmMemoryOperationsHandlerBindFixture : public ::testing::Test { executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.reset(new MockDrmMemoryOperationsHandlerBind(*executionEnvironment->rootDeviceEnvironments[i].get(), i)); + executionEnvironment->rootDeviceEnvironments[i]->initGmm(); devices.emplace_back(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, i)); } @@ -537,8 +538,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportAndMultiSubdevice DebugManager.flags.UseVmBind.set(1); mock->bindAvailable = true; - BufferObject pinBB(mock, 1, 0, 1); - BufferObject boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + BufferObject boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; pinBB.pin(&boToPinPtr, 1u, device->getDefaultEngine().osContext, 0u, 0u); @@ -551,8 +552,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportAndMultiSubdevice DebugManager.flags.UseVmBind.set(1); mock->bindAvailable = true; - BufferObject pinBB(mock, 1, 0, 1); - BufferObject boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + BufferObject boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; pinBB.validateHostPtr(&boToPinPtr, 1u, device->getDefaultEngine().osContext, 0u, 0u); @@ -565,8 +566,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportAndMultiSubdevice DebugManager.flags.UseVmBind.set(1); mock->bindAvailable = true; - BufferObject pinBB(mock, 1, 0, 1); - BufferObject boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + BufferObject boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; uint32_t vmHandleId = 1u; @@ -582,9 +583,9 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportAndMultiSubdevice mock->bindAvailable = true; mock->context.vmBindReturn = -1; - BufferObject pinBB(mock, 1, 0, 1); - BufferObject boToPin(mock, 2, 0, 1); - BufferObject boToPin2(mock, 3, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + BufferObject boToPin(mock, 3, 2, 0, 1); + BufferObject boToPin2(mock, 3, 3, 0, 1); BufferObject *boToPinPtr[] = {&boToPin, &boToPin2}; auto ret = pinBB.validateHostPtr(boToPinPtr, 2u, device->getDefaultEngine().osContext, 0u, 0u); @@ -600,8 +601,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenDirectSubmissionWhenPinBOThenV mock->bindAvailable = true; device->getDefaultEngine().osContext->setDirectSubmissionActive(); - BufferObject pinBB(mock, 1, 0, 1); - BufferObject boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + BufferObject boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; pinBB.pin(&boToPinPtr, 1u, device->getDefaultEngine().osContext, 0u, 0u); @@ -615,8 +616,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenDirectSubmissionAndValidateHos mock->bindAvailable = true; device->getDefaultEngine().osContext->setDirectSubmissionActive(); - BufferObject pinBB(mock, 1, 0, 1); - BufferObject boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + BufferObject boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; pinBB.validateHostPtr(&boToPinPtr, 1u, device->getDefaultEngine().osContext, 0u, 0u); @@ -633,8 +634,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportWhenPinBOThenAllo DebugManager.flags.UseVmBind.set(1); mock->bindAvailable = true; - BufferObject pinBB(mock, 1, 0, 1); - MockBO boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + MockBO boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; auto ret = pinBB.pin(&boToPinPtr, 1u, device->getDefaultEngine().osContext, 0u, 0u); @@ -652,8 +653,8 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportWhenPinBOAndVmBin mock->bindAvailable = true; mock->context.vmBindReturn = -1; - BufferObject pinBB(mock, 1, 0, 1); - MockBO boToPin(mock, 2, 0, 1); + BufferObject pinBB(mock, 3, 1, 0, 1); + MockBO boToPin(mock, 3, 2, 0, 1); BufferObject *boToPinPtr = &boToPin; auto ret = pinBB.pin(&boToPinPtr, 1u, device->getDefaultEngine().osContext, 0u, 0u); @@ -690,14 +691,19 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexProgrammingEnabledWhen auto osContext = memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor()); csr->setupContext(*osContext); - auto timestampStorageAlloc = csr->getTimestampPacketAllocator()->getTag()->getBaseGraphicsAllocation()->getDefaultGraphicsAllocation(); - auto &hwHelper = HwHelper::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eRenderCoreFamily); auto hwInfoConfig = HwInfoConfig::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily); bool closSupported = (hwHelper.getNumCacheRegions() > 0); bool patIndexProgrammingSupported = hwInfoConfig->isVmBindPatIndexProgrammingSupported(); + uint64_t gpuAddress = 0x123000; + size_t size = 1; + BufferObject bo(mock, static_cast(MockGmmClientContextBase::MockPatIndex::cached), 0, 1, 1); + DrmAllocation allocation(0, 1, AllocationType::BUFFER, &bo, nullptr, gpuAddress, size, MemoryPool::System4KBPages); + + auto allocationPtr = static_cast(&allocation); + for (int32_t debugFlag : {-1, 0, 1}) { if (debugFlag == 1 && !closSupported) { continue; @@ -708,12 +714,14 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexProgrammingEnabledWhen mock->context.receivedVmBindPatIndex.reset(); mock->context.receivedVmUnbindPatIndex.reset(); - operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1)); + bo.setPatIndex(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, (debugFlag == 1 && closSupported))); + + operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1)); if (!patIndexProgrammingSupported) { EXPECT_FALSE(mock->context.receivedVmBindPatIndex); - operationHandler->evict(device, *timestampStorageAlloc); + operationHandler->evict(device, allocation); EXPECT_FALSE(mock->context.receivedVmUnbindPatIndex); continue; @@ -724,12 +732,12 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexProgrammingEnabledWhen EXPECT_EQ(expectedIndex, mock->context.receivedVmBindPatIndex.value()); - operationHandler->evict(device, *timestampStorageAlloc); + operationHandler->evict(device, allocation); EXPECT_EQ(expectedIndex, mock->context.receivedVmUnbindPatIndex.value()); } else { EXPECT_EQ(3u, mock->context.receivedVmBindPatIndex.value()); - operationHandler->evict(device, *timestampStorageAlloc); + operationHandler->evict(device, allocation); EXPECT_EQ(3u, mock->context.receivedVmUnbindPatIndex.value()); } } @@ -743,8 +751,6 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorWhenVmBindCalledT auto osContext = memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor()); csr->setupContext(*osContext); - auto timestampStorageAlloc = csr->getTimestampPacketAllocator()->getTag()->getBaseGraphicsAllocation()->getDefaultGraphicsAllocation(); - auto &hwHelper = HwHelper::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eRenderCoreFamily); auto hwInfoConfig = HwInfoConfig::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily); @@ -755,6 +761,13 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorWhenVmBindCalledT GTEST_SKIP(); } + uint64_t gpuAddress = 0x123000; + size_t size = 1; + BufferObject bo(mock, static_cast(MockGmmClientContextBase::MockPatIndex::cached), 0, 1, 1); + DrmAllocation allocation(0, 1, AllocationType::BUFFER, &bo, nullptr, gpuAddress, size, MemoryPool::System4KBPages); + + auto allocationPtr = static_cast(&allocation); + static_cast(executionEnvironment->rootDeviceEnvironments[0]->getGmmClientContext())->returnErrorOnPatIndexQuery = true; for (int32_t debugFlag : {-1, 0, 1}) { @@ -763,11 +776,13 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorWhenVmBindCalledT mock->context.receivedVmBindPatIndex.reset(); mock->context.receivedVmUnbindPatIndex.reset(); - operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1)); + bo.setPatIndex(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false)); + + operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1)); EXPECT_EQ(3u, mock->context.receivedVmBindPatIndex.value()); - operationHandler->evict(device, *timestampStorageAlloc); + operationHandler->evict(device, allocation); EXPECT_EQ(3u, mock->context.receivedVmUnbindPatIndex.value()); } } @@ -781,8 +796,6 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorAndUncachedDebugF auto osContext = memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor()); csr->setupContext(*osContext); - auto timestampStorageAlloc = csr->getTimestampPacketAllocator()->getTag()->getBaseGraphicsAllocation()->getDefaultGraphicsAllocation(); - auto &hwHelper = HwHelper::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eRenderCoreFamily); auto hwInfoConfig = HwInfoConfig::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily); @@ -798,11 +811,20 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorAndUncachedDebugF mock->context.receivedVmBindPatIndex.reset(); mock->context.receivedVmUnbindPatIndex.reset(); - operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1)); + uint64_t gpuAddress = 0x123000; + size_t size = 1; + BufferObject bo(mock, static_cast(MockGmmClientContextBase::MockPatIndex::cached), 0, 1, 1); + DrmAllocation allocation(0, 1, AllocationType::BUFFER, &bo, nullptr, gpuAddress, size, MemoryPool::System4KBPages); + + bo.setPatIndex(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false)); + + auto allocationPtr = static_cast(&allocation); + + operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1)); EXPECT_EQ(0u, mock->context.receivedVmBindPatIndex.value()); - operationHandler->evict(device, *timestampStorageAlloc); + operationHandler->evict(device, allocation); EXPECT_EQ(0u, mock->context.receivedVmUnbindPatIndex.value()); } @@ -875,14 +897,14 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenClosEnabledAndAllocationToBeCach mock->cacheInfo.reset(new CacheInfo(*mock, 64 * MemoryConstants::kiloByte, 2, 32)); - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); - auto &hwHelper = HwHelper::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eRenderCoreFamily); if (hwHelper.getNumCacheRegions() == 0) { GTEST_SKIP(); } + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); + for (auto cacheRegion : {CacheRegion::Default, CacheRegion::Region1, CacheRegion::Region2}) { EXPECT_TRUE(static_cast(allocation)->setCacheAdvice(mock, 32 * MemoryConstants::kiloByte, cacheRegion)); diff --git a/shared/source/helpers/constants.h b/shared/source/helpers/constants.h index 8f3aea17b9..2cc58555dd 100644 --- a/shared/source/helpers/constants.h +++ b/shared/source/helpers/constants.h @@ -86,6 +86,7 @@ enum PostBlitMode : int32_t { } // namespace BlitterConstants namespace CommonConstants { +constexpr uint64_t unsupportedPatIndex = std::numeric_limits::max(); constexpr uint32_t unspecifiedDeviceIndex = std::numeric_limits::max(); constexpr uint32_t invalidStepping = std::numeric_limits::max(); constexpr uint32_t maximalSimdSize = 32; diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 17ad4f05d1..c2ec404117 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -110,6 +110,9 @@ static bool initHwDeviceIdResources(ExecutionEnvironment &executionEnvironment, executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getMutableHardwareInfo()->platform.usRevId = static_cast(DebugManager.flags.OverrideRevision.get()); } + + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initGmm(); + return true; } diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 748f2ded9f..ad043087db 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -71,10 +71,13 @@ bool DrmAllocation::setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regi return false; } + auto patIndex = drm->getPatIndex(getDefaultGmm(), allocationType, regionIndex, CachePolicy::WriteBack, true); + if (fragmentsStorage.fragmentCount > 0) { for (uint32_t i = 0; i < fragmentsStorage.fragmentCount; i++) { auto bo = static_cast(fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo; bo->setCacheRegion(regionIndex); + bo->setPatIndex(patIndex); } return true; } @@ -82,6 +85,7 @@ bool DrmAllocation::setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regi for (auto bo : bufferObjects) { if (bo != nullptr) { bo->setCacheRegion(regionIndex); + bo->setPatIndex(patIndex); } } return true; diff --git a/shared/source/os_interface/linux/drm_buffer_object.cpp b/shared/source/os_interface/linux/drm_buffer_object.cpp index ce84bd78e1..8fdde40ad7 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.cpp +++ b/shared/source/os_interface/linux/drm_buffer_object.cpp @@ -33,9 +33,10 @@ namespace NEO { -BufferObject::BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) { +BufferObject::BufferObject(Drm *drm, uint64_t patIndex, int handle, size_t size, size_t maxOsContextCount) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) { this->tilingMode = I915_TILING_NONE; this->lockedAddress = nullptr; + this->patIndex = patIndex; perContextVmsUsed = drm->isPerContextVMRequired(); requiresExplicitResidency = drm->hasPageFaultSupport(); diff --git a/shared/source/os_interface/linux/drm_buffer_object.h b/shared/source/os_interface/linux/drm_buffer_object.h index 21923fd9e2..6e6c52f71f 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.h +++ b/shared/source/os_interface/linux/drm_buffer_object.h @@ -32,7 +32,7 @@ class OsContext; class BufferObject { public: - BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount); + BufferObject(Drm *drm, uint64_t patIndex, int handle, size_t size, size_t maxOsContextCount); MOCKABLE_VIRTUAL ~BufferObject() = default; struct Deleter { @@ -137,6 +137,8 @@ class BufferObject { std::vector &getColourAddresses() { return this->bindAddresses; } + uint64_t peekPatIndex() const { return patIndex; } + void setPatIndex(uint64_t newPatIndex) { this->patIndex = newPatIndex; } static constexpr int GPU_HANG_DETECTED{-7171}; @@ -152,7 +154,6 @@ class BufferObject { uint64_t size; bool isReused; - //Tiling uint32_t tilingMode; bool allowCapture = false; bool requiresImmediateBinding = false; @@ -166,6 +167,7 @@ class BufferObject { void *lockedAddress; // CPU side virtual address uint64_t unmapSize = 0; + uint64_t patIndex = CommonConstants::unsupportedPatIndex; CacheRegion cacheRegion = CacheRegion::Default; CachePolicy cachePolicy = CachePolicy::WriteBack; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 595a7269f6..44128a12f1 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -243,13 +243,17 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size userptr.user_size = size; userptr.flags = static_cast(flags); - if (this->getDrm(rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_USERPTR, &userptr) != 0) { + auto &drm = this->getDrm(rootDeviceIndex); + + if (drm.ioctl(DRM_IOCTL_I915_GEM_USERPTR, &userptr) != 0) { return nullptr; } PRINT_DEBUG_STRING(DebugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "Created new BO with GEM_USERPTR, handle: BO-%d\n", userptr.handle); - auto res = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), userptr.handle, size, maxOsContextCount); + auto patIndex = drm.getPatIndex(nullptr, AllocationType::EXTERNAL_HOST_PTR, CacheRegion::Default, CachePolicy::WriteBack, false); + + auto res = new (std::nothrow) BufferObject(&drm, patIndex, userptr.handle, size, maxOsContextCount); if (!res) { DEBUG_BREAK_IF(true); return nullptr; @@ -510,10 +514,14 @@ GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData & drm_i915_gem_create create = {0, 0, 0}; create.size = bufferSize; - [[maybe_unused]] auto ret = this->getDrm(allocationData.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); + auto &drm = getDrm(allocationData.rootDeviceIndex); + + [[maybe_unused]] auto ret = drm.ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); DEBUG_BREAK_IF(ret != 0); - std::unique_ptr bo(new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, bufferSize, maxOsContextCount)); + auto patIndex = drm.getPatIndex(gmm.get(), allocationData.type, CacheRegion::Default, CachePolicy::WriteBack, false); + + std::unique_ptr bo(new BufferObject(&drm, patIndex, create.handle, bufferSize, maxOsContextCount)); bo->setAddress(gpuRange); auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), nullptr, gpuRange, bufferSize, MemoryPool::SystemCpuInaccessible); @@ -539,10 +547,14 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A drm_i915_gem_create create = {0, 0, 0}; create.size = allocationData.imgInfo->size; - [[maybe_unused]] auto ret = this->getDrm(allocationData.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); + auto &drm = this->getDrm(allocationData.rootDeviceIndex); + + [[maybe_unused]] auto ret = drm.ioctl(DRM_IOCTL_I915_GEM_CREATE, &create); DEBUG_BREAK_IF(ret != 0); - std::unique_ptr bo(new (std::nothrow) BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.imgInfo->size, maxOsContextCount)); + auto patIndex = drm.getPatIndex(gmm.get(), allocationData.type, CacheRegion::Default, CachePolicy::WriteBack, false); + + std::unique_ptr bo(new (std::nothrow) BufferObject(&drm, patIndex, create.handle, allocationData.imgInfo->size, maxOsContextCount)); if (!bo) { return nullptr; } @@ -652,7 +664,9 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o drm_prime_handle openFd = {0, 0, 0}; openFd.fd = handle; - auto ret = this->getDrm(properties.rootDeviceIndex).ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd); + auto &drm = this->getDrm(properties.rootDeviceIndex); + + auto ret = drm.ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd); if (ret != 0) { [[maybe_unused]] int err = errno; @@ -667,7 +681,9 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (bo == nullptr) { size_t size = lseekFunction(handle, 0, SEEK_END); - bo = new (std::nothrow) BufferObject(&getDrm(properties.rootDeviceIndex), boHandle, size, maxOsContextCount); + auto patIndex = drm.getPatIndex(nullptr, properties.allocationType, CacheRegion::Default, CachePolicy::WriteBack, false); + + bo = new (std::nothrow) BufferObject(&drm, patIndex, boHandle, size, maxOsContextCount); if (!bo) { return nullptr; @@ -699,7 +715,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (properties.imgInfo) { drm_i915_gem_get_tiling getTiling = {0}; getTiling.handle = boHandle; - ret = this->getDrm(properties.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_GET_TILING, &getTiling); + ret = drm.ioctl(DRM_IOCTL_I915_GEM_GET_TILING, &getTiling); if (ret == 0) { if (getTiling.tiling_mode == I915_TILING_NONE) { @@ -709,7 +725,10 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o Gmm *gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getGmmClientContext(), *properties.imgInfo, createStorageInfoFromProperties(properties), properties.flags.preferCompressed); + drmAllocation->setDefaultGmm(gmm); + + bo->setPatIndex(drm.getPatIndex(gmm, properties.allocationType, CacheRegion::Default, CachePolicy::WriteBack, false)); } return drmAllocation; } @@ -1409,11 +1428,8 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A return allocation.release(); } -BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, - uint64_t gpuAddress, - size_t size, - uint32_t memoryBanks, - size_t maxOsContextCount) { +BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, + size_t size, uint32_t memoryBanks, size_t maxOsContextCount) { auto memoryInfo = drm->getMemoryInfo(); if (!memoryInfo) { return nullptr; @@ -1426,7 +1442,9 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, return nullptr; } - auto bo = new (std::nothrow) BufferObject(drm, handle, size, maxOsContextCount); + auto patIndex = drm->getPatIndex(gmm, allocationType, CacheRegion::Default, CachePolicy::WriteBack, false); + + auto bo = new (std::nothrow) BufferObject(drm, patIndex, handle, size, maxOsContextCount); if (!bo) { return nullptr; } @@ -1465,8 +1483,9 @@ bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, } memoryBanks &= 1u << currentBank; } - auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k); - bos[handleId] = createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount); + auto gmm = allocation->getGmm(handleId); + auto boSize = alignUp(gmm->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k); + bos[handleId] = createBufferObjectInMemoryRegion(drm, gmm, allocation->getAllocationType(), boAddress, boSize, memoryBanks, maxOsContextCount); if (nullptr == bos[handleId]) { return false; } @@ -1592,7 +1611,8 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & cpuPointer = alignUp(cpuPointer, alignment); auto pointerDiff = ptrDiff(cpuPointer, cpuBasePointer); - std::unique_ptr bo(this->createBufferObjectInMemoryRegion(&this->getDrm(allocationData.rootDeviceIndex), reinterpret_cast(cpuPointer), alignedSize, 0u, maxOsContextCount)); + std::unique_ptr bo(this->createBufferObjectInMemoryRegion(&this->getDrm(allocationData.rootDeviceIndex), nullptr, allocationData.type, + reinterpret_cast(cpuPointer), alignedSize, 0u, maxOsContextCount)); if (!bo) { this->munmapFunction(cpuBasePointer, totalSizeToAlloc); @@ -1719,7 +1739,9 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const return nullptr; } - std::unique_ptr bo(new BufferObject(&drm, handle, size, maxOsContextCount)); + auto patIndex = drm.getPatIndex(nullptr, allocationData.type, CacheRegion::Default, CachePolicy::WriteBack, false); + + std::unique_ptr bo(new BufferObject(&drm, patIndex, handle, size, maxOsContextCount)); if (!drm.getIoctlHelper()->setVmBoAdvise(&drm, bo->peekHandle(), vmAdviseAttribute, nullptr)) { return nullptr; @@ -1762,25 +1784,28 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl drm_prime_handle openFd = {0, 0, 0}; openFd.fd = handle; - auto ret = this->getDrm(properties.rootDeviceIndex).ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd); + auto &drm = this->getDrm(properties.rootDeviceIndex); + auto patIndex = drm.getPatIndex(nullptr, properties.allocationType, CacheRegion::Default, CachePolicy::WriteBack, false); + + auto ret = drm.ioctl(DRM_IOCTL_PRIME_FD_TO_HANDLE, &openFd); if (ret != 0) { - int err = this->getDrm(properties.rootDeviceIndex).getErrno(); + int err = drm.getErrno(); PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(PRIME_FD_TO_HANDLE) failed with %d. errno=%d(%s)\n", ret, err, strerror(err)); DEBUG_BREAK_IF(ret != 0); return nullptr; } if (hasMappedPtr) { - auto bo = new BufferObject(&getDrm(properties.rootDeviceIndex), openFd.handle, properties.size, maxOsContextCount); + auto bo = new BufferObject(&drm, patIndex, openFd.handle, properties.size, maxOsContextCount); bo->setAddress(properties.gpuAddress); return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast(bo->peekAddress()), bo->peekSize(), handle, MemoryPool::SystemCpuInaccessible); } - const bool useBooMmap = this->getDrm(properties.rootDeviceIndex).getMemoryInfo() && properties.useMmapObject; + const bool useBooMmap = drm.getMemoryInfo() && properties.useMmapObject; if (!useBooMmap) { - auto bo = new BufferObject(&getDrm(properties.rootDeviceIndex), openFd.handle, properties.size, maxOsContextCount); + auto bo = new BufferObject(&drm, patIndex, openFd.handle, properties.size, maxOsContextCount); bo->setAddress(properties.gpuAddress); return new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, reinterpret_cast(bo->peekAddress()), bo->peekSize(), @@ -1794,7 +1819,7 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl void *cpuPointer = nullptr; size_t size = lseekFunction(handle, 0, SEEK_END); - bo = new BufferObject(&getDrm(properties.rootDeviceIndex), boHandle, size, maxOsContextCount); + bo = new BufferObject(&drm, patIndex, boHandle, size, maxOsContextCount); cpuPointer = this->mmapFunction(0, size, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (cpuPointer == MAP_FAILED) { @@ -1812,7 +1837,7 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl return nullptr; } - [[maybe_unused]] auto retPtr = this->mmapFunction(cpuPointer, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, getDrm(properties.rootDeviceIndex).getFileDescriptor(), static_cast(offset)); + [[maybe_unused]] auto retPtr = this->mmapFunction(cpuPointer, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, drm.getFileDescriptor(), static_cast(offset)); DEBUG_BREAK_IF(retPtr != cpuPointer); AllocationData allocationData = {}; diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index a6ce8c4202..6c7755cd41 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -63,7 +63,8 @@ class DrmMemoryManager : public MemoryManager { MOCKABLE_VIRTUAL int obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex); AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override; void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override; - MOCKABLE_VIRTUAL BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount); + MOCKABLE_VIRTUAL BufferObject *createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size, + uint32_t memoryBanks, size_t maxOsContextCount); bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override; diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 9bf04a951a..377feb52bc 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -10,7 +10,9 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/execution_environment/execution_environment.h" #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/resource_info.h" #include "shared/source/helpers/constants.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/hw_helper.h" @@ -1342,20 +1344,34 @@ bool Drm::isVmBindAvailable() { return bindAvailable; } -uint64_t getPatIndex(Drm *drm, const HwHelper &hwHelper, CacheRegion cacheRegion, CachePolicy cachePolicy, bool closEnabled) { +uint64_t Drm::getPatIndex(Gmm *gmm, AllocationType allocationType, CacheRegion cacheRegion, CachePolicy cachePolicy, bool closEnabled) const { if (DebugManager.flags.OverridePatIndex.get() != -1) { return static_cast(DebugManager.flags.OverridePatIndex.get()); } - uint64_t patIndex = drm->getRootDeviceEnvironment().getGmmClientContext()->cachePolicyGetPATIndex(nullptr, GMM_RESOURCE_USAGE_OCL_BUFFER); + auto hwInfo = rootDeviceEnvironment.getHardwareInfo(); - if (DebugManager.flags.ForceAllResourcesUncached.get()) { - patIndex = drm->getRootDeviceEnvironment().getGmmClientContext()->cachePolicyGetPATIndex(nullptr, GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED); + if (!HwInfoConfig::get(hwInfo->platform.eProductFamily)->isVmBindPatIndexProgrammingSupported()) { + return CommonConstants::unsupportedPatIndex; + } + + GMM_RESOURCE_INFO *resourceInfo = nullptr; + GMM_RESOURCE_USAGE_TYPE usageType = CacheSettingsHelper::getGmmUsageType(allocationType, false, *hwInfo); + + if (gmm) { + resourceInfo = gmm->gmmResourceInfo->peekGmmResourceInfo(); + usageType = gmm->resourceParams.Usage; + } + + uint64_t patIndex = rootDeviceEnvironment.getGmmClientContext()->cachePolicyGetPATIndex(resourceInfo, usageType); + + if (DebugManager.flags.ClosEnabled.get() != -1) { + closEnabled = !!DebugManager.flags.ClosEnabled.get(); } if (patIndex == static_cast(GMM_PAT_ERROR) || closEnabled) { DEBUG_BREAK_IF(true); - patIndex = hwHelper.getPatIndex(cacheRegion, cachePolicy); + patIndex = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getPatIndex(cacheRegion, cachePolicy); } return patIndex; @@ -1396,7 +1412,6 @@ int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleI } auto hwInfo = drm->getRootDeviceEnvironment().getHardwareInfo(); - auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily); auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily); int ret = 0; @@ -1416,18 +1431,11 @@ int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleI vmBind.start = bindAddresses[i]; } - bool closEnabled = (hwHelper.getNumCacheRegions() > 0) && (bo->peekCacheRegion() > CacheRegion::Default); - - if (DebugManager.flags.ClosEnabled.get() != -1) { - closEnabled = !!DebugManager.flags.ClosEnabled.get(); - } - VmBindExtSetPatT vmBindExtSetPat{}; if (hwInfoConfig->isVmBindPatIndexProgrammingSupported()) { - uint64_t patIndex = getPatIndex(drm, hwHelper, bo->peekCacheRegion(), bo->peekCachePolicy(), closEnabled); - - ioctlHelper->fillVmBindExtSetPat(vmBindExtSetPat, patIndex, castToUint64(extensions.get())); + UNRECOVERABLE_IF(bo->peekPatIndex() == CommonConstants::unsupportedPatIndex); + ioctlHelper->fillVmBindExtSetPat(vmBindExtSetPat, bo->peekPatIndex(), castToUint64(extensions.get())); vmBind.extensions = castToUint64(vmBindExtSetPat); } else { vmBind.extensions = castToUint64(extensions.get()); diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index efdd8499f8..9896ac4fd5 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -40,9 +40,11 @@ struct GT_SYSTEM_INFO; namespace NEO { #define I915_CONTEXT_PRIVATE_PARAM_BOOST 0x80000000 +enum class AllocationType; class BufferObject; class DeviceFactory; class OsContext; +class Gmm; struct HardwareInfo; struct RootDeviceEnvironment; struct SystemInfo; @@ -253,6 +255,8 @@ class Drm : public DriverModel { MOCKABLE_VIRTUAL uint32_t notifyFirstCommandQueueCreated(); MOCKABLE_VIRTUAL void notifyLastCommandQueueDestroyed(uint32_t handle); + uint64_t getPatIndex(Gmm *gmm, AllocationType allocationType, CacheRegion cacheRegion, CachePolicy cachePolicy, bool closEnabled) const; + protected: Drm(std::unique_ptr &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment); diff --git a/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp b/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp index 837cdcc387..da255561b3 100644 --- a/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp +++ b/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp @@ -284,10 +284,6 @@ void HwHelperHw::setExtraAllocationData(AllocationData &allocationData, template <> uint32_t HwHelperHw::getNumCacheRegions() const { - if (DebugManager.flags.ClosEnabled.get() == 0) { - return 0; - } - constexpr uint32_t numSharedCacheRegions = 1; constexpr uint32_t numReservedCacheRegions = 2; constexpr uint32_t numTotalCacheRegions = numSharedCacheRegions + numReservedCacheRegions; diff --git a/shared/test/common/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp b/shared/test/common/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp index 2a72da08fb..73020f72af 100644 --- a/shared/test/common/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp +++ b/shared/test/common/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp @@ -12,7 +12,7 @@ using namespace NEO; void MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(ExecutionEnvironment &executionEnvironment) { auto memoryManager = static_cast(executionEnvironment.memoryManager.get()); - auto bufferObject = new (std::nothrow) BufferObject(&memoryManager->getDrm(0u), 0, 10, MemoryManager::maxOsContextCount); + auto bufferObject = new (std::nothrow) BufferObject(&memoryManager->getDrm(0u), 3, 0, 10, MemoryManager::maxOsContextCount); memoryManager->pushSharedBufferObject(bufferObject); } diff --git a/shared/test/common/mocks/linux/mock_drm_allocation.h b/shared/test/common/mocks/linux/mock_drm_allocation.h index 06cf0ad75c..19718bc04b 100644 --- a/shared/test/common/mocks/linux/mock_drm_allocation.h +++ b/shared/test/common/mocks/linux/mock_drm_allocation.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 Intel Corporation + * Copyright (C) 2019-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,7 +18,7 @@ class MockBufferObject : public BufferObject { using BufferObject::BufferObject; using BufferObject::handle; - MockBufferObject(Drm *drm) : BufferObject(drm, 0, 0, 1) { + MockBufferObject(Drm *drm) : BufferObject(drm, CommonConstants::unsupportedPatIndex, 0, 0, 1) { } }; diff --git a/shared/test/common/mocks/mock_execution_environment.h b/shared/test/common/mocks/mock_execution_environment.h index 5dd97df3aa..29604aff09 100644 --- a/shared/test/common/mocks/mock_execution_environment.h +++ b/shared/test/common/mocks/mock_execution_environment.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * diff --git a/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h b/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h index b023f0bbb5..45106ca8f9 100644 --- a/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h +++ b/shared/test/common/os_interface/linux/drm_buffer_object_fixture.h @@ -19,10 +19,10 @@ class TestedBufferObject : public BufferObject { public: using BufferObject::handle; - TestedBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) { + TestedBufferObject(Drm *drm) : BufferObject(drm, 3, 1, 0, 1) { } - TestedBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, size, 1) { + TestedBufferObject(Drm *drm, size_t size) : BufferObject(drm, 3, 1, size, 1) { } void tileBy(uint32_t mode) { 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 57ac6d27c1..d2d37cc9d3 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 @@ -35,6 +35,7 @@ class DrmCommandStreamTest : public ::testing::Test { executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); + executionEnvironment.rootDeviceEnvironments[0]->initGmm(); mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo)); osContext = std::make_unique(*mock, 0u, @@ -155,7 +156,7 @@ class DrmCommandStreamEnhancedTemplate : public ::testing::Test { friend DrmCommandStreamEnhancedTemplate; protected: - MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0, 16u) { + MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, CommonConstants::unsupportedPatIndex, 1, 0, 16u) { this->size = alignUp(size, 4096); } }; @@ -235,7 +236,7 @@ class DrmCommandStreamEnhancedWithFailingExecTemplate : public ::testing::Test { friend DrmCommandStreamEnhancedTemplate; protected: - MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0, 16u) { + MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, CommonConstants::unsupportedPatIndex, 1, 0, 16u) { this->size = alignUp(size, 4096); } }; diff --git a/shared/test/common/os_interface/linux/drm_memory_manager_tests.h b/shared/test/common/os_interface/linux/drm_memory_manager_tests.h index a7bab19c71..d98745d1a8 100644 --- a/shared/test/common/os_interface/linux/drm_memory_manager_tests.h +++ b/shared/test/common/os_interface/linux/drm_memory_manager_tests.h @@ -31,10 +31,12 @@ class DrmMemoryManagerBasic : public ::testing::Test { DrmMemoryManagerBasic() : executionEnvironment(defaultHwInfo.get(), false, numRootDevices){}; void SetUp() override { for (auto i = 0u; i < numRootDevices; i++) { + executionEnvironment.rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[i]->osInterface = std::make_unique(); auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[i]); executionEnvironment.rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr(drm)); executionEnvironment.rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, i); + executionEnvironment.rootDeviceEnvironments[i]->initGmm(); } } const uint32_t rootDeviceIndex = 1u; @@ -68,10 +70,12 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { this->mock = mock; for (auto i = 0u; i < numRootDevices; i++) { auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[i].get(); + rootDeviceEnvironment->setHwInfo(defaultHwInfo.get()); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(new DrmMockCustom(*rootDeviceEnvironment))); rootDeviceEnvironment->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*rootDeviceEnvironment->osInterface->getDriverModel()->as(), i); rootDeviceEnvironment->builtins.reset(new MockBuiltins); + rootDeviceEnvironment->initGmm(); } rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get(); @@ -188,6 +192,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation { rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(new DrmMockCustom(*rootDeviceEnvironment))); rootDeviceEnvironment->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*rootDeviceEnvironment->osInterface->getDriverModel()->as(), i); + rootDeviceEnvironment->initGmm(); i++; } mock = static_cast(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->as()); diff --git a/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp index 14254301ec..8d94725d93 100644 --- a/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_debug_prelim_tests.cpp @@ -241,7 +241,7 @@ TEST(DrmPrelimTest, givenContextDebugNotAvailableWhenCheckedForSupportThenTrueIs TEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenBindingWithinDefaultEngineContextThenExtensionsArePassedToVmBindIoctl) { DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.addBindExtHandle(4); bo.addBindExtHandle(5); @@ -261,7 +261,7 @@ TEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenBindingWithinDefaultE TEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenBindingWithinInternalContextThenExtensionsAreNotPassedToVmBindIoctl) { DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.addBindExtHandle(4); bo.addBindExtHandle(5); @@ -275,7 +275,7 @@ TEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenBindingWithinInternal TEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenBindingWithinCopyEngineContextThenExtensionsAreNotPassedToVmBindIoctl) { DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.addBindExtHandle(4); bo.addBindExtHandle(5); @@ -291,7 +291,7 @@ TEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenBindingWithinCopyEngi HWTEST_F(DrmDebugPrelimTest, givenAddedBindExtHandlesInBoWhenUnbindingThenExtensionsAreNotSet) { DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.addBindExtHandle(4); bo.addBindExtHandle(5); diff --git a/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp index 2e9e6e28ad..ba2bd47315 100644 --- a/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_query_prelim_tests.cpp @@ -281,7 +281,7 @@ TEST(DrmBufferObjectTestPrelim, givenBufferObjectSetToColourWithBindWhenBindingT executionEnvironment->rootDeviceEnvironments[0]->initGmm(); executionEnvironment->initializeMemoryManager(); DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - BufferObjectMock bo(&drm, 1, 0, 1); + BufferObjectMock bo(&drm, 3, 1, 0, 1); bo.setColourWithBind(); bo.setColourChunk(MemoryConstants::pageSize64k); bo.addColouringAddress(0xffeeffee); @@ -338,7 +338,7 @@ TEST(DrmBufferObjectTestPrelim, givenBufferObjectMarkedForCaptureWhenBindingThen executionEnvironment->rootDeviceEnvironments[0]->initGmm(); executionEnvironment->initializeMemoryManager(); DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - BufferObjectMock bo(&drm, 1, 0, 1); + BufferObjectMock bo(&drm, 3, 1, 0, 1); OsContextLinux osContext(drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()); osContext.ensureContextInitialized(); bo.markForCapture(); @@ -358,7 +358,7 @@ TEST(DrmBufferObjectTestPrelim, givenNoActiveDirectSubmissionAndForceUseImmediat executionEnvironment->rootDeviceEnvironments[0]->initGmm(); executionEnvironment->initializeMemoryManager(); DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - BufferObjectMock bo(&drm, 1, 0, 1); + BufferObjectMock bo(&drm, 3, 1, 0, 1); OsContextLinux osContext(drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()); osContext.ensureContextInitialized(); @@ -376,7 +376,7 @@ TEST(DrmBufferObjectTestPrelim, whenBindingThenImmediateFlagIsSetAndExtensionLis executionEnvironment->initializeMemoryManager(); DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; drm.setDirectSubmissionActive(true); - BufferObjectMock bo(&drm, 1, 0, 1); + BufferObjectMock bo(&drm, 3, 1, 0, 1); OsContextLinux osContext(drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()); osContext.ensureContextInitialized(); osContext.setDirectSubmissionActive(); diff --git a/shared/test/unit_test/os_interface/linux/drm_special_heap_test.cpp b/shared/test/unit_test/os_interface/linux/drm_special_heap_test.cpp index adb61852bf..1fd375ac90 100644 --- a/shared/test/unit_test/os_interface/linux/drm_special_heap_test.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_special_heap_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,6 +29,7 @@ class DrmMemManagerFixture { executionEnvironment = std::make_unique(); executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); DeviceFactory::prepareDeviceEnvironments(*executionEnvironment); executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]))); memManager = std::unique_ptr(new FrontWindowMemManagerMock(*executionEnvironment)); diff --git a/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp index 99218f3804..2dbe009ac7 100644 --- a/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp @@ -23,7 +23,7 @@ TEST(DrmVmBindTest, givenBoRequiringImmediateBindWhenBindingThenImmediateFlagIsP executionEnvironment->initializeMemoryManager(); DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.requireImmediateBinding(true); OsContextLinux osContext(drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()); @@ -43,7 +43,7 @@ TEST(DrmVmBindTest, givenBoRequiringExplicitResidencyWhenBindingThenMakeResident drm.pageFaultSupported = true; for (auto requireResidency : {false, true}) { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.requireExplicitResidency(requireResidency); OsContextLinux osContext(drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()); @@ -83,7 +83,7 @@ TEST(DrmVmBindTest, givenBoNotRequiringExplicitResidencyWhenCallingWaitForBindTh drm.pageFaultSupported = true; for (auto requireResidency : {false, true}) { - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); bo.requireExplicitResidency(requireResidency); OsContextLinux osContext(drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()); @@ -118,7 +118,7 @@ TEST(DrmVmBindTest, givenUseKmdMigrationWhenCallingBindBoOnUnifiedSharedMemoryTh osContext.ensureContextInitialized(); uint32_t vmHandleId = 0; - MockBufferObject bo(&drm, 0, 0, 1); + MockBufferObject bo(&drm, 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::UNIFIED_SHARED_MEMORY, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; diff --git a/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp index 8837f065cb..8bfde3d0b2 100644 --- a/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp @@ -207,7 +207,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenWaitUserFenceThenCorrectValueRe TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseFailsThenDontUpdateMemAdviceFlags) { drm->ioctlRetVal = -1; - MockBufferObject bo(drm.get(), 0, 0, 1); + MockBufferObject bo(drm.get(), 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -221,7 +221,7 @@ TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseFailsThenDont } TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseWithNonAtomicIsCalledThenUpdateTheCorrespondingVmAdviceForBufferObject) { - MockBufferObject bo(drm.get(), 0, 0, 1); + MockBufferObject bo(drm.get(), 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -237,7 +237,7 @@ TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseWithNonAtomic } TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseWithDevicePreferredLocationIsCalledThenUpdateTheCorrespondingVmAdviceForBufferObject) { - MockBufferObject bo(drm.get(), 0, 0, 1); + MockBufferObject bo(drm.get(), 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -253,7 +253,7 @@ TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseWithDevicePre } TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchSucceedsThenReturnTrue) { - MockBufferObject bo(drm.get(), 0, 0, 1); + MockBufferObject bo(drm.get(), 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo; @@ -262,7 +262,7 @@ TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchSucceedsThe } TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchFailsThenReturnFalse) { - MockBufferObject bo(drm.get(), 0, 0, 1); + MockBufferObject bo(drm.get(), 3, 0, 0, 1); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); allocation.bufferObjects[0] = &bo;