Fix parent MemObj dereference.

Don't dereference parent obj multiple
times (per gfxAllocation). Dereference it once

Related-To: NEO-6418

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2022-01-12 14:37:05 +00:00
committed by Compute-Runtime-Automation
parent eedc77e1ec
commit c282a78b14
4 changed files with 58 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -265,7 +265,6 @@ Image *Image::create(Context *context,
allocationInfo[rootDeviceIndex].zeroCopyAllowed = true;
hostPtr = parentBuffer->getHostPtr();
hostPtrToSet = const_cast<void *>(hostPtr);
parentBuffer->incRefInternal();
GmmTypesConverter::queryImgFromBufferParams(imgInfo, allocationInfo[rootDeviceIndex].memory);
UNRECOVERABLE_IF(imgInfo.offset != 0);
@@ -466,6 +465,10 @@ Image *Image::create(Context *context,
image->mapAllocations.addAllocation(allocationInfo[rootDeviceIndex].mapAllocation);
}
}
if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) {
parentBuffer->incRefInternal();
}
if (errcodeRet != CL_SUCCESS) {
image->release();
image = nullptr;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -103,13 +103,16 @@ MemObj::~MemObj() {
if (associatedMemObject->getGraphicsAllocation(graphicsAllocation->getRootDeviceIndex()) != graphicsAllocation) {
destroyGraphicsAllocation(graphicsAllocation, false);
}
associatedMemObject->decRefInternal();
}
}
if (associatedMemObject) {
associatedMemObject->decRefInternal();
}
if (!associatedMemObject) {
releaseAllocatedMapPtr();
}
}
destructorCallbacks.invoke(this);
context->decRefInternal();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -1731,3 +1731,25 @@ TEST(ImageTest, givenImageWhenFillRegionIsCalledThenProperRegionIsSet) {
EXPECT_EQ(Image3dDefaults::imageDesc.image_depth, region[2]);
}
}
TEST(ImageTest, givenMultiDeviceEnvironmentWhenReleaseImageFromBufferThenMainBufferProperlyDereferenced) {
MockDefaultContext context;
int32_t retVal;
auto *buffer = Buffer::create(&context, CL_MEM_READ_WRITE,
MemoryConstants::pageSize, nullptr, retVal);
auto imageDesc = Image2dDefaults::imageDesc;
cl_mem clBuffer = buffer;
imageDesc.mem_object = clBuffer;
auto image = Image2dHelper<>::create(&context, &imageDesc);
EXPECT_EQ(3u, buffer->getMultiGraphicsAllocation().getGraphicsAllocations().size());
EXPECT_EQ(3u, image->getMultiGraphicsAllocation().getGraphicsAllocations().size());
EXPECT_EQ(2, buffer->getRefInternalCount());
image->release();
EXPECT_EQ(1, buffer->getRefInternalCount());
buffer->release();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -219,4 +219,28 @@ TEST_F(SubBufferTest, givenBufferWithNoHostPtrWhenSubbufferGetsMapPtrThenExpectB
buffer->release();
}
TEST_F(SubBufferTest, givenSubBuffersWithMultipleDevicesWhenReleaseAllSubBuffersThenMainBufferProperlyDereferenced) {
MockDefaultContext ctx;
Buffer *buffer = Buffer::create(&ctx, CL_MEM_READ_WRITE,
MemoryConstants::pageSize, nullptr, retVal);
ASSERT_NE(nullptr, buffer);
ASSERT_EQ(CL_SUCCESS, retVal);
Buffer *subBuffers[8];
for (int i = 0; i < 8; i++) {
cl_buffer_region region = {static_cast<size_t>(i * 4), 4};
subBuffers[i] = buffer->createSubBuffer(CL_MEM_READ_WRITE, 0, &region, retVal);
EXPECT_EQ(3u, subBuffers[i]->getMultiGraphicsAllocation().getGraphicsAllocations().size());
}
EXPECT_EQ(9, buffer->getRefInternalCount());
for (int i = 0; i < 8; i++) {
subBuffers[i]->release();
}
EXPECT_EQ(1, buffer->getRefInternalCount());
buffer->release();
}
} // namespace ULT