mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 07:08:04 +08:00
fix: Deferred SVM allocations look up by gpu address
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
18b43eeb6a
commit
9a8138725a
@@ -417,16 +417,6 @@ void SVMAllocsManager::setUnifiedAllocationProperties(GraphicsAllocation *alloca
|
||||
allocation->setCoherent(svmProperties.coherent);
|
||||
}
|
||||
|
||||
SvmAllocationData *SVMAllocsManager::getSVMAlloc(const void *ptr) {
|
||||
std::shared_lock<std::shared_mutex> lock(mtx);
|
||||
return svmAllocs.get(ptr);
|
||||
}
|
||||
|
||||
SvmAllocationData *SVMAllocsManager::getSVMDeferFreeAlloc(const void *ptr) {
|
||||
std::shared_lock<std::shared_mutex> lock(mtx);
|
||||
return svmDeferFreeAllocs.get(ptr);
|
||||
}
|
||||
|
||||
void SVMAllocsManager::insertSVMAlloc(const SvmAllocationData &svmAllocData) {
|
||||
std::unique_lock<std::shared_mutex> lock(mtx);
|
||||
svmAllocs.insert(svmAllocData);
|
||||
@@ -493,7 +483,7 @@ void SVMAllocsManager::freeSVMAllocImpl(void *ptr, FreePolicyType policy, SvmAll
|
||||
} else if (policy == FreePolicyType::POLICY_DEFER) {
|
||||
if (svmData->cpuAllocation) {
|
||||
if (this->memoryManager->allocInUse(*svmData->cpuAllocation)) {
|
||||
if (getSVMDeferFreeAlloc(svmData) == nullptr) {
|
||||
if (getSVMDeferFreeAlloc(ptr) == nullptr) {
|
||||
this->svmDeferFreeAllocs.insert(*svmData);
|
||||
}
|
||||
return;
|
||||
@@ -502,7 +492,7 @@ void SVMAllocsManager::freeSVMAllocImpl(void *ptr, FreePolicyType policy, SvmAll
|
||||
for (auto &gpuAllocation : svmData->gpuAllocations.getGraphicsAllocations()) {
|
||||
if (gpuAllocation) {
|
||||
if (this->memoryManager->allocInUse(*gpuAllocation)) {
|
||||
if (getSVMDeferFreeAlloc(svmData) == nullptr) {
|
||||
if (getSVMDeferFreeAlloc(ptr) == nullptr) {
|
||||
this->svmDeferFreeAllocs.insert(*svmData);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <type_traits>
|
||||
|
||||
namespace NEO {
|
||||
class CommandStreamReceiver;
|
||||
@@ -177,9 +178,23 @@ class SVMAllocsManager {
|
||||
void *createUnifiedKmdMigratedAllocation(size_t size,
|
||||
const SvmAllocationProperties &svmProperties,
|
||||
const UnifiedMemoryProperties &unifiedMemoryProperties);
|
||||
|
||||
void setUnifiedAllocationProperties(GraphicsAllocation *allocation, const SvmAllocationProperties &svmProperties);
|
||||
SvmAllocationData *getSVMAlloc(const void *ptr);
|
||||
SvmAllocationData *getSVMDeferFreeAlloc(const void *ptr);
|
||||
|
||||
template <typename T,
|
||||
std::enable_if_t<std::is_same_v<T, void> || std::is_same_v<T, const void>, int> = 0>
|
||||
SvmAllocationData *getSVMAlloc(T *ptr) {
|
||||
std::shared_lock<std::shared_mutex> lock(mtx);
|
||||
return svmAllocs.get(ptr);
|
||||
}
|
||||
|
||||
template <typename T,
|
||||
std::enable_if_t<std::is_same_v<T, void *>, int> = 0>
|
||||
SvmAllocationData *getSVMDeferFreeAlloc(T ptr) {
|
||||
std::shared_lock<std::shared_mutex> lock(mtx);
|
||||
return svmDeferFreeAllocs.get(ptr);
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL bool freeSVMAlloc(void *ptr, bool blocking);
|
||||
MOCKABLE_VIRTUAL bool freeSVMAllocDefer(void *ptr);
|
||||
MOCKABLE_VIRTUAL void freeSVMAllocDeferImpl();
|
||||
|
||||
@@ -20,6 +20,7 @@ struct MockSVMAllocsManager : public SVMAllocsManager {
|
||||
using SVMAllocsManager::multiOsContextSupport;
|
||||
using SVMAllocsManager::svmAllocs;
|
||||
using SVMAllocsManager::SVMAllocsManager;
|
||||
using SVMAllocsManager::svmDeferFreeAllocs;
|
||||
using SVMAllocsManager::svmMapOperations;
|
||||
using SVMAllocsManager::usmDeviceAllocationsCache;
|
||||
using SVMAllocsManager::usmDeviceAllocationsCacheEnabled;
|
||||
|
||||
@@ -62,6 +62,36 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenFreeSharedAllocWithOffsetPointerThenReso
|
||||
EXPECT_EQ(pageFaultMemoryData, mockPageFaultManager->memoryData.end());
|
||||
}
|
||||
|
||||
TEST_F(SVMLocalMemoryAllocatorTest, whenFreeSvmAllocationDeferThenAllocationsCountIsProper) {
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.EnableLocalMemory.set(1);
|
||||
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 2));
|
||||
auto device = deviceFactory->rootDevices[0];
|
||||
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
|
||||
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
|
||||
csr->setupContext(*device->getDefaultEngine().osContext);
|
||||
void *cmdQ = reinterpret_cast<void *>(0x12345);
|
||||
|
||||
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, 1, rootDeviceIndices, deviceBitfields);
|
||||
unifiedMemoryProperties.device = device;
|
||||
|
||||
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096, unifiedMemoryProperties, &cmdQ);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
auto memoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
|
||||
memoryManager->deferAllocInUse = true;
|
||||
EXPECT_EQ(svmManager->svmDeferFreeAllocs.allocations.size(), 0u);
|
||||
svmManager->freeSVMAllocDefer(ptr);
|
||||
EXPECT_EQ(svmManager->svmDeferFreeAllocs.allocations.size(), 1u);
|
||||
svmManager->freeSVMAllocDefer(ptr);
|
||||
EXPECT_EQ(svmManager->svmDeferFreeAllocs.allocations.size(), 1u);
|
||||
memoryManager->deferAllocInUse = false;
|
||||
svmManager->freeSVMAllocDefer(ptr);
|
||||
EXPECT_EQ(svmManager->svmDeferFreeAllocs.allocations.size(), 0u);
|
||||
ASSERT_EQ(svmManager->getSVMAlloc(ptr), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(SVMLocalMemoryAllocatorTest, whenFreeSVMAllocIsDeferredThenFreedSubsequently) {
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.EnableLocalMemory.set(1);
|
||||
|
||||
Reference in New Issue
Block a user