diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 972b590973..23581265b4 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -513,7 +513,7 @@ ze_result_t ContextImp::makeMemoryResident(ze_device_handle_t hDevice, void *ptr } NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get(); - auto success = memoryOperationsIface->makeResident(neoDevice, ArrayRef(&allocation, 1)); + auto success = memoryOperationsIface->makeResident(neoDevice, ArrayRef(&allocation, 1), true); ze_result_t res = changeMemoryOperationStatusToL0ResultType(success); if (ZE_RESULT_SUCCESS == res) { @@ -557,9 +557,9 @@ ze_result_t ContextImp::makeImageResident(ze_device_handle_t hDevice, ze_image_h NEO::Device *neoDevice = L0::Device::fromHandle(hDevice)->getNEODevice(); NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get(); - auto success = memoryOperationsIface->makeResident(neoDevice, ArrayRef(&alloc, 1)); + auto success = memoryOperationsIface->makeResident(neoDevice, ArrayRef(&alloc, 1), true); if (implicitArgsAlloc) { - memoryOperationsIface->makeResident(neoDevice, ArrayRef(&implicitArgsAlloc, 1)); + memoryOperationsIface->makeResident(neoDevice, ArrayRef(&implicitArgsAlloc, 1), true); } return changeMemoryOperationStatusToL0ResultType(success); } @@ -1283,7 +1283,7 @@ ze_result_t ContextImp::mapVirtualMem(const void *ptr, virtualMemoryReservation->mappedAllocations.insert(std::pair(const_cast(ptr), mappedRange)); this->driverHandle->getSvmAllocsManager()->insertSVMAlloc(allocData); NEO::MemoryOperationsHandler *memoryOperationsIface = allocationNode->device->getRootDeviceEnvironment().memoryOperationsInterface.get(); - auto success = memoryOperationsIface->makeResident(allocationNode->device, ArrayRef(&allocationNode->allocation, 1)); + auto success = memoryOperationsIface->makeResident(allocationNode->device, ArrayRef(&allocationNode->allocation, 1), false); ze_result_t res = changeMemoryOperationStatusToL0ResultType(success); return res; } diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index 616534e8bd..08f257509f 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -1048,7 +1048,7 @@ void ModuleImp::copyPatchedSegments(const NEO::Linker::PatchableSegments &isaSeg NEO::MemoryOperationsHandler *memoryOperationsIface = rootDeviceEnvironment.memoryOperationsInterface.get(); auto allocation = kernelImmData->getIsaGraphicsAllocation(); if (memoryOperationsIface) { - memoryOperationsIface->makeResident(neoDevice, ArrayRef(&allocation, 1)); + memoryOperationsIface->makeResident(neoDevice, ArrayRef(&allocation, 1), false); } } } diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 33a57f3e81..cb27ec90e9 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -567,7 +567,7 @@ Buffer *Buffer::create(Context *context, auto device = context->getDevice(deviceNum); auto graphicsAllocation = pBuffer->getGraphicsAllocation(device->getRootDeviceIndex()); auto rootDeviceEnvironment = pBuffer->executionEnvironment->rootDeviceEnvironments[device->getRootDeviceIndex()].get(); - rootDeviceEnvironment->memoryOperationsInterface->makeResident(&device->getDevice(), ArrayRef(&graphicsAllocation, 1)); + rootDeviceEnvironment->memoryOperationsInterface->makeResident(&device->getDevice(), ArrayRef(&graphicsAllocation, 1), false); } } diff --git a/opencl/test/unit_test/os_interface/windows/wddm_residency_handler_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_residency_handler_tests.cpp index ce5eb80c98..2c23e4f544 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_residency_handler_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_residency_handler_tests.cpp @@ -57,26 +57,26 @@ struct WddmMemoryOperationsHandlerTest : public WddmTest { }; TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocationWhenMakingResidentAllocationThenMakeResidentCalled) { - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::success); } TEST_F(WddmMemoryOperationsHandlerTest, givenFragmentedAllocationWhenMakingResidentAllocationThenMakeResidentCalled) { allocationPtr = wddmFragmentedAllocation.get(); - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); } TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenMakingResidentAllocationThenMakeResidentCalled) { - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(allocationData)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(allocationData), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); } TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocationWhenEvictingResidentAllocationThenEvictCalled) { wddm->callBaseEvict = true; - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::memoryNotFound); @@ -85,13 +85,13 @@ TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocationWhenEvictingReside TEST_F(WddmMemoryOperationsHandlerTest, givenFragmentedAllocationWhenEvictingResidentAllocationThenEvictCalled) { allocationPtr = wddmFragmentedAllocation.get(); - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::memoryNotFound); } TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenEvictingResidentAllocationThenEvictCalled) { - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(allocationData)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(allocationData), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::memoryNotFound); EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); diff --git a/shared/source/command_stream/command_stream_receiver_hw.h b/shared/source/command_stream/command_stream_receiver_hw.h index 5085bf7d6d..3f433ca1d5 100644 --- a/shared/source/command_stream/command_stream_receiver_hw.h +++ b/shared/source/command_stream/command_stream_receiver_hw.h @@ -137,7 +137,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { SubmissionStatus flushPipeControl(bool stateCacheFlush); SubmissionStatus flushSmallTask(LinearStream &commandStreamTask, size_t commandStreamStartTask); - SubmissionStatus flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency); + MOCKABLE_VIRTUAL SubmissionStatus flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency); SubmissionStatus sendRenderStateCacheFlush() override; bool isUpdateTagFromWaitEnabled() override; diff --git a/shared/source/debugger/debugger_l0.cpp b/shared/source/debugger/debugger_l0.cpp index 3ea7f19f7a..1261ac32ee 100644 --- a/shared/source/debugger/debugger_l0.cpp +++ b/shared/source/debugger/debugger_l0.cpp @@ -98,11 +98,11 @@ void DebuggerL0::initialize() { NEO::MemoryOperationsHandler *memoryOperationsIface = rootDeviceEnvironment.memoryOperationsInterface.get(); if (memoryOperationsIface) { - memoryOperationsIface->makeResident(device, ArrayRef(&moduleDebugArea, 1)); + memoryOperationsIface->makeResident(device, ArrayRef(&moduleDebugArea, 1), false); auto numSubDevices = device->getNumSubDevices(); for (uint32_t i = 0; i < numSubDevices; i++) { auto subDevice = device->getSubDevice(i); - memoryOperationsIface->makeResident(subDevice, ArrayRef(&moduleDebugArea, 1)); + memoryOperationsIface->makeResident(subDevice, ArrayRef(&moduleDebugArea, 1), false); } } @@ -142,7 +142,7 @@ void DebuggerL0::notifyModuleLoadAllocations(Device *device, const StackVecgetRootDeviceEnvironment().memoryOperationsInterface.get(); if (memoryOperationsIface) { for (auto gfxAlloc : allocs) { - memoryOperationsIface->makeResident(device, ArrayRef(&gfxAlloc, 1)); + memoryOperationsIface->makeResident(device, ArrayRef(&gfxAlloc, 1), false); } } } diff --git a/shared/source/helpers/bindless_heaps_helper.cpp b/shared/source/helpers/bindless_heaps_helper.cpp index 3e23a073fe..1e9bf2a867 100644 --- a/shared/source/helpers/bindless_heaps_helper.cpp +++ b/shared/source/helpers/bindless_heaps_helper.cpp @@ -64,7 +64,7 @@ GraphicsAllocation *BindlessHeapsHelper::getHeapAllocation(size_t heapSize, size GraphicsAllocation *allocation = memManager->allocateGraphicsMemoryWithProperties(properties); MemoryOperationsHandler *memoryOperationsIface = rootDevice->getRootDeviceEnvironmentRef().memoryOperationsInterface.get(); - auto result = memoryOperationsIface->makeResident(rootDevice, ArrayRef(&allocation, 1)); + auto result = memoryOperationsIface->makeResident(rootDevice, ArrayRef(&allocation, 1), false); if (result != NEO::MemoryOperationsStatus::success) { memManager->freeGraphicsMemory(allocation); return nullptr; diff --git a/shared/source/memory_manager/memory_operations_handler.h b/shared/source/memory_manager/memory_operations_handler.h index 92b4674818..97407621f3 100644 --- a/shared/source/memory_manager/memory_operations_handler.h +++ b/shared/source/memory_manager/memory_operations_handler.h @@ -20,7 +20,7 @@ class MemoryOperationsHandler { MemoryOperationsHandler() = default; virtual ~MemoryOperationsHandler() = default; - virtual MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) = 0; + virtual MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) = 0; virtual MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) = 0; virtual MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) = 0; virtual MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) = 0; diff --git a/shared/source/os_interface/aub_memory_operations_handler.cpp b/shared/source/os_interface/aub_memory_operations_handler.cpp index 9a3d17625d..2df20ee51c 100644 --- a/shared/source/os_interface/aub_memory_operations_handler.cpp +++ b/shared/source/os_interface/aub_memory_operations_handler.cpp @@ -26,7 +26,7 @@ AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *a this->aubManager = aubManager; } -MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device, ArrayRef gfxAllocations) { +MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) { if (!aubManager) { return MemoryOperationsStatus::deviceUninitialized; } @@ -75,7 +75,7 @@ MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device, } MemoryOperationsStatus AubMemoryOperationsHandler::lock(Device *device, ArrayRef gfxAllocations) { - return makeResident(device, gfxAllocations); + return makeResident(device, gfxAllocations, false); } MemoryOperationsStatus AubMemoryOperationsHandler::evict(Device *device, GraphicsAllocation &gfxAllocation) { @@ -98,7 +98,7 @@ MemoryOperationsStatus AubMemoryOperationsHandler::free(Device *device, Graphics } MemoryOperationsStatus AubMemoryOperationsHandler::makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) { - return makeResident(nullptr, gfxAllocations); + return makeResident(nullptr, gfxAllocations, false); } MemoryOperationsStatus AubMemoryOperationsHandler::evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) { diff --git a/shared/source/os_interface/aub_memory_operations_handler.h b/shared/source/os_interface/aub_memory_operations_handler.h index b80f78450f..a4f56d844d 100644 --- a/shared/source/os_interface/aub_memory_operations_handler.h +++ b/shared/source/os_interface/aub_memory_operations_handler.h @@ -22,7 +22,7 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler { AubMemoryOperationsHandler(aub_stream::AubManager *aubManager); ~AubMemoryOperationsHandler() override = default; - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override; MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index f50ded3cd6..7ea4b2267e 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -345,9 +345,13 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size void DrmMemoryManager::emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const { auto rootDeviceIndex = allocationData.rootDeviceIndex; if (forcePinEnabled && pinBBs.at(rootDeviceIndex) != nullptr && allocationData.flags.forcePin && allocationData.size >= this->pinThreshold) { - pinBBs.at(rootDeviceIndex)->pin(&bo, 1, getDefaultOsContext(rootDeviceIndex), 0, getDefaultDrmContextId(rootDeviceIndex)); + emitPinningRequestForBoContainer(&bo, 1, rootDeviceIndex); } } +SubmissionStatus DrmMemoryManager::emitPinningRequestForBoContainer(BufferObject **bo, uint32_t boCount, uint32_t rootDeviceIndex) const { + auto ret = pinBBs.at(rootDeviceIndex)->pin(bo, boCount, getDefaultOsContext(rootDeviceIndex), 0, getDefaultDrmContextId(rootDeviceIndex)); + return ret == 0 ? SubmissionStatus::success : SubmissionStatus::outOfMemory; +} StorageInfo DrmMemoryManager::createStorageInfoFromProperties(const AllocationProperties &properties) { auto storageInfo{MemoryManager::createStorageInfoFromProperties(properties)}; diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 2d9c2935e7..83ec46cfd1 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/command_stream/submission_status.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/os_interface/linux/drm_buffer_object.h" #include "shared/source/os_interface/os_memory.h" @@ -117,6 +118,7 @@ class DrmMemoryManager : public MemoryManager { bool isCompressionSupportedForShareable(bool isShareable) override; bool usmCompressionSupported(Device *device) override; + MOCKABLE_VIRTUAL SubmissionStatus emitPinningRequestForBoContainer(BufferObject **bo, uint32_t boCount, uint32_t rootDeviceIndex) const; protected: void registerSharedBoHandleAllocation(DrmAllocation *drmAllocation); diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 82fccb58b1..a5dbc1f705 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -26,7 +26,7 @@ DrmMemoryOperationsHandlerBind::DrmMemoryOperationsHandlerBind(const RootDeviceE DrmMemoryOperationsHandlerBind::~DrmMemoryOperationsHandlerBind() = default; -MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *device, ArrayRef gfxAllocations) { +MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) { auto &engines = device->getAllEngines(); MemoryOperationsStatus result = MemoryOperationsStatus::success; for (const auto &engine : engines) { @@ -43,7 +43,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::lock(Device *device, Arra for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) { (*gfxAllocation)->setLockedMemory(true); } - return makeResident(device, gfxAllocations); + return makeResident(device, gfxAllocations, false); } MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) { diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h index 018f67bc7b..e259cd5a72 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h @@ -17,7 +17,7 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler { ~DrmMemoryOperationsHandlerBind() override; MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override; - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override; MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override; diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp index e0e15fb607..eab0d62ddd 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp @@ -7,9 +7,12 @@ #include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" +#include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/device/device.h" #include "shared/source/os_interface/linux/drm_allocation.h" #include "shared/source/os_interface/linux/drm_buffer_object.h" +#include "shared/source/os_interface/linux/drm_memory_manager.h" #include @@ -26,9 +29,13 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResidentWithinOsCo return MemoryOperationsStatus::success; } -MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResident(Device *device, ArrayRef gfxAllocations) { +MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) { OsContext *osContext = nullptr; - return this->makeResidentWithinOsContext(osContext, gfxAllocations, false); + auto ret = this->makeResidentWithinOsContext(osContext, gfxAllocations, false); + if (!isDummyExecNeeded || ret != MemoryOperationsStatus::success) { + return ret; + } + return flushDummyExec(device, gfxAllocations); } MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::lock(Device *device, ArrayRef gfxAllocations) { @@ -95,4 +102,29 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evictUnusedAllocations return MemoryOperationsStatus::success; } +MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::flushDummyExec(Device *device, ArrayRef gfxAllocations) { + std::lock_guard lock(mutex); + OsContext *osContext = nullptr; + auto memoryManager = reinterpret_cast(device->getMemoryManager()); + + std::vector boArray; + uint32_t boCount = 0; + for (auto &alloc : this->residency) { + for (auto &bo : reinterpret_cast(alloc)->getBOs()) { + if (bo != 0) { + boArray.push_back(bo); + boCount++; + } + } + } + + auto submissionStatus = memoryManager->emitPinningRequestForBoContainer(boArray.data(), boCount, rootDeviceIndex); + if (submissionStatus != SubmissionStatus::success) { + for (auto &alloc : gfxAllocations) { + evictWithinOsContext(osContext, *alloc); + } + return MemoryOperationsStatus::outOfMemory; + } + return MemoryOperationsStatus::success; +} } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_default.h b/shared/source/os_interface/linux/drm_memory_operations_handler_default.h index fc1c2b027d..165f37b52a 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_default.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_default.h @@ -20,7 +20,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler { ~DrmMemoryOperationsHandlerDefault() override; MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override; - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override; MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override; @@ -30,6 +30,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler { [[nodiscard]] std::unique_lock lockHandlerIfUsed() override; MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override; + MOCKABLE_VIRTUAL MemoryOperationsStatus flushDummyExec(Device *device, ArrayRef gfxAllocations); protected: std::unordered_set residency; diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h b/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h index 64fb71e7ed..22b0c671b8 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h @@ -36,13 +36,13 @@ class DrmMemoryOperationsHandlerWithAubDump : public BaseOperationsHandler { ~DrmMemoryOperationsHandlerWithAubDump() override = default; - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { - aubMemoryOperationsHandler->makeResident(device, gfxAllocations); - return BaseOperationsHandler::makeResident(device, gfxAllocations); + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override { + aubMemoryOperationsHandler->makeResident(device, gfxAllocations, isDummyExecNeeded); + return BaseOperationsHandler::makeResident(device, gfxAllocations, isDummyExecNeeded); } MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override { - aubMemoryOperationsHandler->makeResident(device, gfxAllocations); + aubMemoryOperationsHandler->makeResident(device, gfxAllocations, false); return BaseOperationsHandler::lock(device, gfxAllocations); } diff --git a/shared/source/os_interface/windows/wddm_memory_operations_handler.cpp b/shared/source/os_interface/windows/wddm_memory_operations_handler.cpp index 4ecc5fcbab..3ccd99ead0 100644 --- a/shared/source/os_interface/windows/wddm_memory_operations_handler.cpp +++ b/shared/source/os_interface/windows/wddm_memory_operations_handler.cpp @@ -20,7 +20,7 @@ WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm WddmMemoryOperationsHandler::~WddmMemoryOperationsHandler() = default; -MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(Device *device, ArrayRef gfxAllocations) { +MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) { uint32_t totalHandlesCount = 0; constexpr uint32_t stackAllocations = 64; constexpr uint32_t stackHandlesCount = NEO::maxFragmentsCount * EngineLimits::maxHandleCount * stackAllocations; diff --git a/shared/source/os_interface/windows/wddm_memory_operations_handler.h b/shared/source/os_interface/windows/wddm_memory_operations_handler.h index 0065e21732..d50ba8ce11 100644 --- a/shared/source/os_interface/windows/wddm_memory_operations_handler.h +++ b/shared/source/os_interface/windows/wddm_memory_operations_handler.h @@ -23,7 +23,7 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler { static std::unique_ptr create(Wddm *wddm, RootDeviceEnvironment *rootDeviceEnvironment, bool withAubDump); - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override; MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; @@ -31,7 +31,7 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override { - return makeResident(nullptr, gfxAllocations); + return makeResident(nullptr, gfxAllocations, false); } MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override { return evict(nullptr, gfxAllocation); diff --git a/shared/source/os_interface/windows/wddm_memory_operations_handler_with_aub_dump.h b/shared/source/os_interface/windows/wddm_memory_operations_handler_with_aub_dump.h index 5450e230c0..4aa9cfc148 100644 --- a/shared/source/os_interface/windows/wddm_memory_operations_handler_with_aub_dump.h +++ b/shared/source/os_interface/windows/wddm_memory_operations_handler_with_aub_dump.h @@ -36,9 +36,9 @@ class WddmMemoryOperationsHandlerWithAubDump : public BaseOperationsHandler { ~WddmMemoryOperationsHandlerWithAubDump() override = default; - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { - aubMemoryOperationsHandler->makeResident(device, gfxAllocations); - return BaseOperationsHandler::makeResident(device, gfxAllocations); + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override { + aubMemoryOperationsHandler->makeResident(device, gfxAllocations, isDummyExecNeeded); + return BaseOperationsHandler::makeResident(device, gfxAllocations, isDummyExecNeeded); } MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { diff --git a/shared/test/common/libult/ult_command_stream_receiver.h b/shared/test/common/libult/ult_command_stream_receiver.h index d62c05ac2e..fb871b3d27 100644 --- a/shared/test/common/libult/ult_command_stream_receiver.h +++ b/shared/test/common/libult/ult_command_stream_receiver.h @@ -534,6 +534,10 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw, publ drainPagingFenceQueueCalled++; BaseClass::drainPagingFenceQueue(); } + SubmissionStatus flushHandler(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override { + flushHandlerCalled++; + return BaseClass::flushHandler(batchBuffer, allocationsForResidency); + } std::vector aubCommentMessages; @@ -564,6 +568,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw, publ uint32_t pollForCompletionCalled = 0; uint32_t initializeDeviceWithFirstSubmissionCalled = 0; uint32_t drainPagingFenceQueueCalled = 0; + uint32_t flushHandlerCalled = 0; mutable uint32_t checkGpuHangDetectedCalled = 0; int ensureCommandBufferAllocationCalled = 0; DispatchFlags recordedDispatchFlags; diff --git a/shared/test/common/mocks/linux/mock_drm_memory_manager.h b/shared/test/common/mocks/linux/mock_drm_memory_manager.h index dcce0359e2..f965397fcc 100644 --- a/shared/test/common/mocks/linux/mock_drm_memory_manager.h +++ b/shared/test/common/mocks/linux/mock_drm_memory_manager.h @@ -199,10 +199,12 @@ struct MockDrmGemCloseWorker : DrmGemCloseWorker { }; struct MockDrmMemoryManager : DrmMemoryManager { + using BaseClass = DrmMemoryManager; using DrmMemoryManager::DrmMemoryManager; using DrmMemoryManager::gemCloseWorker; using DrmMemoryManager::mmapFunction; using DrmMemoryManager::munmapFunction; + ADDMETHOD_CONST(emitPinningRequestForBoContainer, SubmissionStatus, true, SubmissionStatus::success, (BufferObject * *bo, uint32_t boCount, uint32_t rootDeviceIndex), (bo, boCount, rootDeviceIndex)); }; } // namespace NEO diff --git a/shared/test/common/mocks/mock_aub_memory_operations_handler.h b/shared/test/common/mocks/mock_aub_memory_operations_handler.h index 9d014ffed7..ff7340bf50 100644 --- a/shared/test/common/mocks/mock_aub_memory_operations_handler.h +++ b/shared/test/common/mocks/mock_aub_memory_operations_handler.h @@ -21,9 +21,9 @@ struct MockAubMemoryOperationsHandler : public AubMemoryOperationsHandler { using AubMemoryOperationsHandler::getMemoryBanksBitfield; using AubMemoryOperationsHandler::residentAllocations; - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override { makeResidentCalled = true; - return AubMemoryOperationsHandler::makeResident(device, gfxAllocations); + return AubMemoryOperationsHandler::makeResident(device, gfxAllocations, isDummyExecNeeded); } MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { diff --git a/shared/test/common/mocks/mock_command_stream_receiver.h b/shared/test/common/mocks/mock_command_stream_receiver.h index 6985bb1b63..928f901cee 100644 --- a/shared/test/common/mocks/mock_command_stream_receiver.h +++ b/shared/test/common/mocks/mock_command_stream_receiver.h @@ -19,6 +19,7 @@ #include "shared/source/memory_manager/surface.h" #include "shared/source/utilities/tag_allocator.h" #include "shared/test/common/helpers/dispatch_flags_helper.h" +#include "shared/test/common/test_macros/mock_method_macros.h" #include #include @@ -31,6 +32,7 @@ using namespace NEO; class MockCommandStreamReceiver : public CommandStreamReceiver { public: + using BaseClass = CommandStreamReceiver; using CommandStreamReceiver::activePartitions; using CommandStreamReceiver::baseWaitFunction; using CommandStreamReceiver::checkForNewResources; diff --git a/shared/test/common/mocks/mock_memory_operations_handler.h b/shared/test/common/mocks/mock_memory_operations_handler.h index 1b02d06f8c..ea736bb95f 100644 --- a/shared/test/common/mocks/mock_memory_operations_handler.h +++ b/shared/test/common/mocks/mock_memory_operations_handler.h @@ -20,7 +20,7 @@ class GraphicsAllocation; class MockMemoryOperationsHandler : public MemoryOperationsHandler { public: MockMemoryOperationsHandler() {} - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { return MemoryOperationsStatus::unsupported; } + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; } @@ -31,7 +31,7 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler { class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler { public: MockMemoryOperationsHandlerTests() {} - ADDMETHOD_NOBASE(makeResident, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, ArrayRef gfxAllocations)); + ADDMETHOD_NOBASE(makeResident, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, ArrayRef gfxAllocations, bool isDummyExecNeeded)); ADDMETHOD_NOBASE(lock, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, ArrayRef gfxAllocations)); ADDMETHOD_NOBASE(evict, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, GraphicsAllocation &gfxAllocation)); ADDMETHOD_NOBASE(isResident, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, GraphicsAllocation &gfxAllocation)); @@ -43,7 +43,7 @@ class MockMemoryOperations : public MemoryOperationsHandler { public: MockMemoryOperations() {} - MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations, bool isDummyExecNeeded) override { makeResidentCalledCount++; if (captureGfxAllocationsForMakeResident) { for (auto &gfxAllocation : gfxAllocations) { diff --git a/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp b/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp index 1fc272918a..9787412528 100644 --- a/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/shared/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -362,7 +362,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrAndResidentAllocationWhenProc MockGraphicsAllocation allocation2(reinterpret_cast(0x5000), 0x5000, 0x1000); GraphicsAllocation *allocPtr = &allocation2; - memoryOperationsHandler->makeResident(pDevice, ArrayRef(&allocPtr, 1)); + memoryOperationsHandler->makeResident(pDevice, ArrayRef(&allocPtr, 1), false); EXPECT_TRUE(mockManager->writeMemory2Called); mockManager->storeAllocationParams = true; diff --git a/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp b/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp index 82c040e0b0..48c2855a2c 100644 --- a/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp +++ b/shared/test/unit_test/command_stream/tbx_command_stream_tests.cpp @@ -376,7 +376,7 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrAndResidentAllocationWhenProcessR MockGraphicsAllocation allocation2(reinterpret_cast(0x5000), 0x5000, 0x1000); GraphicsAllocation *allocPtr = &allocation2; - memoryOperationsHandler->makeResident(pDevice, ArrayRef(&allocPtr, 1)); + memoryOperationsHandler->makeResident(pDevice, ArrayRef(&allocPtr, 1), false); EXPECT_TRUE(mockManager->writeMemory2Called); mockManager->storeAllocationParams = true; diff --git a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp index f0d15b8c6a..614ead6868 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -3281,7 +3281,7 @@ TEST(MemoryManagerTest, givenMemoryAllocationWhenFreedThenFreeCalledOnMemoryOper auto memoryAllocation = memoryManager.allocateGraphicsMemoryWithProperties(allocationProperties); EXPECT_NE(nullptr, memoryAllocation); - memoryOperationsHandler->makeResident(device.get(), ArrayRef(&memoryAllocation, 1)); + memoryOperationsHandler->makeResident(device.get(), ArrayRef(&memoryAllocation, 1), false); EXPECT_EQ(1u, memoryOperationsHandler->residentAllocations.size()); diff --git a/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp b/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp index a6c7ab8710..bab0d36891 100644 --- a/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp +++ b/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp @@ -23,7 +23,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) { getMemoryOperationsHandler()->setAubManager(nullptr); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::deviceUninitialized); } @@ -31,7 +31,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -41,7 +41,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe aubManager.writeMemory2Called = false; - result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -80,7 +80,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerAndAllocationOfOneTimeAub MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -90,7 +90,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerAndAllocationOfOneTimeAub aubManager.writeMemory2Called = false; - result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_FALSE(aubManager.writeMemory2Called); @@ -106,7 +106,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnW allocPtr->setWriteMemoryOnly(true); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -115,7 +115,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnW EXPECT_EQ(0u, memoryOperationsInterface->residentAllocations.size()); aubManager.writeMemory2Called = false; - result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -140,7 +140,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerAndAllocationInLocalMemor MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_FALSE(aubManager.writeMemory2Called); EXPECT_EQ(1u, csr->writeMemoryAubCalled); @@ -163,7 +163,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_EQ(1u, csr->initializeEngineCalled); @@ -185,7 +185,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledWit MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_EQ(0u, csr->initializeEngineCalled); @@ -204,7 +204,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnC gmm.setCompressionEnabled(true); allocPtr->setDefaultGmm(&gmm); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -228,7 +228,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnU gmm.setCompressionEnabled(false); allocPtr->setDefaultGmm(&gmm); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); @@ -241,7 +241,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAllocationWhenMakeResidentCalledThe MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(aubManager.hintToWriteMemory, AubMemDump::DataTypeHintValues::TraceNotype); } TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenIsResidentCalledThenFalseReturned) { @@ -255,7 +255,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenIsResidentCal MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); auto result = memoryOperationsInterface->isResident(nullptr, allocation); EXPECT_EQ(result, MemoryOperationsStatus::success); } @@ -270,7 +270,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenEvictCalledTh MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); auto result = memoryOperationsInterface->evict(nullptr, allocation); EXPECT_EQ(result, MemoryOperationsStatus::success); } @@ -489,7 +489,7 @@ HWTEST_F(AubMemoryOperationsHandlerTests, givenCloningOfPageTablesWhenProcessing allocPtr->storageInfo.cloningOfPageTables = true; - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager->writeMemory2Called); @@ -519,7 +519,7 @@ HWTEST_F(AubMemoryOperationsHandlerTests, givenNonLocalGfxAllocationWriteableWhe allocPtr = &allocation; allocPtr->storageInfo.cloningOfPageTables = false; - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager->writeMemory2Called); @@ -554,7 +554,7 @@ HWTEST_F(AubMemoryOperationsHandlerTests, givenLocalGfxAllocationWriteableWhenPr auto backupDefaultCsr = std::make_unique>(&device->getDefaultEngine().commandStreamReceiver); device->getDefaultEngine().commandStreamReceiver = csr.get(); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_FALSE(aubManager->writeMemory2Called); @@ -590,7 +590,7 @@ HWTEST_F(AubMemoryOperationsHandlerTests, givenGfxAllocationWriteableWithGmmPres executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter.release()); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); aubManager->writeMemory2Called = false; @@ -623,7 +623,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenDeviceNullWhenProcessingFlushReside memoryOperationsInterface->setAubWritable(true, allocation, device.get()); EXPECT_TRUE(memoryOperationsInterface->isAubWritable(allocation, device.get())); - auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1)); + auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocPtr, 1), false); EXPECT_EQ(result, MemoryOperationsStatus::success); EXPECT_TRUE(aubManager.writeMemory2Called); diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index 6a302ee4ad..0ef7667bcb 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -1534,7 +1534,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocsInMemoryOperationHan PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1), false); auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); LinearStream cs(commandBuffer); @@ -1558,7 +1558,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInt BatchBuffer batchBuffer = BatchBufferHelper::createDefaultBatchBuffer(cs.getGraphicsAllocation(), &cs, cs.getUsed()); auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1), false); csr->flush(batchBuffer, csr->getResidencyAllocations()); diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp index 3dbef83fd8..b98aa41aa7 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp @@ -678,7 +678,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenProcessResidencyFailingOnO BatchBuffer batchBuffer = BatchBufferHelper::createDefaultBatchBuffer(cs.getGraphicsAllocation(), &cs, cs.getUsed()); auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1), false); auto testedCsr = static_cast *>(csr); testedCsr->processResidencyCallBase = false; @@ -700,7 +700,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenProcessResidencyFailingOnO BatchBuffer batchBuffer = BatchBufferHelper::createDefaultBatchBuffer(cs.getGraphicsAllocation(), &cs, cs.getUsed()); auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1), false); auto testedCsr = static_cast *>(csr); testedCsr->processResidencyCallBase = false; @@ -722,7 +722,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenFailingExecWhenFlushingThe BatchBuffer batchBuffer = BatchBufferHelper::createDefaultBatchBuffer(cs.getGraphicsAllocation(), &cs, cs.getUsed()); auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1), false); auto testedCsr = static_cast *>(csr); testedCsr->processResidencyCallBase = true; diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp index 1b098b6753..a01a2c6984 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp @@ -261,8 +261,8 @@ TEST_F(DrmMemoryOperationsHandlerBindMultiRootDeviceTest2, givenOperationHandler EXPECT_EQ(operationHandlerDefault->getRootDeviceIndex(), 0u); EXPECT_EQ(operationHandler->getRootDeviceIndex(), 1u); - operationHandlerDefault->makeResident(device, ArrayRef(&allocationDefault, 1)); - operationHandler->makeResident(device, ArrayRef(&allocation, 1)); + operationHandlerDefault->makeResident(device, ArrayRef(&allocationDefault, 1), false); + operationHandler->makeResident(device, ArrayRef(&allocation, 1), false); operationHandlerDefault->setRootDeviceIndex(1u); operationHandler->setRootDeviceIndex(0u); @@ -294,7 +294,7 @@ TEST_F(DrmMemoryOperationsHandlerBindMultiRootDeviceTest2, whenNoSpaceLeftOnDevi EXPECT_EQ(allocationDefault, registeredAllocations[1]); EXPECT_EQ(operationHandler->evictUnusedCalled, 0u); - auto res = operationHandler->makeResident(device, ArrayRef(&allocation, 1)); + auto res = operationHandler->makeResident(device, ArrayRef(&allocation, 1), false); EXPECT_EQ(MemoryOperationsStatus::outOfMemory, res); EXPECT_EQ(operationHandler->evictUnusedCalled, 1u); @@ -634,7 +634,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenDrmMemoryOperationBindWhenChangi auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::memoryNotFound); - EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->evict(device, *allocation), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::memoryNotFound); @@ -649,7 +649,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenDeviceWithMultipleSubdevicesWhen EXPECT_EQ(operationHandler->isResident(device->getSubDevice(0u), *allocation), MemoryOperationsStatus::memoryNotFound); EXPECT_EQ(operationHandler->isResident(device->getSubDevice(1u), *allocation), MemoryOperationsStatus::memoryNotFound); - auto retVal = operationHandler->makeResident(device->getSubDevice(1u), ArrayRef(&allocation, 1)); + auto retVal = operationHandler->makeResident(device->getSubDevice(1u), ArrayRef(&allocation, 1), false); EXPECT_EQ(retVal, MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::memoryNotFound); @@ -677,7 +677,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, whenIoctlFailDuringEvictingThenUnreco auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::memoryNotFound); - EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::success); mock->context.vmUnbindReturn = -1; @@ -691,8 +691,8 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, whenIoctlFailDuringEvictingThenUnreco TEST_F(DrmMemoryOperationsHandlerBindTest, whenMakeResidentTwiceThenAllocIsBoundOnlyOnce) { auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); - EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1)), MemoryOperationsStatus::success); - EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1), false), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::success); EXPECT_EQ(mock->context.vmBindCalled, 2u); @@ -712,7 +712,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenNoVmBindSupportInDrmWhenCheckFor mock->context.vmBindCalled = 0u; auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); - handler->makeResident(device, ArrayRef(&allocation, 1)); + handler->makeResident(device, ArrayRef(&allocation, 1), false); EXPECT_FALSE(mock->context.vmBindCalled); memoryManager->freeGraphicsMemory(allocation); @@ -727,7 +727,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenVmBindSupportAndNoMultiTileWhenC mock->context.vmBindCalled = 0u; auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); - handler->makeResident(device, ArrayRef(&allocation, 1)); + handler->makeResident(device, ArrayRef(&allocation, 1), false); EXPECT_FALSE(mock->context.vmBindCalled); memoryManager->freeGraphicsMemory(allocation); @@ -741,7 +741,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenDisabledVmBindWhenCreateDrmHandl mock->context.vmBindCalled = false; auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); - handler->makeResident(device, ArrayRef(&allocation, 1)); + handler->makeResident(device, ArrayRef(&allocation, 1), false); EXPECT_FALSE(mock->context.vmBindCalled); memoryManager->freeGraphicsMemory(allocation); @@ -1072,9 +1072,9 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenCsrTagAllocatorsWhenDestructin auto hwTimeStampsAlloc = csr->getEventTsAllocator()->getTag()->getBaseGraphicsAllocation()->getDefaultGraphicsAllocation(); auto hwPerfCounterAlloc = csr->getEventPerfCountAllocator(4)->getTag()->getBaseGraphicsAllocation()->getDefaultGraphicsAllocation(); - operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1)); - operationHandler->makeResident(device, ArrayRef(&hwTimeStampsAlloc, 1)); - operationHandler->makeResident(device, ArrayRef(&hwPerfCounterAlloc, 1)); + operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1), false); + operationHandler->makeResident(device, ArrayRef(&hwTimeStampsAlloc, 1), false); + operationHandler->makeResident(device, ArrayRef(&hwPerfCounterAlloc, 1), false); csr.reset(); @@ -1113,7 +1113,7 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexProgrammingEnabledWhen bo.setPatIndex(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::defaultRegion, CachePolicy::writeBack, (debugFlag == 1 && closSupported), true)); - operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1)); + operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1), false); if (!patIndexProgrammingSupported) { EXPECT_FALSE(mock->context.receivedVmBindPatIndex); @@ -1184,7 +1184,7 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenUncachedDebugFlagSetWhenVmBind mock->context.receivedVmUnbindPatIndex.reset(); auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); - operationHandler->makeResident(device, ArrayRef(&allocation, 1)); + operationHandler->makeResident(device, ArrayRef(&allocation, 1), false); auto expectedIndex = productHelper.overridePatIndex(true, static_cast(MockGmmClientContextBase::MockPatIndex::uncached), allocation->getAllocationType()); @@ -1214,7 +1214,7 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenDebugFlagSetWhenVmBindCalledTh GTEST_SKIP(); } - operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1)); + operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1), false); EXPECT_EQ(1u, mock->context.receivedVmBindPatIndex.value()); @@ -1245,7 +1245,7 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenDebugFlagSetWhenVmBindCalledTh GraphicsAllocation *allocPtr = &allocation; - operationHandler->makeResident(device, ArrayRef(&allocPtr, 1)); + operationHandler->makeResident(device, ArrayRef(&allocPtr, 1), false); EXPECT_EQ(2u, mock->context.receivedVmBindPatIndex.value()); @@ -1276,7 +1276,7 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenDebugFlagSetWhenVmBindCalledTh GraphicsAllocation *allocPtr = &allocation; - operationHandler->makeResident(device, ArrayRef(&allocPtr, 1)); + operationHandler->makeResident(device, ArrayRef(&allocPtr, 1), false); EXPECT_EQ(3u, mock->context.receivedVmBindPatIndex.value()); @@ -1308,7 +1308,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenClosEnabledAndAllocationToBeCach EXPECT_TRUE(static_cast(allocation)->setCacheAdvice(mock, 32 * MemoryConstants::kiloByte, cacheRegion, false)); mock->context.receivedVmBindPatIndex.reset(); - operationHandler->makeResident(device, ArrayRef(&allocation, 1)); + operationHandler->makeResident(device, ArrayRef(&allocation, 1), false); auto patIndex = productHelper.getPatIndex(cacheRegion, CachePolicy::writeBack); @@ -1375,7 +1375,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenPreviouslyLockedMemoryWhenCallin EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::memoryNotFound); EXPECT_FALSE(mockDrmAllocation->isLockedMemory()); - EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&mockDrmAllocation, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::success); EXPECT_FALSE(mockDrmAllocation->isLockedMemory()); EXPECT_FALSE(mockBo.isExplicitLockedMemoryRequired()); @@ -1393,7 +1393,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenLockedAndResidentAllocationsWhen EXPECT_EQ(operationHandler->lock(device, ArrayRef(&allocation1, 1)), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation1), MemoryOperationsStatus::success); - EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation2, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation2, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(operationHandler->isResident(device, *allocation2), MemoryOperationsStatus::success); operationHandler->useBaseEvictUnused = true; diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp index 772b281983..3767939413 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp @@ -8,6 +8,9 @@ #include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" #include "shared/test/common/libult/linux/drm_query_mock.h" #include "shared/test/common/mocks/linux/mock_drm_allocation.h" +#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" +#include "shared/test/common/mocks/mock_command_stream_receiver.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/test_macros/test.h" @@ -17,8 +20,12 @@ using namespace NEO; struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault { + using BaseClass = DrmMemoryOperationsHandlerDefault; using DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault; using DrmMemoryOperationsHandlerDefault::residency; + ADDMETHOD(makeResidentWithinOsContext, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (OsContext * osContext, ArrayRef gfxAllocations, bool evictable), (osContext, gfxAllocations, evictable)); + ADDMETHOD(flushDummyExec, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (Device * device, ArrayRef gfxAllocations), (device, gfxAllocations)); + ADDMETHOD(evictWithinOsContext, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (OsContext * osContext, GraphicsAllocation &gfxAllocation), (osContext, gfxAllocation)); }; struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test { void SetUp() override { @@ -66,7 +73,7 @@ TEST_F(DrmMemoryOperationsHandlerBaseTest, whenMakingAllocationResidentThenAlloc initializeAllocation(1); EXPECT_EQ(1u, drmAllocation->storageInfo.getNumBanks()); - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *allocationPtr), MemoryOperationsStatus::success); @@ -77,7 +84,7 @@ TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingResidentAllocationThenAll EXPECT_EQ(1u, drmAllocation->storageInfo.getNumBanks()); EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *allocationPtr), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); @@ -161,3 +168,87 @@ TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingLockedAllocationWithChunk EXPECT_FALSE(drmAllocation->isLockedMemory()); EXPECT_FALSE(mockBos[0]->isExplicitLockedMemoryRequired()); } + +TEST_F(DrmMemoryOperationsHandlerBaseTest, givenOperationsHandlerWhenCallingMakeResidentWithDummyExecNotNeededThenFlushDummyExecNotCalled) { + drmMemoryOperationsHandler->flushDummyExecCallBase = false; + drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = false; + + initializeAllocation(1); + drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false); + EXPECT_EQ(drmMemoryOperationsHandler->flushDummyExecCalled, 0u); +} +TEST_F(DrmMemoryOperationsHandlerBaseTest, givenOperationsHandlerWhenMakeResidentWithinOsContextReturnFailhenFlushDummyExecNotCalled) { + drmMemoryOperationsHandler->flushDummyExecCallBase = false; + drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = false; + drmMemoryOperationsHandler->makeResidentWithinOsContextResult = MemoryOperationsStatus::failed; + + initializeAllocation(1); + drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), true); + EXPECT_EQ(drmMemoryOperationsHandler->flushDummyExecCalled, 0u); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTest, givenOperationsHandlerWhenCallingMakeResidentWithDummyExecNeededThenFlushDummyExecCalled) { + drmMemoryOperationsHandler->flushDummyExecCallBase = false; + drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = false; + + initializeAllocation(1); + drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1), true); + EXPECT_EQ(drmMemoryOperationsHandler->flushDummyExecCalled, 1u); +} +struct DrmMemoryOperationsHandlerBaseTestFlushDummyExec : public DrmMemoryOperationsHandlerBaseTest { + using BaseClass = DrmMemoryOperationsHandlerBaseTest; + void SetUp() override { + BaseClass::SetUp(); + drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = false; + drmMemoryOperationsHandler->evictWithinOsContextCallBase = false; + auto mockExecutionEnvironment = std::make_unique(); + + auto rootDeviceEnvironment = mockExecutionEnvironment->rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->setHwInfoAndInitHelpers(defaultHwInfo.get()); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(new DrmMock(*rootDeviceEnvironment))); + + auto memoryManager = std::make_unique(GemCloseWorkerMode::gemCloseWorkerInactive, false, false, *mockExecutionEnvironment); + memoryManager->emitPinningRequestForBoContainerCallBase = false; + pMemManager = memoryManager.get(); + mockExecutionEnvironment->memoryManager.reset(memoryManager.release()); + device = std::unique_ptr(MockDevice::create(mockExecutionEnvironment.release(), 0u)); + initializeAllocation(1); + } + + void TearDown() override { + BaseClass::TearDown(); + } + MockDrmMemoryManager *pMemManager; + std::unique_ptr device; + std::unique_ptr commandStreamReceiver; +}; + +TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestCalledThenEmitPinRequestCalled) { + pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::outOfMemory; + drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef(&allocationPtr, 1)); + EXPECT_EQ(pMemManager->emitPinningRequestForBoContainerCalled, 1u); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnFailThenOutOfMemoryReturned) { + pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::outOfMemory; + auto ret = drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef(&allocationPtr, 1)); + EXPECT_EQ(ret, MemoryOperationsStatus::outOfMemory); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnFailThenEvictWithinOsContextCalled) { + pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::outOfMemory; + drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef(&allocationPtr, 1)); + EXPECT_EQ(drmMemoryOperationsHandler->evictWithinOsContextCalled, 1u); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnSuccessThenSuccessReturned) { + pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::success; + auto ret = drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef(&allocationPtr, 1)); + EXPECT_EQ(ret, MemoryOperationsStatus::success); +} +TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnSuccessThenEvictWithinOsContextNotCalled) { + pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::success; + drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef(&allocationPtr, 1)); + EXPECT_EQ(drmMemoryOperationsHandler->evictWithinOsContextCalled, 0u); +} \ No newline at end of file diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp index 69458f865d..6ff0a89c71 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp @@ -52,7 +52,7 @@ struct DrmMemoryOperationsHandlerWithAubDumpTest : public ::testing::Test { }; TEST_F(DrmMemoryOperationsHandlerWithAubDumpTest, whenMakingAllocationResidentThenAllocationIsResident) { - EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 1u); EXPECT_TRUE(drmMemoryOperationsHandlerWithAubDumpMock->residency.find(allocationPtr) != drmMemoryOperationsHandlerWithAubDumpMock->residency.end()); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::success); @@ -71,7 +71,7 @@ TEST_F(DrmMemoryOperationsHandlerWithAubDumpTest, whenEvictingResidentAllocation GraphicsAllocation *mockDrmAllocation = new MockDrmAllocation(AllocationType::unknown, MemoryPool::localMemory, bos); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 0u); - EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&mockDrmAllocation, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *mockDrmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 1u); EXPECT_TRUE(drmMemoryOperationsHandlerWithAubDumpMock->residency.find(mockDrmAllocation) != drmMemoryOperationsHandlerWithAubDumpMock->residency.end()); diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp index 34143bb59c..9b065e742e 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp @@ -65,7 +65,7 @@ struct WddmMemoryOperationsHandlerWithAubDumpTest : public WddmTest { }; TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenRegularAllocationWhenMakingResidentAllocationThenMakeResidentCalled) { - EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_TRUE(mockAubMemoryOperationsHandler->makeResidentCalled); EXPECT_TRUE(mockAubMemoryOperationsHandler->isResidentCalled); @@ -73,14 +73,14 @@ TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenRegularAllocationWhenMak TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenFragmentedAllocationWhenMakingResidentAllocationThenMakeResidentCalled) { allocationPtr = wddmFragmentedAllocation.get(); - EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); EXPECT_TRUE(mockAubMemoryOperationsHandler->makeResidentCalled); EXPECT_TRUE(mockAubMemoryOperationsHandler->isResidentCalled); } TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenVariousAllocationsWhenMakingResidentAllocationThenMakeResidentCalled) { - EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(allocationData)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(allocationData), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); EXPECT_TRUE(mockAubMemoryOperationsHandler->makeResidentCalled); @@ -89,7 +89,7 @@ TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenVariousAllocationsWhenMa TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenRegularAllocationWhenEvictingResidentAllocationThenEvictCalled) { wddm->callBaseEvict = true; - EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::memoryNotFound); @@ -99,7 +99,7 @@ TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenRegularAllocationWhenEvi TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenFragmentedAllocationWhenEvictingResidentAllocationThenEvictCalled) { allocationPtr = wddmFragmentedAllocation.get(); - EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::memoryNotFound); EXPECT_TRUE(mockAubMemoryOperationsHandler->makeResidentCalled); @@ -107,7 +107,7 @@ TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenFragmentedAllocationWhen } TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenVariousAllocationsWhenEvictingResidentAllocationThenEvictCalled) { - EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(allocationData)), MemoryOperationsStatus::success); + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(allocationData), false), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, *wddmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::memoryNotFound); EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, *wddmFragmentedAllocation), MemoryOperationsStatus::success);