mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Drain deferred deletions when cannot allocate memory for tiled image
Change-Id: I68b15269da4b5a58e02571a9c594c52b9a95edeb
This commit is contained in:
committed by
sys_ocldev
parent
45990a8181
commit
f12b5861fd
@@ -34,6 +34,10 @@
|
||||
#include "unit_tests/mock_gdi/mock_gdi.h"
|
||||
#include "unit_tests/mocks/mock_gmm_memory.h"
|
||||
#include "unit_tests//os_interface/windows/mock_gdi_interface.h"
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4005)
|
||||
#include <ntstatus.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
@@ -103,9 +107,15 @@ class WddmMock : public Wddm {
|
||||
freeGpuVirtualAddresResult.called++;
|
||||
return freeGpuVirtualAddresResult.success = Wddm::freeGpuVirtualAddres(gpuPtr, size);
|
||||
}
|
||||
bool createAllocation(WddmAllocation *alloc) override {
|
||||
NTSTATUS createAllocation(WddmAllocation *alloc) override {
|
||||
createAllocationResult.called++;
|
||||
return createAllocationResult.success = Wddm::createAllocation(alloc);
|
||||
if (callBaseDestroyAllocations) {
|
||||
createAllocationResult.success = Wddm::createAllocation(alloc) == STATUS_SUCCESS;
|
||||
} else {
|
||||
createAllocationResult.success = true;
|
||||
return createAllocationStatus;
|
||||
}
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
bool createAllocation64k(WddmAllocation *alloc) override {
|
||||
createAllocationResult.called++;
|
||||
@@ -246,6 +256,7 @@ class WddmMock : public Wddm {
|
||||
CallResult unlockResult;
|
||||
CallResult waitFromCpuResult;
|
||||
CallResult releaseGpuPtrResult;
|
||||
NTSTATUS createAllocationStatus;
|
||||
bool callBaseDestroyAllocations = true;
|
||||
bool failOpenSharedHandle = false;
|
||||
};
|
||||
|
||||
@@ -1475,6 +1475,62 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledT
|
||||
EXPECT_EQ(1u, wddm->releaseGpuPtrResult.called);
|
||||
}
|
||||
|
||||
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) {
|
||||
WddmMock *wddm = new WddmMock;
|
||||
wddm->callBaseDestroyAllocations = false;
|
||||
MockDeferredDeleter *deleter = new MockDeferredDeleter;
|
||||
MockWddmMemoryManager memoryManager(wddm);
|
||||
memoryManager.setDeferredDeleter(deleter);
|
||||
|
||||
cl_image_desc imgDesc;
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
ImageInfo imgInfo;
|
||||
imgInfo.imgDesc = &imgDesc;
|
||||
wddm->createAllocationStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
|
||||
EXPECT_EQ(0, deleter->drainCalled);
|
||||
EXPECT_EQ(0u, wddm->createAllocationResult.called);
|
||||
deleter->expectDrainBlockingValue(true);
|
||||
memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr);
|
||||
EXPECT_EQ(1, deleter->drainCalled);
|
||||
EXPECT_EQ(2u, wddm->createAllocationResult.called);
|
||||
}
|
||||
|
||||
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) {
|
||||
WddmMock *wddm = new WddmMock;
|
||||
wddm->callBaseDestroyAllocations = false;
|
||||
MockDeferredDeleter *deleter = new MockDeferredDeleter;
|
||||
MockWddmMemoryManager memoryManager(wddm);
|
||||
memoryManager.setDeferredDeleter(deleter);
|
||||
|
||||
cl_image_desc imgDesc;
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
ImageInfo imgInfo;
|
||||
imgInfo.imgDesc = &imgDesc;
|
||||
wddm->createAllocationStatus = STATUS_SUCCESS;
|
||||
EXPECT_EQ(0, deleter->drainCalled);
|
||||
EXPECT_EQ(0u, wddm->createAllocationResult.called);
|
||||
auto allocation = memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr);
|
||||
EXPECT_EQ(0, deleter->drainCalled);
|
||||
EXPECT_EQ(1u, wddm->createAllocationResult.called);
|
||||
memoryManager.freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) {
|
||||
WddmMock *wddm = new WddmMock;
|
||||
wddm->callBaseDestroyAllocations = false;
|
||||
MockWddmMemoryManager memoryManager(wddm);
|
||||
memoryManager.setDeferredDeleter(nullptr);
|
||||
|
||||
cl_image_desc imgDesc;
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
ImageInfo imgInfo;
|
||||
imgInfo.imgDesc = &imgDesc;
|
||||
wddm->createAllocationStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY;
|
||||
EXPECT_EQ(0u, wddm->createAllocationResult.called);
|
||||
memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr);
|
||||
EXPECT_EQ(1u, wddm->createAllocationResult.called);
|
||||
}
|
||||
|
||||
HWTEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) {
|
||||
WddmMock *wddm = new WddmMock;
|
||||
EXPECT_TRUE(wddm->init<FamilyType>());
|
||||
|
||||
@@ -105,12 +105,12 @@ HWTEST_F(WddmTest, allocation) {
|
||||
ASSERT_NE(gmm, nullptr);
|
||||
|
||||
allocation.gmm = gmm;
|
||||
bool error = wddm->createAllocation(&allocation);
|
||||
auto status = wddm->createAllocation(&allocation);
|
||||
|
||||
EXPECT_TRUE(error);
|
||||
EXPECT_EQ(STATUS_SUCCESS, status);
|
||||
EXPECT_TRUE(allocation.handle != 0);
|
||||
|
||||
error = mockWddm->destroyAllocation(&allocation);
|
||||
auto error = mockWddm->destroyAllocation(&allocation);
|
||||
EXPECT_TRUE(error);
|
||||
|
||||
releaseGmm(gmm);
|
||||
@@ -139,9 +139,9 @@ HWTEST_F(WddmTest, createAllocation32bit) {
|
||||
allocation.gmm = gmm;
|
||||
allocation.is32BitAllocation = true; // mark 32 bit allocation
|
||||
|
||||
bool success = wddm->createAllocation(&allocation);
|
||||
auto status = wddm->createAllocation(&allocation);
|
||||
|
||||
EXPECT_TRUE(success);
|
||||
EXPECT_EQ(STATUS_SUCCESS, status);
|
||||
EXPECT_TRUE(allocation.handle != 0);
|
||||
|
||||
EXPECT_EQ(1u, wddmMock->mapGpuVirtualAddressResult.called);
|
||||
@@ -149,7 +149,7 @@ HWTEST_F(WddmTest, createAllocation32bit) {
|
||||
EXPECT_LE(heap32baseAddress, allocation.gpuPtr);
|
||||
EXPECT_GT(heap32baseAddress + heap32Size, allocation.gpuPtr);
|
||||
|
||||
success = mockWddm->destroyAllocation(&allocation);
|
||||
auto success = mockWddm->destroyAllocation(&allocation);
|
||||
EXPECT_TRUE(success);
|
||||
|
||||
releaseGmm(gmm);
|
||||
@@ -200,12 +200,12 @@ HWTEST_F(WddmTest, mapAndFreeGpuVa) {
|
||||
ASSERT_NE(gmm, nullptr);
|
||||
|
||||
allocation.gmm = gmm;
|
||||
bool error = wddm->createAllocation(&allocation);
|
||||
auto status = wddm->createAllocation(&allocation);
|
||||
|
||||
EXPECT_TRUE(error);
|
||||
EXPECT_EQ(STATUS_SUCCESS, status);
|
||||
EXPECT_TRUE(allocation.handle != 0);
|
||||
|
||||
error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false);
|
||||
auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false);
|
||||
EXPECT_TRUE(error);
|
||||
EXPECT_TRUE(allocation.gpuPtr != 0);
|
||||
|
||||
@@ -231,7 +231,8 @@ HWTEST_F(WddmTest, givenNullAllocationWhenCreateThenAllocateAndMap) {
|
||||
ASSERT_NE(gmm, nullptr);
|
||||
|
||||
allocation.gmm = gmm;
|
||||
bool error = wddm->createAllocation(&allocation);
|
||||
auto status = wddm->createAllocation(&allocation);
|
||||
EXPECT_EQ(STATUS_SUCCESS, status);
|
||||
EXPECT_TRUE(allocation.gpuPtr != 0);
|
||||
EXPECT_TRUE(allocation.gpuPtr == Gmm::canonize(allocation.gpuPtr));
|
||||
|
||||
@@ -251,12 +252,12 @@ HWTEST_F(WddmTest, makeResidentNonResident) {
|
||||
ASSERT_NE(gmm, nullptr);
|
||||
|
||||
allocation.gmm = gmm;
|
||||
bool error = wddm->createAllocation(&allocation);
|
||||
auto status = wddm->createAllocation(&allocation);
|
||||
|
||||
EXPECT_TRUE(error);
|
||||
EXPECT_EQ(STATUS_SUCCESS, status);
|
||||
EXPECT_TRUE(allocation.handle != 0);
|
||||
|
||||
error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false);
|
||||
auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false);
|
||||
EXPECT_TRUE(error);
|
||||
EXPECT_TRUE(allocation.gpuPtr != 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user