mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Remove redundant/recursive checks in unmap operations
- Some of the paths were made only for ULTs - Params like mappedPtr were ignored - Improve confusing method names - Fix for memory leak in map shared buffer path (not tested code) Change-Id: I8a69035f1d1c340f2d131a6f8d7e13116e3ddabc
This commit is contained in:
4
Jenkinsfile
vendored
4
Jenkinsfile
vendored
@ -1,5 +1,5 @@
|
||||
#!groovy
|
||||
neoDependenciesRev='733920-765'
|
||||
strategy='EQUAL'
|
||||
allowedF=47
|
||||
allowedCD=363
|
||||
allowedF=44
|
||||
allowedCD=359
|
||||
|
@ -2470,13 +2470,10 @@ cl_int CL_API_CALL clEnqueueUnmapMemObject(cl_command_queue commandQueue,
|
||||
"event", event);
|
||||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
|
||||
retVal = pMemObj->unmapObj(
|
||||
pCommandQueue,
|
||||
mappedPtr,
|
||||
numEventsInWaitList,
|
||||
eventWaitList,
|
||||
event);
|
||||
if (mappedPtr != pMemObj->getMappedPtr()) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
retVal = pCommandQueue->enqueueUnmapMemObject(pMemObj, mappedPtr, numEventsInWaitList, eventWaitList, event);
|
||||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
pMemObj->decMapCount();
|
||||
|
@ -491,4 +491,37 @@ bool CommandQueue::sendPerfCountersConfig() {
|
||||
return getPerfCounters()->sendPmRegsCfgCommands(perfConfigurationData, &perfCountersRegsCfgHandle, &perfCountersRegsCfgPending);
|
||||
}
|
||||
|
||||
cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) {
|
||||
auto image = castToObject<Image>(memObj);
|
||||
if (image) {
|
||||
auto mappedRegion = image->getMappedRegion();
|
||||
size_t region[] = {mappedRegion[0] ? mappedRegion[0] : 1,
|
||||
mappedRegion[1] ? mappedRegion[1] : 1,
|
||||
mappedRegion[2] ? mappedRegion[2] : 1};
|
||||
|
||||
auto retVal = enqueueWriteImage(image, CL_FALSE, image->getMappedOrigin(), region, image->getHostPtrRowPitch(), image->getHostPtrSlicePitch(),
|
||||
mappedPtr, numEventsInWaitList, eventWaitList, event);
|
||||
bool mustCallFinish = true;
|
||||
if (!(image->getFlags() & CL_MEM_USE_HOST_PTR)) {
|
||||
mustCallFinish = true;
|
||||
} else {
|
||||
mustCallFinish = (CommandQueue::getTaskLevelFromWaitList(this->taskLevel, numEventsInWaitList, eventWaitList) != Event::eventNotReady);
|
||||
}
|
||||
if (mustCallFinish) {
|
||||
finish(true);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
auto buffer = castToObject<Buffer>(memObj);
|
||||
if (buffer) {
|
||||
auto writePtr = ptrOffset(mappedPtr, buffer->getMappedOffset());
|
||||
|
||||
return enqueueWriteBuffer(buffer, CL_TRUE, buffer->getMappedOffset(), buffer->getMappedSize(), writePtr,
|
||||
numEventsInWaitList, eventWaitList, event);
|
||||
}
|
||||
|
||||
return CL_INVALID_MEM_OBJECT;
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
@ -400,6 +400,8 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
|
||||
Event *virtualEvent;
|
||||
|
||||
protected:
|
||||
cl_int enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event);
|
||||
|
||||
Context *context;
|
||||
Device *device;
|
||||
|
||||
|
@ -246,7 +246,7 @@ class CommandQueueHw : public CommandQueue {
|
||||
cl_event *event) override {
|
||||
cl_int retVal;
|
||||
if (memObj->allowTiling() || memObj->peekSharingHandler()) {
|
||||
retVal = memObj->unmapObj(this, mappedPtr, numEventsInWaitList, eventWaitList, event);
|
||||
retVal = enqueueWriteMemObjForUnmap(memObj, mappedPtr, numEventsInWaitList, eventWaitList, event);
|
||||
} else {
|
||||
cpuDataTransferHandler(memObj,
|
||||
CL_COMMAND_UNMAP_MEM_OBJECT,
|
||||
|
@ -45,7 +45,7 @@ void *CommandQueueHw<GfxFamily>::enqueueMapSharedBuffer(Buffer *buffer, cl_bool
|
||||
auto memoryManager = device->getMemoryManager();
|
||||
if (!buffer->getMappedPtr()) {
|
||||
auto memory = memoryManager->allocateSystemMemory(buffer->getGraphicsAllocation()->getUnderlyingBufferSize(), 0);
|
||||
buffer->setMappedPtr(memory);
|
||||
buffer->setAllocatedMappedPtr(memory);
|
||||
}
|
||||
|
||||
auto returnPtr = ptrOffset(buffer->getMappedPtr(), offset);
|
||||
@ -59,4 +59,4 @@ void *CommandQueueHw<GfxFamily>::enqueueMapSharedBuffer(Buffer *buffer, cl_bool
|
||||
buffer->setMappedOffset(offset);
|
||||
return returnPtr;
|
||||
}
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
@ -346,15 +346,4 @@ void Buffer::setSurfaceState(Context *context,
|
||||
buffer->graphicsAllocation = nullptr;
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
cl_int Buffer::unmapObj(CommandQueue *cmdQ, void *ptr, cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList, cl_event *event) {
|
||||
if (!peekSharingHandler()) {
|
||||
return cmdQ->enqueueUnmapMemObject(this, ptr, numEventsInWaitList, eventWaitList, event);
|
||||
}
|
||||
auto writePtr = ptrOffset(getMappedPtr(), getMappedOffset());
|
||||
|
||||
return cmdQ->enqueueWriteBuffer(this, CL_TRUE, getMappedOffset(), getMappedSize(), writePtr,
|
||||
numEventsInWaitList, eventWaitList, event);
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
@ -104,9 +104,6 @@ class Buffer : public MemObj {
|
||||
|
||||
bool isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitList, void *ptr, size_t size);
|
||||
|
||||
cl_int unmapObj(CommandQueue *cmdQ, void *ptr, cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList, cl_event *event) override;
|
||||
|
||||
protected:
|
||||
Buffer(Context *context,
|
||||
cl_mem_flags flags,
|
||||
|
@ -415,44 +415,6 @@ Image *Image::createSharedImage(Context *context, SharingHandler *sharingHandler
|
||||
return sharedImage;
|
||||
}
|
||||
|
||||
cl_int Image::unmapObj(CommandQueue *cmdQ, void *ptr,
|
||||
cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList,
|
||||
cl_event *event) {
|
||||
if (!allowTiling() && !peekSharingHandler()) {
|
||||
return cmdQ->enqueueUnmapMemObject(this, ptr, numEventsInWaitList, eventWaitList, event);
|
||||
}
|
||||
|
||||
if (ptr != getMappedPtr()) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
cl_int retVal;
|
||||
|
||||
size_t Region[] = {mappedRegion[0] ? mappedRegion[0] : 1,
|
||||
+mappedRegion[1] ? mappedRegion[1] : 1,
|
||||
+mappedRegion[2] ? mappedRegion[2] : 1};
|
||||
|
||||
size_t rowPitch = getHostPtrRowPitch();
|
||||
size_t slicePitch = getHostPtrSlicePitch();
|
||||
|
||||
retVal = cmdQ->enqueueWriteImage(this,
|
||||
CL_FALSE, mappedOrigin, Region, rowPitch, slicePitch, getMappedPtr(),
|
||||
numEventsInWaitList,
|
||||
eventWaitList,
|
||||
event);
|
||||
bool mustCallFinish = true;
|
||||
if (!(flags & CL_MEM_USE_HOST_PTR)) {
|
||||
mustCallFinish = true;
|
||||
} else {
|
||||
mustCallFinish = (CommandQueue::getTaskLevelFromWaitList(cmdQ->taskLevel, numEventsInWaitList, eventWaitList) != Event::eventNotReady);
|
||||
}
|
||||
if (mustCallFinish) {
|
||||
cmdQ->finish(true);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
cl_int Image::validate(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const SurfaceFormatInfo *surfaceFormat,
|
||||
|
@ -127,14 +127,12 @@ class Image : public MemObj {
|
||||
virtual void setMediaSurfaceRotation(void *memory) = 0;
|
||||
virtual void setSurfaceMemoryObjectControlStateIndexToMocsTable(void *memory, uint32_t value) = 0;
|
||||
|
||||
cl_int unmapObj(CommandQueue *cmdQ, void *ptr,
|
||||
cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList,
|
||||
cl_event *event) override;
|
||||
|
||||
void setMappedRegion(size_t *region) { memcpy_s(mappedRegion, 3 * sizeof(size_t), region, 3 * sizeof(size_t)); }
|
||||
void setMappedOrigin(size_t *origin) { memcpy_s(mappedOrigin, 3 * sizeof(size_t), origin, 3 * sizeof(size_t)); }
|
||||
|
||||
size_t *getMappedRegion() { return mappedRegion; }
|
||||
size_t *getMappedOrigin() { return mappedOrigin; }
|
||||
|
||||
const cl_image_desc &getImageDesc() const;
|
||||
const cl_image_format &getImageFormat() const;
|
||||
const SurfaceFormatInfo &getSurfaceFormatInfo() const;
|
||||
|
@ -84,10 +84,6 @@ MemObj::~MemObj() {
|
||||
destroyGraphicsAllocation(mcsAllocation, false);
|
||||
}
|
||||
|
||||
if (mappedPtr && !getCpuAddressForMapping()) {
|
||||
memoryManager->freeSystemMemory(mappedPtr);
|
||||
}
|
||||
|
||||
if (associatedMemObject) {
|
||||
if (associatedMemObject->getGraphicsAllocation() != this->getGraphicsAllocation()) {
|
||||
destroyGraphicsAllocation(graphicsAllocation, false);
|
||||
|
@ -104,11 +104,6 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
Device *getAssociatedDevice() { return device; }
|
||||
bool isImageFromImage() const { return isImageFromImageCreated; }
|
||||
|
||||
virtual cl_int unmapObj(CommandQueue *cmdQ, void *ptr, cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList, cl_event *event) {
|
||||
return CL_INVALID_MEM_OBJECT;
|
||||
}
|
||||
|
||||
void *setAndReturnMappedPtr(size_t offset);
|
||||
void *getCpuAddressForMapping();
|
||||
void *getCpuAddressForMemoryTransfer();
|
||||
|
@ -29,15 +29,36 @@ using namespace OCLRT;
|
||||
|
||||
typedef api_tests clEnqueueUnmapMemObjTests;
|
||||
|
||||
TEST_F(clEnqueueUnmapMemObjTests, validAddressShouldReturnSuccess) {
|
||||
TEST_F(clEnqueueUnmapMemObjTests, givenValidAddressWhenUnmappingThenReturnSuccess) {
|
||||
auto buffer = std::unique_ptr<Buffer>(BufferHelper<BufferUseHostPtr<>>::create(pContext));
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
auto retVal = clEnqueueUnmapMemObject(
|
||||
auto mappedPtr = clEnqueueMapBuffer(pCommandQueue, buffer.get(), CL_TRUE, CL_MAP_READ, 0, 1, 0, nullptr, nullptr, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clEnqueueUnmapMemObject(
|
||||
pCommandQueue,
|
||||
buffer.get(),
|
||||
buffer->getHostPtr(),
|
||||
mappedPtr,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST_F(clEnqueueUnmapMemObjTests, givenInvalidAddressWhenUnmappingThenReturnError) {
|
||||
auto buffer = std::unique_ptr<Buffer>(BufferHelper<BufferUseHostPtr<>>::create(pContext));
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
auto mappedPtr = clEnqueueMapBuffer(pCommandQueue, buffer.get(), CL_TRUE, CL_MAP_READ, 0, 1, 0, nullptr, nullptr, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clEnqueueUnmapMemObject(
|
||||
pCommandQueue,
|
||||
buffer.get(),
|
||||
ptrOffset(mappedPtr, buffer->getSize() + 1),
|
||||
0,
|
||||
nullptr,
|
||||
nullptr);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "unit_tests/helpers/memory_management.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "unit_tests/mocks/mock_command_queue.h"
|
||||
#include "unit_tests/fixtures/platform_fixture.h"
|
||||
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
||||
#include "runtime/helpers/options.h"
|
||||
@ -805,3 +806,53 @@ HWTEST_F(BufferSetSurfaceTests, givenBufferWithOffsetWhenSetArgStatefulIsCalledT
|
||||
alignedFree(ptr);
|
||||
DebugManager.flags.Force32bitAddressing.set(false);
|
||||
}
|
||||
|
||||
struct BufferUnmapTest : public DeviceFixture, public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DeviceFixture::SetUp();
|
||||
}
|
||||
void TearDown() override {
|
||||
DeviceFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
HWTEST_F(BufferUnmapTest, givenBufferWithSharingHandlerWhenUnmappingThenUseEnqueueWriteBuffer) {
|
||||
MockContext context(pDevice);
|
||||
MockCommandQueueHw<FamilyType> cmdQ(&context, pDevice, nullptr);
|
||||
|
||||
auto retVal = CL_SUCCESS;
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_ALLOC_HOST_PTR, 123, nullptr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
buffer->setSharingHandler(new SharingHandler());
|
||||
EXPECT_NE(nullptr, buffer->peekSharingHandler());
|
||||
|
||||
auto mappedPtr = clEnqueueMapBuffer(&cmdQ, buffer.get(), CL_TRUE, CL_MAP_READ, 0, 1, 0, nullptr, nullptr, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(0u, cmdQ.EnqueueWriteBufferCounter);
|
||||
retVal = clEnqueueUnmapMemObject(&cmdQ, buffer.get(), mappedPtr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(1u, cmdQ.EnqueueWriteBufferCounter);
|
||||
EXPECT_TRUE(cmdQ.blockingWriteBuffer);
|
||||
}
|
||||
|
||||
HWTEST_F(BufferUnmapTest, givenBufferWithoutSharingHandlerWhenUnmappingThenDontUseEnqueueWriteBuffer) {
|
||||
MockContext context(pDevice);
|
||||
MockCommandQueueHw<FamilyType> cmdQ(&context, pDevice, nullptr);
|
||||
|
||||
auto retVal = CL_SUCCESS;
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_ALLOC_HOST_PTR, 123, nullptr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(nullptr, buffer->peekSharingHandler());
|
||||
|
||||
auto mappedPtr = clEnqueueMapBuffer(&cmdQ, buffer.get(), CL_TRUE, CL_MAP_READ, 0, 1, 0, nullptr, nullptr, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clEnqueueUnmapMemObject(&cmdQ, buffer.get(), mappedPtr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(0u, cmdQ.EnqueueWriteBufferCounter);
|
||||
}
|
||||
|
@ -20,8 +20,8 @@
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "runtime/command_queue/command_queue.h"
|
||||
#include "test.h"
|
||||
#include "runtime/command_queue/command_queue_hw.h"
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "unit_tests/fixtures/image_fixture.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
@ -30,10 +30,11 @@
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class MockCommandQueue : public CommandQueue {
|
||||
template <typename Family>
|
||||
class MyMockCommandQueue : public CommandQueueHw<Family> {
|
||||
|
||||
public:
|
||||
MockCommandQueue(Context *context) : CommandQueue(context, nullptr, 0){};
|
||||
MyMockCommandQueue(Context *context) : CommandQueueHw<Family>(context, nullptr, 0){};
|
||||
|
||||
cl_int enqueueWriteImage(Image *dstImage, cl_bool blockingWrite,
|
||||
const size_t *origin, const size_t *region,
|
||||
@ -66,11 +67,11 @@ class ImageUnmapTest : public ::testing::Test {
|
||||
std::unique_ptr<Image> image;
|
||||
};
|
||||
|
||||
TEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledThenEnqueueNonBlockingMapImage) {
|
||||
std::unique_ptr<MockCommandQueue> commandQueue(new MockCommandQueue(&context));
|
||||
HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledThenEnqueueNonBlockingMapImage) {
|
||||
std::unique_ptr<MyMockCommandQueue<FamilyType>> commandQueue(new MyMockCommandQueue<FamilyType>(&context));
|
||||
void *ptr = alignedMalloc(MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
|
||||
image->setAllocatedMappedPtr(ptr);
|
||||
image->unmapObj(commandQueue.get(), ptr, 0, nullptr, nullptr);
|
||||
commandQueue->enqueueUnmapMemObject(image.get(), ptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(ptr, commandQueue->passedPtr);
|
||||
EXPECT_EQ((cl_bool)CL_FALSE, commandQueue->passedBlockingWrite);
|
||||
EXPECT_EQ(1u, commandQueue->enqueueWriteImageCalled);
|
||||
@ -80,37 +81,37 @@ TEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledThenEnqueueNonBlockingMa
|
||||
EXPECT_EQ(nullptr, image->getMappedPtr());
|
||||
}
|
||||
|
||||
TEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWithoutEventsThenFinishIsCalled) {
|
||||
std::unique_ptr<MockCommandQueue> commandQueue(new MockCommandQueue(&context));
|
||||
HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWithoutEventsThenFinishIsCalled) {
|
||||
std::unique_ptr<MyMockCommandQueue<FamilyType>> commandQueue(new MyMockCommandQueue<FamilyType>(&context));
|
||||
image.reset(ImageHelper<ImageUseHostPtr<Image3dDefaults>>::create(&context));
|
||||
image->unmapObj(commandQueue.get(), nullptr, 0, nullptr, nullptr);
|
||||
commandQueue->enqueueUnmapMemObject(image.get(), nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(1u, commandQueue->finishCalled);
|
||||
}
|
||||
|
||||
TEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithoutMemUseHostPtrThenFinishIsCalled) {
|
||||
std::unique_ptr<MockCommandQueue> commandQueue(new MockCommandQueue(&context));
|
||||
image->unmapObj(commandQueue.get(), nullptr, 0, nullptr, nullptr);
|
||||
HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithoutMemUseHostPtrThenFinishIsCalled) {
|
||||
std::unique_ptr<MyMockCommandQueue<FamilyType>> commandQueue(new MyMockCommandQueue<FamilyType>(&context));
|
||||
commandQueue->enqueueUnmapMemObject(image.get(), nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(1u, commandQueue->finishCalled);
|
||||
}
|
||||
|
||||
TEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWithNotReadyEventsThenFinishIsNotCalled) {
|
||||
std::unique_ptr<MockCommandQueue> commandQueue(new MockCommandQueue(&context));
|
||||
HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWithNotReadyEventsThenFinishIsNotCalled) {
|
||||
std::unique_ptr<MyMockCommandQueue<FamilyType>> commandQueue(new MyMockCommandQueue<FamilyType>(&context));
|
||||
image.reset(ImageHelper<ImageUseHostPtr<Image3dDefaults>>::create(&context));
|
||||
|
||||
MockEvent<UserEvent> mockEvent(&context);
|
||||
mockEvent.setStatus(Event::eventNotReady);
|
||||
cl_event clEvent = &mockEvent;
|
||||
image->unmapObj(commandQueue.get(), nullptr, 1, &clEvent, nullptr);
|
||||
commandQueue->enqueueUnmapMemObject(image.get(), nullptr, 1, &clEvent, nullptr);
|
||||
EXPECT_EQ(0u, commandQueue->finishCalled);
|
||||
}
|
||||
|
||||
TEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWithoutNotReadyEventsThenFinishIsCalled) {
|
||||
std::unique_ptr<MockCommandQueue> commandQueue(new MockCommandQueue(&context));
|
||||
HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledWithMemUseHostPtrAndWithoutNotReadyEventsThenFinishIsCalled) {
|
||||
std::unique_ptr<MyMockCommandQueue<FamilyType>> commandQueue(new MyMockCommandQueue<FamilyType>(&context));
|
||||
image.reset(ImageHelper<ImageUseHostPtr<Image3dDefaults>>::create(&context));
|
||||
MockEvent<UserEvent> mockEvent(&context);
|
||||
mockEvent.setStatus(0);
|
||||
cl_event clEvent = &mockEvent;
|
||||
image->unmapObj(commandQueue.get(), nullptr, 1, &clEvent, nullptr);
|
||||
commandQueue->enqueueUnmapMemObject(image.get(), nullptr, 1, &clEvent, nullptr);
|
||||
EXPECT_EQ(1u, commandQueue->finishCalled);
|
||||
}
|
||||
|
||||
@ -127,7 +128,7 @@ TEST_F(ImageUnmapTest, givenImageWhenEnqueueMapImageIsCalledTwiceThenAllocatedMe
|
||||
EXPECT_EQ(alignUp(ptr, MemoryConstants::pageSize), ptr);
|
||||
commandQueue->enqueueMapImage(clImage, CL_FALSE, 0, origin, region, nullptr, nullptr, 0, nullptr, nullptr, retVal);
|
||||
EXPECT_EQ(ptr, image->getAllocatedMappedPtr());
|
||||
image->unmapObj(commandQueue.get(), ptr, 0, nullptr, nullptr);
|
||||
commandQueue->enqueueUnmapMemObject(image.get(), ptr, 0, nullptr, nullptr);
|
||||
image->releaseAllocatedMappedPtr();
|
||||
EXPECT_EQ(nullptr, image->getMappedPtr());
|
||||
image.reset(nullptr);
|
||||
|
@ -193,8 +193,10 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled
|
||||
CL_MEM_READ_WRITE,
|
||||
size,
|
||||
storage, nullptr, allocation, true, false, false);
|
||||
}
|
||||
memObj->setMappedPtr(storage);
|
||||
} else {
|
||||
memObj->setAllocatedMappedPtr(storage);
|
||||
}
|
||||
|
||||
makeMemObjUsed();
|
||||
auto mockCsr = new ::testing::NiceMock<MyCsr<FamilyType>>(device->getHardwareInfo());
|
||||
|
@ -98,17 +98,16 @@ TEST_F(PipeTest, FailedAllocationInjection) {
|
||||
injectFailures(method);
|
||||
}
|
||||
|
||||
TEST_F(PipeTest, givenPipeWhenUnmapIsCalledThenReturnError) {
|
||||
TEST_F(PipeTest, givenPipeWhenEnqueueWriteForUnmapIsCalledThenReturnError) {
|
||||
struct MyCommandQueue : public CommandQueue {
|
||||
using CommandQueue::enqueueWriteMemObjForUnmap;
|
||||
} myCmdQ;
|
||||
|
||||
int errCode = CL_SUCCESS;
|
||||
auto pipe = Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode);
|
||||
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);
|
||||
auto cmdQ = CommandQueue::create(&context, context.getDevice(0), 0, errCode);
|
||||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
|
||||
errCode = pipe->unmapObj(cmdQ, nullptr, 0, nullptr, nullptr);
|
||||
errCode = myCmdQ.enqueueWriteMemObjForUnmap(pipe.get(), nullptr, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_INVALID_MEM_OBJECT, errCode);
|
||||
|
||||
delete pipe;
|
||||
delete cmdQ;
|
||||
}
|
||||
|
@ -30,8 +30,8 @@
|
||||
namespace OCLRT {
|
||||
class MockCommandQueue : public CommandQueue {
|
||||
public:
|
||||
using CommandQueue::indirectHeap;
|
||||
using CommandQueue::device;
|
||||
using CommandQueue::indirectHeap;
|
||||
|
||||
void setProfilingEnabled() {
|
||||
commandQueueProperties |= CL_QUEUE_PROFILING_ENABLE;
|
||||
@ -81,6 +81,13 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
|
||||
event);
|
||||
}
|
||||
|
||||
cl_int enqueueWriteBuffer(Buffer *buffer, cl_bool blockingWrite, size_t offset, size_t size,
|
||||
const void *ptr, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override {
|
||||
EnqueueWriteBufferCounter++;
|
||||
blockingWriteBuffer = blockingWrite == CL_TRUE;
|
||||
return BaseClass::enqueueWriteBuffer(buffer, blockingWrite, offset, size, ptr, numEventsInWaitList, eventWaitList, event);
|
||||
}
|
||||
|
||||
void enqueueHandlerHook(const unsigned int commandType, const MultiDispatchInfo &dispatchInfo) override {
|
||||
lastCommandType = commandType;
|
||||
for (auto &di : dispatchInfo) {
|
||||
@ -91,6 +98,8 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
|
||||
unsigned int lastCommandType;
|
||||
std::vector<Kernel *> lastEnqueuedKernels;
|
||||
size_t EnqueueWriteImageCounter = 0;
|
||||
size_t EnqueueWriteBufferCounter = 0;
|
||||
bool blockingWriteBuffer = false;
|
||||
|
||||
LinearStream *peekCommandStream() {
|
||||
return this->commandStream;
|
||||
|
Reference in New Issue
Block a user