mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
Map/unmap enqueue fixes [5/n]: Unify offset calculation
Change-Id: I53eafe89532d43c5cf5139ed3fac0a87619dc7a3
This commit is contained in:

committed by
sys_ocldev

parent
63732513bb
commit
b4f79e036f
@ -2482,6 +2482,9 @@ cl_int CL_API_CALL clEnqueueUnmapMemObject(cl_command_queue commandQueue,
|
||||
"event", event);
|
||||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
if (pMemObj->peekClMemObjType() == CL_MEM_OBJECT_PIPE) {
|
||||
return CL_INVALID_MEM_OBJECT;
|
||||
}
|
||||
if (!mappedPtr || mappedPtr != pMemObj->getMappedPtr()) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
@ -457,11 +457,16 @@ bool CommandQueue::sendPerfCountersConfig() {
|
||||
}
|
||||
|
||||
cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr, EventsRequest &eventsRequest) {
|
||||
auto image = castToObject<Image>(memObj);
|
||||
if (image) {
|
||||
auto retVal = enqueueWriteImage(image, CL_FALSE, &image->getMappedOffset()[0], &image->getMappedSize()[0],
|
||||
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), mappedPtr,
|
||||
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
|
||||
cl_int retVal;
|
||||
if (memObj->peekClMemObjType() == CL_MEM_OBJECT_BUFFER) {
|
||||
auto buffer = castToObject<Buffer>(memObj);
|
||||
retVal = enqueueWriteBuffer(buffer, CL_TRUE, buffer->getMappedOffset()[0], buffer->getMappedSize()[0], mappedPtr,
|
||||
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
|
||||
} else {
|
||||
auto image = castToObject<Image>(memObj);
|
||||
retVal = enqueueWriteImage(image, CL_FALSE, &image->getMappedOffset()[0], &image->getMappedSize()[0],
|
||||
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), mappedPtr,
|
||||
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
|
||||
bool mustCallFinish = true;
|
||||
if (!(image->getFlags() & CL_MEM_USE_HOST_PTR)) {
|
||||
mustCallFinish = true;
|
||||
@ -471,32 +476,21 @@ cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr,
|
||||
if (mustCallFinish) {
|
||||
finish(true);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
auto buffer = castToObject<Buffer>(memObj);
|
||||
if (buffer) {
|
||||
return enqueueWriteBuffer(buffer, CL_TRUE, buffer->getMappedOffset()[0], buffer->getMappedSize()[0], mappedPtr,
|
||||
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
|
||||
}
|
||||
|
||||
return CL_INVALID_MEM_OBJECT;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void *CommandQueue::enqueueReadMemObjForMap(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &errcodeRet) {
|
||||
void *baseMapPtr = transferProperties.memObj->getBasePtrForMap();
|
||||
void *returnPtr = nullptr;
|
||||
void *returnPtr = ptrOffset(transferProperties.memObj->getBasePtrForMap(),
|
||||
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offsetPtr));
|
||||
|
||||
auto buffer = castToObject<Buffer>(transferProperties.memObj);
|
||||
if (buffer) {
|
||||
returnPtr = ptrOffset(baseMapPtr, *transferProperties.offsetPtr);
|
||||
if (transferProperties.memObj->peekClMemObjType() == CL_MEM_OBJECT_BUFFER) {
|
||||
auto buffer = castToObject<Buffer>(transferProperties.memObj);
|
||||
errcodeRet = enqueueReadBuffer(buffer, transferProperties.blocking, *transferProperties.offsetPtr, *transferProperties.sizePtr, returnPtr,
|
||||
eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent);
|
||||
} else {
|
||||
auto image = castToObject<Image>(transferProperties.memObj);
|
||||
|
||||
returnPtr = ptrOffset(baseMapPtr, image->calculateOffset(image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), transferProperties.offsetPtr));
|
||||
|
||||
errcodeRet = enqueueReadImage(image, transferProperties.blocking, transferProperties.offsetPtr, transferProperties.sizePtr,
|
||||
image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(), returnPtr, eventsRequest.numEventsInWaitList,
|
||||
eventsRequest.eventWaitList, eventsRequest.outEvent);
|
||||
|
@ -151,14 +151,8 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
|
||||
}
|
||||
|
||||
if (transferProperties.cmdType == CL_COMMAND_MAP_BUFFER || transferProperties.cmdType == CL_COMMAND_MAP_IMAGE) {
|
||||
size_t mapPtrOffset;
|
||||
if (image) {
|
||||
mapPtrOffset = image->calculateOffset(image->getImageDesc().image_row_pitch, image->getImageDesc().image_slice_pitch,
|
||||
transferProperties.offsetPtr);
|
||||
} else {
|
||||
mapPtrOffset = *transferProperties.offsetPtr;
|
||||
}
|
||||
returnPtr = ptrOffset(transferProperties.memObj->getCpuAddressForMapping(), mapPtrOffset);
|
||||
returnPtr = ptrOffset(transferProperties.memObj->getCpuAddressForMapping(),
|
||||
transferProperties.memObj->calculateOffsetForMapping(transferProperties.offsetPtr));
|
||||
transferProperties.memObj->setMapInfo(returnPtr, transferProperties.sizePtr, transferProperties.offsetPtr);
|
||||
}
|
||||
|
||||
|
@ -1189,7 +1189,10 @@ bool Image::hasAlphaChannel(const cl_image_format *imageFormat) {
|
||||
(channelOrder == CL_ABGR);
|
||||
}
|
||||
|
||||
size_t Image::calculateOffset(size_t rowPitch, size_t slicePitch, size_t *origin) const {
|
||||
size_t Image::calculateOffsetForMapping(size_t *origin) const {
|
||||
size_t rowPitch = mappingOnCpuAllowed() ? imageDesc.image_row_pitch : getHostPtrRowPitch();
|
||||
size_t slicePitch = mappingOnCpuAllowed() ? imageDesc.image_slice_pitch : getHostPtrSlicePitch();
|
||||
|
||||
return getSurfaceFormatInfo().ImageElementSizeInBytes * origin[0] + rowPitch * origin[1] + slicePitch * origin[2];
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
@ -142,9 +142,9 @@ class Image : public MemObj {
|
||||
|
||||
uint32_t getQPitch() { return qPitch; }
|
||||
void setQPitch(uint32_t qPitch) { this->qPitch = qPitch; }
|
||||
size_t getHostPtrRowPitch() { return hostPtrRowPitch; }
|
||||
size_t getHostPtrRowPitch() const { return hostPtrRowPitch; }
|
||||
void setHostPtrRowPitch(size_t pitch) { this->hostPtrRowPitch = pitch; }
|
||||
size_t getHostPtrSlicePitch() { return hostPtrSlicePitch; }
|
||||
size_t getHostPtrSlicePitch() const { return hostPtrSlicePitch; }
|
||||
void setHostPtrSlicePitch(size_t pitch) { this->hostPtrSlicePitch = pitch; }
|
||||
size_t getImageCount() const { return imageCount; }
|
||||
void setImageCount(size_t imageCount) { this->imageCount = imageCount; }
|
||||
@ -171,7 +171,7 @@ class Image : public MemObj {
|
||||
cl_int writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch);
|
||||
void setMcsSurfaceInfo(McsSurfaceInfo &info) { mcsSurfaceInfo = info; }
|
||||
const McsSurfaceInfo &getMcsSurfaceInfo() { return mcsSurfaceInfo; }
|
||||
size_t calculateOffset(size_t rowPitch, size_t slicePitch, size_t *origin) const;
|
||||
size_t calculateOffsetForMapping(size_t *origin) const override;
|
||||
|
||||
const bool isTiledImage;
|
||||
|
||||
|
@ -124,6 +124,8 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
void destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy);
|
||||
bool checkIfMemoryTransferIsRequired(size_t offsetInMemObjest, size_t offsetInHostPtr, const void *ptr, cl_command_type cmdType);
|
||||
bool mappingOnCpuAllowed() const { return !allowTiling() && !peekSharingHandler(); }
|
||||
virtual size_t calculateOffsetForMapping(size_t *offset) const { return *offset; }
|
||||
cl_mem_object_type peekClMemObjType() const { return memObjectType; }
|
||||
|
||||
protected:
|
||||
void getOsSpecificMemObjectInfo(const cl_mem_info ¶mName, size_t *srcParamSize, void **srcParam);
|
||||
|
@ -493,8 +493,7 @@ HWTEST_F(EnqueueMapImageTest, givenImageWithouUsetHostPtrFlagWhenMappedOnCpuThen
|
||||
EXPECT_EQ(region[1], image->getMappedSize()[1]);
|
||||
EXPECT_EQ(region[2], image->getMappedSize()[2]);
|
||||
|
||||
auto offset = image->calculateOffset(image->getImageDesc().image_row_pitch, image->getImageDesc().image_slice_pitch, origin);
|
||||
auto expectedPtr = ptrOffset(image->getCpuAddressForMapping(), offset);
|
||||
auto expectedPtr = ptrOffset(image->getCpuAddressForMapping(), image->calculateOffsetForMapping(origin));
|
||||
|
||||
EXPECT_EQ(mappedPtr, expectedPtr);
|
||||
}
|
||||
@ -517,8 +516,7 @@ HWTEST_F(EnqueueMapImageTest, givenImageWithUseHostPtrFlagWhenMappedOnCpuThenSet
|
||||
EXPECT_EQ(region[1], image->getMappedSize()[1]);
|
||||
EXPECT_EQ(region[2], image->getMappedSize()[2]);
|
||||
|
||||
auto offset = image->calculateOffset(image->getImageDesc().image_row_pitch, image->getImageDesc().image_slice_pitch, origin);
|
||||
auto expectedPtr = ptrOffset(image->getCpuAddressForMapping(), offset);
|
||||
auto expectedPtr = ptrOffset(image->getCpuAddressForMapping(), image->calculateOffsetForMapping(origin));
|
||||
|
||||
EXPECT_EQ(mappedPtr, expectedPtr);
|
||||
}
|
||||
|
@ -992,16 +992,34 @@ TEST_F(ImageCompressionTests, givenNonTiledImageWhenCreatingAllocationThenDontPr
|
||||
EXPECT_FALSE(myMemoryManager->capturedImgInfo.preferRenderCompression);
|
||||
}
|
||||
|
||||
TEST(ImageTest, givenImageWhenAskedForPtrOffsetThenReturnCorrectValue) {
|
||||
TEST(ImageTest, givenImageWhenAskedForPtrOffsetForGpuMappingThenReturnCorrectValue) {
|
||||
MockContext ctx;
|
||||
std::unique_ptr<Image> image(ImageHelper<Image3dDefaults>::create(&ctx));
|
||||
EXPECT_FALSE(image->mappingOnCpuAllowed());
|
||||
|
||||
size_t origin[3] = {4, 5, 6};
|
||||
size_t rowPitch = 7;
|
||||
size_t slicePitch = 8;
|
||||
|
||||
auto retOffset = image->calculateOffset(rowPitch, slicePitch, origin);
|
||||
size_t expectedOffset = image->getSurfaceFormatInfo().ImageElementSizeInBytes * origin[0] + rowPitch * origin[1] + slicePitch * origin[2];
|
||||
auto retOffset = image->calculateOffsetForMapping(origin);
|
||||
size_t expectedOffset = image->getSurfaceFormatInfo().ImageElementSizeInBytes * origin[0] +
|
||||
image->getHostPtrRowPitch() * origin[1] + image->getHostPtrSlicePitch() * origin[2];
|
||||
|
||||
EXPECT_EQ(expectedOffset, retOffset);
|
||||
}
|
||||
|
||||
TEST(ImageTest, givenImageWhenAskedForPtrOffsetForCpuMappingThenReturnCorrectValue) {
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.ForceLinearImages.set(true);
|
||||
MockContext ctx;
|
||||
std::unique_ptr<Image> image(ImageHelper<Image3dDefaults>::create(&ctx));
|
||||
|
||||
EXPECT_TRUE(image->mappingOnCpuAllowed());
|
||||
|
||||
size_t origin[3] = {4, 5, 6};
|
||||
|
||||
auto retOffset = image->calculateOffsetForMapping(origin);
|
||||
size_t expectedOffset = image->getSurfaceFormatInfo().ImageElementSizeInBytes * origin[0] +
|
||||
image->getImageDesc().image_row_pitch * origin[1] +
|
||||
image->getImageDesc().image_slice_pitch * origin[2];
|
||||
|
||||
EXPECT_EQ(expectedOffset, retOffset);
|
||||
}
|
||||
|
@ -99,16 +99,12 @@ TEST_F(PipeTest, FailedAllocationInjection) {
|
||||
}
|
||||
|
||||
TEST_F(PipeTest, givenPipeWhenEnqueueWriteForUnmapIsCalledThenReturnError) {
|
||||
struct MyCommandQueue : public CommandQueue {
|
||||
using CommandQueue::enqueueWriteMemObjForUnmap;
|
||||
} myCmdQ;
|
||||
|
||||
int errCode = CL_SUCCESS;
|
||||
std::unique_ptr<Pipe> pipe(Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode));
|
||||
ASSERT_NE(nullptr, pipe);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
EventsRequest eventsRequest(0, nullptr, nullptr);
|
||||
errCode = myCmdQ.enqueueWriteMemObjForUnmap(pipe.get(), nullptr, eventsRequest);
|
||||
CommandQueue cmdQ;
|
||||
errCode = clEnqueueUnmapMemObject(&cmdQ, pipe.get(), nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_INVALID_MEM_OBJECT, errCode);
|
||||
}
|
||||
|
Reference in New Issue
Block a user