mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 22:12:59 +08:00
Add returned status to MemoryOperationsHandler
Change-Id: Ic8685e3711cec03d8f83d371fa7152ee095a47a0 Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
77e22bd81b
commit
7827501b91
@@ -8,6 +8,7 @@ set(NEO_CORE_MEMORY_MANAGER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/eviction_status.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_handler.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_status.h
|
||||
)
|
||||
|
||||
set_property(GLOBAL PROPERTY NEO_CORE_MEMORY_MANAGER ${NEO_CORE_MEMORY_MANAGER})
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "core/memory_manager/memory_operations_status.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@@ -16,8 +17,8 @@ class MemoryOperationsHandler {
|
||||
MemoryOperationsHandler() = default;
|
||||
virtual ~MemoryOperationsHandler() = default;
|
||||
|
||||
virtual bool makeResident(GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual bool evict(GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual bool isResident(GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) = 0;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
22
core/memory_manager/memory_operations_status.h
Normal file
22
core/memory_manager/memory_operations_status.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
enum class MemoryOperationsStatus : uint32_t {
|
||||
SUCCESS = 0,
|
||||
FAILED,
|
||||
MEMORY_NOT_FOUND,
|
||||
OUT_OF_MEMORY,
|
||||
UNSUPPORTED,
|
||||
DEVICE_UNINITIALIZED,
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
@@ -18,35 +18,35 @@ AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *a
|
||||
this->aubManager = aubManager;
|
||||
}
|
||||
|
||||
bool AubMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
|
||||
MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
|
||||
if (!aubManager) {
|
||||
return false;
|
||||
return MemoryOperationsStatus::DEVICE_UNINITIALIZED;
|
||||
}
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
|
||||
aubManager->writeMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), gfxAllocation.storageInfo.getMemoryBanks(), hint, gfxAllocation.getUsedPageSize());
|
||||
residentAllocations.push_back(&gfxAllocation);
|
||||
return true;
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
|
||||
bool AubMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
|
||||
MemoryOperationsStatus AubMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
|
||||
if (itor == residentAllocations.end()) {
|
||||
return false;
|
||||
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
||||
} else {
|
||||
residentAllocations.erase(itor, itor + 1);
|
||||
return true;
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
bool AubMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
|
||||
MemoryOperationsStatus AubMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
|
||||
if (itor == residentAllocations.end()) {
|
||||
return false;
|
||||
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
||||
} else {
|
||||
return true;
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
}
|
||||
void AubMemoryOperationsHandler::setAubManager(aub_stream::AubManager *aubManager) {
|
||||
|
||||
@@ -21,9 +21,9 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
AubMemoryOperationsHandler(aub_stream::AubManager *aubManager);
|
||||
~AubMemoryOperationsHandler() override = default;
|
||||
|
||||
bool makeResident(GraphicsAllocation &gfxAllocation) override;
|
||||
bool evict(GraphicsAllocation &gfxAllocation) override;
|
||||
bool isResident(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override;
|
||||
void setAubManager(aub_stream::AubManager *aubManager);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) {
|
||||
getMemoryOperationsHandler()->setAubManager(nullptr);
|
||||
auto memoryOperationsInterface = getMemoryOperationsHandler();
|
||||
bool result = memoryOperationsInterface->makeResident(allocation);
|
||||
EXPECT_FALSE(result);
|
||||
auto result = memoryOperationsInterface->makeResident(allocation);
|
||||
EXPECT_EQ(result, MemoryOperationsStatus::DEVICE_UNINITIALIZED);
|
||||
}
|
||||
|
||||
TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThenTrueReturnedAndWriteCalled) {
|
||||
MockAubManager aubManager;
|
||||
getMemoryOperationsHandler()->setAubManager(&aubManager);
|
||||
auto memoryOperationsInterface = getMemoryOperationsHandler();
|
||||
bool result = memoryOperationsInterface->makeResident(allocation);
|
||||
EXPECT_TRUE(result);
|
||||
auto result = memoryOperationsInterface->makeResident(allocation);
|
||||
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
|
||||
EXPECT_TRUE(aubManager.writeMemoryCalled);
|
||||
}
|
||||
|
||||
@@ -37,29 +37,29 @@ TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenIsResident
|
||||
MockAubManager aubManager;
|
||||
getMemoryOperationsHandler()->setAubManager(&aubManager);
|
||||
auto memoryOperationsInterface = getMemoryOperationsHandler();
|
||||
bool result = memoryOperationsInterface->isResident(allocation);
|
||||
EXPECT_FALSE(result);
|
||||
auto result = memoryOperationsInterface->isResident(allocation);
|
||||
EXPECT_EQ(result, MemoryOperationsStatus::MEMORY_NOT_FOUND);
|
||||
}
|
||||
TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenIsResidentCalledThenTrueReturned) {
|
||||
MockAubManager aubManager;
|
||||
getMemoryOperationsHandler()->setAubManager(&aubManager);
|
||||
auto memoryOperationsInterface = getMemoryOperationsHandler();
|
||||
memoryOperationsInterface->makeResident(allocation);
|
||||
bool result = memoryOperationsInterface->isResident(allocation);
|
||||
EXPECT_TRUE(result);
|
||||
auto result = memoryOperationsInterface->isResident(allocation);
|
||||
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
|
||||
}
|
||||
TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenEvictCalledThenFalseReturned) {
|
||||
MockAubManager aubManager;
|
||||
getMemoryOperationsHandler()->setAubManager(&aubManager);
|
||||
auto memoryOperationsInterface = getMemoryOperationsHandler();
|
||||
bool result = memoryOperationsInterface->evict(allocation);
|
||||
EXPECT_FALSE(result);
|
||||
auto result = memoryOperationsInterface->evict(allocation);
|
||||
EXPECT_EQ(result, MemoryOperationsStatus::MEMORY_NOT_FOUND);
|
||||
}
|
||||
TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenEvictCalledThenTrueReturned) {
|
||||
MockAubManager aubManager;
|
||||
getMemoryOperationsHandler()->setAubManager(&aubManager);
|
||||
auto memoryOperationsInterface = getMemoryOperationsHandler();
|
||||
memoryOperationsInterface->makeResident(allocation);
|
||||
bool result = memoryOperationsInterface->evict(allocation);
|
||||
EXPECT_TRUE(result);
|
||||
auto result = memoryOperationsInterface->evict(allocation);
|
||||
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
|
||||
}
|
||||
@@ -12,16 +12,16 @@ namespace NEO {
|
||||
DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() {
|
||||
}
|
||||
|
||||
bool DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
|
||||
return false;
|
||||
MemoryOperationsStatus DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
|
||||
return MemoryOperationsStatus::UNSUPPORTED;
|
||||
}
|
||||
|
||||
bool DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
|
||||
return false;
|
||||
MemoryOperationsStatus DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
|
||||
return MemoryOperationsStatus::UNSUPPORTED;
|
||||
}
|
||||
|
||||
bool DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
|
||||
return false;
|
||||
MemoryOperationsStatus DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
|
||||
return MemoryOperationsStatus::UNSUPPORTED;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -15,8 +15,8 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
DrmMemoryOperationsHandler();
|
||||
~DrmMemoryOperationsHandler() override = default;
|
||||
|
||||
bool makeResident(GraphicsAllocation &gfxAllocation) override;
|
||||
bool evict(GraphicsAllocation &gfxAllocation) override;
|
||||
bool isResident(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "core/command_stream/preemption_mode.h"
|
||||
#include "core/memory_manager/eviction_status.h"
|
||||
#include "core/utilities/spinlock.h"
|
||||
#include "runtime/gmm_helper/gmm_lib.h"
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
|
||||
@@ -292,7 +292,7 @@ void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocatio
|
||||
wddm->unlockResource(wddmAllocation.getDefaultHandle());
|
||||
if (wddmAllocation.needsMakeResidentBeforeLock) {
|
||||
auto evictionStatus = wddm->getTemporaryResourcesContainer()->evictResource(wddmAllocation.getDefaultHandle());
|
||||
DEBUG_BREAK_IF(evictionStatus == EvictionStatus::FAILED);
|
||||
DEBUG_BREAK_IF(evictionStatus == MemoryOperationsStatus::FAILED);
|
||||
}
|
||||
}
|
||||
void WddmMemoryManager::freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) {
|
||||
|
||||
@@ -19,18 +19,17 @@ WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm
|
||||
residentAllocations = std::make_unique<WddmResidentAllocationsContainer>(wddm);
|
||||
}
|
||||
|
||||
bool WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
|
||||
MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) {
|
||||
WddmAllocation &wddmAllocation = reinterpret_cast<WddmAllocation &>(gfxAllocation);
|
||||
return residentAllocations->makeResidentResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles());
|
||||
}
|
||||
|
||||
bool WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
|
||||
MemoryOperationsStatus WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) {
|
||||
WddmAllocation &wddmAllocation = reinterpret_cast<WddmAllocation &>(gfxAllocation);
|
||||
auto result = residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles());
|
||||
return result == EvictionStatus::SUCCESS;
|
||||
return residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles());
|
||||
}
|
||||
|
||||
bool WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
|
||||
MemoryOperationsStatus WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) {
|
||||
WddmAllocation &wddmAllocation = reinterpret_cast<WddmAllocation &>(gfxAllocation);
|
||||
return residentAllocations->isAllocationResident(wddmAllocation.getDefaultHandle());
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
WddmMemoryOperationsHandler(Wddm *wddm);
|
||||
~WddmMemoryOperationsHandler() override = default;
|
||||
|
||||
bool makeResident(GraphicsAllocation &gfxAllocation) override;
|
||||
bool evict(GraphicsAllocation &gfxAllocation) override;
|
||||
bool isResident(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override;
|
||||
|
||||
protected:
|
||||
Wddm *wddm;
|
||||
|
||||
@@ -17,58 +17,58 @@ WddmResidentAllocationsContainer::~WddmResidentAllocationsContainer() {
|
||||
evictAllResources();
|
||||
}
|
||||
|
||||
bool WddmResidentAllocationsContainer::isAllocationResident(const D3DKMT_HANDLE &handle) {
|
||||
MemoryOperationsStatus WddmResidentAllocationsContainer::isAllocationResident(const D3DKMT_HANDLE &handle) {
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
auto position = std::find(resourceHandles.begin(), resourceHandles.end(), handle);
|
||||
return position != resourceHandles.end();
|
||||
return position != resourceHandles.end() ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
||||
}
|
||||
|
||||
EvictionStatus WddmResidentAllocationsContainer::evictAllResources() {
|
||||
MemoryOperationsStatus WddmResidentAllocationsContainer::evictAllResources() {
|
||||
decltype(resourceHandles) resourcesToEvict;
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
resourceHandles.swap(resourcesToEvict);
|
||||
if (resourcesToEvict.empty()) {
|
||||
return EvictionStatus::NOT_APPLIED;
|
||||
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
||||
}
|
||||
uint64_t sizeToTrim = 0;
|
||||
uint32_t evictedResources = static_cast<uint32_t>(resourcesToEvict.size());
|
||||
bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim);
|
||||
return success ? EvictionStatus::SUCCESS : EvictionStatus::FAILED;
|
||||
return success ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED;
|
||||
}
|
||||
|
||||
EvictionStatus WddmResidentAllocationsContainer::evictResource(const D3DKMT_HANDLE &handle) {
|
||||
MemoryOperationsStatus WddmResidentAllocationsContainer::evictResource(const D3DKMT_HANDLE &handle) {
|
||||
return evictResources(&handle, 1u);
|
||||
}
|
||||
|
||||
EvictionStatus WddmResidentAllocationsContainer::evictResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
|
||||
MemoryOperationsStatus WddmResidentAllocationsContainer::evictResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
auto position = std::find(resourceHandles.begin(), resourceHandles.end(), handles[0]);
|
||||
if (position == resourceHandles.end()) {
|
||||
return EvictionStatus::NOT_APPLIED;
|
||||
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
||||
}
|
||||
auto distance = static_cast<size_t>(std::distance(resourceHandles.begin(), position));
|
||||
UNRECOVERABLE_IF(distance + count > resourceHandles.size());
|
||||
resourceHandles.erase(position, position + count);
|
||||
uint64_t sizeToTrim = 0;
|
||||
if (!wddm->evict(handles, count, sizeToTrim)) {
|
||||
return EvictionStatus::FAILED;
|
||||
return MemoryOperationsStatus::FAILED;
|
||||
}
|
||||
return EvictionStatus::SUCCESS;
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
|
||||
bool WddmResidentAllocationsContainer::makeResidentResource(const D3DKMT_HANDLE &handle) {
|
||||
MemoryOperationsStatus WddmResidentAllocationsContainer::makeResidentResource(const D3DKMT_HANDLE &handle) {
|
||||
return makeResidentResources(&handle, 1u);
|
||||
}
|
||||
|
||||
bool WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
|
||||
MemoryOperationsStatus WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count) {
|
||||
bool madeResident = false;
|
||||
while (!(madeResident = wddm->makeResident(handles, count, false, nullptr))) {
|
||||
if (evictAllResources() == EvictionStatus::SUCCESS) {
|
||||
if (evictAllResources() == MemoryOperationsStatus::SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
if (!wddm->makeResident(handles, count, false, nullptr)) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return false;
|
||||
return MemoryOperationsStatus::OUT_OF_MEMORY;
|
||||
};
|
||||
break;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ bool WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE
|
||||
}
|
||||
lock.unlock();
|
||||
wddm->waitOnPagingFenceFromCpu();
|
||||
return madeResident;
|
||||
return madeResident ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED;
|
||||
}
|
||||
|
||||
void WddmResidentAllocationsContainer::removeResource(const D3DKMT_HANDLE &handle) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "core/memory_manager/eviction_status.h"
|
||||
#include "core/memory_manager/memory_operations_status.h"
|
||||
#include "core/utilities/spinlock.h"
|
||||
#include "runtime/os_interface/windows/windows_defs.h"
|
||||
|
||||
@@ -21,12 +21,12 @@ class WddmResidentAllocationsContainer {
|
||||
WddmResidentAllocationsContainer(Wddm *wddm) : wddm(wddm) {}
|
||||
virtual ~WddmResidentAllocationsContainer();
|
||||
|
||||
bool isAllocationResident(const D3DKMT_HANDLE &handle);
|
||||
MOCKABLE_VIRTUAL EvictionStatus evictAllResources();
|
||||
MOCKABLE_VIRTUAL EvictionStatus evictResource(const D3DKMT_HANDLE &handle);
|
||||
EvictionStatus evictResources(const D3DKMT_HANDLE *handles, const uint32_t count);
|
||||
MOCKABLE_VIRTUAL bool makeResidentResource(const D3DKMT_HANDLE &handle);
|
||||
bool makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count);
|
||||
MemoryOperationsStatus isAllocationResident(const D3DKMT_HANDLE &handle);
|
||||
MOCKABLE_VIRTUAL MemoryOperationsStatus evictAllResources();
|
||||
MOCKABLE_VIRTUAL MemoryOperationsStatus evictResource(const D3DKMT_HANDLE &handle);
|
||||
MemoryOperationsStatus evictResources(const D3DKMT_HANDLE *handles, const uint32_t count);
|
||||
MOCKABLE_VIRTUAL MemoryOperationsStatus makeResidentResource(const D3DKMT_HANDLE &handle);
|
||||
MemoryOperationsStatus makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count);
|
||||
MOCKABLE_VIRTUAL void removeResource(const D3DKMT_HANDLE &handle);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -343,10 +343,10 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine
|
||||
const bool trimmingDone = this->trimResidencyToBudget(bytesToTrim);
|
||||
if (!trimmingDone) {
|
||||
auto evictionStatus = wddm.getTemporaryResourcesContainer()->evictAllResources();
|
||||
if (evictionStatus == EvictionStatus::SUCCESS) {
|
||||
if (evictionStatus == MemoryOperationsStatus::SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
DEBUG_BREAK_IF(evictionStatus != EvictionStatus::NOT_APPLIED);
|
||||
DEBUG_BREAK_IF(evictionStatus != MemoryOperationsStatus::MEMORY_NOT_FOUND);
|
||||
result = wddm.makeResident(handlesForResidency.get(), totalHandlesCount, true, &bytesToTrim);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
public:
|
||||
MockMemoryOperationsHandler() {}
|
||||
virtual ~MockMemoryOperationsHandler() {}
|
||||
bool makeResident(GraphicsAllocation &gfxAllocation) { return false; }
|
||||
bool evict(GraphicsAllocation &gfxAllocation) { return false; }
|
||||
bool isResident(GraphicsAllocation &gfxAllocation) { return false; }
|
||||
MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
};
|
||||
} // namespace NEO
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "core/memory_manager/memory_operations_status.h"
|
||||
#include "runtime/os_interface/windows/wddm_residency_allocations_container.h"
|
||||
#include "unit_tests/mocks/wddm_mock_helpers.h"
|
||||
|
||||
@@ -20,22 +21,22 @@ class MockWddmResidentAllocationsContainer : public WddmResidentAllocationsConta
|
||||
MockWddmResidentAllocationsContainer(Wddm *wddm) : WddmResidentAllocationsContainer(wddm) {}
|
||||
virtual ~MockWddmResidentAllocationsContainer() = default;
|
||||
|
||||
bool makeResidentResource(const D3DKMT_HANDLE &handle) override {
|
||||
MemoryOperationsStatus makeResidentResource(const D3DKMT_HANDLE &handle) override {
|
||||
makeResidentResult.called++;
|
||||
makeResidentResult.success = WddmResidentAllocationsContainer::makeResidentResource(handle);
|
||||
return makeResidentResult.success;
|
||||
makeResidentResult.operationSuccess = WddmResidentAllocationsContainer::makeResidentResource(handle);
|
||||
return makeResidentResult.operationSuccess;
|
||||
}
|
||||
|
||||
EvictionStatus evictAllResources() override {
|
||||
MemoryOperationsStatus evictAllResources() override {
|
||||
evictAllResourcesResult.called++;
|
||||
evictAllResourcesResult.status = WddmResidentAllocationsContainer::evictAllResources();
|
||||
return evictAllResourcesResult.status;
|
||||
evictAllResourcesResult.operationSuccess = WddmResidentAllocationsContainer::evictAllResources();
|
||||
return evictAllResourcesResult.operationSuccess;
|
||||
}
|
||||
|
||||
EvictionStatus evictResource(const D3DKMT_HANDLE &handle) override {
|
||||
MemoryOperationsStatus evictResource(const D3DKMT_HANDLE &handle) override {
|
||||
evictResourceResult.called++;
|
||||
evictResourceResult.status = WddmResidentAllocationsContainer::evictResource(handle);
|
||||
return evictResourceResult.status;
|
||||
evictResourceResult.operationSuccess = WddmResidentAllocationsContainer::evictResource(handle);
|
||||
return evictResourceResult.operationSuccess;
|
||||
}
|
||||
|
||||
std::unique_lock<SpinLock> acquireLock(SpinLock &lock) override {
|
||||
@@ -49,11 +50,11 @@ class MockWddmResidentAllocationsContainer : public WddmResidentAllocationsConta
|
||||
WddmResidentAllocationsContainer::removeResource(handle);
|
||||
}
|
||||
|
||||
WddmMockHelpers::CallResult makeResidentResult;
|
||||
WddmMockHelpers::CallResult acquireLockResult;
|
||||
WddmMockHelpers::CallResult removeResourceResult;
|
||||
WddmMockHelpers::EvictCallResult evictAllResourcesResult;
|
||||
WddmMockHelpers::EvictCallResult evictResourceResult;
|
||||
WddmMockHelpers::MemoryOperationResult makeResidentResult;
|
||||
WddmMockHelpers::MemoryOperationResult acquireLockResult;
|
||||
WddmMockHelpers::MemoryOperationResult removeResourceResult;
|
||||
WddmMockHelpers::MemoryOperationResult evictAllResourcesResult;
|
||||
WddmMockHelpers::MemoryOperationResult evictResourceResult;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -27,9 +27,6 @@ struct MakeResidentCall : CallResult {
|
||||
std::vector<D3DKMT_HANDLE> handlePack;
|
||||
uint32_t handleCount = 0;
|
||||
};
|
||||
struct EvictCallResult : CallResult {
|
||||
EvictionStatus status = EvictionStatus::UNKNOWN;
|
||||
};
|
||||
struct KmDafLockCall : CallResult {
|
||||
std::vector<D3DKMT_HANDLE> lockedAllocations;
|
||||
};
|
||||
@@ -39,6 +36,9 @@ struct WaitFromCpuResult : CallResult {
|
||||
struct FreeGpuVirtualAddressCall : CallResult {
|
||||
uint64_t sizePassed = -1;
|
||||
};
|
||||
struct MemoryOperationResult : CallResult {
|
||||
MemoryOperationsStatus operationSuccess = MemoryOperationsStatus::UNSUPPORTED;
|
||||
};
|
||||
} // namespace WddmMockHelpers
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -23,12 +23,12 @@ struct DrmMemoryOperationsHandlerTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(DrmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) {
|
||||
EXPECT_FALSE(drmMemoryOperationsHandler->makeResident(graphicsAllocation));
|
||||
EXPECT_FALSE(drmMemoryOperationsHandler->isResident(graphicsAllocation));
|
||||
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED);
|
||||
EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) {
|
||||
EXPECT_FALSE(drmMemoryOperationsHandler->makeResident(graphicsAllocation));
|
||||
EXPECT_FALSE(drmMemoryOperationsHandler->evict(graphicsAllocation));
|
||||
EXPECT_FALSE(drmMemoryOperationsHandler->isResident(graphicsAllocation));
|
||||
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED);
|
||||
EXPECT_EQ(drmMemoryOperationsHandler->evict(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED);
|
||||
EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED);
|
||||
}
|
||||
|
||||
@@ -844,7 +844,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeReside
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingAllTemporaryResourcesThenEvictionIsNotApplied) {
|
||||
wddm->getTemporaryResourcesContainer()->evictAllResources();
|
||||
EXPECT_EQ(EvictionStatus::NOT_APPLIED, mockTemporaryResources->evictAllResourcesResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictAllResourcesResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesThenAcquireTemporaryResourcesLock) {
|
||||
wddm->getTemporaryResourcesContainer()->evictAllResources();
|
||||
@@ -859,7 +859,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesAndAllEvi
|
||||
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true));
|
||||
gmockWddm.getTemporaryResourcesContainer()->evictAllResources();
|
||||
EXPECT_EQ(1u, mockTemporaryResources->evictAllResourcesResult.called);
|
||||
EXPECT_EQ(EvictionStatus::SUCCESS, mockTemporaryResources->evictAllResourcesResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictAllResourcesResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCallEvictForEachAllocationAndCleanList) {
|
||||
GmockWddm gmockWddm;
|
||||
@@ -881,11 +881,11 @@ TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTempor
|
||||
}
|
||||
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false));
|
||||
gmockWddm.getTemporaryResourcesContainer()->evictAllResources();
|
||||
EXPECT_EQ(EvictionStatus::FAILED, mockTemporaryResources->evictAllResourcesResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictAllResourcesResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingTemporaryResourceThenEvictionIsNotApplied) {
|
||||
wddm->getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE);
|
||||
EXPECT_EQ(EvictionStatus::NOT_APPLIED, mockTemporaryResources->evictResourceResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictResourceResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenAcquireTemporaryResourcesLock) {
|
||||
wddm->getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE);
|
||||
@@ -897,7 +897,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingNonExistingTemporaryResourceTh
|
||||
EXPECT_FALSE(mockTemporaryResources->resourceHandles.empty());
|
||||
wddm->getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE + 1);
|
||||
EXPECT_FALSE(mockTemporaryResources->resourceHandles.empty());
|
||||
EXPECT_EQ(EvictionStatus::NOT_APPLIED, mockTemporaryResources->evictResourceResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictResourceResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) {
|
||||
GmockWddm gmockWddm;
|
||||
@@ -906,7 +906,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFails
|
||||
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false));
|
||||
gmockWddm.getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE);
|
||||
EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty());
|
||||
EXPECT_EQ(EvictionStatus::FAILED, mockTemporaryResources->evictResourceResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictResourceResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSuccess) {
|
||||
GmockWddm gmockWddm;
|
||||
@@ -915,7 +915,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucce
|
||||
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true));
|
||||
gmockWddm.getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE);
|
||||
EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty());
|
||||
EXPECT_EQ(EvictionStatus::SUCCESS, mockTemporaryResources->evictResourceResult.status);
|
||||
EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictResourceResult.operationSuccess);
|
||||
}
|
||||
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheList) {
|
||||
mockTemporaryResources->resourceHandles.push_back(0x1);
|
||||
|
||||
@@ -26,12 +26,12 @@ struct WddmMemoryOperationsHandlerTest : public WddmTest {
|
||||
};
|
||||
|
||||
TEST_F(WddmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentCalled) {
|
||||
EXPECT_TRUE(wddmMemoryOperationsHandler->makeResident(wddmAllocation));
|
||||
EXPECT_TRUE(wddmMemoryOperationsHandler->isResident(wddmAllocation));
|
||||
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(wddmAllocation), MemoryOperationsStatus::SUCCESS);
|
||||
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(WddmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictCalled) {
|
||||
EXPECT_TRUE(wddmMemoryOperationsHandler->makeResident(wddmAllocation));
|
||||
EXPECT_TRUE(wddmMemoryOperationsHandler->evict(wddmAllocation));
|
||||
EXPECT_FALSE(wddmMemoryOperationsHandler->isResident(wddmAllocation));
|
||||
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(wddmAllocation), MemoryOperationsStatus::SUCCESS);
|
||||
EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmAllocation), MemoryOperationsStatus::SUCCESS);
|
||||
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user