diff --git a/runtime/command_queue/enqueue_read_buffer.h b/runtime/command_queue/enqueue_read_buffer.h index 726f02be85..c1c23daf72 100644 --- a/runtime/command_queue/enqueue_read_buffer.h +++ b/runtime/command_queue/enqueue_read_buffer.h @@ -80,7 +80,8 @@ cl_int CommandQueueHw::enqueueReadBuffer( } else { surfaces[1] = &hostPtrSurf; if (size != 0) { - bool status = getGpgpuCommandStreamReceiver().createAllocationForHostSurface(hostPtrSurf, true); + auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); + bool status = csr.createAllocationForHostSurface(hostPtrSurf, true); if (!status) { return CL_OUT_OF_RESOURCES; } diff --git a/runtime/command_queue/enqueue_write_buffer.h b/runtime/command_queue/enqueue_write_buffer.h index e4f8f145d9..5e6c3ae8d8 100644 --- a/runtime/command_queue/enqueue_write_buffer.h +++ b/runtime/command_queue/enqueue_write_buffer.h @@ -76,7 +76,8 @@ cl_int CommandQueueHw::enqueueWriteBuffer( } else { surfaces[1] = &hostPtrSurf; if (size != 0) { - bool status = getGpgpuCommandStreamReceiver().createAllocationForHostSurface(hostPtrSurf, false); + auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); + bool status = csr.createAllocationForHostSurface(hostPtrSurf, false); if (!status) { return CL_OUT_OF_RESOURCES; } diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index 2490ad9be6..be85a56ca6 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -1140,7 +1140,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenInputAndOutputTimestampPacketWhenBlitCal EXPECT_EQ(cmdQ->taskCount, outputTimestampPacketAllocation->getTaskCount(bcsCsr->getOsContext().getContextId())); } -HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingEnqueueWhenUsingBcsThenCallWait) { +HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingWriteBufferWhenUsingBcsThenCallWait) { auto myMockCsr = new MyMockCsr(*device->getExecutionEnvironment(), device->getRootDeviceIndex()); myMockCsr->taskCount = 1234; myMockCsr->initializeTagAllocation(); @@ -1161,11 +1161,11 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingEnqueueWhenUsingBcsThenCallWait) cmdQ->enqueueWriteBuffer(buffer.get(), false, 0, 1, hostPtr, nullptr, 0, nullptr, nullptr); EXPECT_EQ(0u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled); - EXPECT_FALSE(gpgpuCsr.getTemporaryAllocations().peekIsEmpty()); - EXPECT_TRUE(myMockCsr->getTemporaryAllocations().peekIsEmpty()); + EXPECT_TRUE(gpgpuCsr.getTemporaryAllocations().peekIsEmpty()); + EXPECT_FALSE(myMockCsr->getTemporaryAllocations().peekIsEmpty()); bool tempAllocationFound = false; - auto tempAllocation = gpgpuCsr.getTemporaryAllocations().peekHead(); + auto tempAllocation = myMockCsr->getTemporaryAllocations().peekHead(); while (tempAllocation) { if (tempAllocation->getUnderlyingBuffer() == hostPtr) { tempAllocationFound = true; @@ -1179,6 +1179,45 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingEnqueueWhenUsingBcsThenCallWait) EXPECT_EQ(1u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled); } +HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingReadBufferWhenUsingBcsThenCallWait) { + auto myMockCsr = new MyMockCsr(*device->getExecutionEnvironment(), device->getRootDeviceIndex()); + myMockCsr->taskCount = 1234; + myMockCsr->initializeTagAllocation(); + myMockCsr->setupContext(*bcsMockContext->bcsOsContext); + bcsMockContext->bcsCsr.reset(myMockCsr); + + EngineControl bcsEngineControl = {myMockCsr, bcsMockContext->bcsOsContext.get()}; + + auto cmdQ = clUniquePtr(new MockCommandQueueHw(bcsMockContext.get(), device.get(), nullptr)); + cmdQ->bcsEngine = &bcsEngineControl; + auto &gpgpuCsr = cmdQ->getGpgpuCommandStreamReceiver(); + myMockCsr->gpgpuCsr = &gpgpuCsr; + + cl_int retVal = CL_SUCCESS; + auto buffer = clUniquePtr(Buffer::create(bcsMockContext.get(), CL_MEM_READ_WRITE, 1, nullptr, retVal)); + buffer->forceDisallowCPUCopy = true; + void *hostPtr = reinterpret_cast(0x12340000); + + cmdQ->enqueueReadBuffer(buffer.get(), false, 0, 1, hostPtr, nullptr, 0, nullptr, nullptr); + EXPECT_EQ(0u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled); + EXPECT_TRUE(gpgpuCsr.getTemporaryAllocations().peekIsEmpty()); + EXPECT_FALSE(myMockCsr->getTemporaryAllocations().peekIsEmpty()); + + bool tempAllocationFound = false; + auto tempAllocation = myMockCsr->getTemporaryAllocations().peekHead(); + while (tempAllocation) { + if (tempAllocation->getUnderlyingBuffer() == hostPtr) { + tempAllocationFound = true; + break; + } + tempAllocation = tempAllocation->next; + } + EXPECT_TRUE(tempAllocationFound); + + cmdQ->enqueueReadBuffer(buffer.get(), true, 0, 1, hostPtr, nullptr, 0, nullptr, nullptr); + EXPECT_EQ(1u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled); +} + HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockedEnqueueWhenUsingBcsThenWaitForValidTaskCountOnBlockingCall) { auto myMockCsr = new MyMockCsr(*device->getExecutionEnvironment(), device->getRootDeviceIndex()); myMockCsr->taskCount = 1234;