Add unified memory aub tests

Related-To: NEO-2998

Change-Id: I1d047bc98de3cafe50ed7f54bfd3a6b695ec4dbd
Signed-off-by: Jobczyk, Lukasz <lukasz.jobczyk@intel.com>
This commit is contained in:
Jobczyk, Lukasz
2019-11-13 14:19:55 +01:00
parent dd466c23bb
commit 61e91a376b
11 changed files with 274 additions and 0 deletions

View File

@@ -218,6 +218,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
StorageInfo storageInfo = {};
static constexpr uint32_t defaultBank = 0b1u;
static constexpr uint32_t allBanks = 0xffffffff;
protected:
constexpr static uint32_t objectNotResident = std::numeric_limits<uint32_t>::max();

View File

@@ -9,6 +9,8 @@
#include "core/helpers/debug_helpers.h"
#include "core/helpers/ptr_math.h"
#include "core/memory_manager/graphics_allocation.h"
#include "core/memory_manager/unified_memory_manager.h"
#include <mutex>
@@ -37,6 +39,7 @@ void PageFaultManager::moveAllocationToGpuDomain(void *ptr) {
if (alloc != memoryData.end()) {
auto &pageFaultData = alloc->second;
if (pageFaultData.isInGpuDomain == false) {
this->setAubWritable(false, ptr, pageFaultData.unifiedMemoryManager);
this->transferToGpu(ptr, pageFaultData.cmdQ);
this->protectCPUMemoryAccess(ptr, pageFaultData.size);
pageFaultData.isInGpuDomain = true;
@@ -50,6 +53,7 @@ void PageFaultManager::moveAllocationsWithinUMAllocsManagerToGpuDomain(SVMAllocs
auto allocPtr = alloc.first;
auto &pageFaultData = alloc.second;
if (pageFaultData.unifiedMemoryManager == unifiedMemoryManager && pageFaultData.isInGpuDomain == false) {
this->setAubWritable(false, allocPtr, pageFaultData.unifiedMemoryManager);
this->transferToGpu(allocPtr, pageFaultData.cmdQ);
this->protectCPUMemoryAccess(allocPtr, pageFaultData.size);
pageFaultData.isInGpuDomain = true;
@@ -64,6 +68,7 @@ bool PageFaultManager::verifyPageFault(void *ptr) {
auto &pageFaultData = alloc.second;
if (ptr >= allocPtr && ptr < ptrOffset(allocPtr, pageFaultData.size)) {
this->allowCPUMemoryAccess(allocPtr, pageFaultData.size);
this->setAubWritable(true, allocPtr, pageFaultData.unifiedMemoryManager);
this->transferToCpu(allocPtr, pageFaultData.size, pageFaultData.cmdQ);
pageFaultData.isInGpuDomain = false;
return true;
@@ -71,4 +76,9 @@ bool PageFaultManager::verifyPageFault(void *ptr) {
}
return false;
}
void PageFaultManager::setAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager) {
auto gpuAlloc = unifiedMemoryManager->getSVMAlloc(ptr)->gpuAllocation;
gpuAlloc->setAubWritable(writable, GraphicsAllocation::allBanks);
}
} // namespace NEO

View File

@@ -41,6 +41,7 @@ class PageFaultManager : public NonCopyableOrMovableClass {
MOCKABLE_VIRTUAL bool verifyPageFault(void *ptr);
MOCKABLE_VIRTUAL void transferToCpu(void *ptr, size_t size, void *cmdQ);
MOCKABLE_VIRTUAL void transferToGpu(void *ptr, void *cmdQ);
MOCKABLE_VIRTUAL void setAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager);
std::unordered_map<void *, PageFaultData> memoryData;
SpinLock mtx;

View File

@@ -5,7 +5,11 @@
*
*/
#include "core/memory_manager/graphics_allocation.h"
#include "core/memory_manager/unified_memory_manager.h"
#include "core/unified_memory/unified_memory.h"
#include "core/unit_tests/page_fault_manager/cpu_page_fault_manager_tests_fixture.h"
#include "unit_tests/mocks/mock_memory_manager.h"
using namespace NEO;
@@ -26,6 +30,7 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenInsertingAllocsThenAllo
EXPECT_EQ(pageFaultManager->protectMemoryCalled, 0);
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 1);
EXPECT_EQ(pageFaultManager->transferToGpuCalled, 0);
EXPECT_TRUE(pageFaultManager->isAubWritable);
pageFaultManager->insertAllocation(alloc2, 20, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager), cmdQ);
EXPECT_EQ(pageFaultManager->memoryData.size(), 2u);
@@ -41,6 +46,7 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenInsertingAllocsThenAllo
EXPECT_EQ(pageFaultManager->protectMemoryCalled, 0);
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 2);
EXPECT_EQ(pageFaultManager->transferToGpuCalled, 0);
EXPECT_TRUE(pageFaultManager->isAubWritable);
pageFaultManager->removeAllocation(alloc1);
EXPECT_EQ(pageFaultManager->memoryData.size(), 1u);
@@ -100,6 +106,7 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenMovingToGpuDomainAllocs
EXPECT_EQ(pageFaultManager->protectedMemoryAccessAddress, alloc1);
EXPECT_EQ(pageFaultManager->protectedSize, 10u);
EXPECT_EQ(pageFaultManager->transferToGpuAddress, alloc1);
EXPECT_FALSE(pageFaultManager->isAubWritable);
}
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocWhenMoveToGpuDomainThenTransferToGpuIsCalled) {
@@ -121,6 +128,7 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocWhenMoveToGpuDomainThenTrans
EXPECT_EQ(pageFaultManager->protectedMemoryAccessAddress, alloc);
EXPECT_EQ(pageFaultManager->protectedSize, 10u);
EXPECT_EQ(pageFaultManager->transferToGpuAddress, alloc);
EXPECT_FALSE(pageFaultManager->isAubWritable);
}
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocInGpuDomainWhenMovingToGpuDomainThenNothingIsCalled) {
@@ -139,6 +147,7 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocInGpuDomainWhenMovingToGpuDo
EXPECT_EQ(pageFaultManager->protectMemoryCalled, 0);
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 1);
EXPECT_EQ(pageFaultManager->transferToGpuCalled, 0);
EXPECT_TRUE(pageFaultManager->isAubWritable);
}
TEST_F(PageFaultManagerTest, whenMovingToGpuDomainUntrackedAllocThenNothingIsCalled) {
@@ -152,6 +161,7 @@ TEST_F(PageFaultManagerTest, whenMovingToGpuDomainUntrackedAllocThenNothingIsCal
EXPECT_EQ(pageFaultManager->protectMemoryCalled, 0);
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0);
EXPECT_EQ(pageFaultManager->transferToGpuCalled, 0);
EXPECT_TRUE(pageFaultManager->isAubWritable);
}
TEST_F(PageFaultManagerTest, givenHandlerRegisteredAndUntrackedPageFaultAddressWhenVerifyingThenFalseIsReturned) {
@@ -187,4 +197,24 @@ TEST_F(PageFaultManagerTest, givenTrackedPageFaultAddressWhenVerifyingThenProper
EXPECT_EQ(pageFaultManager->accessAllowedSize, 10u);
EXPECT_EQ(pageFaultManager->transferToCpuAddress, alloc1);
EXPECT_EQ(pageFaultManager->transferToCpuSize, 10u);
EXPECT_TRUE(pageFaultManager->isAubWritable);
}
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocWhenSetAubWritableIsCalledThenAllocIsAubWritable) {
MockExecutionEnvironment executionEnvironment;
if (!executionEnvironment.getHardwareInfo()->capabilityTable.ftrSvm) {
GTEST_SKIP();
}
void *cmdQ = reinterpret_cast<void *>(0xFFFF);
auto memoryManager = std::make_unique<MockMemoryManager>(executionEnvironment);
auto unifiedMemoryManager = std::make_unique<SVMAllocsManager>(memoryManager.get());
void *alloc1 = unifiedMemoryManager->createSharedUnifiedMemoryAllocation(0, 10, SVMAllocsManager::UnifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY), cmdQ);
pageFaultManager->baseAubWritable(false, alloc1, unifiedMemoryManager.get());
auto gpuAlloc = unifiedMemoryManager->getSVMAlloc(alloc1)->gpuAllocation;
EXPECT_FALSE(gpuAlloc->isAubWritable(GraphicsAllocation::allBanks));
unifiedMemoryManager->freeSVMAlloc(alloc1);
}

View File

@@ -37,6 +37,12 @@ class MockPageFaultManager : public PageFaultManager {
transferToGpuCalled++;
transferToGpuAddress = ptr;
}
void setAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager) override {
isAubWritable = writable;
}
void baseAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager) {
PageFaultManager::setAubWritable(writable, ptr, unifiedMemoryManager);
}
void baseCpuTransfer(void *ptr, size_t size, void *cmdQ) {
PageFaultManager::transferToCpu(ptr, size, cmdQ);
}
@@ -55,6 +61,7 @@ class MockPageFaultManager : public PageFaultManager {
size_t transferToCpuSize = 0;
size_t accessAllowedSize = 0;
size_t protectedSize = 0;
bool isAubWritable = true;
};
template <class T>