From 6ab6a06b1b4621aa55eda35ff420c832c595944a Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Tue, 10 Sep 2019 11:55:38 +0200 Subject: [PATCH] Add error handling in allocateGraphicsMemoryForImageImpl and improve ULTs Change-Id: I418a888fe31d5a7f008bdcfa0a3aabb77bc4df39 Signed-off-by: Dunajski, Bartosz --- .../os_agnostic_memory_manager.cpp | 4 ++- .../enqueue_map_image_aub_tests.cpp | 3 ++- .../enqueue_read_image_aub_tests.cpp | 3 ++- unit_tests/mem_obj/image_tests.cpp | 26 +++++++++++++++++-- .../linux/drm_memory_manager_tests.cpp | 16 +++++++++--- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 9ddb69e0e9..4d926c4199 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -273,7 +273,9 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImageImpl( if (allocationData.imgInfo->linearStorage && allocationData.imgInfo->mipCount == 0) { alloc = allocateGraphicsMemoryWithAlignment(allocationData); - alloc->setDefaultGmm(gmm.release()); + if (alloc) { + alloc->setDefaultGmm(gmm.release()); + } return alloc; } diff --git a/unit_tests/aub_tests/command_queue/enqueue_map_image_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_map_image_aub_tests.cpp index 09cbfe78eb..a0434ff9eb 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_map_image_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_map_image_aub_tests.cpp @@ -148,7 +148,8 @@ HWTEST_P(AUBMapImage, MapUpdateUnmapVerify) { uint8_t *mappedPtrStart; uint8_t *srcMemoryStart; - if (srcImage->isTiledAllocation()) { + bool isGpuCopy = srcImage->isTiledAllocation() || !MemoryPool::isSystemMemoryPool(srcImage->getGraphicsAllocation()->getMemoryPool()); + if (isGpuCopy) { mappedPtrStart = static_cast(mappedPtr); srcMemoryStart = srcMemory; diff --git a/unit_tests/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp index d86c065e6c..165cab1ecd 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_read_image_aub_tests.cpp @@ -175,7 +175,8 @@ HWTEST_P(AUBReadImage, simpleUnalignedMemory) { auto imageMemory = srcMemory; - if (!srcImage->isMemObjZeroCopy() && !srcImage->isTiledAllocation()) { + bool isGpuCopy = srcImage->isTiledAllocation() || !MemoryPool::isSystemMemoryPool(srcImage->getGraphicsAllocation()->getMemoryPool()); + if (!isGpuCopy) { imageMemory = (uint8_t *)(srcImage->getCpuAddress()); } diff --git a/unit_tests/mem_obj/image_tests.cpp b/unit_tests/mem_obj/image_tests.cpp index df6950dca9..db6e46f46d 100644 --- a/unit_tests/mem_obj/image_tests.cpp +++ b/unit_tests/mem_obj/image_tests.cpp @@ -580,9 +580,9 @@ TEST_P(CreateImageHostPtr, getAddress) { EXPECT_NE(pHostPtr, address); } - if (flags & CL_MEM_COPY_HOST_PTR && !image->isTiledAllocation()) { + if (flags & CL_MEM_COPY_HOST_PTR && image->isMemObjZeroCopy()) { // Buffer should contain a copy of host memory - EXPECT_EQ(0, memcmp(pHostPtr, address, sizeof(testImageDimensions))); + EXPECT_EQ(0, memcmp(pHostPtr, image->getGraphicsAllocation()->getUnderlyingBuffer(), sizeof(testImageDimensions))); } } @@ -645,6 +645,28 @@ TEST_P(CreateImageHostPtr, failedAllocationInjection) { injectFailures(method, 4); // check only first 5 allocations - avoid checks on writeImg call allocations for tiled imgs } +TEST_P(CreateImageHostPtr, givenLinearImageWhenFailedAtCreationThenReturnError) { + DebugManagerStateRestore restore; + DebugManager.flags.ForceLinearImages.set(true); + + InjectedFunction method = [this](size_t failureIndex) { + // System under test + image = createImage(retVal); + + if (MemoryManagement::nonfailingAllocation == failureIndex) { + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_NE(nullptr, image); + } else { + EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal) << "for allocation " << failureIndex; + EXPECT_EQ(nullptr, image); + } + + delete image; + image = nullptr; + }; + injectFailures(method, 4); // check only first 5 allocations - avoid checks on writeImg call allocations for tiled imgs +} + TEST_P(CreateImageHostPtr, checkWritingOutsideAllocatedMemoryWhileCreatingImage) { auto mockMemoryManager = new MockMemoryManager(*pDevice->executionEnvironment); pDevice->injectMemoryManager(mockMemoryManager); diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 78f52cc03b..cc29517375 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -28,6 +28,7 @@ #include "runtime/os_interface/os_context.h" #include "runtime/utilities/tag_allocator.h" #include "test.h" +#include "unit_tests/helpers/unit_test_helper.h" #include "unit_tests/mocks/linux/mock_drm_command_stream_receiver.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_gfx_partition.h" @@ -1128,7 +1129,10 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag memoryManager->freeGraphicsMemory(imageGraphicsAllocation); } -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { +HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { + if (!UnitTestHelper::tiledImagesSupported) { + GTEST_SKIP(); + } mock->ioctl_expected.gemCreate = 1; mock->ioctl_expected.gemSetTiling = 1; mock->ioctl_expected.gemWait = 1; @@ -1171,7 +1175,10 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZero EXPECT_EQ(1u, this->mock->setTilingHandle); } -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { +HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { + if (!UnitTestHelper::tiledImagesSupported) { + GTEST_SKIP(); + } mock->ioctl_expected.gemCreate = 1; mock->ioctl_expected.gemSetTiling = 1; mock->ioctl_expected.gemWait = 1; @@ -1248,7 +1255,10 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedAn mock->ioctl_expected.contextDestroy = static_cast(device->getExecutionEnvironment()->commandStreamReceivers[0].size()); } -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { +HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { + if (!UnitTestHelper::tiledImagesSupported) { + GTEST_SKIP(); + } mock->ioctl_expected.gemCreate = 1; mock->ioctl_expected.gemSetTiling = 1; mock->ioctl_expected.gemUserptr = 1;