Skip to content

Commit

Permalink
fix: don't fail entire initialization when at least one device is com…
Browse files Browse the repository at this point in the history
…patible

Related-To: NEO-6683

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
  • Loading branch information
JablonskiMateusz authored and Compute-Runtime-Automation committed Nov 21, 2023
1 parent 490f1d9 commit f63dd1f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct RootDeviceEnvironment : NonCopyableClass {
bool isWddmOnLinux() const;

MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType);
bool initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex);
MOCKABLE_VIRTUAL bool initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex);
void initOsTime();
void initGmm();
void initDebuggerL0(Device *neoDevice);
Expand Down
8 changes: 7 additions & 1 deletion shared/source/os_interface/device_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,18 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv

for (auto &hwDeviceId : hwDeviceIds) {
if (initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceId), rootDeviceIndex) == false) {
return false;
continue;
}

rootDeviceIndex++;
}

executionEnvironment.rootDeviceEnvironments.resize(rootDeviceIndex);

if (rootDeviceIndex == 0) {
return false;
}

executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment.sortNeoDevices();
executionEnvironment.parseAffinityMask();
Expand Down
19 changes: 19 additions & 0 deletions shared/test/common/mocks/mock_execution_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "shared/test/common/fixtures/mock_aub_center_fixture.h"
#include "shared/test/common/helpers/default_hw_info.h"

#include "gtest/gtest.h"

namespace NEO {
extern bool useMockGmm;

Expand All @@ -24,6 +26,23 @@ void MockRootDeviceEnvironment::initAubCenter(bool localMemoryEnabled, const std
}
RootDeviceEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType);
}
bool MockRootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) {
initOsInterfaceCalled++;
if (!initOsInterfaceResults.empty()) {
auto retVal = initOsInterfaceResults[initOsInterfaceCalled - 1];
if (retVal) {
RootDeviceEnvironment::initOsInterface(std::move(hwDeviceId), rootDeviceIndex);
}
return retVal;
}
return RootDeviceEnvironment::initOsInterface(std::move(hwDeviceId), rootDeviceIndex);
}

MockRootDeviceEnvironment::~MockRootDeviceEnvironment() {
if (initOsInterfaceExpectedCallCount) {
EXPECT_EQ(*initOsInterfaceExpectedCallCount, initOsInterfaceCalled);
}
}

MockExecutionEnvironment::MockExecutionEnvironment() : MockExecutionEnvironment(defaultHwInfo.get()) {}
MockExecutionEnvironment::MockExecutionEnvironment(const HardwareInfo *hwInfo) : MockExecutionEnvironment(hwInfo, true, 1u) {
Expand Down
10 changes: 9 additions & 1 deletion shared/test/common/mocks/mock_execution_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"

#include <optional>

namespace NEO {

struct MockRootDeviceEnvironment : public RootDeviceEnvironment {
using BaseClass = RootDeviceEnvironment;
using RootDeviceEnvironment::hwInfo;
using RootDeviceEnvironment::isDummyAllocationInitialized;
using RootDeviceEnvironment::isWddmOnLinuxEnable;
using RootDeviceEnvironment::RootDeviceEnvironment;
~MockRootDeviceEnvironment() override = default;
~MockRootDeviceEnvironment() override;

void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) override;
bool initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) override;

std::vector<bool> initOsInterfaceResults;
uint32_t initOsInterfaceCalled = 0u;
std::optional<uint32_t> initOsInterfaceExpectedCallCount;
bool initAubCenterCalled = false;
bool localMemoryEnabledReceived = false;
std::string aubFileNameReceived = "";
Expand Down
53 changes: 53 additions & 0 deletions shared/test/unit_test/os_interface/device_factory_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,56 @@ TEST_F(DeviceFactoryTests, givenDisabledRcsWhenPrepareDeviceEnvironmentsCalledTh
EXPECT_NE(executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo()->featureTable.flags.ftrRcsNode, releaseHelper->isRcsExposureDisabled());
}
}

TEST_F(DeviceFactoryTests, givenMultipleDevicesWhenInitializeResourcesSucceedsForAtLeastOneDeviceThenSuccessIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleRootDevices.set(3);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 3u);

EXPECT_EQ(3u, executionEnvironment.rootDeviceEnvironments.size());
auto rootDeviceEnvironment0 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[0].get());
auto rootDeviceEnvironment1 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[1].get());
auto rootDeviceEnvironment2 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[2].get());

rootDeviceEnvironment0->initOsInterfaceResults.push_back(true);
rootDeviceEnvironment0->initOsInterfaceExpectedCallCount = 1u;

// making rootDeviceEnvironment1 returning false on first call and true on second call
rootDeviceEnvironment1->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment1->initOsInterfaceResults.push_back(true);
rootDeviceEnvironment1->initOsInterfaceExpectedCallCount = 2u;

rootDeviceEnvironment2->initOsInterfaceExpectedCallCount = 0u;

bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
ASSERT_TRUE(success);

EXPECT_EQ(2u, executionEnvironment.rootDeviceEnvironments.size());

EXPECT_EQ(1u, rootDeviceEnvironment0->initOsInterfaceCalled);
EXPECT_EQ(2u, rootDeviceEnvironment1->initOsInterfaceCalled);
}

TEST_F(DeviceFactoryTests, givenMultipleDevicesWhenInitializeResourcesFailsForAllDevicesThenFailureIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleRootDevices.set(3);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get(), true, 3u);

EXPECT_EQ(3u, executionEnvironment.rootDeviceEnvironments.size());
auto rootDeviceEnvironment0 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[0].get());
auto rootDeviceEnvironment1 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[1].get());
auto rootDeviceEnvironment2 = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[2].get());

// making root device environment failing three times (once per device)
rootDeviceEnvironment0->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment0->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment0->initOsInterfaceResults.push_back(false);
rootDeviceEnvironment0->initOsInterfaceExpectedCallCount = 3u;
rootDeviceEnvironment1->initOsInterfaceExpectedCallCount = 0u;
rootDeviceEnvironment2->initOsInterfaceExpectedCallCount = 0u;

bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_FALSE(success);

EXPECT_EQ(0u, executionEnvironment.rootDeviceEnvironments.size());
}

0 comments on commit f63dd1f

Please sign in to comment.