From 11f76befda6d75f326a0fd52f5ce7784467e9c75 Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Fri, 6 Mar 2020 19:02:24 +0100 Subject: [PATCH] Limit direct submission to default context by default Change-Id: I274d402eead87afca634d3b876fe500777910f96 Signed-off-by: Zbigniew Zdanowicz --- .../windows/wddm_device_command_stream.inl | 3 ++ opencl/test/unit_test/device/device_tests.cpp | 7 ++++ .../os_interface/os_context_tests.cpp | 8 ++++ .../windows/device_command_stream_tests.cpp | 40 +++++++++++++++++++ shared/source/device/device.cpp | 15 +++++-- .../direct_submission_properties.h | 3 +- shared/source/os_interface/os_context.h | 3 ++ .../direct_submission_tests.cpp | 4 +- 8 files changed, 76 insertions(+), 7 deletions(-) diff --git a/opencl/source/os_interface/windows/wddm_device_command_stream.inl b/opencl/source/os_interface/windows/wddm_device_command_stream.inl index bc9c9110a9..00fe0b8d44 100644 --- a/opencl/source/os_interface/windows/wddm_device_command_stream.inl +++ b/opencl/source/os_interface/windows/wddm_device_command_stream.inl @@ -163,6 +163,9 @@ bool WddmCommandStreamReceiver::initDirectSubmission(Device &device, device.getHardwareInfo().capabilityTable.directSubmissionEngines.data[contextEngineType]; bool startDirect = true; + if (!osContext.isDefaultContext()) { + startDirect = directSubmissionProperty.useNonDefault; + } if (osContext.isLowPriority()) { startDirect = directSubmissionProperty.useLowPriority; } diff --git a/opencl/test/unit_test/device/device_tests.cpp b/opencl/test/unit_test/device/device_tests.cpp index 9d3a27091c..4a659f0570 100644 --- a/opencl/test/unit_test/device/device_tests.cpp +++ b/opencl/test/unit_test/device/device_tests.cpp @@ -353,3 +353,10 @@ TEST(DeviceGenEngineTest, whenCreateDeviceThenInternalEngineHasDefaultType) { auto defaultEngineType = getChosenEngineType(device->getHardwareInfo()); EXPECT_EQ(defaultEngineType, internalEngineType); } + +TEST(DeviceGenEngineTest, givenCreatedDeviceWhenRetrievingDefaultEngineThenOsContextHasDefaultFieldSet) { + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + auto &defaultEngine = device->getDefaultEngine(); + EXPECT_TRUE(defaultEngine.osContext->isDefaultContext()); +} diff --git a/opencl/test/unit_test/os_interface/os_context_tests.cpp b/opencl/test/unit_test/os_interface/os_context_tests.cpp index d2ba7538e8..6eaf94c5f9 100644 --- a/opencl/test/unit_test/os_interface/os_context_tests.cpp +++ b/opencl/test/unit_test/os_interface/os_context_tests.cpp @@ -27,3 +27,11 @@ TEST(OSContext, givenLowPriorityRootDeviceInternalAreTrueWhenCreatingDefaultOsCo EXPECT_TRUE(osContext->isRootDevice()); delete osContext; } + +TEST(OSContext, givenOsContextCreatedDefaultIsFalseWhenSettingTrueThenFlagTrueReturned) { + OsContext *osContext = OsContext::create(nullptr, 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false); + EXPECT_FALSE(osContext->isDefaultContext()); + osContext->setDefaultContext(true); + EXPECT_TRUE(osContext->isDefaultContext()); + delete osContext; +} diff --git a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp index 2c1c497b09..a964c78762 100644 --- a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp @@ -69,6 +69,7 @@ class WddmCommandStreamFixture { osContext.reset(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::ThreadGroup, false, false, false)); + osContext->setDefaultContext(true); csr = new WddmCommandStreamReceiver(*executionEnvironment, 0); device.reset(MockDevice::create(executionEnvironment, 0u)); @@ -969,6 +970,7 @@ TEST_F(WddmCommandStreamTest, whenDirectSubmissionEnabledOnBcsThenExpectFeatureA osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, 0, aub_stream::ENGINE_BCS, PreemptionMode::ThreadGroup, false, false, false)); + osContext->setDefaultContext(true); auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_BCS].engineSupported = true; @@ -984,6 +986,7 @@ TEST_F(WddmCommandStreamTest, givenDirectSubmissionEnabledWhenPlatformNotSupport osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, 0, aub_stream::ENGINE_BCS, PreemptionMode::ThreadGroup, false, false, false)); + osContext->setDefaultContext(true); auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_BCS].engineSupported = false; @@ -999,6 +1002,7 @@ TEST_F(WddmCommandStreamTest, givenLowPriorityContextWhenDirectSubmissionDisable osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::ThreadGroup, true, false, false)); + osContext->setDefaultContext(true); auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -1030,6 +1034,7 @@ TEST_F(WddmCommandStreamTest, givenInternalContextWhenDirectSubmissionDisabledOn osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::ThreadGroup, false, true, false)); + osContext->setDefaultContext(true); auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -1062,6 +1067,7 @@ TEST_F(WddmCommandStreamTest, givenRootDeviceContextWhenDirectSubmissionDisabled osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::ThreadGroup, false, false, true)); + osContext->setDefaultContext(true); auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -1087,3 +1093,37 @@ TEST_F(WddmCommandStreamTest, givenRootDeviceContextWhenDirectSubmissionEnabledO EXPECT_TRUE(ret); EXPECT_TRUE(csr->isDirectSubmissionEnabled()); } + +TEST_F(WddmCommandStreamTest, givenNonDefaultContextWhenDirectSubmissionDisabledOnNonDefaultThenExpectFeatureNotAvailable) { + DebugManager.flags.EnableDirectSubmission.set(1); + + osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), + 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::ThreadGroup, + false, false, false)); + osContext->setDefaultContext(false); + + auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); + hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; + hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].useNonDefault = false; + + bool ret = csr->initDirectSubmission(*device.get(), *osContext.get()); + EXPECT_TRUE(ret); + EXPECT_FALSE(csr->isDirectSubmissionEnabled()); +} + +TEST_F(WddmCommandStreamTest, givenNonDefaultContextContextWhenDirectSubmissionEnabledOnNonDefaultContextThenExpectFeatureAvailable) { + DebugManager.flags.EnableDirectSubmission.set(1); + + osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), + 0, 0, aub_stream::ENGINE_RCS, PreemptionMode::ThreadGroup, + false, false, false)); + osContext->setDefaultContext(false); + + auto hwInfo = device->getExecutionEnvironment()->getMutableHardwareInfo(); + hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; + hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].useNonDefault = true; + + bool ret = csr->initDirectSubmission(*device.get(), *osContext.get()); + EXPECT_TRUE(ret); + EXPECT_TRUE(csr->isDirectSubmissionEnabled()); +} diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 9fc75834ab..f5a40dc77a 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -62,6 +62,17 @@ bool Device::createDeviceImpl() { if (!createEngines()) { return false; } + + getDefaultEngine().osContext->setDefaultContext(true); + + for (auto &engine : engines) { + auto commandStreamReceiver = engine.commandStreamReceiver; + auto osContext = engine.osContext; + if (!commandStreamReceiver->initDirectSubmission(*this, *osContext)) { + return false; + } + } + executionEnvironment->memoryManager->setDefaultEngineIndex(defaultEngineIndex); auto osInterface = getRootDeviceEnvironment().osInterface.get(); @@ -144,10 +155,6 @@ bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engine return false; } - if (!commandStreamReceiver->initDirectSubmission(*this, *osContext)) { - return false; - } - engines.push_back({commandStreamReceiver.get(), osContext}); commandStreamReceivers.push_back(std::move(commandStreamReceiver)); diff --git a/shared/source/direct_submission/direct_submission_properties.h b/shared/source/direct_submission/direct_submission_properties.h index 8a45deec1b..ba484f0d75 100644 --- a/shared/source/direct_submission/direct_submission_properties.h +++ b/shared/source/direct_submission/direct_submission_properties.h @@ -15,9 +15,10 @@ namespace NEO { struct DirectSubmissionProperties { bool engineSupported = false; bool submitOnInit = false; + bool useNonDefault = false; + bool useRootDevice = false; bool useInternal = false; bool useLowPriority = false; - bool useRootDevice = false; }; using EngineDirectSubmissionInitVec = std::vector>; diff --git a/shared/source/os_interface/os_context.h b/shared/source/os_interface/os_context.h index d071fbafb7..284bdffa7a 100644 --- a/shared/source/os_interface/os_context.h +++ b/shared/source/os_interface/os_context.h @@ -33,6 +33,8 @@ class OsContext : public ReferenceTrackedObject { bool isInternalEngine() const { return internalEngine; } bool isRootDevice() const { return rootDevice; } virtual bool isInitialized() const { return true; } + bool isDefaultContext() const { return defaultContext; } + void setDefaultContext(bool value) { defaultContext = value; } protected: OsContext(uint32_t contextId, DeviceBitfield deviceBitfield, aub_stream::EngineType engineType, PreemptionMode preemptionMode, @@ -54,5 +56,6 @@ class OsContext : public ReferenceTrackedObject { const bool lowPriority = false; const bool internalEngine = false; const bool rootDevice = false; + bool defaultContext = false; }; } // namespace NEO diff --git a/shared/test/unit_test/direct_submission/direct_submission_tests.cpp b/shared/test/unit_test/direct_submission/direct_submission_tests.cpp index 87ea05efb5..c42e456d72 100644 --- a/shared/test/unit_test/direct_submission/direct_submission_tests.cpp +++ b/shared/test/unit_test/direct_submission/direct_submission_tests.cpp @@ -617,6 +617,6 @@ HWTEST_F(DirectSubmissionTest, givenDirectSubmissionAvailableWhenProgrammingEndi HWTEST_F(DirectSubmissionTest, whenInitDirectSubmissionFailThenEngineIsNotCreated) { VariableBackup backup(&ultHwConfig); ultHwConfig.csrFailInitDirectSubmission = true; - bool ret = pDevice->createEngine(0u, aub_stream::ENGINE_RCS); - EXPECT_FALSE(ret); + auto device = MockDevice::createWithNewExecutionEnvironment(&hardwareInfo); + EXPECT_EQ(nullptr, device); }