mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Map/unmap enqueue fixes [2/n]: CPU operations on limited range
- Curently each non-zerocopy CPU operation on map/unmap make a full copy using hostPtr - This commit adds functionality to select specific range of copy - Multiple mapping with different size is not supported yet, so copy will be made on full range for now. This is for future usage. Change-Id: I7652e85482ba6fffb2474169447baf9b080dcd1e
This commit is contained in:
committed by
sys_ocldev
parent
ff44e9922d
commit
4f2a05ac88
@@ -731,6 +731,10 @@ cl_mem CL_API_CALL clCreateImage(cl_context context,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) && !hostPtr) {
|
||||
retVal = CL_INVALID_HOST_PTR;
|
||||
break;
|
||||
}
|
||||
image = Image::validateAndCreateImage(pContext, flags, imageFormat, imageDesc, hostPtr, retVal);
|
||||
|
||||
} while (false);
|
||||
|
||||
@@ -35,11 +35,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
|
||||
bool eventCompleted = false;
|
||||
ErrorCodeHelper err(&retVal, CL_SUCCESS);
|
||||
|
||||
auto memObj = transferProperties.memObj;
|
||||
auto image = castToObject<Image>(memObj);
|
||||
auto cmdType = transferProperties.cmdType;
|
||||
auto size = transferProperties.size;
|
||||
auto offset = transferProperties.offset;
|
||||
auto image = castToObject<Image>(transferProperties.memObj);
|
||||
|
||||
if (eventsRequest.outEvent) {
|
||||
eventBuilder.create<Event>(this, transferProperties.cmdType, Event::eventNotReady, Event::eventNotReady);
|
||||
@@ -84,8 +80,8 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
|
||||
eventBuilder.getEvent()->setSubmitTimeStamp();
|
||||
}
|
||||
//wait for the completness of previous commands
|
||||
if (cmdType != CL_COMMAND_UNMAP_MEM_OBJECT) {
|
||||
if (!memObj->isMemObjZeroCopy() || transferProperties.blocking) {
|
||||
if (transferProperties.cmdType != CL_COMMAND_UNMAP_MEM_OBJECT) {
|
||||
if (!transferProperties.memObj->isMemObjZeroCopy() || transferProperties.blocking) {
|
||||
finish(true);
|
||||
eventCompleted = true;
|
||||
}
|
||||
@@ -95,33 +91,37 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
|
||||
eventBuilder.getEvent()->setStartTimeStamp();
|
||||
}
|
||||
|
||||
switch (cmdType) {
|
||||
switch (transferProperties.cmdType) {
|
||||
case CL_COMMAND_MAP_BUFFER:
|
||||
if (!memObj->isMemObjZeroCopy()) {
|
||||
if (!transferProperties.memObj->isMemObjZeroCopy()) {
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_MAP_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(memObj));
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_MAP_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(transferProperties.memObj));
|
||||
}
|
||||
memObj->transferDataToHostPtr();
|
||||
transferProperties.memObj->transferDataToHostPtr({{transferProperties.memObj->getSize(), 0, 0}}, {{0, 0, 0}});
|
||||
eventCompleted = true;
|
||||
} else {
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_ENQUEUE_MAP_BUFFER_DOESNT_REQUIRE_COPY_DATA, static_cast<cl_mem>(memObj));
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_ENQUEUE_MAP_BUFFER_DOESNT_REQUIRE_COPY_DATA, static_cast<cl_mem>(transferProperties.memObj));
|
||||
}
|
||||
}
|
||||
memObj->incMapCount();
|
||||
transferProperties.memObj->incMapCount();
|
||||
break;
|
||||
case CL_COMMAND_MAP_IMAGE:
|
||||
if (!image->isMemObjZeroCopy()) {
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_MAP_IMAGE_REQUIRES_COPY_DATA, static_cast<cl_mem>(image));
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_MAP_IMAGE_REQUIRES_COPY_DATA, static_cast<cl_mem>(transferProperties.memObj));
|
||||
}
|
||||
image->transferDataToHostPtr();
|
||||
auto &imgDesc = image->getImageDesc();
|
||||
std::array<size_t, 3> copySize = {{getValidParam(imgDesc.image_width),
|
||||
getValidParam(imgDesc.image_height),
|
||||
getValidParam((std::max(imgDesc.image_depth, imgDesc.image_array_size)))}};
|
||||
image->transferDataToHostPtr(copySize, {{0, 0, 0}});
|
||||
GetInfoHelper::set(transferProperties.retSlicePitch, image->getHostPtrSlicePitch());
|
||||
GetInfoHelper::set(transferProperties.retRowPitch, image->getHostPtrRowPitch());
|
||||
eventCompleted = true;
|
||||
} else {
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_ENQUEUE_MAP_IMAGE_DOESNT_REQUIRE_COPY_DATA, static_cast<cl_mem>(image));
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_ENQUEUE_MAP_IMAGE_DOESNT_REQUIRE_COPY_DATA, static_cast<cl_mem>(transferProperties.memObj));
|
||||
}
|
||||
GetInfoHelper::set(transferProperties.retSlicePitch, image->getImageDesc().image_slice_pitch);
|
||||
GetInfoHelper::set(transferProperties.retRowPitch, image->getImageDesc().image_row_pitch);
|
||||
@@ -129,31 +129,38 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
|
||||
image->incMapCount();
|
||||
break;
|
||||
case CL_COMMAND_UNMAP_MEM_OBJECT:
|
||||
if (!memObj->isMemObjZeroCopy()) {
|
||||
if (!transferProperties.memObj->isMemObjZeroCopy()) {
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_UNMAP_MEM_OBJ_REQUIRES_COPY_DATA, transferProperties.ptr, static_cast<cl_mem>(memObj));
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_UNMAP_MEM_OBJ_REQUIRES_COPY_DATA, transferProperties.ptr, static_cast<cl_mem>(transferProperties.memObj));
|
||||
}
|
||||
memObj->transferDataFromHostPtrToMemoryStorage();
|
||||
std::array<size_t, 3> copySize = {{transferProperties.memObj->getSize(), 0, 0}};
|
||||
if (image) {
|
||||
auto imgDesc = image->getImageDesc();
|
||||
copySize = {{getValidParam(imgDesc.image_width),
|
||||
getValidParam(imgDesc.image_height),
|
||||
getValidParam((std::max(imgDesc.image_depth, imgDesc.image_array_size)))}};
|
||||
}
|
||||
transferProperties.memObj->transferDataFromHostPtr(copySize, {{0, 0, 0}});
|
||||
eventCompleted = true;
|
||||
} else {
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_ENQUEUE_UNMAP_MEM_OBJ_DOESNT_REQUIRE_COPY_DATA, transferProperties.ptr);
|
||||
}
|
||||
}
|
||||
memObj->decMapCount();
|
||||
transferProperties.memObj->decMapCount();
|
||||
break;
|
||||
case CL_COMMAND_READ_BUFFER:
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(memObj), transferProperties.ptr);
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(transferProperties.memObj), transferProperties.ptr);
|
||||
}
|
||||
memcpy_s(transferProperties.ptr, *size, ptrOffset(memObj->getCpuAddressForMemoryTransfer(), *offset), *size);
|
||||
memcpy_s(transferProperties.ptr, *transferProperties.size, ptrOffset(transferProperties.memObj->getCpuAddressForMemoryTransfer(), *transferProperties.offset), *transferProperties.size);
|
||||
eventCompleted = true;
|
||||
break;
|
||||
case CL_COMMAND_WRITE_BUFFER:
|
||||
if (context->isProvidingPerformanceHints()) {
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(memObj), transferProperties.ptr);
|
||||
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(transferProperties.memObj), transferProperties.ptr);
|
||||
}
|
||||
memcpy_s(ptrOffset(memObj->getCpuAddressForMemoryTransfer(), *offset), *size, transferProperties.ptr, *size);
|
||||
memcpy_s(ptrOffset(transferProperties.memObj->getCpuAddressForMemoryTransfer(), *transferProperties.offset), *transferProperties.size, transferProperties.ptr, *transferProperties.size);
|
||||
eventCompleted = true;
|
||||
break;
|
||||
case CL_COMMAND_MARKER:
|
||||
@@ -173,15 +180,14 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdType == CL_COMMAND_MAP_BUFFER) {
|
||||
return memObj->setAndReturnMappedPtr(*offset);
|
||||
if (transferProperties.cmdType == CL_COMMAND_MAP_BUFFER) {
|
||||
return transferProperties.memObj->setAndReturnMappedPtr(*transferProperties.offset);
|
||||
}
|
||||
|
||||
if (cmdType == CL_COMMAND_MAP_IMAGE) {
|
||||
size_t mapOffset =
|
||||
image->getSurfaceFormatInfo().ImageElementSizeInBytes * offset[0] +
|
||||
image->getImageDesc().image_row_pitch * offset[1] +
|
||||
image->getImageDesc().image_slice_pitch * offset[2];
|
||||
if (transferProperties.cmdType == CL_COMMAND_MAP_IMAGE) {
|
||||
size_t mapOffset = image->getSurfaceFormatInfo().ImageElementSizeInBytes * transferProperties.offset[0] +
|
||||
image->getImageDesc().image_row_pitch * transferProperties.offset[1] +
|
||||
image->getImageDesc().image_slice_pitch * transferProperties.offset[2];
|
||||
void *ptrToReturn = nullptr;
|
||||
if (image->isMemObjZeroCopy()) {
|
||||
ptrToReturn = ptrOffset(image->getCpuAddress(), mapOffset);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "runtime/command_queue/enqueue_common.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/device_queue/device_queue.h"
|
||||
#include "runtime/mem_obj/mem_obj.h"
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "runtime/memory_manager/surface.h"
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/helpers/string.h"
|
||||
@@ -87,12 +87,22 @@ CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
|
||||
|
||||
cmdQ.waitUntilComplete(completionStamp.taskCount, completionStamp.flushStamp);
|
||||
|
||||
if (memObj.isMemObjZeroCopy() == false) {
|
||||
if (!memObj.isMemObjZeroCopy()) {
|
||||
std::array<size_t, 3> copySize = {{memObj.getSize(), 0, 0}};
|
||||
|
||||
auto image = castToObject<Image>(&memObj);
|
||||
if (image) {
|
||||
auto &imgDesc = image->getImageDesc();
|
||||
copySize = {{getValidParam(imgDesc.image_width),
|
||||
getValidParam(imgDesc.image_height),
|
||||
getValidParam((std::max(imgDesc.image_depth, imgDesc.image_array_size)))}};
|
||||
}
|
||||
|
||||
if (op == MAP) {
|
||||
memObj.transferDataToHostPtr();
|
||||
memObj.transferDataToHostPtr(copySize, {{0, 0, 0}});
|
||||
} else {
|
||||
DEBUG_BREAK_IF(op != UNMAP);
|
||||
memObj.transferDataFromHostPtrToMemoryStorage();
|
||||
memObj.transferDataFromHostPtr(copySize, {{0, 0, 0}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,10 +291,19 @@ bool Buffer::bufferRectPitchSet(const size_t *bufferOrigin,
|
||||
return true;
|
||||
}
|
||||
|
||||
void *Buffer::transferDataToHostPtr() {
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, "hostPtr:", hostPtr, "size:", size, "memoryStorage:", memoryStorage);
|
||||
memcpy_s(hostPtr, size, memoryStorage, size);
|
||||
return hostPtr;
|
||||
void Buffer::transferData(void *dst, void *src, size_t copySize, size_t copyOffset) {
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, " hostPtr: ", hostPtr, ", size: ", copySize, ", offset: ", copyOffset, ", memoryStorage: ", memoryStorage);
|
||||
auto dstPtr = ptrOffset(dst, copyOffset);
|
||||
auto srcPtr = ptrOffset(src, copyOffset);
|
||||
memcpy_s(dstPtr, copySize, srcPtr, copySize);
|
||||
}
|
||||
|
||||
void Buffer::transferDataToHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) {
|
||||
transferData(hostPtr, memoryStorage, copySize[0], copyOffset[0]);
|
||||
}
|
||||
|
||||
void Buffer::transferDataFromHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) {
|
||||
transferData(memoryStorage, hostPtr, copySize[0], copyOffset[0]);
|
||||
}
|
||||
|
||||
size_t Buffer::calculateHostPtrSize(const size_t *origin, const size_t *region, size_t rowPitch, size_t slicePitch) {
|
||||
|
||||
@@ -100,7 +100,8 @@ class Buffer : public MemObj {
|
||||
|
||||
static size_t calculateHostPtrSize(const size_t *origin, const size_t *region, size_t rowPitch, size_t slicePitch);
|
||||
|
||||
void *transferDataToHostPtr() override;
|
||||
void transferDataToHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) override;
|
||||
void transferDataFromHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) override;
|
||||
|
||||
bool isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitList, void *ptr, size_t size);
|
||||
|
||||
@@ -125,6 +126,8 @@ class Buffer : public MemObj {
|
||||
bool &allocateMemory,
|
||||
bool ©MemoryFromHostPtr,
|
||||
MemoryManager *memMngr);
|
||||
|
||||
void transferData(void *dst, void *src, size_t copySize, size_t copyOffset);
|
||||
};
|
||||
|
||||
template <typename GfxFamily>
|
||||
|
||||
@@ -81,23 +81,25 @@ Image::Image(Context *context,
|
||||
setSurfaceOffsets(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void Image::transferData(void *src, size_t srcRowPitch, size_t srcSlicePitch, void *dest, size_t destRowPitch, size_t destSlicePitch, cl_image_desc *imageDesc, size_t pixelSize, size_t imageCount) {
|
||||
size_t imageHeight = getValidParam(imageDesc->image_height);
|
||||
size_t imageDepth = getValidParam(imageDesc->image_depth);
|
||||
size_t lineWidth = getValidParam(imageDesc->image_width) * pixelSize;
|
||||
void Image::transferData(void *dest, size_t destRowPitch, size_t destSlicePitch,
|
||||
void *src, size_t srcRowPitch, size_t srcSlicePitch,
|
||||
std::array<size_t, 3> ©Region, std::array<size_t, 3> ©Origin) {
|
||||
|
||||
size_t pixelSize = surfaceFormatInfo.ImageElementSizeInBytes;
|
||||
size_t lineWidth = copyRegion[0] * pixelSize;
|
||||
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, "memcpy dest:", dest, "sizeRowToCopy:", lineWidth, "src:", src);
|
||||
for (size_t count = 0; count < imageCount; count++) {
|
||||
for (size_t depth = 0; depth < imageDepth; ++depth) {
|
||||
auto currentImage = std::max(depth, count);
|
||||
auto srcPtr = ptrOffset(src, srcSlicePitch * currentImage);
|
||||
auto destPtr = ptrOffset(dest, destSlicePitch * currentImage);
|
||||
|
||||
for (size_t height = 0; height < imageHeight; ++height) {
|
||||
memcpy_s(destPtr, lineWidth, srcPtr, lineWidth);
|
||||
srcPtr = ptrOffset(srcPtr, srcRowPitch);
|
||||
destPtr = ptrOffset(destPtr, destRowPitch);
|
||||
}
|
||||
for (size_t slice = copyOrigin[2]; slice < (copyOrigin[2] + copyRegion[2]); slice++) {
|
||||
auto srcSliceOffset = ptrOffset(src, srcSlicePitch * slice);
|
||||
auto dstSliceOffset = ptrOffset(dest, destSlicePitch * slice);
|
||||
|
||||
for (size_t height = copyOrigin[1]; height < (copyOrigin[1] + copyRegion[1]); height++) {
|
||||
auto srcRowOffset = ptrOffset(srcSliceOffset, srcRowPitch * height);
|
||||
auto dstRowOffset = ptrOffset(dstSliceOffset, destRowPitch * height);
|
||||
|
||||
memcpy_s(ptrOffset(dstRowOffset, copyOrigin[0] * pixelSize), lineWidth,
|
||||
ptrOffset(srcRowOffset, copyOrigin[0] * pixelSize), lineWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,39 +214,35 @@ Image *Image::create(Context *context,
|
||||
} else {
|
||||
gmm = new Gmm();
|
||||
gmm->queryImageParams(imgInfo, hwInfo);
|
||||
|
||||
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
errcodeRet = CL_INVALID_HOST_PTR;
|
||||
if (hostPtr) {
|
||||
size_t pointerPassedSize = hostPtrRowPitch * imageHeight * imageDepth * imageCount;
|
||||
auto alignedSizePassedPointer = alignSizeWholePage(const_cast<void *>(hostPtr), pointerPassedSize);
|
||||
auto alignedSizeRequiredForAllocation = alignSizeWholePage(const_cast<void *>(hostPtr), imgInfo.size);
|
||||
size_t pointerPassedSize = hostPtrRowPitch * imageHeight * imageDepth * imageCount;
|
||||
auto alignedSizePassedPointer = alignSizeWholePage(const_cast<void *>(hostPtr), pointerPassedSize);
|
||||
auto alignedSizeRequiredForAllocation = alignSizeWholePage(const_cast<void *>(hostPtr), imgInfo.size);
|
||||
|
||||
// Passed pointer doesn't have enough memory, copy is needed
|
||||
copyRequired = (alignedSizeRequiredForAllocation > alignedSizePassedPointer) |
|
||||
(imgInfo.rowPitch != hostPtrRowPitch) |
|
||||
(imgInfo.slicePitch != hostPtrSlicePitch) |
|
||||
((reinterpret_cast<uintptr_t>(hostPtr) & (MemoryConstants::cacheLineSize - 1)) != 0) |
|
||||
isTilingAllowed;
|
||||
// Passed pointer doesn't have enough memory, copy is needed
|
||||
copyRequired = (alignedSizeRequiredForAllocation > alignedSizePassedPointer) |
|
||||
(imgInfo.rowPitch != hostPtrRowPitch) |
|
||||
(imgInfo.slicePitch != hostPtrSlicePitch) |
|
||||
((reinterpret_cast<uintptr_t>(hostPtr) & (MemoryConstants::cacheLineSize - 1)) != 0) |
|
||||
isTilingAllowed;
|
||||
|
||||
if (copyRequired && !context->isSharedContext) {
|
||||
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, gmm);
|
||||
zeroCopy = false;
|
||||
transferNeeded = true;
|
||||
} else {
|
||||
// To avoid having two pointers in a MemObj we cast off the const here
|
||||
// However, in USE_HOST_PTR cases we shouldn't be modifying the memory
|
||||
memory = memoryManager->allocateGraphicsMemory(imgInfo.size, hostPtr);
|
||||
memory->gmm = gmm;
|
||||
zeroCopy = true;
|
||||
}
|
||||
if (copyRequired && !context->isSharedContext) {
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, gmm);
|
||||
zeroCopy = false;
|
||||
transferNeeded = true;
|
||||
} else {
|
||||
memory = memoryManager->allocateGraphicsMemory(imgInfo.size, hostPtr);
|
||||
memory->gmm = gmm;
|
||||
zeroCopy = true;
|
||||
}
|
||||
} else {
|
||||
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, gmm);
|
||||
zeroCopy = true;
|
||||
}
|
||||
}
|
||||
transferNeeded |= !!(flags & CL_MEM_COPY_HOST_PTR);
|
||||
|
||||
switch (imageDesc->image_type) {
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
@@ -286,19 +284,6 @@ Image *Image::create(Context *context,
|
||||
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, "hostPtr:", hostPtr, "size:", memory->getUnderlyingBufferSize(), "memoryStorage:", memory->getUnderlyingBuffer(), "GPU address:", std::hex, memory->getGpuAddress());
|
||||
|
||||
if (!isTilingAllowed) {
|
||||
errcodeRet = CL_INVALID_VALUE;
|
||||
if (flags & CL_MEM_COPY_HOST_PTR || transferNeeded) {
|
||||
if (hostPtr) {
|
||||
Image::transferData((void *)hostPtr, hostPtrRowPitch, hostPtrSlicePitch,
|
||||
memory->getUnderlyingBuffer(), imgInfo.rowPitch, imgInfo.slicePitch,
|
||||
(cl_image_desc *)imageDesc, surfaceFormat->ImageElementSizeInBytes, imageCount);
|
||||
} else {
|
||||
memoryManager->freeGraphicsMemory(memory);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parentImage) {
|
||||
imageDescriptor.image_height = imageHeight;
|
||||
imageDescriptor.image_width = imageWidth;
|
||||
@@ -341,39 +326,33 @@ Image *Image::create(Context *context,
|
||||
}
|
||||
errcodeRet = CL_SUCCESS;
|
||||
|
||||
if (isTilingAllowed) {
|
||||
if (flags & CL_MEM_COPY_HOST_PTR || transferNeeded) {
|
||||
if (!hostPtr) {
|
||||
errcodeRet = CL_INVALID_VALUE;
|
||||
image->release();
|
||||
image = nullptr;
|
||||
memory = nullptr;
|
||||
break;
|
||||
}
|
||||
auto cmdQ = context->getSpecialQueue();
|
||||
if (transferNeeded) {
|
||||
std::array<size_t, 3> copyOrigin = {{0, 0, 0}};
|
||||
std::array<size_t, 3> copyRegion = {{imageWidth, imageHeight, std::max(imageDepth, imageCount)}};
|
||||
|
||||
size_t Origin[] = {0, 0, 0};
|
||||
size_t Region[] = {imageWidth, imageHeight, imageDepth};
|
||||
if (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY) {
|
||||
Region[2] = imageDesc->image_array_size;
|
||||
}
|
||||
if (isTilingAllowed) {
|
||||
auto cmdQ = context->getSpecialQueue();
|
||||
|
||||
if (IsNV12Image(&image->getImageFormat())) {
|
||||
errcodeRet = image->writeNV12Planes(hostPtr, hostPtrRowPitch);
|
||||
} else {
|
||||
errcodeRet = cmdQ->enqueueWriteImage(image, CL_TRUE, Origin, Region,
|
||||
errcodeRet = cmdQ->enqueueWriteImage(image, CL_TRUE, ©Origin[0], ©Region[0],
|
||||
hostPtrRowPitch, hostPtrSlicePitch,
|
||||
hostPtr, 0, nullptr, nullptr);
|
||||
}
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
image->release();
|
||||
image = nullptr;
|
||||
memory = nullptr;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
image->transferData(memory->getUnderlyingBuffer(), imgInfo.rowPitch, imgInfo.slicePitch,
|
||||
const_cast<void *>(hostPtr), hostPtrRowPitch, hostPtrSlicePitch,
|
||||
copyRegion, copyOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
image->release();
|
||||
image = nullptr;
|
||||
memory = nullptr;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return image;
|
||||
@@ -860,16 +839,16 @@ Image *Image::redescribe() {
|
||||
return image;
|
||||
}
|
||||
|
||||
void *Image::transferDataToHostPtr() {
|
||||
Image::transferData(graphicsAllocation->getUnderlyingBuffer(), imageDesc.image_row_pitch, imageDesc.image_slice_pitch,
|
||||
hostPtr, hostPtrRowPitch, hostPtrSlicePitch, &imageDesc, surfaceFormatInfo.ImageElementSizeInBytes, imageCount);
|
||||
return hostPtr;
|
||||
void Image::transferDataToHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) {
|
||||
transferData(hostPtr, hostPtrRowPitch, hostPtrSlicePitch,
|
||||
graphicsAllocation->getUnderlyingBuffer(), imageDesc.image_row_pitch, imageDesc.image_slice_pitch,
|
||||
copySize, copyOffset);
|
||||
}
|
||||
|
||||
void Image::transferDataFromHostPtrToMemoryStorage() {
|
||||
Image::transferData(hostPtr, hostPtrRowPitch, hostPtrSlicePitch,
|
||||
memoryStorage, imageDesc.image_row_pitch, imageDesc.image_slice_pitch,
|
||||
&imageDesc, surfaceFormatInfo.ImageElementSizeInBytes, imageCount);
|
||||
void Image::transferDataFromHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) {
|
||||
transferData(memoryStorage, imageDesc.image_row_pitch, imageDesc.image_slice_pitch,
|
||||
hostPtr, hostPtrRowPitch, hostPtrSlicePitch,
|
||||
copySize, copyOffset);
|
||||
}
|
||||
|
||||
cl_int Image::writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch) {
|
||||
|
||||
@@ -138,12 +138,13 @@ class Image : public MemObj {
|
||||
const cl_image_desc &getImageDesc() const;
|
||||
const cl_image_format &getImageFormat() const;
|
||||
const SurfaceFormatInfo &getSurfaceFormatInfo() const;
|
||||
void *transferDataToHostPtr() override;
|
||||
|
||||
void transferDataToHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) override;
|
||||
void transferDataFromHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) override;
|
||||
|
||||
Image *redescribe();
|
||||
Image *redescribeFillImage();
|
||||
ImageCreatFunc createFunction;
|
||||
void transferDataFromHostPtrToMemoryStorage() override;
|
||||
|
||||
uint32_t getQPitch() { return qPitch; }
|
||||
void setQPitch(uint32_t qPitch) { this->qPitch = qPitch; }
|
||||
@@ -151,7 +152,7 @@ class Image : public MemObj {
|
||||
void setHostPtrRowPitch(size_t pitch) { this->hostPtrRowPitch = pitch; }
|
||||
size_t getHostPtrSlicePitch() { return hostPtrSlicePitch; }
|
||||
void setHostPtrSlicePitch(size_t pitch) { this->hostPtrSlicePitch = pitch; }
|
||||
size_t getImageCount() { return imageCount; }
|
||||
size_t getImageCount() const { return imageCount; }
|
||||
void setImageCount(size_t imageCount) { this->imageCount = imageCount; }
|
||||
bool allowTiling() const override { return this->isTiledImage; }
|
||||
void setImageRowPitch(size_t rowPitch) { imageDesc.image_row_pitch = rowPitch; }
|
||||
@@ -176,7 +177,6 @@ class Image : public MemObj {
|
||||
cl_int writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch);
|
||||
void setMcsSurfaceInfo(McsSurfaceInfo &info) { mcsSurfaceInfo = info; }
|
||||
const McsSurfaceInfo &getMcsSurfaceInfo() { return mcsSurfaceInfo; }
|
||||
static void transferData(void *src, size_t srcRowPitch, size_t srcSlicePitch, void *dest, size_t destRowPitch, size_t destSlicePitch, cl_image_desc *imageDesc, size_t pixelSize, size_t imageCount);
|
||||
|
||||
const bool isTiledImage;
|
||||
|
||||
@@ -197,6 +197,10 @@ class Image : public MemObj {
|
||||
|
||||
void getOsSpecificImageInfo(const cl_mem_info ¶mName, size_t *srcParamSize, void **srcParam);
|
||||
|
||||
void transferData(void *dst, size_t dstRowPitch, size_t dstSlicePitch,
|
||||
void *src, size_t srcRowPitch, size_t srcSlicePitch,
|
||||
std::array<size_t, 3> ©Region, std::array<size_t, 3> ©Origin);
|
||||
|
||||
cl_image_format imageFormat;
|
||||
cl_image_desc imageDesc;
|
||||
SurfaceFormatInfo surfaceFormatInfo;
|
||||
|
||||
@@ -247,11 +247,6 @@ bool MemObj::isMemObjWithHostPtrSVM() const {
|
||||
return isHostPtrSVM;
|
||||
}
|
||||
|
||||
void MemObj::transferDataFromHostPtrToMemoryStorage() {
|
||||
size_t dataBytesToTransfer = std::min(size, hostPtrMinSize);
|
||||
memcpy_s(memoryStorage, size, hostPtr, dataBytesToTransfer);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MemObj::getGraphicsAllocation() {
|
||||
return graphicsAllocation;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
namespace OCLRT {
|
||||
class GraphicsAllocation;
|
||||
@@ -88,8 +89,9 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
void decMapCount();
|
||||
bool isMemObjZeroCopy() const;
|
||||
bool isMemObjWithHostPtrSVM() const;
|
||||
virtual void *transferDataToHostPtr() { return nullptr; };
|
||||
virtual void transferDataFromHostPtrToMemoryStorage();
|
||||
virtual void transferDataToHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) { UNRECOVERABLE_IF(true); };
|
||||
virtual void transferDataFromHostPtr(std::array<size_t, 3> copySize, std::array<size_t, 3> copyOffset) { UNRECOVERABLE_IF(true); };
|
||||
|
||||
GraphicsAllocation *getGraphicsAllocation();
|
||||
GraphicsAllocation *getMcsAllocation() { return mcsAllocation; }
|
||||
void setMcsAllocation(GraphicsAllocation *alloc) { mcsAllocation = alloc; }
|
||||
|
||||
Reference in New Issue
Block a user