Move storage of mapped operations to OpenCL context

Relate-To: NEO-6352
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban 2021-10-15 11:03:30 +00:00 committed by Compute-Runtime-Automation
parent ca0138da2e
commit 8c9dd3085b
13 changed files with 230 additions and 85 deletions

View File

@ -16,6 +16,7 @@
#include "opencl/source/gtpin/gtpin_notify.h"
#include "opencl/source/helpers/base_object.h"
#include "opencl/source/helpers/destructor_callbacks.h"
#include "opencl/source/mem_obj/map_operations_handler.h"
#include <list>
#include <map>
@ -93,6 +94,8 @@ class Context : public BaseObject<_cl_context> {
return svmAllocsManager;
}
auto &getMapOperationsStorage() { return mapOperationsStorage; }
const std::set<uint32_t> &getRootDeviceIndices() const;
uint32_t getMaxRootDeviceIndex() const;
@ -199,6 +202,7 @@ class Context : public BaseObject<_cl_context> {
void *userData = nullptr;
MemoryManager *memoryManager = nullptr;
SVMAllocsManager *svmAllocsManager = nullptr;
MapOperationsStorage mapOperationsStorage = {};
StackVec<CommandQueue *, 1> specialQueues;
DeviceQueue *defaultDeviceQueue = nullptr;
DriverDiagnostics *driverDiagnostics = nullptr;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -72,3 +72,21 @@ void MapOperationsHandler::remove(void *mappedPtr) {
}
}
}
MapOperationsHandler &NEO::MapOperationsStorage::getHandler(cl_mem memObj) {
return handlers[memObj];
}
MapOperationsHandler *NEO::MapOperationsStorage::getHandlerIfExists(cl_mem memObj) {
auto iterator = handlers.find(memObj);
if (iterator == handlers.end()) {
return nullptr;
}
return &iterator->second;
}
void NEO::MapOperationsStorage::removeHandler(cl_mem memObj) {
auto iterator = handlers.find(memObj);
handlers.erase(iterator);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -9,6 +9,7 @@
#include "opencl/source/helpers/properties_helper.h"
#include <mutex>
#include <unordered_map>
#include <vector>
namespace NEO {
@ -28,4 +29,16 @@ class MapOperationsHandler {
mutable std::mutex mtx;
};
class MapOperationsStorage {
public:
using HandlersMap = std::unordered_map<cl_mem, MapOperationsHandler>;
MapOperationsHandler &getHandler(cl_mem memObj);
MapOperationsHandler *getHandlerIfExists(cl_mem memObj);
void removeHandler(cl_mem memObj);
protected:
HandlersMap handlers{};
};
} // namespace NEO

View File

@ -62,9 +62,14 @@ MemObj::~MemObj() {
if (allocatedMapPtr != nullptr) {
needWait = true;
}
if (mapOperationsHandler.size() > 0 && !getCpuAddressForMapping()) {
needWait = true;
if (auto mapOperationsHandler = getMapOperationsHandlerIfExists(); mapOperationsHandler != nullptr) {
if (mapOperationsHandler->size() > 0 && !getCpuAddressForMapping()) {
needWait = true;
}
context->getMapOperationsStorage().removeHandler(this);
}
if (!destructorCallbacks.empty()) {
needWait = true;
}
@ -172,7 +177,7 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
case CL_MEM_MAP_COUNT:
srcParamSize = sizeof(mapCount);
mapCount = static_cast<cl_uint>(mapOperationsHandler.size());
mapCount = static_cast<cl_uint>(getMapOperationsHandler().size());
srcParam = &mapCount;
break;
@ -382,11 +387,26 @@ void *MemObj::getBasePtrForMap(uint32_t rootDeviceIndex) {
}
}
MapOperationsHandler &MemObj::getMapOperationsHandler() {
return context->getMapOperationsStorage().getHandler(this);
}
MapOperationsHandler *MemObj::getMapOperationsHandlerIfExists() {
return context->getMapOperationsStorage().getHandlerIfExists(this);
}
bool MemObj::addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags,
MemObjSizeArray &size, MemObjOffsetArray &offset,
uint32_t mipLevel) {
return mapOperationsHandler.add(ptr, ptrLength, mapFlags, size, offset,
mipLevel);
return getMapOperationsHandler().add(ptr, ptrLength, mapFlags, size, offset, mipLevel);
}
bool MemObj::findMappedPtr(void *mappedPtr, MapInfo &outMapInfo) {
return getMapOperationsHandler().find(mappedPtr, outMapInfo);
}
void MemObj::removeMappedPtr(void *mappedPtr) {
getMapOperationsHandler().remove(mappedPtr);
}
bool MemObj::isTiledAllocation() const {

View File

@ -86,9 +86,11 @@ class MemObj : public BaseObject<_cl_mem> {
bool getIsObjectRedescribed() const { return isObjectRedescribed; };
size_t getSize() const;
MapOperationsHandler &getMapOperationsHandler();
MapOperationsHandler *getMapOperationsHandlerIfExists();
bool addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset, uint32_t mipLevel);
bool findMappedPtr(void *mappedPtr, MapInfo &outMapInfo) { return mapOperationsHandler.find(mappedPtr, outMapInfo); }
void removeMappedPtr(void *mappedPtr) { mapOperationsHandler.remove(mappedPtr); }
bool findMappedPtr(void *mappedPtr, MapInfo &outMapInfo);
void removeMappedPtr(void *mappedPtr);
void *getBasePtrForMap(uint32_t rootDeviceIndex);
MOCKABLE_VIRTUAL void setAllocatedMapPtr(void *allocatedMapPtr);
@ -173,7 +175,6 @@ class MemObj : public BaseObject<_cl_mem> {
void *memoryStorage;
void *hostPtr;
void *allocatedMapPtr = nullptr;
MapOperationsHandler mapOperationsHandler;
size_t offset = 0;
MemObj *associatedMemObject = nullptr;
cl_uint refCount = 0;

View File

@ -89,7 +89,9 @@ TEST_F(clEnqueueUnmapMemObjTests, givenInvalidAddressWhenUnmappingOnGpuThenRetur
}
TEST_F(clEnqueueUnmapMemObjTests, GivenInvalidMemObjectTypeWhenUnmappingImageThenInvalidMemObjectIsReturned) {
MockBuffer buffer{};
MockContext context{};
MockGraphicsAllocation allocation{};
MockBuffer buffer{&context, allocation};
cl_int retVal = CL_SUCCESS;
auto mappedPtr = clEnqueueMapBuffer(pCommandQueue, &buffer, CL_TRUE, CL_MAP_READ, 0, 1, 0, nullptr, nullptr, &retVal);

View File

@ -59,7 +59,7 @@ struct EnqueueWaitlistTest : public EnqueueWaitlistFixture,
void SetUp() override {
EnqueueWaitlistFixture::SetUp();
buffer = BufferHelper<>::create();
bufferNonZeroCopy = new UnalignedBuffer;
bufferNonZeroCopy = new UnalignedBuffer(BufferDefaults::context, &bufferNonZeroCopyAlloc);
image = Image1dHelper<>::create(BufferDefaults::context);
imageNonZeroCopy = ImageHelper<ImageUseHostPtr<Image1dDefaults>>::create(BufferDefaults::context);
}
@ -75,6 +75,7 @@ struct EnqueueWaitlistTest : public EnqueueWaitlistFixture,
cl_int retVal = CL_SUCCESS;
cl_int error = CL_SUCCESS;
MockGraphicsAllocation bufferNonZeroCopyAlloc{nullptr, MemoryConstants::pageSize};
Buffer *buffer;
Buffer *bufferNonZeroCopy;
Image *image;

View File

@ -20,8 +20,6 @@ using namespace NEO;
struct MultipleMapBufferTest : public ClDeviceFixture, public ::testing::Test {
template <typename T>
struct MockBuffer : public BufferHw<T> {
using Buffer::mapOperationsHandler;
template <class... Params>
MockBuffer(Params... params) : BufferHw<T>(params...) {
this->createFunction = BufferHw<T>::create;
@ -135,13 +133,13 @@ HWTEST_F(MultipleMapBufferTest, givenValidReadAndWriteBufferWhenMappedOnGpuThenA
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE, offset, size, 0, nullptr, nullptr, nullptr);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->readBufferCalled, 1u);
EXPECT_EQ(cmdQ->enqueueSize, size);
EXPECT_EQ(cmdQ->enqueueOffset, offset);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->writeBufferCalled, 1u);
EXPECT_EQ(cmdQ->enqueueSize, size);
EXPECT_EQ(cmdQ->enqueueOffset, offset);
@ -157,11 +155,11 @@ HWTEST_F(MultipleMapBufferTest, givenReadOnlyMapWhenUnmappedOnGpuThenEnqueueMark
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_READ, offset, size, 0, nullptr, nullptr, nullptr);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->readBufferCalled, 1u);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->writeBufferCalled, 0u);
EXPECT_EQ(cmdQ->enqueueMarkerCalled, 1u);
}
@ -175,12 +173,12 @@ HWTEST_F(MultipleMapBufferTest, givenWriteInvalidateMapWhenMappedOnGpuThenCallEn
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE_INVALIDATE_REGION, offset, size, 0, nullptr, nullptr, nullptr);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->readBufferCalled, 0u);
EXPECT_EQ(cmdQ->enqueueMarkerCalled, 1u);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->writeBufferCalled, 1u);
EXPECT_EQ(cmdQ->enqueueMarkerCalled, 1u);
}
@ -190,7 +188,7 @@ HWTEST_F(MultipleMapBufferTest, givenNotMappedPtrWhenUnmapedOnGpuThenReturnError
auto cmdQ = createMockCmdQ<FamilyType>();
EXPECT_FALSE(buffer->mappingOnCpuAllowed());
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), buffer->getBasePtrForMap(cmdQ->getDevice().getRootDeviceIndex()), 0, nullptr, nullptr);
EXPECT_EQ(CL_INVALID_VALUE, retVal);
}
@ -206,7 +204,7 @@ HWTEST_F(MultipleMapBufferTest, givenErrorFromReadBufferWhenMappedOnGpuThenDontA
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_READ, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_EQ(nullptr, mappedPtr);
EXPECT_EQ(CL_OUT_OF_RESOURCES, retVal);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
}
HWTEST_F(MultipleMapBufferTest, givenErrorFromWriteBufferWhenUnmappedOnGpuThenDontRemoveMappedPtr) {
@ -219,12 +217,12 @@ HWTEST_F(MultipleMapBufferTest, givenErrorFromWriteBufferWhenUnmappedOnGpuThenDo
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(1u, cmdQ->writeBufferCalled);
EXPECT_EQ(CL_OUT_OF_RESOURCES, retVal);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
}
HWTEST_F(MultipleMapBufferTest, givenUnblockedQueueWhenMappedOnCpuThenAddMappedPtrAndRemoveOnUnmap) {
@ -236,13 +234,13 @@ HWTEST_F(MultipleMapBufferTest, givenUnblockedQueueWhenMappedOnCpuThenAddMappedP
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(1u, buffer->transferToHostPtrCalled);
EXPECT_EQ(buffer->copySize, size);
EXPECT_EQ(buffer->copyOffset, offset);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(1u, buffer->transferFromHostPtrCalled);
EXPECT_EQ(buffer->copySize, size);
EXPECT_EQ(buffer->copyOffset, offset);
@ -257,11 +255,11 @@ HWTEST_F(MultipleMapBufferTest, givenUnblockedQueueWhenReadOnlyMappedOnCpuThenDo
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_READ, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(1u, buffer->transferToHostPtrCalled);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(0u, buffer->transferFromHostPtrCalled);
}
@ -274,11 +272,11 @@ HWTEST_F(MultipleMapBufferTest, givenUnblockedQueueWhenWriteInvalidateMappedOnCp
size_t size = 3;
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE_INVALIDATE_REGION, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(0u, buffer->transferToHostPtrCalled);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(1u, buffer->transferFromHostPtrCalled);
}
@ -296,14 +294,14 @@ HWTEST_F(MultipleMapBufferTest, givenBlockedQueueWhenMappedOnCpuThenAddMappedPtr
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE, offset, size, 1, &clMapEvent, nullptr, &retVal);
mapEvent.setStatus(CL_COMPLETE);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(buffer->copySize, size);
EXPECT_EQ(buffer->copyOffset, offset);
EXPECT_EQ(1u, buffer->transferToHostPtrCalled);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 1, &clUnmapEvent, nullptr);
unmapEvent.setStatus(CL_COMPLETE);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(buffer->copySize, size);
EXPECT_EQ(buffer->copyOffset, offset);
EXPECT_EQ(1u, buffer->transferFromHostPtrCalled);
@ -324,11 +322,11 @@ HWTEST_F(MultipleMapBufferTest, givenBlockedQueueWhenMappedReadOnlyOnCpuThenDont
mapEvent.setStatus(CL_COMPLETE);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, buffer->transferToHostPtrCalled);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
retVal = clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtr, 1, &clUnmapEvent, nullptr);
unmapEvent.setStatus(CL_COMPLETE);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(0u, buffer->transferFromHostPtrCalled);
}
@ -355,26 +353,26 @@ HWTEST_F(MultipleMapBufferTest, givenMultimpleMapsWhenUnmappingThenRemoveCorrect
mappedPtrs[i].ptr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE,
mappedPtrs[i].offset[0], mappedPtrs[i].size[0], 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtrs[i].ptr);
EXPECT_EQ(i + 1, buffer->mapOperationsHandler.size());
EXPECT_EQ(i + 1, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->enqueueSize, mappedPtrs[i].size[0]);
EXPECT_EQ(cmdQ->enqueueOffset, mappedPtrs[i].offset[0]);
}
// reordered unmap
clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtrs[1].ptr, 0, nullptr, nullptr);
EXPECT_EQ(2u, buffer->mapOperationsHandler.size());
EXPECT_EQ(2u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->unmapPtr, mappedPtrs[1].ptr);
EXPECT_EQ(cmdQ->enqueueSize, mappedPtrs[1].size[0]);
EXPECT_EQ(cmdQ->enqueueOffset, mappedPtrs[1].offset[0]);
clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtrs[2].ptr, 0, nullptr, nullptr);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->unmapPtr, mappedPtrs[2].ptr);
EXPECT_EQ(cmdQ->enqueueSize, mappedPtrs[2].size[0]);
EXPECT_EQ(cmdQ->enqueueOffset, mappedPtrs[2].offset[0]);
clEnqueueUnmapMemObject(cmdQ.get(), buffer.get(), mappedPtrs[0].ptr, 0, nullptr, nullptr);
EXPECT_EQ(0u, buffer->mapOperationsHandler.size());
EXPECT_EQ(0u, buffer->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->unmapPtr, mappedPtrs[0].ptr);
EXPECT_EQ(cmdQ->enqueueSize, mappedPtrs[0].size[0]);
EXPECT_EQ(cmdQ->enqueueOffset, mappedPtrs[0].offset[0]);
@ -390,13 +388,13 @@ HWTEST_F(MultipleMapBufferTest, givenOverlapingPtrWhenMappingOnGpuForWriteThenRe
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_READ, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
offset++;
void *mappedPtr2 = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_EQ(nullptr, mappedPtr2);
EXPECT_EQ(CL_INVALID_OPERATION, retVal);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
}
HWTEST_F(MultipleMapBufferTest, givenOverlapingPtrWhenMappingOnCpuForWriteThenReturnError) {
@ -409,11 +407,11 @@ HWTEST_F(MultipleMapBufferTest, givenOverlapingPtrWhenMappingOnCpuForWriteThenRe
void *mappedPtr = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_READ, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
offset++;
void *mappedPtr2 = clEnqueueMapBuffer(cmdQ.get(), buffer.get(), CL_FALSE, CL_MAP_WRITE, offset, size, 0, nullptr, nullptr, &retVal);
EXPECT_EQ(nullptr, mappedPtr2);
EXPECT_EQ(CL_INVALID_OPERATION, retVal);
EXPECT_EQ(1u, buffer->mapOperationsHandler.size());
EXPECT_EQ(1u, buffer->getMapOperationsHandler().size());
}

View File

@ -21,7 +21,6 @@ extern ImageFactoryFuncs imageFactory[IGFX_MAX_CORE];
struct MultipleMapImageTest : public ClDeviceFixture, public ::testing::Test {
template <typename T>
struct MockImage : public ImageHw<T> {
using Image::mapOperationsHandler;
using ImageHw<T>::isZeroCopy;
using ImageHw<T>::ImageHw;
@ -156,13 +155,13 @@ HWTEST_F(MultipleMapImageTest, givenValidReadAndWriteImageWhenMappedOnGpuThenAdd
MemObjSizeArray region = {{3, 4, 1}};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->enqueueRegion, region);
EXPECT_EQ(cmdQ->enqueueOrigin, origin);
EXPECT_EQ(cmdQ->readImageCalled, 1u);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->enqueueRegion, region);
EXPECT_EQ(cmdQ->enqueueOrigin, origin);
EXPECT_EQ(cmdQ->unmapPtr, mappedPtr);
@ -181,13 +180,13 @@ HWTEST_F(MultipleMapImageTest, givenReadOnlyMapWhenUnmappedOnGpuThenEnqueueMarke
MemObjSizeArray region = {{3, 4, 1}};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_READ, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->enqueueRegion, region);
EXPECT_EQ(cmdQ->enqueueOrigin, origin);
EXPECT_EQ(cmdQ->readImageCalled, 1u);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->writeImageCalled, 0u);
EXPECT_EQ(cmdQ->enqueueMarkerCalled, 1u);
}
@ -204,12 +203,12 @@ HWTEST_F(MultipleMapImageTest, givenWriteInvalidateMapWhenMappedOnGpuThenEnqueue
MemObjSizeArray region = {{3, 4, 1}};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE_INVALIDATE_REGION, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->readImageCalled, 0u);
EXPECT_EQ(cmdQ->enqueueMarkerCalled, 1u);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->writeImageCalled, 1u);
EXPECT_EQ(cmdQ->enqueueMarkerCalled, 1u);
EXPECT_EQ(cmdQ->enqueueRegion, region);
@ -221,7 +220,7 @@ HWTEST_F(MultipleMapImageTest, givenNotMappedPtrWhenUnmapedThenReturnError) {
auto cmdQ = createMockCmdQ<FamilyType>();
EXPECT_EQ(!UnitTestHelper<FamilyType>::tiledImagesSupported, image->mappingOnCpuAllowed());
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), image->getBasePtrForMap(cmdQ->getDevice().getRootDeviceIndex()), 0, nullptr, nullptr);
EXPECT_EQ(CL_INVALID_VALUE, retVal);
}
@ -240,7 +239,7 @@ HWTEST_F(MultipleMapImageTest, givenErrorFromReadImageWhenMappedOnGpuThenDontAdd
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_READ, origin, region, nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_EQ(nullptr, mappedPtr);
EXPECT_EQ(CL_OUT_OF_RESOURCES, retVal);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
}
HWTEST_F(MultipleMapImageTest, givenErrorFromWriteImageWhenUnmappedOnGpuThenDontRemoveMappedPtr) {
@ -256,12 +255,12 @@ HWTEST_F(MultipleMapImageTest, givenErrorFromWriteImageWhenUnmappedOnGpuThenDont
size_t region[] = {2, 1, 1};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, origin, region, nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(CL_OUT_OF_RESOURCES, retVal);
EXPECT_EQ(cmdQ->writeImageCalled, 1u);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
}
HWTEST_F(MultipleMapImageTest, givenUnblockedQueueWhenMappedOnCpuThenAddMappedPtrAndRemoveOnUnmap) {
@ -274,13 +273,13 @@ HWTEST_F(MultipleMapImageTest, givenUnblockedQueueWhenMappedOnCpuThenAddMappedPt
MemObjSizeArray region = {{3, 1, 1}};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(1u, image->transferToHostPtrCalled);
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(1u, image->transferFromHostPtrCalled);
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
@ -297,13 +296,13 @@ HWTEST_F(MultipleMapImageTest, givenUnblockedQueueWhenReadOnlyUnmappedOnCpuThenD
MemObjSizeArray region = {{3, 1, 1}};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_READ, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(1u, image->transferToHostPtrCalled);
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(0u, image->transferFromHostPtrCalled);
}
@ -318,11 +317,11 @@ HWTEST_F(MultipleMapImageTest, givenUnblockedQueueWhenWriteInvalidateMappedOnCpu
MemObjSizeArray region = {{3, 1, 1}};
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE_INVALIDATE_REGION, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(0u, image->transferToHostPtrCalled);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(1u, image->transferFromHostPtrCalled);
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
@ -345,13 +344,13 @@ HWTEST_F(MultipleMapImageTest, givenBlockedQueueWhenMappedOnCpuThenAddMappedPtrA
mapEvent.setStatus(CL_COMPLETE);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->transferToHostPtrCalled);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 1, &clUnmapEvent, nullptr);
unmapEvent.setStatus(CL_COMPLETE);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(1u, image->transferFromHostPtrCalled);
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
@ -374,13 +373,13 @@ HWTEST_F(MultipleMapImageTest, givenBlockedQueueWhenMappedReadOnlyOnCpuThenDontM
mapEvent.setStatus(CL_COMPLETE);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(1u, image->transferToHostPtrCalled);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(image->copyRegion, region);
EXPECT_EQ(image->copyOrigin, origin);
retVal = clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtr, 1, &clUnmapEvent, nullptr);
unmapEvent.setStatus(CL_COMPLETE);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(0u, image->transferFromHostPtrCalled);
}
@ -408,26 +407,26 @@ HWTEST_F(MultipleMapImageTest, givenMultimpleMapsWhenUnmappingThenRemoveCorrectP
mappedPtrs[i].ptr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &mappedPtrs[i].offset[0], &mappedPtrs[i].size[0],
nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtrs[i].ptr);
EXPECT_EQ(i + 1, image->mapOperationsHandler.size());
EXPECT_EQ(i + 1, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->enqueueRegion, mappedPtrs[i].size);
EXPECT_EQ(cmdQ->enqueueOrigin, mappedPtrs[i].offset);
}
// reordered unmap
clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtrs[1].ptr, 0, nullptr, nullptr);
EXPECT_EQ(2u, image->mapOperationsHandler.size());
EXPECT_EQ(2u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->unmapPtr, mappedPtrs[1].ptr);
EXPECT_EQ(cmdQ->enqueueRegion, mappedPtrs[1].size);
EXPECT_EQ(cmdQ->enqueueOrigin, mappedPtrs[1].offset);
clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtrs[2].ptr, 0, nullptr, nullptr);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->unmapPtr, mappedPtrs[2].ptr);
EXPECT_EQ(cmdQ->enqueueRegion, mappedPtrs[2].size);
EXPECT_EQ(cmdQ->enqueueOrigin, mappedPtrs[2].offset);
clEnqueueUnmapMemObject(cmdQ.get(), image.get(), mappedPtrs[0].ptr, 0, nullptr, nullptr);
EXPECT_EQ(0u, image->mapOperationsHandler.size());
EXPECT_EQ(0u, image->getMapOperationsHandler().size());
EXPECT_EQ(cmdQ->unmapPtr, mappedPtrs[0].ptr);
EXPECT_EQ(cmdQ->enqueueRegion, mappedPtrs[0].size);
EXPECT_EQ(cmdQ->enqueueOrigin, mappedPtrs[0].offset);
@ -443,13 +442,13 @@ HWTEST_F(MultipleMapImageTest, givenOverlapingPtrWhenMappingForWriteThenReturnEr
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_READ, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
origin[0]++;
void *mappedPtr2 = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_EQ(nullptr, mappedPtr2);
EXPECT_EQ(CL_INVALID_OPERATION, retVal);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
}
HWTEST_F(MultipleMapImageTest, givenOverlapingPtrWhenMappingOnCpuForWriteThenReturnError) {
@ -462,12 +461,12 @@ HWTEST_F(MultipleMapImageTest, givenOverlapingPtrWhenMappingOnCpuForWriteThenRet
void *mappedPtr = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_READ, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_NE(nullptr, mappedPtr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
origin[0]++;
void *mappedPtr2 = clEnqueueMapImage(cmdQ.get(), image.get(), CL_TRUE, CL_MAP_WRITE, &origin[0], &region[0], nullptr, nullptr, 0, nullptr, nullptr, &retVal);
EXPECT_EQ(nullptr, mappedPtr2);
EXPECT_EQ(CL_INVALID_OPERATION, retVal);
EXPECT_EQ(1u, image->mapOperationsHandler.size());
EXPECT_EQ(1u, image->getMapOperationsHandler().size());
}
} // namespace NEO

View File

@ -283,7 +283,9 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, GivenNonBlockingMapEnqueueWhenFini
size_t tempBuffer[] = {0, 1, 2};
cl_int retVal;
AlignedBuffer mockBuffer;
auto cpuAllocation = std::make_unique<std::byte[]>(MemoryConstants::pageSize);
MockGraphicsAllocation allocation{cpuAllocation.get(), MemoryConstants::pageSize};
AlignedBuffer mockBuffer{&ctx, &allocation};
uint32_t taskCount = 0;
taskLevel = taskCount;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -8,6 +8,7 @@
#include "shared/source/helpers/ptr_math.h"
#include "opencl/source/mem_obj/map_operations_handler.h"
#include "opencl/test/unit_test/mocks/mock_buffer.h"
#include "test.h"
#include <tuple>
@ -160,3 +161,56 @@ TEST_P(MapOperationsHandlerOverlapTests, givenAlreadyMappedPtrWhenAskingForOverl
INSTANTIATE_TEST_CASE_P(MapOperationsHandlerOverlapTests,
MapOperationsHandlerOverlapTests,
::testing::ValuesIn(overlappingCombinations));
struct MapOperationsStorageWhitebox : MapOperationsStorage {
using MapOperationsStorage::handlers;
};
TEST(MapOperationsStorageTest, givenMapOperationsStorageWhenGetHandlerIsUsedThenCreateHandler) {
MockBuffer buffer1{};
MockBuffer buffer2{};
MapOperationsStorageWhitebox storage{};
EXPECT_EQ(0u, storage.handlers.size());
storage.getHandler(&buffer1);
EXPECT_EQ(1u, storage.handlers.size());
storage.getHandler(&buffer2);
EXPECT_EQ(2u, storage.handlers.size());
storage.getHandler(&buffer1);
EXPECT_EQ(2u, storage.handlers.size());
}
TEST(MapOperationsStorageTest, givenMapOperationsStorageWhenGetHandlerIfExistsIsUsedThenDoNotCreateHandler) {
MockBuffer buffer1{};
MockBuffer buffer2{};
MapOperationsStorageWhitebox storage{};
EXPECT_EQ(0u, storage.handlers.size());
EXPECT_EQ(nullptr, storage.getHandlerIfExists(&buffer1));
EXPECT_EQ(nullptr, storage.getHandlerIfExists(&buffer2));
storage.getHandler(&buffer1);
EXPECT_EQ(1u, storage.handlers.size());
EXPECT_NE(nullptr, storage.getHandlerIfExists(&buffer1));
EXPECT_EQ(nullptr, storage.getHandlerIfExists(&buffer2));
storage.getHandler(&buffer2);
EXPECT_EQ(2u, storage.handlers.size());
EXPECT_NE(nullptr, storage.getHandlerIfExists(&buffer1));
EXPECT_NE(nullptr, storage.getHandlerIfExists(&buffer2));
EXPECT_NE(storage.getHandlerIfExists(&buffer1), storage.getHandlerIfExists(&buffer2));
}
TEST(MapOperationsStorageTest, givenMapOperationsStorageWhenRemoveHandlerIsUsedThenRemoveHandler) {
MockBuffer buffer{};
MapOperationsStorageWhitebox storage{};
storage.getHandler(&buffer);
ASSERT_EQ(1u, storage.handlers.size());
storage.removeHandler(&buffer);
EXPECT_EQ(0u, storage.handlers.size());
}

View File

@ -35,16 +35,21 @@ class MockBuffer : public MockBufferStorage, public Buffer {
using Buffer::magic;
using Buffer::offset;
using Buffer::size;
using MemObj::context;
using MemObj::isZeroCopy;
using MemObj::memObjectType;
using MockBufferStorage::device;
MockBuffer(GraphicsAllocation &alloc)
MockBuffer(GraphicsAllocation &alloc) : MockBuffer(nullptr, alloc) {}
MockBuffer(Context *context, GraphicsAllocation &alloc)
: MockBufferStorage(), Buffer(
nullptr, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
CL_MEM_USE_HOST_PTR, 0, alloc.getUnderlyingBufferSize(), alloc.getUnderlyingBuffer(), alloc.getUnderlyingBuffer(),
GraphicsAllocationHelper::toMultiGraphicsAllocation(&alloc), true, false, false),
externalAlloc(&alloc) {
}
MockBuffer()
: MockBufferStorage(), Buffer(
nullptr, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
@ -53,9 +58,8 @@ class MockBuffer : public MockBufferStorage, public Buffer {
}
~MockBuffer() override {
if (externalAlloc != nullptr) {
// no ownership over graphics allocation
// return to mock allocations
this->multiGraphicsAllocation.addAllocation(&this->mockGfxAllocation);
// no ownership over graphics allocation, do not release it
this->multiGraphicsAllocation.removeAllocation(0u);
}
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device, bool useGlobalAtomics, bool areMultipleSubDevicesInContext) override {
@ -73,15 +77,29 @@ class AlignedBuffer : public MockBufferStorage, public Buffer {
CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64),
GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation), true, false, false) {
}
AlignedBuffer(GraphicsAllocation *gfxAllocation)
AlignedBuffer(GraphicsAllocation *gfxAllocation) : AlignedBuffer(nullptr, gfxAllocation) {}
AlignedBuffer(Context *context, GraphicsAllocation *gfxAllocation)
: MockBufferStorage(), Buffer(
nullptr, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64),
GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), true, false, false) {
GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), true, false, false),
externalAlloc(gfxAllocation) {
}
~AlignedBuffer() override {
if (externalAlloc != nullptr) {
// no ownership over graphics allocation, do not release it
this->multiGraphicsAllocation.removeAllocation(0u);
}
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device, bool useGlobalAtomics, bool areMultipleSubDevicesInContext) override {
Buffer::setSurfaceState(this->device.get(), memory, forceNonAuxMode, disableL3, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0, false, false);
}
GraphicsAllocation *externalAlloc = nullptr;
};
class UnalignedBuffer : public MockBufferStorage, public Buffer {
@ -93,15 +111,29 @@ class UnalignedBuffer : public MockBufferStorage, public Buffer {
CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4),
GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation), false, false, false) {
}
UnalignedBuffer(GraphicsAllocation *gfxAllocation)
UnalignedBuffer(GraphicsAllocation *gfxAllocation) : UnalignedBuffer(nullptr, gfxAllocation) {}
UnalignedBuffer(Context *context, GraphicsAllocation *gfxAllocation)
: MockBufferStorage(true), Buffer(
nullptr, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()),
CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4),
GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), false, false, false) {
GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), false, false, false),
externalAlloc(gfxAllocation) {
}
~UnalignedBuffer() override {
if (externalAlloc != nullptr) {
// no ownership over graphics allocation, do not release it
this->multiGraphicsAllocation.removeAllocation(0u);
}
}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device, bool useGlobalAtomics, bool areMultipleSubDevicesInContext) override {
Buffer::setSurfaceState(this->device.get(), memory, forceNonAuxMode, disableL3, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0, false, false);
}
GraphicsAllocation *externalAlloc = nullptr;
};
class MockPublicAccessBuffer : public Buffer {

View File

@ -86,7 +86,8 @@ TEST_F(IOQTaskTestsMt, GivenBlockedOnUserEventWhenEnqueingMarkerThenSuccessIsRet
}
TEST_F(IOQTaskTestsMt, GivenMultipleThreadsWhenMappingBufferThenEventsAreCompleted) {
AlignedBuffer alignedBuffer;
MockGraphicsAllocation alignedBufferAlloc{nullptr, MemoryConstants::pageSize};
AlignedBuffer alignedBuffer{pContext, &alignedBufferAlloc};
auto userEvent = clCreateUserEvent(pContext, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);