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

@@ -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>