Don't copy compressed buffer on CPU

Change-Id: I9c36ee8f23284286bb846fd9a0fd196733d0f8f9
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-04-03 13:15:07 +02:00
parent 3c8b3e9633
commit f76c0e84fb
6 changed files with 94 additions and 4 deletions

View File

@ -304,7 +304,7 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
cl_event *oclEvent,
cl_uint cmdType);
void *cpuDataTransferHandler(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &retVal);
MOCKABLE_VIRTUAL void *cpuDataTransferHandler(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &retVal);
virtual cl_int finish(bool dcFlush) { return CL_SUCCESS; }

View File

@ -36,7 +36,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
cl_int retVal = CL_SUCCESS;
bool isMemTransferNeeded = buffer->isMemObjZeroCopy() ? buffer->checkIfMemoryTransferIsRequired(offset, 0, ptr, CL_COMMAND_READ_BUFFER) : true;
if (((DebugManager.flags.DoCpuCopyOnReadBuffer.get() && !Event::checkUserEventDependencies(numEventsInWaitList, eventWaitList)) ||
if (((DebugManager.flags.DoCpuCopyOnReadBuffer.get() && !Event::checkUserEventDependencies(numEventsInWaitList, eventWaitList) &&
buffer->getGraphicsAllocation()->getAllocationType() != GraphicsAllocation::AllocationType::BUFFER_COMPRESSED) ||
buffer->isReadWriteOnCpuAllowed(blockingRead, numEventsInWaitList, ptr, size)) &&
context->getDevice(0)->getDeviceInfo().cpuCopyAllowed) {
if (!isMemTransferNeeded) {

View File

@ -33,7 +33,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
cl_int retVal = CL_SUCCESS;
auto isMemTransferNeeded = buffer->isMemObjZeroCopy() ? buffer->checkIfMemoryTransferIsRequired(offset, 0, ptr, CL_COMMAND_READ_BUFFER) : true;
if (((DebugManager.flags.DoCpuCopyOnWriteBuffer.get() && !Event::checkUserEventDependencies(numEventsInWaitList, eventWaitList)) ||
if (((DebugManager.flags.DoCpuCopyOnWriteBuffer.get() && !Event::checkUserEventDependencies(numEventsInWaitList, eventWaitList) &&
buffer->getGraphicsAllocation()->getAllocationType() != GraphicsAllocation::AllocationType::BUFFER_COMPRESSED) ||
buffer->isReadWriteOnCpuAllowed(blockingWrite, numEventsInWaitList, const_cast<void *>(ptr), size)) &&
context->getDevice(0)->getDeviceInfo().cpuCopyAllowed) {
if (!isMemTransferNeeded) {

View File

@ -482,6 +482,48 @@ HWTEST_F(EnqueueReadBufferTypeTest, givenEnqueueReadBufferCalledWhenLockedPtrInT
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
}
HWTEST_F(EnqueueReadBufferTypeTest, givenForcedCpuCopyWhenEnqueueReadCompressedBufferThenDontCopyOnCpu) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.DoCpuCopyOnReadBuffer.set(true);
MockExecutionEnvironment executionEnvironment(*platformDevices);
MockMemoryManager memoryManager(false, true, executionEnvironment);
MockContext ctx;
cl_int retVal;
ctx.setMemoryManager(&memoryManager);
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(&ctx, 0, 1, nullptr, retVal));
static_cast<MemoryAllocation *>(buffer->getGraphicsAllocation())->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
void *ptr = nonZeroCopyBuffer->getCpuAddressForMemoryTransfer();
buffer->getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
retVal = mockCmdQ->enqueueReadBuffer(buffer.get(),
CL_TRUE,
0,
MemoryConstants::cacheLineSize,
ptr,
0,
nullptr,
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_FALSE(mockCmdQ->cpuDataTransferHandlerCalled);
buffer->getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
retVal = mockCmdQ->enqueueReadBuffer(buffer.get(),
CL_TRUE,
0,
MemoryConstants::cacheLineSize,
ptr,
0,
nullptr,
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_TRUE(mockCmdQ->cpuDataTransferHandlerCalled);
}
HWTEST_F(EnqueueReadBufferTypeTest, gicenEnqueueReadBufferCalledWhenLockedPtrInTransferPropertisIsNotAvailableThenItIsNotUnlocked) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.DoCpuCopyOnReadBuffer.set(true);

View File

@ -391,6 +391,48 @@ HWTEST_F(EnqueueWriteBufferTypeTest, givenEnqueueWriteBufferCalledWhenLockedPtrI
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
}
HWTEST_F(EnqueueWriteBufferTypeTest, givenForcedCpuCopyWhenEnqueueWriteCompressedBufferThenDontCopyOnCpu) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.DoCpuCopyOnWriteBuffer.set(true);
MockExecutionEnvironment executionEnvironment(*platformDevices);
MockMemoryManager memoryManager(false, true, executionEnvironment);
MockContext ctx;
cl_int retVal;
ctx.setMemoryManager(&memoryManager);
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(&ctx, 0, 1, nullptr, retVal));
static_cast<MemoryAllocation *>(buffer->getGraphicsAllocation())->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
void *ptr = srcBuffer->getCpuAddressForMemoryTransfer();
buffer->getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
retVal = mockCmdQ->enqueueWriteBuffer(buffer.get(),
CL_FALSE,
0,
MemoryConstants::cacheLineSize,
ptr,
0,
nullptr,
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_FALSE(mockCmdQ->cpuDataTransferHandlerCalled);
buffer->getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
retVal = mockCmdQ->enqueueWriteBuffer(buffer.get(),
CL_FALSE,
0,
MemoryConstants::cacheLineSize,
ptr,
0,
nullptr,
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_TRUE(mockCmdQ->cpuDataTransferHandlerCalled);
}
HWTEST_F(EnqueueWriteBufferTypeTest, givenEnqueueWriteBufferCalledWhenLockedPtrInTransferPropertisIsNotAvailableThenItIsNotUnlocked) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.DoCpuCopyOnWriteBuffer.set(true);

View File

@ -109,7 +109,10 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
eventWaitList,
event);
}
void *cpuDataTransferHandler(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &retVal) override {
cpuDataTransferHandlerCalled = true;
return BaseClass::cpuDataTransferHandler(transferProperties, eventsRequest, retVal);
}
cl_int enqueueWriteBuffer(Buffer *buffer, cl_bool blockingWrite, size_t offset, size_t size,
const void *ptr, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override {
EnqueueWriteBufferCounter++;
@ -138,6 +141,7 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
bool blockingWriteBuffer = false;
bool notifyEnqueueReadBufferCalled = false;
bool notifyEnqueueReadImageCalled = false;
bool cpuDataTransferHandlerCalled = false;
uint32_t completionStampTaskCount = 0;
uint32_t deltaTaskCount = 0;