Map/unmap enqueue fixes [6/n]: Support multiple map operations

- Dont make cpu/gpu writes on read-only unmap
- Read/Write on limited map range only
- Overlaps checks for non read-only maps
- Fixed cmd type on returned event

Change-Id: I98ca542e8d369d2426a87279f86cadb0bf3db299
This commit is contained in:
Dunajski, Bartosz
2018-02-17 22:26:28 +01:00
committed by sys_ocldev
parent 42baecd2d4
commit dd44a87d5f
37 changed files with 1685 additions and 264 deletions

View File

@@ -61,6 +61,7 @@ set(RUNTIME_SRCS_HELPERS_BASE
${CMAKE_CURRENT_SOURCE_DIR}/preamble.h
${CMAKE_CURRENT_SOURCE_DIR}/preamble.inl
${CMAKE_CURRENT_SOURCE_DIR}/properties_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/properties_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ptr_math.h
${CMAKE_CURRENT_SOURCE_DIR}/queue_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/sampler_helpers.h

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* 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 "runtime/helpers/properties_helper.h"
#include "runtime/mem_obj/mem_obj.h"
namespace OCLRT {
TransferProperties::TransferProperties(MemObj *memObj, cl_command_type cmdType, cl_map_flags mapFlags, bool blocking,
size_t *offsetPtr, size_t *sizePtr, void *ptr)
: memObj(memObj), cmdType(cmdType), mapFlags(mapFlags), blocking(blocking), ptr(ptr) {
// no size or offset passed for unmap operation
if (cmdType != CL_COMMAND_UNMAP_MEM_OBJECT) {
if (memObj->peekClMemObjType() == CL_MEM_OBJECT_BUFFER) {
size[0] = *sizePtr;
offset[0] = *offsetPtr;
} else {
size = {{sizePtr[0], sizePtr[1], sizePtr[2]}};
offset = {{offsetPtr[0], offsetPtr[1], offsetPtr[2]}};
}
}
}
} // namespace OCLRT

View File

@@ -45,27 +45,32 @@ struct EventsRequest {
cl_event *outEvent;
};
using MemObjSizeArray = std::array<size_t, 3>;
using MemObjOffsetArray = std::array<size_t, 3>;
struct TransferProperties {
TransferProperties() = delete;
TransferProperties(MemObj *memObj, cl_command_type cmdType, bool blocking, size_t *offsetPtr, size_t *sizePtr, void *ptr)
: memObj(memObj), cmdType(cmdType), blocking(blocking), offsetPtr(offsetPtr), sizePtr(sizePtr), ptr(ptr){};
TransferProperties(MemObj *memObj, cl_command_type cmdType, cl_map_flags mapFlags, bool blocking, size_t *offsetPtr, size_t *sizePtr,
void *ptr);
MemObj *memObj;
cl_command_type cmdType;
cl_map_flags mapFlags;
bool blocking;
size_t *offsetPtr;
size_t *sizePtr;
MemObjOffsetArray offset = {{0, 0, 0}};
MemObjSizeArray size = {{0, 0, 0}};
void *ptr;
};
struct MapInfo {
using SizeArray = std::array<size_t, 3>;
using OffsetArray = std::array<size_t, 3>;
MapInfo() = default;
MapInfo(void *ptr, size_t ptrLength, MemObjSizeArray size, MemObjOffsetArray offset) : ptr(ptr), ptrLength(ptrLength), size(size), offset(offset) {}
void *ptr = nullptr;
SizeArray size = {{0, 0, 0}};
OffsetArray offset = {{0, 0, 0}};
size_t ptrLength = 0;
MemObjSizeArray size = {{0, 0, 0}};
MemObjOffsetArray offset = {{0, 0, 0}};
bool readOnly = false;
};
} // namespace OCLRT

View File

@@ -27,7 +27,7 @@
#include "runtime/device/device.h"
#include "runtime/device_queue/device_queue.h"
#include "runtime/gtpin/gtpin_notify.h"
#include "runtime/mem_obj/image.h"
#include "runtime/mem_obj/mem_obj.h"
#include "runtime/memory_manager/surface.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/string.h"
@@ -46,8 +46,9 @@ KernelOperation::~KernelOperation() {
alignedFree(commandStream->getBase());
}
CommandMapUnmap::CommandMapUnmap(MapOperationType op, MemObj &memObj, CommandStreamReceiver &csr, CommandQueue &cmdQ)
: memObj(memObj), csr(csr), cmdQ(cmdQ), op(op) {
CommandMapUnmap::CommandMapUnmap(MapOperationType op, MemObj &memObj, MemObjSizeArray &copySize, MemObjOffsetArray &copyOffset, bool readOnly,
CommandStreamReceiver &csr, CommandQueue &cmdQ)
: memObj(memObj), copySize(copySize), copyOffset(copyOffset), readOnly(readOnly), csr(csr), cmdQ(cmdQ), op(op) {
memObj.incRefInternal();
}
@@ -91,21 +92,11 @@ CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
cmdQ.waitUntilComplete(completionStamp.taskCount, completionStamp.flushStamp);
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(copySize, {{0, 0, 0}});
} else {
memObj.transferDataToHostPtr(copySize, copyOffset);
} else if (!readOnly) {
DEBUG_BREAK_IF(op != UNMAP);
memObj.transferDataFromHostPtr(copySize, {{0, 0, 0}});
memObj.transferDataFromHostPtr(copySize, copyOffset);
}
}

View File

@@ -25,6 +25,7 @@
#include "runtime/indirect_heap/indirect_heap.h"
#include "runtime/utilities/iflist.h"
#include "runtime/helpers//completion_stamp.h"
#include "runtime/helpers/properties_helper.h"
#include <memory>
#include <vector>
@@ -59,12 +60,16 @@ class Command : public IFNode<Command> {
class CommandMapUnmap : public Command {
public:
CommandMapUnmap(MapOperationType op, MemObj &memObj, CommandStreamReceiver &csr, CommandQueue &cmdQ);
CommandMapUnmap(MapOperationType op, MemObj &memObj, MemObjSizeArray &copySize, MemObjOffsetArray &copyOffset, bool readOnly,
CommandStreamReceiver &csr, CommandQueue &cmdQ);
~CommandMapUnmap() override;
CompletionStamp &submit(uint32_t taskLevel, bool terminated) override;
private:
MemObj &memObj;
MemObjSizeArray copySize;
MemObjOffsetArray copyOffset;
bool readOnly;
CommandStreamReceiver &csr;
CommandQueue &cmdQ;
MapOperationType op;