Add entry points for detecting whether cpu copy is required.

Change-Id: I04438da6241eedf127fd7e51ab257d22186d904e
Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2020-02-28 09:59:18 +01:00
committed by sys_ocldev
parent 4c781c1b98
commit 4803e82eda
4 changed files with 29 additions and 0 deletions

View File

@ -556,6 +556,10 @@ 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) {

View File

@ -263,6 +263,27 @@ TEST(ReadWriteBufferOnCpu, givenNoHostPtrAndAlignedSizeWhenMemoryAllocationIsInN
}
}
TEST(ReadWriteBufferOnCpu, givenPointerThatRequiresCpuCopyWhenCpuCopyIsEvaluatedThenTrueIsReturned) {
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(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(Buffer::create(&ctx, flags, MemoryConstants::pageSize, nullptr, retVal));
buffer->forceDisallowCPUCopy = true;
ASSERT_NE(nullptr, buffer.get());
auto mockCommandQueue = std::unique_ptr<MockCommandQueue>(new MockCommandQueue);
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));
}
TEST(ReadWriteBufferOnCpu, given32BitApplicationWhenLocalMemoryPoolAllocationIsAskedForPreferenceThenCpuIsChoosen) {
if (is64bit) {
GTEST_SKIP();

View File

@ -105,6 +105,8 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
return OsAgnosticMemoryManager::reserveCpuAddressRange(size, rootDeviceIndex);
}
bool isCpuCopyRequired(const void *ptr) override { return cpuCopyRequired; }
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType);
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
@ -126,6 +128,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
bool failReserveAddress = false;
bool failAllocateSystemMemory = false;
bool failAllocate32Bit = false;
bool cpuCopyRequired = false;
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;
};

View File

@ -164,6 +164,7 @@ class MemoryManager {
static uint32_t maxOsContextCount;
virtual void commonCleanup(){};
virtual bool isCpuCopyRequired(const void *ptr) { return false; }
protected:
struct AllocationData {