From f2e24797aee43db72d2b9f267936164a262f4322 Mon Sep 17 00:00:00 2001 From: Michal Mrozek Date: Thu, 12 Mar 2020 07:23:27 +0100 Subject: [PATCH] Do not require cpu copy for incompatible buffers. Change-Id: Ida337e7bb7b4bdae1b30d51a22e0c1bf75e6bcea Signed-off-by: Michal Mrozek --- opencl/source/command_queue/command_queue.cpp | 8 +++---- .../read_write_buffer_cpu_copy.cpp | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index f09823cd99..9893e5e927 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -553,10 +553,6 @@ size_t CommandQueue::estimateTimestampPacketNodesCount(const MultiDispatchInfo & bool CommandQueue::bufferCpuCopyAllowed(Buffer *buffer, cl_command_type commandType, cl_bool blocking, size_t size, void *ptr, cl_uint numEventsInWaitList, const cl_event *eventWaitList) { - if (buffer->getMemoryManager() && buffer->getMemoryManager()->isCpuCopyRequired(ptr)) { - return true; - } - auto debugVariableSet = false; // Requested by debug variable or allowed by Buffer if (CL_COMMAND_READ_BUFFER == commandType && DebugManager.flags.DoCpuCopyOnReadBuffer.get() != -1) { @@ -582,6 +578,10 @@ bool CommandQueue::bufferCpuCopyAllowed(Buffer *buffer, cl_command_type commandT return false; } + if (buffer->getMemoryManager() && buffer->getMemoryManager()->isCpuCopyRequired(ptr)) { + return true; + } + if (debugVariableSet) { return true; } diff --git a/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp b/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp index bfed04744f..313119bdb1 100644 --- a/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp +++ b/opencl/test/unit_test/command_queue/read_write_buffer_cpu_copy.cpp @@ -274,14 +274,34 @@ TEST(ReadWriteBufferOnCpu, givenPointerThatRequiresCpuCopyWhenCpuCopyIsEvaluated cl_mem_flags flags = CL_MEM_READ_WRITE; std::unique_ptr buffer(Buffer::create(&ctx, flags, MemoryConstants::pageSize, nullptr, retVal)); - buffer->forceDisallowCPUCopy = true; ASSERT_NE(nullptr, buffer.get()); auto mockCommandQueue = std::unique_ptr(new MockCommandQueue); + EXPECT_FALSE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, false, MemoryConstants::pageSize, nullptr, 0u, nullptr)); + memoryManager->cpuCopyRequired = true; + EXPECT_TRUE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, false, MemoryConstants::pageSize, nullptr, 0u, nullptr)); +} + +TEST(ReadWriteBufferOnCpu, givenPointerThatRequiresCpuCopyButItIsNotPossibleWhenCpuCopyIsEvaluatedThenFalseIsReturned) { + auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto memoryManager = new MockMemoryManager(*device->getExecutionEnvironment()); + + device->injectMemoryManager(memoryManager); + MockContext ctx(device.get()); + + cl_int retVal = 0; + cl_mem_flags flags = CL_MEM_READ_WRITE; + + std::unique_ptr buffer(Buffer::create(&ctx, flags, MemoryConstants::pageSize, nullptr, retVal)); + + ASSERT_NE(nullptr, buffer.get()); + auto mockCommandQueue = std::unique_ptr(new MockCommandQueue); + + buffer->forceDisallowCPUCopy = true; EXPECT_FALSE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, true, MemoryConstants::pageSize, nullptr, 0u, nullptr)); memoryManager->cpuCopyRequired = true; - EXPECT_TRUE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, true, MemoryConstants::pageSize, nullptr, 0u, nullptr)); + EXPECT_FALSE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, true, MemoryConstants::pageSize, nullptr, 0u, nullptr)); } TEST(ReadWriteBufferOnCpu, given32BitApplicationWhenLocalMemoryPoolAllocationIsAskedForPreferenceThenCpuIsChoosen) {