From 3f43224e1befb9d5e474ba8fd8f1e1df22a1be50 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Thu, 28 Nov 2019 07:58:10 +0100 Subject: [PATCH] Make EXTERNAL_HOST_PTR one time aub writable Change-Id: Ib8ac51ebad8997a0b10431d8c78239dc38beb616 Signed-off-by: Dunajski, Bartosz --- runtime/aub/aub_helper.h | 1 + runtime/command_queue/command_queue.cpp | 4 ++ .../enqueue_unmap_memobject_tests.cpp | 52 +++++++++++++++++++ .../aub_command_stream_receiver_1_tests.cpp | 3 +- .../image_release_mapped_ptr_tests.cpp | 5 ++ 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/runtime/aub/aub_helper.h b/runtime/aub/aub_helper.h index 9ae8d75165..a7e7e41a02 100644 --- a/runtime/aub/aub_helper.h +++ b/runtime/aub/aub_helper.h @@ -28,6 +28,7 @@ class AubHelper : public NonCopyableOrMovableClass { case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED: case GraphicsAllocation::AllocationType::IMAGE: case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER: + case GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR: return true; default: return false; diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index 4c75e50b7f..70f9be1561 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -327,8 +327,12 @@ cl_int CommandQueue::enqueueWriteMemObjForUnmap(MemObj *memObj, void *mappedPtr, } if (!unmapInfo.readOnly) { + memObj->getMapAllocation()->setAubWritable(true, GraphicsAllocation::defaultBank); + memObj->getMapAllocation()->setTbxWritable(true, GraphicsAllocation::defaultBank); + if (memObj->peekClMemObjType() == CL_MEM_OBJECT_BUFFER) { auto buffer = castToObject(memObj); + retVal = enqueueWriteBuffer(buffer, CL_TRUE, unmapInfo.offset[0], unmapInfo.size[0], mappedPtr, memObj->getMapAllocation(), eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList, eventsRequest.outEvent); } else { diff --git a/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp b/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp index 11c9a6bae7..ddef1af41a 100644 --- a/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp +++ b/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp @@ -5,12 +5,15 @@ * */ +#include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "runtime/command_stream/command_stream_receiver.h" #include "runtime/event/event.h" #include "test.h" #include "unit_tests/command_queue/command_queue_fixture.h" #include "unit_tests/fixtures/buffer_fixture.h" #include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/fixtures/image_fixture.h" +#include "unit_tests/mocks/mock_command_queue.h" #include @@ -210,3 +213,52 @@ HWTEST_F(EnqueueUnmapMemObjTest, givenEnqueueUnmapMemObjectWhenNonAubWritableBuf EXPECT_TRUE(buffer->getGraphicsAllocation()->isAubWritable(GraphicsAllocation::defaultBank)); EXPECT_TRUE(buffer->getGraphicsAllocation()->isTbxWritable(GraphicsAllocation::defaultBank)); } + +HWTEST_F(EnqueueUnmapMemObjTest, givenMemObjWhenUnmappingThenSetAubWritableBeforeEnqueueWrite) { + DebugManagerStateRestore restore; + DebugManager.flags.DisableZeroCopyForBuffers.set(true); + auto buffer = std::unique_ptr(BufferHelper<>::create()); + auto image = std::unique_ptr(Image2dHelper<>::create(BufferDefaults::context)); + + class MyMockCommandQueue : public MockCommandQueue { + public: + using MockCommandQueue::MockCommandQueue; + cl_int enqueueWriteBuffer(Buffer *buffer, cl_bool blockingWrite, size_t offset, size_t cb, const void *ptr, GraphicsAllocation *mapAllocation, + cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override { + EXPECT_TRUE(buffer->getMapAllocation()->isAubWritable(GraphicsAllocation::defaultBank)); + EXPECT_TRUE(buffer->getMapAllocation()->isTbxWritable(GraphicsAllocation::defaultBank)); + return CL_SUCCESS; + } + + cl_int enqueueWriteImage(Image *dstImage, cl_bool blockingWrite, const size_t *origin, const size_t *region, + size_t inputRowPitch, size_t inputSlicePitch, const void *ptr, GraphicsAllocation *mapAllocation, + cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override { + EXPECT_TRUE(dstImage->getMapAllocation()->isAubWritable(GraphicsAllocation::defaultBank)); + EXPECT_TRUE(dstImage->getMapAllocation()->isTbxWritable(GraphicsAllocation::defaultBank)); + return CL_SUCCESS; + } + }; + + MyMockCommandQueue myMockCmdQ(BufferDefaults::context, pDevice, nullptr); + + { + auto mapPtr = myMockCmdQ.enqueueMapBuffer(buffer.get(), CL_TRUE, CL_MAP_WRITE, 0, 8, 0, nullptr, nullptr, retVal); + + buffer->getMapAllocation()->setAubWritable(false, GraphicsAllocation::defaultBank); + buffer->getMapAllocation()->setTbxWritable(false, GraphicsAllocation::defaultBank); + + myMockCmdQ.enqueueUnmapMemObject(buffer.get(), mapPtr, 0, nullptr, nullptr); + } + + { + size_t region[] = {1, 0, 0}; + size_t origin[] = {0, 0, 0}; + auto mapPtr = myMockCmdQ.enqueueMapImage(image.get(), CL_TRUE, CL_MAP_WRITE, origin, region, nullptr, nullptr, 0, + nullptr, nullptr, retVal); + + image->getMapAllocation()->setAubWritable(false, GraphicsAllocation::defaultBank); + image->getMapAllocation()->setTbxWritable(false, GraphicsAllocation::defaultBank); + + myMockCmdQ.enqueueUnmapMemObject(image.get(), mapPtr, 0, nullptr, nullptr); + } +} diff --git a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp index 2eba3cc102..e46bac8a9b 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -735,7 +735,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, GraphicsAllocation::AllocationType::IMAGE, - GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER}; + GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, + GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR}; for (auto allocationType : onlyOneTimeAubWritableTypes) { gfxAllocation->setAubWritable(true, GraphicsAllocation::defaultBank); diff --git a/unit_tests/mem_obj/image_release_mapped_ptr_tests.cpp b/unit_tests/mem_obj/image_release_mapped_ptr_tests.cpp index 6046b977a9..8326c345aa 100644 --- a/unit_tests/mem_obj/image_release_mapped_ptr_tests.cpp +++ b/unit_tests/mem_obj/image_release_mapped_ptr_tests.cpp @@ -65,6 +65,11 @@ HWTEST_F(ImageUnmapTest, givenImageWhenUnmapMemObjIsCalledThenEnqueueNonBlocking image->setAllocatedMapPtr(ptr); cl_map_flags mapFlags = CL_MAP_WRITE; image->addMappedPtr(ptr, 1, mapFlags, region, origin, 0); + + AllocationProperties properties{0, false, MemoryConstants::cacheLineSize, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, false}; + auto allocation = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties, ptr); + image->setMapAllocation(allocation); + commandQueue->enqueueUnmapMemObject(image.get(), ptr, 0, nullptr, nullptr); if (UnitTestHelper::tiledImagesSupported) {