Skip to content

Commit 5f4f1eb

Browse files
Add helper function to detect if hw mode is selected
Related-To: NEO-4208 Change-Id: Iac34e9e9cea36d7ab354d7d5b5c716e8ea3a483d Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 2343cd7 commit 5f4f1eb

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

core/os_interface/device_factory.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(size_t &numDevices, Execu
6464
return true;
6565
}
6666

67+
bool DeviceFactory::isHwModeSelected() {
68+
int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get();
69+
switch (csr) {
70+
case CSR_AUB:
71+
case CSR_TBX:
72+
case CSR_TBX_WITH_AUB:
73+
return false;
74+
default:
75+
return true;
76+
}
77+
}
6778
} // namespace NEO

core/os_interface/device_factory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DeviceFactory {
1717
static bool getDevices(size_t &numDevices, ExecutionEnvironment &executionEnvironment);
1818
static bool getDevicesForProductFamilyOverride(size_t &numDevices, ExecutionEnvironment &executionEnvironment);
1919
static void releaseDevices();
20+
static bool isHwModeSelected();
2021

2122
protected:
2223
static size_t numDevices;

runtime/command_stream/create_command_stream_impl.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,10 @@ CommandStreamReceiver *createCommandStreamImpl(ExecutionEnvironment &executionEn
4848
}
4949

5050
bool getDevicesImpl(size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment) {
51-
bool result;
52-
int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get();
53-
if (csr < 0) {
54-
csr = CommandStreamReceiverType::CSR_HW;
55-
}
56-
switch (csr) {
57-
case CSR_HW:
58-
result = DeviceFactory::getDevices(numDevicesReturned, executionEnvironment);
59-
DEBUG_BREAK_IF(!result);
60-
return result;
61-
case CSR_AUB:
62-
case CSR_TBX:
63-
case CSR_TBX_WITH_AUB:
64-
return DeviceFactory::getDevicesForProductFamilyOverride(numDevicesReturned, executionEnvironment);
65-
case CSR_HW_WITH_AUB:
51+
if (DeviceFactory::isHwModeSelected()) {
6652
return DeviceFactory::getDevices(numDevicesReturned, executionEnvironment);
67-
default:
68-
return false;
6953
}
54+
return DeviceFactory::getDevicesForProductFamilyOverride(numDevicesReturned, executionEnvironment);
7055
}
7156

7257
} // namespace NEO

unit_tests/os_interface/device_factory_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,21 @@ TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAlloca
227227
EXPECT_TRUE(success);
228228
EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface);
229229
}
230+
231+
TEST(DeviceFactory, givenHwModeSelectedWhenIsHwModeSelectedIsCalledThenTrueIsReturned) {
232+
DebugManagerStateRestore stateRestore;
233+
constexpr int32_t hwModes[] = {-1, CommandStreamReceiverType::CSR_HW, CommandStreamReceiverType::CSR_HW_WITH_AUB};
234+
for (const auto &hwMode : hwModes) {
235+
DebugManager.flags.SetCommandStreamReceiver.set(hwMode);
236+
EXPECT_TRUE(DeviceFactory::isHwModeSelected());
237+
}
238+
}
239+
240+
TEST(DeviceFactory, givenNonHwModeSelectedWhenIsHwModeSelectedIsCalledThenFalseIsReturned) {
241+
DebugManagerStateRestore stateRestore;
242+
constexpr int32_t nonHwModes[] = {CommandStreamReceiverType::CSR_AUB, CommandStreamReceiverType::CSR_TBX, CommandStreamReceiverType::CSR_TBX_WITH_AUB};
243+
for (const auto &nonHwMode : nonHwModes) {
244+
DebugManager.flags.SetCommandStreamReceiver.set(nonHwMode);
245+
EXPECT_FALSE(DeviceFactory::isHwModeSelected());
246+
}
247+
}

0 commit comments

Comments
 (0)