From 0e85ccf084f48381b8e227c0052260b49094d1c0 Mon Sep 17 00:00:00 2001 From: Michal Mrozek Date: Mon, 24 Feb 2020 13:56:41 +0100 Subject: [PATCH] Choose cpu copy for 32 bit application using local memory. Change-Id: I74aed9475185b09d4569fafb3427052fff73fd89 Signed-off-by: Michal Mrozek --- opencl/source/mem_obj/buffer.cpp | 19 +++++++++++-------- .../read_write_buffer_cpu_copy.cpp | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 4f2b2db1a1..c782cb36be 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -518,19 +518,22 @@ bool Buffer::isReadWriteOnCpuAllowed() { } bool Buffer::isReadWriteOnCpuPreffered(void *ptr, size_t size) { - //if buffer is not zero copy and pointer is aligned it will be more beneficial to do the transfer on GPU - if (!isMemObjZeroCopy() && (reinterpret_cast(ptr) & (MemoryConstants::cacheLineSize - 1)) == 0) { - return false; - } + if (MemoryPool::isSystemMemoryPool(graphicsAllocation->getMemoryPool())) { + //if buffer is not zero copy and pointer is aligned it will be more beneficial to do the transfer on GPU + if (!isMemObjZeroCopy() && (reinterpret_cast(ptr) & (MemoryConstants::cacheLineSize - 1)) == 0) { + return false; + } - //on low power devices larger transfers are better on the GPU - if (context->getDevice(0)->getDeviceInfo().platformLP && size > maxBufferSizeForReadWriteOnCpu) { - return false; + //on low power devices larger transfers are better on the GPU + if (context->getDevice(0)->getDeviceInfo().platformLP && size > maxBufferSizeForReadWriteOnCpu) { + return false; + } + return true; } //if we are not in System Memory Pool, it is more beneficial to do the transfer on GPU //for 32 bit applications, utilize CPU transfers here. - if (!MemoryPool::isSystemMemoryPool(graphicsAllocation->getMemoryPool()) && is64bit) { + if (is64bit) { return false; } 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 346699b6c1..00b604e9ee 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 @@ -7,6 +7,7 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/helpers/basic_math.h" +#include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "opencl/test/unit_test/command_queue/enqueue_read_buffer_fixture.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" @@ -251,3 +252,20 @@ TEST(ReadWriteBufferOnCpu, given32BitApplicationWhenLocalMemoryPoolAllocationIsA EXPECT_TRUE(buffer->isReadWriteOnCpuAllowed()); EXPECT_TRUE(buffer->isReadWriteOnCpuPreffered(reinterpret_cast(0x1000), MemoryConstants::pageSize)); } + +TEST(ReadWriteBufferOnCpu, given32BitAppAndLocalMemoryBufferWhenAskedForCpuTransferPreferenceThenTrueIsReturned) { + if (is64bit) { + GTEST_SKIP(); + } + DebugManagerStateRestore restorer; + DebugManager.flags.EnableLocalMemory.set(true); + auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); + MockContext ctx(device.get()); + + cl_int retVal = 0; + std::unique_ptr buffer(Buffer::create(&ctx, CL_MEM_READ_WRITE, MemoryConstants::pageSize, nullptr, retVal)); + ASSERT_NE(nullptr, buffer.get()); + + EXPECT_TRUE(buffer->isReadWriteOnCpuAllowed()); + EXPECT_TRUE(buffer->isReadWriteOnCpuPreffered(reinterpret_cast(0x1000), MemoryConstants::pageSize)); +} \ No newline at end of file