From 1022ad4aaccbf99c7d57050c8dde43555ddaf78d Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Fri, 5 Jul 2019 10:02:27 +0200 Subject: [PATCH] Release reference to mem_object after command submission. Change-Id: I1d3899ee3320869dd245dc1af22bd9b0dbfce9cf Signed-off-by: Mrozek, Michal --- runtime/helpers/task_information.cpp | 7 +++---- runtime/helpers/task_information.h | 2 +- unit_tests/event/event_tests.cpp | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/runtime/helpers/task_information.cpp b/runtime/helpers/task_information.cpp index 57707ec6a5..cdd6fd1f70 100644 --- a/runtime/helpers/task_information.cpp +++ b/runtime/helpers/task_information.cpp @@ -42,12 +42,9 @@ CommandMapUnmap::CommandMapUnmap(MapOperationType op, MemObj &memObj, MemObjSize memObj.incRefInternal(); } -CommandMapUnmap::~CommandMapUnmap() { - memObj.decRefInternal(); -} - CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) { if (terminated) { + memObj.decRefInternal(); return completionStamp; } @@ -90,6 +87,8 @@ CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) { } } + memObj.decRefInternal(); + return completionStamp; } diff --git a/runtime/helpers/task_information.h b/runtime/helpers/task_information.h index ffc94bb78d..01e2bb9042 100644 --- a/runtime/helpers/task_information.h +++ b/runtime/helpers/task_information.h @@ -52,7 +52,7 @@ class CommandMapUnmap : public Command { public: CommandMapUnmap(MapOperationType op, MemObj &memObj, MemObjSizeArray ©Size, MemObjOffsetArray ©Offset, bool readOnly, CommandStreamReceiver &csr, CommandQueue &cmdQ); - ~CommandMapUnmap() override; + ~CommandMapUnmap() override = default; CompletionStamp &submit(uint32_t taskLevel, bool terminated) override; private: diff --git a/unit_tests/event/event_tests.cpp b/unit_tests/event/event_tests.cpp index e04ffa8a07..078653d9a9 100644 --- a/unit_tests/event/event_tests.cpp +++ b/unit_tests/event/event_tests.cpp @@ -738,6 +738,26 @@ TEST_F(InternalsEventTest, processBlockedCommandsUnMapOperation) { delete pCmdQ; } +TEST_F(InternalsEventTest, givenBlockedMapCommandWhenSubmitIsCalledItReleasesMemObjectReference) { + MockEvent event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0); + const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; + auto pCmdQ = std::make_unique(mockContext, pDevice, props); + + auto &csr = pCmdQ->getCommandStreamReceiver(); + auto buffer = new UnalignedBuffer; + + auto currentBufferRefInternal = buffer->getRefInternalCount(); + + MemObjSizeArray size = {{1, 1, 1}}; + MemObjOffsetArray offset = {{0, 0, 0}}; + event.setCommand(std::unique_ptr(new CommandMapUnmap(UNMAP, *buffer, size, offset, false, csr, *pCmdQ))); + EXPECT_EQ(currentBufferRefInternal + 1, buffer->getRefInternalCount()); + + event.submitCommand(false); + + EXPECT_EQ(currentBufferRefInternal, buffer->getRefInternalCount()); + buffer->decRefInternal(); +} TEST_F(InternalsEventTest, processBlockedCommandsUnMapOperationNonZeroCopyBuffer) { MockEvent event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0); const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};