Add support for reduced GPU address space

Change-Id: I9ebbc8c51039bb533b44c6b80e717e1489a20a43
Signed-off-by: Pawel Wilma <pawel.wilma@intel.com>
This commit is contained in:
Pawel Wilma
2018-08-24 15:23:45 +02:00
committed by sys_ocldev
parent f6743ced2a
commit 4a12deea2b
44 changed files with 473 additions and 270 deletions

View File

@@ -40,6 +40,7 @@
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_event.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_program.h"
@@ -1047,7 +1048,15 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
size_t size = sizeof(memory);
HostPtrSurface surface(const_cast<char *>(memory), size, true);
EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)).Times(1).WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer));
if (mockCmdQ->isFullRangeSvm()) {
EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_))
.Times(1)
.WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer));
} else {
EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryForNonSvmHostPtr(::testing::_, ::testing::_))
.Times(1)
.WillOnce(::testing::Return(nullptr));
}
bool result = mockCmdQ->createAllocationForHostSurface(surface);
EXPECT_TRUE(result);
@@ -1080,7 +1089,15 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
size_t size = sizeof(memory);
HostPtrSurface surface(const_cast<char *>(memory), size, false);
EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)).Times(1).WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer));
if (mockCmdQ->isFullRangeSvm()) {
EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_))
.Times(1)
.WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer));
} else {
EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryForNonSvmHostPtr(::testing::_, ::testing::_))
.Times(1)
.WillOnce(::testing::Return(nullptr));
}
bool result = mockCmdQ->createAllocationForHostSurface(surface);
EXPECT_FALSE(result);
@@ -1092,3 +1109,46 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
mockCmdQ->release();
mockContext->release();
}
struct ReducedAddrSpaceCommandQueueHwTest : public CommandQueueHwTest {
HardwareInfo hwInfoToModify;
std::unique_ptr<MockDevice> device;
MockContext *mockContext = nullptr;
::testing::NiceMock<GMockMemoryManager> *gmockMemoryManager = nullptr;
void SetUp() override {
CommandQueueHwTest::SetUp();
hwInfoToModify = *platformDevices[0];
hwInfoToModify.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress;
device.reset(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfoToModify));
ASSERT_NE(nullptr, device.get());
gmockMemoryManager = new ::testing::NiceMock<GMockMemoryManager>;
ASSERT_NE(nullptr, gmockMemoryManager);
device->injectMemoryManager(gmockMemoryManager);
mockContext = new MockContext(device.get());
ASSERT_NE(nullptr, mockContext);
}
void TearDown() override {
CommandQueueHwTest::TearDown();
gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
mockContext->release();
}
};
HWTEST_F(ReducedAddrSpaceCommandQueueHwTest,
givenReducedGpuAddressSpaceWhenAllocationForHostSurfaceIsCreatedThenAllocateGraphicsMemoryForNonSvmHostPtrIsCalled) {
std::unique_ptr<MockCommandQueueHw<FamilyType>, std::function<void(MockCommandQueueHw<FamilyType> *)>> mockCmdQ(
new MockCommandQueueHw<FamilyType>(mockContext, device.get(), 0), [](MockCommandQueueHw<FamilyType> *ptr) { ptr->release(); });
char memory[8] = {};
HostPtrSurface surface(const_cast<char *>(memory), sizeof(memory), false);
EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryForNonSvmHostPtr(::testing::_, ::testing::_))
.Times(1)
.WillOnce(::testing::Return(nullptr));
bool result = mockCmdQ->createAllocationForHostSurface(surface);
EXPECT_FALSE(result);
}

View File

@@ -388,7 +388,8 @@ HWTEST_F(EnqueueThreading, enqueueWriteBufferRect) {
size_t hostOrigin[3] = {1024u, 1, 0};
size_t region[3] = {1024u, 1, 1};
void *ptr = ::alignedMalloc(1024u, 4096);
auto hostPtrSize = Buffer::calculateHostPtrSize(hostOrigin, region, 0, 0);
void *ptr = ::alignedMalloc(hostPtrSize, MemoryConstants::pageSize);
ASSERT_NE(nullptr, ptr);
pCmdQ->enqueueWriteBufferRect(buffer.get(), CL_TRUE, bufferOrigin, hostOrigin, region, 0, 0, 0, 0, ptr, 0, nullptr, nullptr);

View File

@@ -221,10 +221,10 @@ HWTEST_F(EnqueueWriteImageTest, GivenImage1DarrayWhenReadWriteImageIsCalledThenH
EXPECT_EQ(temporaryAllocation1->getUnderlyingBufferSize(), imageSize);
EnqueueReadImageHelper<>::enqueueReadImage(pCmdQ, dstImage, CL_FALSE, origin, region);
EnqueueReadImageHelper<>::enqueueReadImage(pCmdQ, dstImage2, CL_FALSE, origin, region);
auto temporaryAllocation2 = temporaryAllocation1->next;
ASSERT_NE(nullptr, temporaryAllocation2);
EXPECT_EQ(temporaryAllocation1->getUnderlyingBufferSize(), imageSize);
EXPECT_EQ(temporaryAllocation2->getUnderlyingBufferSize(), imageSize);
delete dstImage2;
}
@@ -430,7 +430,10 @@ HWTEST_P(MipMapWriteImageTest, GivenImageWithMipLevelNonZeroWhenReadImageIsCalle
}
EXPECT_NE(nullptr, image.get());
std::unique_ptr<uint32_t[]> ptr = std::unique_ptr<uint32_t[]>(new uint32_t[3]);
auto hostPtrSize = Image::calculateHostPtrSize(region, image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(),
image->getSurfaceFormatInfo().ImageElementSizeInBytes, image_type);
std::unique_ptr<uint32_t[]> ptr = std::unique_ptr<uint32_t[]>(new uint32_t[hostPtrSize]);
retVal = pCmdQ->enqueueWriteImage(image.get(),
CL_FALSE,
origin,

View File

@@ -102,13 +102,13 @@ struct MultipleMapImageTest : public DeviceFixture, public ::testing::Test {
template <typename Traits, typename FamilyType>
std::unique_ptr<MockImage<FamilyType>> createMockImage() {
auto mockAlloc = pDevice->getMemoryManager()->allocateGraphicsMemory(1024);
auto allocationSize = Traits::imageDesc.image_width * 4 * Traits::imageDesc.image_height * Traits::imageDesc.image_depth;
auto mockAlloc = pDevice->getMemoryManager()->allocateGraphicsMemory(allocationSize);
auto tiledImage = GmmHelper::allowTiling(Traits::imageDesc);
auto surfaceFormat = Image::getSurfaceFormatFromTable(Traits::flags, &Traits::imageFormat);
auto img = new MockImage<FamilyType>(context, Traits::flags, 1024, Traits::hostPtr,
Traits::imageFormat, Traits::imageDesc, false, mockAlloc, false,
tiledImage, 0, 0, *surfaceFormat);
auto img = new MockImage<FamilyType>(context, Traits::flags, allocationSize, Traits::hostPtr, Traits::imageFormat,
Traits::imageDesc, false, mockAlloc, false, tiledImage, 0, 0, *surfaceFormat);
return std::unique_ptr<MockImage<FamilyType>>(img);
}
@@ -320,10 +320,9 @@ HWTEST_F(MultipleMapImageTest, givenMultimpleMapsWhenUnmappingThenRemoveCorrectP
auto image = createMockImage<Image3dDefaults, FamilyType>();
auto cmdQ = createMockCmdQ<FamilyType>();
MapInfo mappedPtrs[3] = {
{nullptr, 1, {{1, 1, 1}}, {{1, 1, 1}}, 0},
{nullptr, 1, {{4, 4, 2}}, {{4, 4, 4}}, 0},
{nullptr, 1, {{10, 10, 10}}, {{10, 10, 10}}, 0}};
MapInfo mappedPtrs[3] = {{nullptr, 1, {{1, 1, 1}}, {{1, 1, 1}}, 0},
{nullptr, 1, {{2, 2, 2}}, {{2, 2, 2}}, 0},
{nullptr, 1, {{3, 5, 7}}, {{4, 4, 4}}, 0}};
for (size_t i = 0; i < 3; i++) {
mappedPtrs[i].ptr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &mappedPtrs[i].offset[0], &mappedPtrs[i].size[0],