From 5f4f1eb55a1e6ac79f742441dbecb61b991c164e Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 7 Feb 2020 09:00:25 +0100 Subject: [PATCH] Add helper function to detect if hw mode is selected Related-To: NEO-4208 Change-Id: Iac34e9e9cea36d7ab354d7d5b5c716e8ea3a483d Signed-off-by: Mateusz Jablonski --- core/os_interface/device_factory.cpp | 11 +++++++++++ core/os_interface/device_factory.h | 1 + .../create_command_stream_impl.cpp | 19 ++----------------- .../os_interface/device_factory_tests.cpp | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/core/os_interface/device_factory.cpp b/core/os_interface/device_factory.cpp index c83b1c65fc..31f6314a3e 100644 --- a/core/os_interface/device_factory.cpp +++ b/core/os_interface/device_factory.cpp @@ -64,4 +64,15 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(size_t &numDevices, Execu return true; } +bool DeviceFactory::isHwModeSelected() { + int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get(); + switch (csr) { + case CSR_AUB: + case CSR_TBX: + case CSR_TBX_WITH_AUB: + return false; + default: + return true; + } +} } // namespace NEO diff --git a/core/os_interface/device_factory.h b/core/os_interface/device_factory.h index 5ffabc057d..ca2e06b5c9 100644 --- a/core/os_interface/device_factory.h +++ b/core/os_interface/device_factory.h @@ -17,6 +17,7 @@ class DeviceFactory { static bool getDevices(size_t &numDevices, ExecutionEnvironment &executionEnvironment); static bool getDevicesForProductFamilyOverride(size_t &numDevices, ExecutionEnvironment &executionEnvironment); static void releaseDevices(); + static bool isHwModeSelected(); protected: static size_t numDevices; diff --git a/runtime/command_stream/create_command_stream_impl.cpp b/runtime/command_stream/create_command_stream_impl.cpp index b02cb6e473..91681ca367 100644 --- a/runtime/command_stream/create_command_stream_impl.cpp +++ b/runtime/command_stream/create_command_stream_impl.cpp @@ -48,25 +48,10 @@ CommandStreamReceiver *createCommandStreamImpl(ExecutionEnvironment &executionEn } bool getDevicesImpl(size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment) { - bool result; - int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get(); - if (csr < 0) { - csr = CommandStreamReceiverType::CSR_HW; - } - switch (csr) { - case CSR_HW: - result = DeviceFactory::getDevices(numDevicesReturned, executionEnvironment); - DEBUG_BREAK_IF(!result); - return result; - case CSR_AUB: - case CSR_TBX: - case CSR_TBX_WITH_AUB: - return DeviceFactory::getDevicesForProductFamilyOverride(numDevicesReturned, executionEnvironment); - case CSR_HW_WITH_AUB: + if (DeviceFactory::isHwModeSelected()) { return DeviceFactory::getDevices(numDevicesReturned, executionEnvironment); - default: - return false; } + return DeviceFactory::getDevicesForProductFamilyOverride(numDevicesReturned, executionEnvironment); } } // namespace NEO diff --git a/unit_tests/os_interface/device_factory_tests.cpp b/unit_tests/os_interface/device_factory_tests.cpp index 2f26fa0ef0..7cabea537d 100644 --- a/unit_tests/os_interface/device_factory_tests.cpp +++ b/unit_tests/os_interface/device_factory_tests.cpp @@ -227,3 +227,21 @@ TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAlloca EXPECT_TRUE(success); EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface); } + +TEST(DeviceFactory, givenHwModeSelectedWhenIsHwModeSelectedIsCalledThenTrueIsReturned) { + DebugManagerStateRestore stateRestore; + constexpr int32_t hwModes[] = {-1, CommandStreamReceiverType::CSR_HW, CommandStreamReceiverType::CSR_HW_WITH_AUB}; + for (const auto &hwMode : hwModes) { + DebugManager.flags.SetCommandStreamReceiver.set(hwMode); + EXPECT_TRUE(DeviceFactory::isHwModeSelected()); + } +} + +TEST(DeviceFactory, givenNonHwModeSelectedWhenIsHwModeSelectedIsCalledThenFalseIsReturned) { + DebugManagerStateRestore stateRestore; + constexpr int32_t nonHwModes[] = {CommandStreamReceiverType::CSR_AUB, CommandStreamReceiverType::CSR_TBX, CommandStreamReceiverType::CSR_TBX_WITH_AUB}; + for (const auto &nonHwMode : nonHwModes) { + DebugManager.flags.SetCommandStreamReceiver.set(nonHwMode); + EXPECT_FALSE(DeviceFactory::isHwModeSelected()); + } +} \ No newline at end of file