mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
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:
committed by
Compute-Runtime-Automation
parent
eedc77e1ec
commit
c282a78b14
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2021 Intel Corporation
|
* Copyright (C) 2018-2022 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@@ -265,7 +265,6 @@ Image *Image::create(Context *context,
|
|||||||
allocationInfo[rootDeviceIndex].zeroCopyAllowed = true;
|
allocationInfo[rootDeviceIndex].zeroCopyAllowed = true;
|
||||||
hostPtr = parentBuffer->getHostPtr();
|
hostPtr = parentBuffer->getHostPtr();
|
||||||
hostPtrToSet = const_cast<void *>(hostPtr);
|
hostPtrToSet = const_cast<void *>(hostPtr);
|
||||||
parentBuffer->incRefInternal();
|
|
||||||
GmmTypesConverter::queryImgFromBufferParams(imgInfo, allocationInfo[rootDeviceIndex].memory);
|
GmmTypesConverter::queryImgFromBufferParams(imgInfo, allocationInfo[rootDeviceIndex].memory);
|
||||||
|
|
||||||
UNRECOVERABLE_IF(imgInfo.offset != 0);
|
UNRECOVERABLE_IF(imgInfo.offset != 0);
|
||||||
@@ -466,6 +465,10 @@ Image *Image::create(Context *context,
|
|||||||
image->mapAllocations.addAllocation(allocationInfo[rootDeviceIndex].mapAllocation);
|
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) {
|
if (errcodeRet != CL_SUCCESS) {
|
||||||
image->release();
|
image->release();
|
||||||
image = nullptr;
|
image = nullptr;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2021 Intel Corporation
|
* Copyright (C) 2018-2022 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@@ -103,13 +103,16 @@ MemObj::~MemObj() {
|
|||||||
if (associatedMemObject->getGraphicsAllocation(graphicsAllocation->getRootDeviceIndex()) != graphicsAllocation) {
|
if (associatedMemObject->getGraphicsAllocation(graphicsAllocation->getRootDeviceIndex()) != graphicsAllocation) {
|
||||||
destroyGraphicsAllocation(graphicsAllocation, false);
|
destroyGraphicsAllocation(graphicsAllocation, false);
|
||||||
}
|
}
|
||||||
associatedMemObject->decRefInternal();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (associatedMemObject) {
|
||||||
|
associatedMemObject->decRefInternal();
|
||||||
|
}
|
||||||
if (!associatedMemObject) {
|
if (!associatedMemObject) {
|
||||||
releaseAllocatedMapPtr();
|
releaseAllocatedMapPtr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destructorCallbacks.invoke(this);
|
destructorCallbacks.invoke(this);
|
||||||
|
|
||||||
context->decRefInternal();
|
context->decRefInternal();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2021 Intel Corporation
|
* Copyright (C) 2018-2022 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@@ -1731,3 +1731,25 @@ TEST(ImageTest, givenImageWhenFillRegionIsCalledThenProperRegionIsSet) {
|
|||||||
EXPECT_EQ(Image3dDefaults::imageDesc.image_depth, region[2]);
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018-2021 Intel Corporation
|
* Copyright (C) 2018-2022 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
@@ -219,4 +219,28 @@ TEST_F(SubBufferTest, givenBufferWithNoHostPtrWhenSubbufferGetsMapPtrThenExpectB
|
|||||||
buffer->release();
|
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, ®ion, 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
|
} // namespace ULT
|
||||||
|
|||||||
Reference in New Issue
Block a user