Image / Buffer refactor.

- do not use redescribe flag for image/buffer from other image/buffer.
- use redescribe flag only when image is redescribed via redescribe interface
- remove image specific functions from mem object
- remove redundant fields
- add new implementation of isImageFromBuffer/isImageFromImage basing
on associated mem object.
- pass associated mem object to redescrbed images.
- remove redundant setters

Change-Id: I267637a48fbc2afdad9a9f5e5e9ccd6bd0c09972
This commit is contained in:
Mrozek, Michal 2018-12-19 20:15:32 +01:00
parent c17d0d11d0
commit b99cf6c3ff
10 changed files with 31 additions and 47 deletions

View File

@ -935,8 +935,8 @@ inline void Kernel::makeArgsResident(CommandStreamReceiver &commandStreamReceive
} else if (Kernel::isMemObj(kernelArguments[argIndex].type)) { } else if (Kernel::isMemObj(kernelArguments[argIndex].type)) {
auto clMem = const_cast<cl_mem>(static_cast<const _cl_mem *>(kernelArguments[argIndex].object)); auto clMem = const_cast<cl_mem>(static_cast<const _cl_mem *>(kernelArguments[argIndex].object));
auto memObj = castToObjectOrAbort<MemObj>(clMem); auto memObj = castToObjectOrAbort<MemObj>(clMem);
DEBUG_BREAK_IF(memObj == nullptr); auto image = castToObject<Image>(clMem);
if (memObj->isImageFromImage()) { if (image && image->isImageFromImage()) {
commandStreamReceiver.setSamplerCacheFlushRequired(CommandStreamReceiver::SamplerCacheFlushState::samplerCacheFlushBefore); commandStreamReceiver.setSamplerCacheFlushRequired(CommandStreamReceiver::SamplerCacheFlushState::samplerCacheFlushBefore);
} }
commandStreamReceiver.makeResident(*memObj->getGraphicsAllocation()); commandStreamReceiver.makeResident(*memObj->getGraphicsAllocation());

View File

@ -352,7 +352,7 @@ Buffer *Buffer::createSubBuffer(cl_mem_flags flags,
ptrOffset(this->memoryStorage, region->origin), ptrOffset(this->memoryStorage, region->origin),
this->hostPtr ? ptrOffset(this->hostPtr, region->origin) : nullptr, this->hostPtr ? ptrOffset(this->hostPtr, region->origin) : nullptr,
this->graphicsAllocation, this->graphicsAllocation,
this->isZeroCopy, this->isHostPtrSVM, true); this->isZeroCopy, this->isHostPtrSVM, false);
if (this->context->isProvidingPerformanceHints()) { if (this->context->isProvidingPerformanceHints()) {
this->context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, SUBBUFFER_SHARES_MEMORY, static_cast<cl_mem>(this)); this->context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, SUBBUFFER_SHARES_MEMORY, static_cast<cl_mem>(this));

View File

@ -114,7 +114,6 @@ Image *Image::create(Context *context,
MemoryManager *memoryManager = context->getMemoryManager(); MemoryManager *memoryManager = context->getMemoryManager();
Buffer *parentBuffer = castToObject<Buffer>(imageDesc->mem_object); Buffer *parentBuffer = castToObject<Buffer>(imageDesc->mem_object);
Image *parentImage = castToObject<Image>(imageDesc->mem_object); Image *parentImage = castToObject<Image>(imageDesc->mem_object);
bool isImageFromBuffer = false;
do { do {
size_t imageWidth = imageDesc->image_width; size_t imageWidth = imageDesc->image_width;
@ -181,10 +180,7 @@ Image *Image::create(Context *context,
bool zeroCopy = false; bool zeroCopy = false;
bool transferNeeded = false; bool transferNeeded = false;
bool imageRedescribed = false;
if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) { if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) {
isImageFromBuffer = true;
imageRedescribed = true;
memory = parentBuffer->getGraphicsAllocation(); memory = parentBuffer->getGraphicsAllocation();
// Image from buffer - we never allocate memory, we use what buffer provides // Image from buffer - we never allocate memory, we use what buffer provides
zeroCopy = true; zeroCopy = true;
@ -289,7 +285,7 @@ Image *Image::create(Context *context,
} }
image = createImageHw(context, flags, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat, image = createImageHw(context, flags, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat,
imageDescriptor, zeroCopy, memory, imageRedescribed, isTilingAllowed, 0, 0, surfaceFormat); imageDescriptor, zeroCopy, memory, false, isTilingAllowed, 0, 0, surfaceFormat);
if (imageDesc->image_type != CL_MEM_OBJECT_IMAGE1D_ARRAY && imageDesc->image_type != CL_MEM_OBJECT_IMAGE2D_ARRAY) { if (imageDesc->image_type != CL_MEM_OBJECT_IMAGE1D_ARRAY && imageDesc->image_type != CL_MEM_OBJECT_IMAGE2D_ARRAY) {
image->imageDesc.image_array_size = 0; image->imageDesc.image_array_size = 0;
@ -297,9 +293,7 @@ Image *Image::create(Context *context,
if ((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || ((imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D) && (imageDesc->mem_object != nullptr))) { if ((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || ((imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D) && (imageDesc->mem_object != nullptr))) {
image->associatedMemObject = castToObject<MemObj>(imageDesc->mem_object); image->associatedMemObject = castToObject<MemObj>(imageDesc->mem_object);
} }
if (parentImage) {
image->isImageFromImageCreated = true;
}
// Driver needs to store rowPitch passed by the app in order to synchronize the host_ptr later on map call // Driver needs to store rowPitch passed by the app in order to synchronize the host_ptr later on map call
image->setHostPtrRowPitch(imageDesc->image_row_pitch ? imageDesc->image_row_pitch : hostPtrRowPitch); image->setHostPtrRowPitch(imageDesc->image_row_pitch ? imageDesc->image_row_pitch : hostPtrRowPitch);
image->setHostPtrSlicePitch(hostPtrSlicePitch); image->setHostPtrSlicePitch(hostPtrSlicePitch);
@ -310,7 +304,6 @@ Image *Image::create(Context *context,
image->setQPitch(imgInfo.qPitch); image->setQPitch(imgInfo.qPitch);
image->setSurfaceOffsets(imgInfo.offset, imgInfo.xOffset, imgInfo.yOffset, imgInfo.yOffsetForUVPlane); image->setSurfaceOffsets(imgInfo.offset, imgInfo.xOffset, imgInfo.yOffset, imgInfo.yOffsetForUVPlane);
image->setMipCount(imgInfo.mipCount); image->setMipCount(imgInfo.mipCount);
image->setIsImageFromBuffer(isImageFromBuffer);
if (parentImage) { if (parentImage) {
image->setMediaPlaneType(static_cast<cl_uint>(imageDesc->image_depth)); image->setMediaPlaneType(static_cast<cl_uint>(imageDesc->image_depth));
image->setParentSharingHandler(parentImage->getSharingHandler()); image->setParentSharingHandler(parentImage->getSharingHandler());
@ -838,7 +831,7 @@ Image *Image::redescribeFillImage() {
&this->surfaceOffsets); &this->surfaceOffsets);
image->setQPitch(this->getQPitch()); image->setQPitch(this->getQPitch());
image->setCubeFaceIndex(this->getCubeFaceIndex()); image->setCubeFaceIndex(this->getCubeFaceIndex());
image->setIsImageFromBuffer(this->isImageFromBuffer()); image->associatedMemObject = this->associatedMemObject;
return image; return image;
} }
@ -886,7 +879,7 @@ Image *Image::redescribe() {
&this->surfaceOffsets); &this->surfaceOffsets);
image->setQPitch(this->getQPitch()); image->setQPitch(this->getQPitch());
image->setCubeFaceIndex(this->getCubeFaceIndex()); image->setCubeFaceIndex(this->getCubeFaceIndex());
image->setIsImageFromBuffer(this->isImageFromBuffer()); image->associatedMemObject = this->associatedMemObject;
return image; return image;
} }

View File

@ -177,6 +177,9 @@ class Image : public MemObj {
bool hasSameDescriptor(const cl_image_desc &imageDesc) const; bool hasSameDescriptor(const cl_image_desc &imageDesc) const;
bool hasValidParentImageFormat(const cl_image_format &imageFormat) const; bool hasValidParentImageFormat(const cl_image_format &imageFormat) const;
bool isImageFromBuffer() const { return castToObject<Buffer>(static_cast<cl_mem>(associatedMemObject)) ? true : false; }
bool isImageFromImage() const { return castToObject<Image>(static_cast<cl_mem>(associatedMemObject)) ? true : false; }
protected: protected:
Image(Context *context, Image(Context *context,
cl_mem_flags flags, cl_mem_flags flags,

View File

@ -55,11 +55,11 @@ MemObj::~MemObj() {
needWait = true; needWait = true;
} }
if (memoryManager) { if (memoryManager && !isObjectRedescribed) {
if (peekSharingHandler()) { if (peekSharingHandler()) {
peekSharingHandler()->releaseReusedGraphicsAllocation(); peekSharingHandler()->releaseReusedGraphicsAllocation();
} }
if (graphicsAllocation && !associatedMemObject && !isObjectRedescribed && !isHostPtrSVM && graphicsAllocation->peekReuseCount() == 0) { if (graphicsAllocation && !associatedMemObject && !isHostPtrSVM && graphicsAllocation->peekReuseCount() == 0) {
memoryManager->removeAllocationFromHostPtrManager(graphicsAllocation); memoryManager->removeAllocationFromHostPtrManager(graphicsAllocation);
bool doAsyncDestrucions = DebugManager.flags.EnableAsyncDestroyAllocations.get(); bool doAsyncDestrucions = DebugManager.flags.EnableAsyncDestroyAllocations.get();
if (!doAsyncDestrucions) { if (!doAsyncDestrucions) {

View File

@ -85,10 +85,6 @@ class MemObj : public BaseObject<_cl_mem> {
virtual bool allowTiling() const { return false; } virtual bool allowTiling() const { return false; }
bool isImageFromImage() const { return isImageFromImageCreated; }
void setIsImageFromBuffer(bool isImageFromBuffer) { isImageFromBufferCreated = isImageFromBuffer; }
bool isImageFromBuffer() const { return isImageFromBufferCreated; }
void *getCpuAddressForMapping(); void *getCpuAddressForMapping();
void *getCpuAddressForMemoryTransfer(); void *getCpuAddressForMemoryTransfer();
@ -130,8 +126,6 @@ class MemObj : public BaseObject<_cl_mem> {
bool isZeroCopy; bool isZeroCopy;
bool isHostPtrSVM; bool isHostPtrSVM;
bool isObjectRedescribed; bool isObjectRedescribed;
bool isImageFromImageCreated = false;
bool isImageFromBufferCreated = false;
MemoryManager *memoryManager = nullptr; MemoryManager *memoryManager = nullptr;
GraphicsAllocation *graphicsAllocation; GraphicsAllocation *graphicsAllocation;
GraphicsAllocation *mcsAllocation = nullptr; GraphicsAllocation *mcsAllocation = nullptr;

View File

@ -209,6 +209,7 @@ HWTEST_F(EnqueueMapImageTest, givenTiledImageWhenMapImageIsCalledThenStorageIsSe
region, nullptr, nullptr, 0, region, nullptr, nullptr, 0,
nullptr, nullptr, retVal); nullptr, nullptr, retVal);
EXPECT_TRUE(mockImage.ownershipTaken); EXPECT_TRUE(mockImage.ownershipTaken);
mockImage.releaseAllocatedMapPtr();
} }
TEST_F(EnqueueMapImageTest, checkPointer) { TEST_F(EnqueueMapImageTest, checkPointer) {

View File

@ -1,23 +1,8 @@
/* /*
* Copyright (c) 2017, Intel Corporation * Copyright (C) 2017-2018 Intel Corporation
* *
* Permission is hereby granted, free of charge, to any person obtaining a * SPDX-License-Identifier: MIT
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "hw_cmds.h" #include "hw_cmds.h"
@ -122,6 +107,8 @@ HWTEST_P(CreateImage1DType, validTypes) {
EXPECT_EQ(image->getCubeFaceIndex(), static_cast<uint32_t>(__GMM_NO_CUBE_MAP)); EXPECT_EQ(image->getCubeFaceIndex(), static_cast<uint32_t>(__GMM_NO_CUBE_MAP));
ASSERT_EQ(true, image->isMemObjZeroCopy()); ASSERT_EQ(true, image->isMemObjZeroCopy());
EXPECT_FALSE(image->isImageFromImage());
auto address = image->getCpuAddress(); auto address = image->getCpuAddress();
EXPECT_NE(nullptr, address); EXPECT_NE(nullptr, address);
@ -129,8 +116,11 @@ HWTEST_P(CreateImage1DType, validTypes) {
Buffer *inputBuffer = castToObject<Buffer>(imageDesc.buffer); Buffer *inputBuffer = castToObject<Buffer>(imageDesc.buffer);
EXPECT_NE(nullptr, inputBuffer->getCpuAddress()); EXPECT_NE(nullptr, inputBuffer->getCpuAddress());
EXPECT_EQ(inputBuffer->getCpuAddress(), image->getCpuAddress()); EXPECT_EQ(inputBuffer->getCpuAddress(), image->getCpuAddress());
EXPECT_TRUE(image->getIsObjectRedescribed()); EXPECT_FALSE(image->getIsObjectRedescribed());
EXPECT_GE(2, inputBuffer->getRefInternalCount()); EXPECT_GE(2, inputBuffer->getRefInternalCount());
EXPECT_TRUE(image->isImageFromBuffer());
} else {
EXPECT_FALSE(image->isImageFromBuffer());
} }
typedef typename FamilyType::RENDER_SURFACE_STATE SURFACE_STATE; typedef typename FamilyType::RENDER_SURFACE_STATE SURFACE_STATE;

View File

@ -241,6 +241,15 @@ TEST_F(Image2dFromBufferTest, InterceptBuffersHostPtr) {
delete imageFromBuffer; delete imageFromBuffer;
} }
TEST_F(Image2dFromBufferTest, givenImageFromBufferWhenItIsRedescribedThenItReturnsProperImageFromBufferValue) {
std::unique_ptr<Image> imageFromBuffer(createImage());
EXPECT_TRUE(imageFromBuffer->isImageFromBuffer());
std::unique_ptr<Image> redescribedImage(imageFromBuffer->redescribe());
EXPECT_TRUE(redescribedImage->isImageFromBuffer());
std::unique_ptr<Image> redescribedfillImage(imageFromBuffer->redescribeFillImage());
EXPECT_TRUE(redescribedfillImage->isImageFromBuffer());
}
TEST_F(Image2dFromBufferTest, givenMemoryManagerNotSupportingVirtualPaddingWhenImageIsCreatedThenPaddingIsNotApplied) { TEST_F(Image2dFromBufferTest, givenMemoryManagerNotSupportingVirtualPaddingWhenImageIsCreatedThenPaddingIsNotApplied) {
auto memoryManager = context.getMemoryManager(); auto memoryManager = context.getMemoryManager();
memoryManager->setVirtualPaddingSupport(false); memoryManager->setVirtualPaddingSupport(false);

View File

@ -573,17 +573,11 @@ TEST_P(CreateImageHostPtr, getAddress) {
} }
} }
TEST_P(CreateImageHostPtr, getSize) { TEST_P(CreateImageHostPtr, givenImageWhenItIsCreateItHasProperSizeAndGraphicsAllocation) {
image = createImage(retVal); image = createImage(retVal);
ASSERT_NE(nullptr, image); ASSERT_NE(nullptr, image);
EXPECT_NE(0u, image->getSize()); EXPECT_NE(0u, image->getSize());
}
TEST_P(CreateImageHostPtr, graphicsAllocationPresent) {
image = createImage(retVal);
ASSERT_NE(nullptr, image);
EXPECT_NE(nullptr, image->getGraphicsAllocation()); EXPECT_NE(nullptr, image->getGraphicsAllocation());
} }