Ensure base ptr is passed to PageFaultManager::removeAllocation

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2022-11-17 10:33:19 +00:00
committed by Compute-Runtime-Automation
parent f5fb26d017
commit e197736b6f
4 changed files with 58 additions and 31 deletions

View File

@@ -8,11 +8,9 @@
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/helpers/local_memory_access_modes.h"
#include "shared/source/memory_manager/allocations_list.h"
#include "shared/test/common/fixtures/cpu_page_fault_manager_tests_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.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/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_svm_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
@@ -32,34 +30,7 @@
using namespace NEO;
template <bool enableLocalMemory>
struct SVMMemoryAllocatorFixture {
SVMMemoryAllocatorFixture() : executionEnvironment(defaultHwInfo.get()) {}
void setUp() {
bool svmSupported = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->capabilityTable.ftrSvm;
if (!svmSupported) {
GTEST_SKIP();
}
executionEnvironment.initGmm();
memoryManager = std::make_unique<MockMemoryManager>(false, enableLocalMemory, executionEnvironment);
svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
if (enableLocalMemory) {
memoryManager->pageFaultManager.reset(new MockPageFaultManager);
}
}
void tearDown() {
}
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<MockMemoryManager> memoryManager;
std::unique_ptr<MockSVMAllocsManager> svmManager;
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
};
using SVMMemoryAllocatorTest = Test<SVMMemoryAllocatorFixture<false>>;
using SVMLocalMemoryAllocatorTest = Test<SVMMemoryAllocatorFixture<true>>;
TEST_F(SVMMemoryAllocatorTest, whenCreateZeroSizedSVMAllocationThenReturnNullptr) {

View File

@@ -425,8 +425,8 @@ void SVMAllocsManager::freeSVMAllocImpl(void *ptr, bool blocking, SvmAllocationD
}
auto pageFaultManager = this->memoryManager->getPageFaultManager();
if (pageFaultManager) {
pageFaultManager->removeAllocation(ptr);
if (svmData->cpuAllocation && pageFaultManager) {
pageFaultManager->removeAllocation(svmData->cpuAllocation->getUnderlyingBuffer());
}
std::unique_lock<std::mutex> lockForIndirect(mtxForIndirectAccess);
std::unique_lock<std::shared_mutex> lock(mtx);

View File

@@ -7,6 +7,8 @@
#pragma once
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/test/common/fixtures/cpu_page_fault_manager_tests_fixture.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
namespace NEO {
struct MockSVMAllocsManager : public SVMAllocsManager {
public:
@@ -19,4 +21,31 @@ struct MockSVMAllocsManager : public SVMAllocsManager {
using SVMAllocsManager::usmDeviceAllocationsCache;
using SVMAllocsManager::usmDeviceAllocationsCacheEnabled;
};
template <bool enableLocalMemory>
struct SVMMemoryAllocatorFixture {
SVMMemoryAllocatorFixture() : executionEnvironment(defaultHwInfo.get()) {}
void setUp() {
bool svmSupported = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->capabilityTable.ftrSvm;
if (!svmSupported) {
GTEST_SKIP();
}
executionEnvironment.initGmm();
memoryManager = std::make_unique<MockMemoryManager>(false, enableLocalMemory, executionEnvironment);
svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
if (enableLocalMemory) {
memoryManager->pageFaultManager.reset(new MockPageFaultManager);
}
}
void tearDown() {
}
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<MockMemoryManager> memoryManager;
std::unique_ptr<MockSVMAllocsManager> svmManager;
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
};
} // namespace NEO

View File

@@ -5,10 +5,12 @@
*
*/
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_svm_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/common/test_macros/test.h"
#include "gtest/gtest.h"
@@ -32,3 +34,28 @@ TEST(SvmDeviceAllocationTest, givenGivenSvmAllocsManagerWhenObtainOwnershipCalle
});
th2.join();
}
using SVMLocalMemoryAllocatorTest = Test<SVMMemoryAllocatorFixture<true>>;
TEST_F(SVMLocalMemoryAllocatorTest, whenFreeSharedAllocWithOffsetPointerThenResourceIsRemovedProperly) {
DebugManagerStateRestore restore;
DebugManager.flags.EnableLocalMemory.set(1);
void *cmdQ = reinterpret_cast<void *>(0x12345);
auto mockPageFaultManager = new MockPageFaultManager();
memoryManager->pageFaultManager.reset(mockPageFaultManager);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
auto allocationSize = 4096u;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(allocationSize, unifiedMemoryProperties, &cmdQ);
EXPECT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
auto pageFaultMemoryData = mockPageFaultManager->memoryData.find(ptr);
EXPECT_NE(svmData, nullptr);
EXPECT_NE(pageFaultMemoryData, mockPageFaultManager->memoryData.end());
svmManager->freeSVMAlloc(ptrOffset(ptr, allocationSize / 4));
svmData = svmManager->getSVMAlloc(ptr);
pageFaultMemoryData = mockPageFaultManager->memoryData.find(ptr);
EXPECT_EQ(svmData, nullptr);
EXPECT_EQ(pageFaultMemoryData, mockPageFaultManager->memoryData.end());
}