Create function to get proper CSR

Add function getCommandStreamReceiverByCommandType to get
GpgpuCommandStreamReceiver or BcsCommandStreamReceiver
according to given cmdType.

Related-To: NEO-4013
Change-Id: I16385ada79fe9048cdf9b14a6c5a18652fb788b1
Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala 2020-04-21 12:04:47 +02:00 committed by sys_ocldev
parent 9a0764d422
commit d5e34d2d10
8 changed files with 39 additions and 11 deletions

View File

@ -118,6 +118,15 @@ CommandStreamReceiver *CommandQueue::getBcsCommandStreamReceiver() const {
return nullptr; return nullptr;
} }
CommandStreamReceiver &CommandQueue::getCommandStreamReceiverByCommandType(cl_command_type cmdType) const {
if (blitEnqueueAllowed(cmdType)) {
auto csr = getBcsCommandStreamReceiver();
UNRECOVERABLE_IF(!csr);
return *csr;
}
return getGpgpuCommandStreamReceiver();
}
Device &CommandQueue::getDevice() const noexcept { Device &CommandQueue::getDevice() const noexcept {
return device->getDevice(); return device->getDevice();
} }

View File

@ -222,6 +222,7 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
MOCKABLE_VIRTUAL CommandStreamReceiver &getGpgpuCommandStreamReceiver() const; MOCKABLE_VIRTUAL CommandStreamReceiver &getGpgpuCommandStreamReceiver() const;
CommandStreamReceiver *getBcsCommandStreamReceiver() const; CommandStreamReceiver *getBcsCommandStreamReceiver() const;
MOCKABLE_VIRTUAL CommandStreamReceiver &getCommandStreamReceiverByCommandType(cl_command_type cmdType) const;
Device &getDevice() const noexcept; Device &getDevice() const noexcept;
Context &getContext() const { return *context; } Context &getContext() const { return *context; }
Context *getContextPtr() const { return context; } Context *getContextPtr() const { return context; }

View File

@ -96,7 +96,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
} else { } else {
surfaces[1] = &hostPtrSurf; surfaces[1] = &hostPtrSurf;
if (size != 0) { if (size != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(hostPtrSurf, true); bool status = csr.createAllocationForHostSurface(hostPtrSurf, true);
if (!status) { if (!status) {
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;

View File

@ -66,7 +66,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBufferRect(
if (region[0] != 0 && if (region[0] != 0 &&
region[1] != 0 && region[1] != 0 &&
region[2] != 0) { region[2] != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(hostPtrSurf, true); bool status = csr.createAllocationForHostSurface(hostPtrSurf, true);
if (!status) { if (!status) {
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;

View File

@ -348,7 +348,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
HostPtrSurface dstHostPtrSurf(dstPtr, size); HostPtrSurface dstHostPtrSurf(dstPtr, size);
cmdType = CL_COMMAND_READ_BUFFER; cmdType = CL_COMMAND_READ_BUFFER;
if (size != 0) { if (size != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(dstHostPtrSurf, true); bool status = csr.createAllocationForHostSurface(dstHostPtrSurf, true);
if (!status) { if (!status) {
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
@ -371,7 +371,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
GeneralSurface dstSvmSurf(dstSvmData->gpuAllocation); GeneralSurface dstSvmSurf(dstSvmData->gpuAllocation);
cmdType = CL_COMMAND_WRITE_BUFFER; cmdType = CL_COMMAND_WRITE_BUFFER;
if (size != 0) { if (size != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(srcHostPtrSurf, false); bool status = csr.createAllocationForHostSurface(srcHostPtrSurf, false);
if (!status) { if (!status) {
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
@ -408,7 +408,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
HostPtrSurface dstHostPtrSurf(dstPtr, size); HostPtrSurface dstHostPtrSurf(dstPtr, size);
cmdType = CL_COMMAND_WRITE_BUFFER; cmdType = CL_COMMAND_WRITE_BUFFER;
if (size != 0) { if (size != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(srcHostPtrSurf, false); bool status = csr.createAllocationForHostSurface(srcHostPtrSurf, false);
status &= csr.createAllocationForHostSurface(dstHostPtrSurf, true); status &= csr.createAllocationForHostSurface(dstHostPtrSurf, true);
if (!status) { if (!status) {

View File

@ -93,7 +93,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
} else { } else {
surfaces[1] = &hostPtrSurf; surfaces[1] = &hostPtrSurf;
if (size != 0) { if (size != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(hostPtrSurf, false); bool status = csr.createAllocationForHostSurface(hostPtrSurf, false);
if (!status) { if (!status) {
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;

View File

@ -65,7 +65,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBufferRect(
if (region[0] != 0 && if (region[0] != 0 &&
region[1] != 0 && region[1] != 0 &&
region[2] != 0) { region[2] != 0) {
auto &csr = blitEnqueueAllowed(cmdType) ? *getBcsCommandStreamReceiver() : getGpgpuCommandStreamReceiver(); auto &csr = getCommandStreamReceiverByCommandType(cmdType);
bool status = csr.createAllocationForHostSurface(hostPtrSurf, false); bool status = csr.createAllocationForHostSurface(hostPtrSurf, false);
if (!status) { if (!status) {
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;

View File

@ -211,17 +211,23 @@ TEST(CommandQueue, givenDeviceWhenCreatingCommandQueueThenPickCsrFromDefaultEngi
EXPECT_EQ(defaultCsr, &cmdQ.getGpgpuCommandStreamReceiver()); EXPECT_EQ(defaultCsr, &cmdQ.getGpgpuCommandStreamReceiver());
} }
TEST(CommandQueue, givenDeviceNotSupportingBlitOperationsWhenQueueIsCreatedThenDontRegisterBcsCsr) { struct CommandQueueWithBlitOperationsTests : public ::testing::TestWithParam<uint32_t> {};
TEST_P(CommandQueueWithBlitOperationsTests, givenDeviceNotSupportingBlitOperationsWhenQueueIsCreatedThenDontRegisterBcsCsr) {
HardwareInfo hwInfo = *defaultHwInfo; HardwareInfo hwInfo = *defaultHwInfo;
hwInfo.capabilityTable.blitterOperationsSupported = false; hwInfo.capabilityTable.blitterOperationsSupported = false;
auto mockDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo)); auto mockDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
MockCommandQueue cmdQ(nullptr, mockDevice.get(), 0); MockCommandQueue cmdQ(nullptr, mockDevice.get(), 0);
auto cmdType = GetParam();
EXPECT_EQ(nullptr, cmdQ.getBcsCommandStreamReceiver()); EXPECT_EQ(nullptr, cmdQ.getBcsCommandStreamReceiver());
auto defaultCsr = mockDevice->getDefaultEngine().commandStreamReceiver;
EXPECT_EQ(defaultCsr, &cmdQ.getGpgpuCommandStreamReceiver());
EXPECT_EQ(defaultCsr, &cmdQ.getCommandStreamReceiverByCommandType(cmdType));
} }
using CommandQueueWithSubDevicesTest = ::testing::Test; HWTEST_P(CommandQueueWithBlitOperationsTests, givenDeviceWithSubDevicesSupportingBlitOperationsWhenQueueIsCreatedThenBcsIsTakenFromFirstSubDevice) {
HWTEST_F(CommandQueueWithSubDevicesTest, givenDeviceWithSubDevicesSupportingBlitOperationsWhenQueueIsCreatedThenBcsIsTakenFromFirstSubDevice) {
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
VariableBackup<bool> mockDeviceFlagBackup{&MockDevice::createSingleDevice, false}; VariableBackup<bool> mockDeviceFlagBackup{&MockDevice::createSingleDevice, false};
DebugManager.flags.CreateMultipleSubDevices.set(2); DebugManager.flags.CreateMultipleSubDevices.set(2);
@ -244,12 +250,24 @@ HWTEST_F(CommandQueueWithSubDevicesTest, givenDeviceWithSubDevicesSupportingBlit
auto bcsEngine = subDevice->getEngine(aub_stream::EngineType::ENGINE_BCS, false); auto bcsEngine = subDevice->getEngine(aub_stream::EngineType::ENGINE_BCS, false);
MockCommandQueue cmdQ(nullptr, device.get(), 0); MockCommandQueue cmdQ(nullptr, device.get(), 0);
auto cmdType = GetParam();
EXPECT_NE(nullptr, cmdQ.getBcsCommandStreamReceiver()); EXPECT_NE(nullptr, cmdQ.getBcsCommandStreamReceiver());
EXPECT_EQ(bcsEngine.commandStreamReceiver, cmdQ.getBcsCommandStreamReceiver()); EXPECT_EQ(bcsEngine.commandStreamReceiver, cmdQ.getBcsCommandStreamReceiver());
EXPECT_EQ(bcsEngine.osContext, &cmdQ.getBcsCommandStreamReceiver()->getOsContext()); EXPECT_EQ(bcsEngine.commandStreamReceiver, &cmdQ.getCommandStreamReceiverByCommandType(cmdType));
EXPECT_EQ(bcsEngine.osContext, &cmdQ.getCommandStreamReceiverByCommandType(cmdType).getOsContext());
} }
INSTANTIATE_TEST_CASE_P(uint32_t,
CommandQueueWithBlitOperationsTests,
::testing::Values(CL_COMMAND_WRITE_BUFFER,
CL_COMMAND_WRITE_BUFFER_RECT,
CL_COMMAND_READ_BUFFER,
CL_COMMAND_READ_BUFFER_RECT,
CL_COMMAND_COPY_BUFFER,
CL_COMMAND_COPY_BUFFER_RECT,
CL_COMMAND_SVM_MEMCPY));
TEST(CommandQueue, givenCmdQueueBlockedByReadyVirtualEventWhenUnblockingThenUpdateFlushTaskFromEvent) { TEST(CommandQueue, givenCmdQueueBlockedByReadyVirtualEventWhenUnblockingThenUpdateFlushTaskFromEvent) {
auto mockDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)); auto mockDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
auto context = new MockContext; auto context = new MockContext;