Implement UUID using pcie bdf

This patch implements the fallback method for Device UUID
using the BDF of the device for all product families.


Related-To: LOCI-2827

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2021-12-20 12:58:34 +00:00
committed by Compute-Runtime-Automation
parent 40ea30be0b
commit 7fc9b2c3dc
6 changed files with 228 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -271,6 +271,11 @@ bool Device::createDeviceImpl() {
if (!isEngineInstanced()) {
auto hardwareInfo = getRootDeviceEnvironment().getMutableHardwareInfo();
uuid.isValid = HwInfoConfig::get(hardwareInfo->platform.eProductFamily)->getUuid(this, uuid.id);
if (!uuid.isValid && getRootDeviceEnvironment().osInterface != nullptr) {
PhysicalDevicePciBusInfo pciBusInfo = getRootDeviceEnvironment().osInterface->getDriverModel()->getPciBusInfo();
uuid.isValid = generateUuidFromPciBusInfo(pciBusInfo, uuid.id);
}
}
return true;
@@ -646,8 +651,28 @@ OSTime *Device::getOSTime() const { return getRootDeviceEnvironment().osTime.get
bool Device::getUuid(std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) {
if (this->uuid.isValid) {
uuid = this->uuid.id;
if (!isSubDevice() && deviceBitfield.count() == 1) {
// In case of no sub devices created (bits set in affinity mask == 1), return the UUID of enabled sub-device.
uint32_t subDeviceIndex = Math::log2(static_cast<uint32_t>(deviceBitfield.to_ulong()));
uuid[HwInfoConfig::uuidSize - 1] = subDeviceIndex + 1;
}
}
return this->uuid.isValid;
}
bool Device::generateUuidFromPciBusInfo(const PhysicalDevicePciBusInfo &pciBusInfo, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) {
if (pciBusInfo.pciDomain != PhysicalDevicePciBusInfo::InvalidValue) {
uuid.fill(0);
memcpy_s(&uuid[0], 2, &pciBusInfo.pciDomain, 2);
memcpy_s(&uuid[2], 1, &pciBusInfo.pciBus, 1);
memcpy_s(&uuid[3], 1, &pciBusInfo.pciDevice, 1);
memcpy_s(&uuid[4], 1, &pciBusInfo.pciFunction, 1);
uuid[HwInfoConfig::uuidSize - 1] = isSubDevice() ? static_cast<SubDevice *>(this)->getSubDeviceIndex() + 1 : 0;
return true;
}
return false;
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -24,6 +24,7 @@ namespace NEO {
class OSTime;
class SourceLevelDebugger;
class SubDevice;
struct PhysicalDevicePciBusInfo;
struct SelectorCopyEngine : NonCopyableOrMovableClass {
std::atomic<bool> isMainUsed = false;
@@ -200,6 +201,7 @@ class Device : public ReferenceTrackedObject<Device> {
bool isValid = false;
std::array<uint8_t, HwInfoConfig::uuidSize> id;
} uuid;
bool generateUuidFromPciBusInfo(const PhysicalDevicePciBusInfo &pciBusInfo, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid);
};
inline EngineControl &Device::getDefaultEngine() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -184,8 +184,8 @@ class MemoryManager {
const ExecutionEnvironment &peekExecutionEnvironment() const { return executionEnvironment; }
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
const EngineDescriptor &engineDescriptor);
MOCKABLE_VIRTUAL OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
const EngineDescriptor &engineDescriptor);
uint32_t getRegisteredEnginesCount() const { return static_cast<uint32_t>(registeredEngines.size()); }
EngineControlContainer &getRegisteredEngines();
EngineControl *getRegisteredEngineForCsr(CommandStreamReceiver *commandStreamReceiver);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -83,6 +83,7 @@ class HwInfoConfig {
virtual bool isDcFlushAllowed() const = 0;
virtual uint32_t computeMaxNeededSubSliceSpace(const HardwareInfo &hwInfo) const = 0;
virtual bool getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const = 0;
MOCKABLE_VIRTUAL ~HwInfoConfig() = default;
protected:
virtual LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const = 0;

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2019-2021 Intel Corporation
# Copyright (C) 2019-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -10,5 +10,15 @@ set(NEO_CORE_OS_INTERFACE_AUB_TESTS
${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler_tests.h
)
set(NEO_CORE_OS_INTERFACE_TESTS
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/device_uuid_tests.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS ${NEO_CORE_OS_INTERFACE_TESTS})
target_sources(${TARGET_NAME} PRIVATE
${NEO_CORE_OS_INTERFACE_TESTS}
)
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_AUB_TESTS ${NEO_CORE_OS_INTERFACE_AUB_TESTS})
add_subdirectories()

View File

@@ -0,0 +1,183 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/ult_hw_config.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/test.h"
namespace NEO {
class MockMemoryManagerOsAgnosticContext : public MockMemoryManager {
public:
MockMemoryManagerOsAgnosticContext(ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
OsContext *createAndRegisterOsContext(CommandStreamReceiver *commandStreamReceiver,
const EngineDescriptor &engineDescriptor) {
auto osContext = new OsContext(0, engineDescriptor);
osContext->incRefInternal();
registeredEngines.emplace_back(commandStreamReceiver, osContext);
return osContext;
}
};
struct MockDriverModel : NEO::DriverModel {
PhysicalDevicePciBusInfo pciBusInfo{};
MockDriverModel() : NEO::DriverModel(NEO::DriverModelType::UNKNOWN) {}
void setGmmInputArgs(void *args) override {}
uint32_t getDeviceHandle() const override { return {}; }
PhysicalDevicePciBusInfo getPciBusInfo() const override { return pciBusInfo; }
size_t getMaxMemAllocSize() const override {
return 0;
}
};
template <PRODUCT_FAMILY gfxProduct>
class MockHwInfoConfigHw : public HwInfoConfigHw<gfxProduct> {
public:
bool getUuid(Device *device, std::array<uint8_t, HwInfoConfig::uuidSize> &uuid) const {
return false;
}
};
struct MultipleDeviceBdfUuidTest : public ::testing::Test {
std::unique_ptr<UltDeviceFactory> createDevices(PhysicalDevicePciBusInfo &pciBusInfo, uint32_t numSubDevices) {
std::unique_ptr<MockDriverModel> mockDriverModel = std::make_unique<MockDriverModel>();
mockDriverModel->pciBusInfo = pciBusInfo;
DebugManager.flags.CreateMultipleSubDevices.set(numSubDevices);
ExecutionEnvironment *executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 1);
executionEnvironment->parseAffinityMask();
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new OSInterface);
executionEnvironment->memoryManager.reset(new MockMemoryManagerOsAgnosticContext(*executionEnvironment));
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(mockDriverModel));
return std::make_unique<UltDeviceFactory>(1, numSubDevices, *executionEnvironment);
}
template <PRODUCT_FAMILY gfxProduct>
void setupMockHwInfoConfig() {
mockHwInfoConfig.reset(new MockHwInfoConfigHw<gfxProduct>());
}
DebugManagerStateRestore restorer;
std::unique_ptr<HwInfoConfig> mockHwInfoConfig = nullptr;
};
HWTEST2_F(MultipleDeviceBdfUuidTest, GivenValidBdfWithCombinationOfAffinityMaskThenUuidIsCorrectForRootAndSubDevices, MatchAny) {
setupMockHwInfoConfig<productFamily>();
VariableBackup<HwInfoConfig *> backupHwInfoConfig(&hwInfoConfigFactory[productFamily], mockHwInfoConfig.get());
DebugManager.flags.ZE_AFFINITY_MASK.set("0.0,0.2,0.3");
PhysicalDevicePciBusInfo pciBusInfo(0x00, 0x34, 0xab, 0xcd);
const auto deviceFactory = createDevices(pciBusInfo, 4);
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {0x00, 0x00, 0x34, 0xab,
0xcd, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0};
EXPECT_EQ(true, deviceFactory->rootDevices[0]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
const auto &subDevices = deviceFactory->rootDevices[0]->getSubDevices();
ASSERT_EQ(subDevices.size(), 4u);
expectedUuid[15] = 1;
ASSERT_NE(subDevices[0], nullptr);
EXPECT_EQ(true, subDevices[0]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
expectedUuid[15] = 3;
ASSERT_NE(subDevices[2], nullptr);
EXPECT_EQ(true, subDevices[2]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
expectedUuid[15] = 4;
ASSERT_NE(subDevices[3], nullptr);
EXPECT_EQ(true, subDevices[3]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
}
HWTEST2_F(MultipleDeviceBdfUuidTest, GivenDefaultAffinityMaskWhenRetrievingDeviceUuidFromBdfThenCorrectUuidIsRetrieved, MatchAny) {
setupMockHwInfoConfig<productFamily>();
VariableBackup<HwInfoConfig *> backupHwInfoConfig(&hwInfoConfigFactory[productFamily], mockHwInfoConfig.get());
std::array<uint8_t, 16> uuid;
const uint32_t numSubDevices = 2;
uint8_t expectedUuid[16] = {0xad, 0x54, 0x34, 0xab,
0xcd, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0};
DebugManager.flags.ZE_AFFINITY_MASK.set("default");
PhysicalDevicePciBusInfo pciBusInfo(0x54ad, 0x34, 0xab, 0xcd);
const auto deviceFactory = createDevices(pciBusInfo, numSubDevices);
EXPECT_EQ(true, deviceFactory->rootDevices[0]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
const auto &subDevices = deviceFactory->rootDevices[0]->getSubDevices();
for (auto i = 0u; i < numSubDevices; i++) {
expectedUuid[15] = i + 1;
EXPECT_EQ(true, subDevices[i]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
}
}
HWTEST2_F(MultipleDeviceBdfUuidTest, GivenIncorrectBdfWhenRetrievingDeviceUuidFromBdfThenUuidIsNotRetrieved, MatchAny) {
setupMockHwInfoConfig<productFamily>();
VariableBackup<HwInfoConfig *> backupHwInfoConfig(&hwInfoConfigFactory[productFamily], mockHwInfoConfig.get());
PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::InvalidValue,
PhysicalDevicePciBusInfo::InvalidValue,
PhysicalDevicePciBusInfo::InvalidValue,
PhysicalDevicePciBusInfo::InvalidValue);
const auto deviceFactory = createDevices(pciBusInfo, 2);
std::array<uint8_t, 16> uuid;
EXPECT_EQ(false, deviceFactory->rootDevices[0]->getUuid(uuid));
}
HWTEST2_F(MultipleDeviceBdfUuidTest, GivenNoSubDevicesInAffinityMaskwhenRetrievingDeviceUuidFromBdfThenUuidOfRootDeviceIsRetrieved, MatchAny) {
setupMockHwInfoConfig<productFamily>();
VariableBackup<HwInfoConfig *> backupHwInfoConfig(&hwInfoConfigFactory[productFamily], mockHwInfoConfig.get());
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {0x00, 0x00, 0x34, 0xab,
0xcd, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0};
DebugManager.flags.ZE_AFFINITY_MASK.set("0");
PhysicalDevicePciBusInfo pciBusInfo(0x00, 0x34, 0xab, 0xcd);
const auto deviceFactory = createDevices(pciBusInfo, 2);
EXPECT_EQ(true, deviceFactory->rootDevices[0]->getUuid(uuid));
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
}
HWTEST2_F(MultipleDeviceBdfUuidTest, GivenValidBdfWithOneBitEnabledInAffinityMaskThenUuidOfRootDeviceIsBasedOnAffinityMask, MatchAny) {
setupMockHwInfoConfig<productFamily>();
VariableBackup<HwInfoConfig *> backupHwInfoConfig(&hwInfoConfigFactory[productFamily], mockHwInfoConfig.get());
DebugManager.flags.ZE_AFFINITY_MASK.set("0.3");
PhysicalDevicePciBusInfo pciBusInfo(0x00, 0x34, 0xab, 0xcd);
const auto deviceFactory = createDevices(pciBusInfo, 4);
std::array<uint8_t, 16> uuid;
uint8_t expectedUuid[16] = {0x00, 0x00, 0x34, 0xab,
0xcd, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0};
EXPECT_EQ(true, deviceFactory->rootDevices[0]->getUuid(uuid));
expectedUuid[15] = 4;
EXPECT_TRUE(0 == std::memcmp(uuid.data(), expectedUuid, sizeof(expectedUuid)));
}
} // namespace NEO