feature: supports core device handle with zesInit
Related-To: NEO-13805 Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
This commit is contained in:
parent
83637404bf
commit
f52c81c0e4
|
@ -24,6 +24,7 @@ struct OsSysman {
|
|||
static OsSysman *create(SysmanDeviceImp *pSysmanImp);
|
||||
virtual uint32_t getSubDeviceCount() = 0;
|
||||
virtual const NEO::HardwareInfo &getHardwareInfo() const = 0;
|
||||
virtual void getDeviceUuids(std::vector<std::string> &deviceUuids) = 0;
|
||||
};
|
||||
|
||||
} // namespace Sysman
|
||||
|
|
|
@ -34,8 +34,7 @@ SysmanDevice *SysmanDevice::fromHandle(zes_device_handle_t handle) {
|
|||
return nullptr;
|
||||
}
|
||||
if (std::find(globalSysmanDriver->sysmanDevices.begin(), globalSysmanDriver->sysmanDevices.end(), sysmanDevice) == globalSysmanDriver->sysmanDevices.end()) {
|
||||
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "SysmanDevice::fromHandle: Device not found in sysmanDevices list%s\n", "");
|
||||
return nullptr;
|
||||
return globalSysmanDriver->getSysmanDeviceFromCoreDeviceHandle(handle);
|
||||
}
|
||||
return sysmanDevice;
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@ struct SysmanDevice : _ze_device_handle_t {
|
|||
static ze_result_t deviceEnumEnabledVF(zes_device_handle_t hDevice, uint32_t *pCount, zes_vf_handle_t *phVFhandle);
|
||||
|
||||
virtual OsSysman *deviceGetOsInterface() = 0;
|
||||
virtual void getDeviceUuids(std::vector<std::string> &deviceUuids) = 0;
|
||||
};
|
||||
|
||||
} // namespace Sysman
|
||||
|
|
|
@ -211,6 +211,10 @@ ze_result_t SysmanDeviceImp::fabricPortGetMultiPortThroughput(uint32_t numPorts,
|
|||
return pFabricPortHandleContext->fabricPortGetMultiPortThroughput(numPorts, phPort, pThroughput);
|
||||
}
|
||||
|
||||
void SysmanDeviceImp::getDeviceUuids(std::vector<std::string> &deviceUuids) {
|
||||
return pOsSysman->getDeviceUuids(deviceUuids);
|
||||
}
|
||||
|
||||
OsSysman *SysmanDeviceImp::deviceGetOsInterface() {
|
||||
return pOsSysman;
|
||||
}
|
||||
|
|
|
@ -93,8 +93,8 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableAndNonMovableClass {
|
|||
bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
|
||||
ze_result_t fabricPortGetMultiPortThroughput(uint32_t numPorts, zes_fabric_port_handle_t *phPort, zes_fabric_port_throughput_t **pThroughput) override;
|
||||
ze_result_t deviceEnumEnabledVF(uint32_t *pCount, zes_vf_handle_t *phVFhandle) override;
|
||||
|
||||
OsSysman *deviceGetOsInterface() override;
|
||||
void getDeviceUuids(std::vector<std::string> &deviceUuids) override;
|
||||
|
||||
private:
|
||||
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
|
|
|
@ -28,11 +28,55 @@ struct SysmanDriverHandleImp *globalSysmanDriver;
|
|||
|
||||
SysmanDriverHandleImp::SysmanDriverHandleImp() = default;
|
||||
|
||||
void SysmanDriverHandleImp::updateUuidMap(SysmanDevice *sysmanDevice) {
|
||||
std::vector<std::string> uuidArr;
|
||||
sysmanDevice->getDeviceUuids(uuidArr);
|
||||
for (auto &uuid : uuidArr) {
|
||||
uuidDeviceMap[uuid] = sysmanDevice;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SysmanDevice *SysmanDriverHandleImp::findSysmanDeviceFromCoreToSysmanDeviceMap(ze_device_handle_t handle) {
|
||||
auto iterator = coreToSysmanDeviceMap.find(handle);
|
||||
if (iterator != coreToSysmanDeviceMap.end()) {
|
||||
SysmanDevice *sysmanDevice = iterator->second;
|
||||
return sysmanDevice;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SysmanDevice *SysmanDriverHandleImp::getSysmanDeviceFromCoreDeviceHandle(ze_device_handle_t hDevice) {
|
||||
const std::lock_guard<std::mutex> lock(this->coreToSysmanDeviceMapLock);
|
||||
if (hDevice == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SysmanDevice *sysmanDevice = findSysmanDeviceFromCoreToSysmanDeviceMap(hDevice);
|
||||
if (sysmanDevice != nullptr) {
|
||||
return sysmanDevice;
|
||||
}
|
||||
|
||||
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
|
||||
Device::fromHandle(hDevice)->getProperties(&deviceProperties);
|
||||
std::string uuid(reinterpret_cast<char const *>(deviceProperties.uuid.id));
|
||||
auto it = uuidDeviceMap.find(uuid);
|
||||
if (it == uuidDeviceMap.end()) {
|
||||
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "SysmanDriverHandleImp::getSysmanDeviceFromCoreDeviceHandle() - sysman device handle equivalent to core device handle not found!! %s\n", "");
|
||||
return nullptr;
|
||||
}
|
||||
sysmanDevice = it->second;
|
||||
coreToSysmanDeviceMap[hDevice] = sysmanDevice;
|
||||
|
||||
return sysmanDevice;
|
||||
}
|
||||
|
||||
ze_result_t SysmanDriverHandleImp::initialize(NEO::ExecutionEnvironment &executionEnvironment) {
|
||||
for (uint32_t rootDeviceIndex = 0u; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) {
|
||||
auto pSysmanDevice = SysmanDevice::create(executionEnvironment, rootDeviceIndex);
|
||||
if (pSysmanDevice != nullptr) {
|
||||
this->sysmanDevices.push_back(pSysmanDevice);
|
||||
updateUuidMap(pSysmanDevice);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
#include "level_zero/sysman/source/driver/sysman_driver_handle.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -29,6 +30,16 @@ struct SysmanDriverHandleImp : SysmanDriverHandle {
|
|||
uint32_t numDevices = 0;
|
||||
ze_result_t getExtensionFunctionAddress(const char *pFuncName, void **pfunc) override;
|
||||
struct OsSysmanDriver *pOsSysmanDriver = nullptr;
|
||||
SysmanDevice *getSysmanDeviceFromCoreDeviceHandle(ze_device_handle_t hDevice);
|
||||
|
||||
private:
|
||||
void updateUuidMap(SysmanDevice *sysmanDevice);
|
||||
SysmanDevice *findSysmanDeviceFromCoreToSysmanDeviceMap(ze_device_handle_t handle);
|
||||
std::mutex coreToSysmanDeviceMapLock;
|
||||
std::unordered_map<ze_device_handle_t, SysmanDevice *> coreToSysmanDeviceMap;
|
||||
|
||||
protected:
|
||||
std::unordered_map<std::string, SysmanDevice *> uuidDeviceMap;
|
||||
};
|
||||
|
||||
extern struct SysmanDriverHandleImp *globalSysmanDriver;
|
||||
|
|
|
@ -496,6 +496,100 @@ bool LinuxSysmanImp::getTelemData(uint32_t subDeviceId, std::string &telemDir, s
|
|||
return true;
|
||||
}
|
||||
|
||||
void LinuxSysmanImp::getDeviceUuids(std::vector<std::string> &deviceUuids) {
|
||||
constexpr uint32_t rootDeviceCount = 1;
|
||||
uint32_t totalUuidCountForDevice = this->getSubDeviceCount() + rootDeviceCount;
|
||||
deviceUuids.clear();
|
||||
for (uint32_t index = 0; index < totalUuidCountForDevice; index++) {
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> deviceUuid;
|
||||
bool uuidValid = this->getUuidFromSubDeviceInfo(index, deviceUuid);
|
||||
if (uuidValid) {
|
||||
uint8_t uuid[ZE_MAX_DEVICE_UUID_SIZE] = {};
|
||||
std::copy_n(std::begin(deviceUuid), ZE_MAX_DEVICE_UUID_SIZE, std::begin(uuid));
|
||||
std::string uuidString(reinterpret_cast<char const *>(uuid));
|
||||
deviceUuids.push_back(uuidString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LinuxSysmanImp::generateUuidFromPciAndSubDeviceInfo(uint32_t subDeviceID, const NEO::PhysicalDevicePciBusInfo &pciBusInfo, std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid) {
|
||||
if (pciBusInfo.pciDomain != NEO::PhysicalDevicePciBusInfo::invalidValue) {
|
||||
uuid.fill(0);
|
||||
|
||||
// Device UUID uniquely identifies a device within a system.
|
||||
// We generate it based on device information along with PCI information
|
||||
// This guarantees uniqueness of UUIDs on a system even when multiple
|
||||
// identical Intel GPUs are present.
|
||||
|
||||
// We want to have UUID matching between different GPU APIs (including outside
|
||||
// of compute_runtime project - i.e. other than L0 or OCL). This structure definition
|
||||
// has been agreed upon by various Intel driver teams.
|
||||
//
|
||||
// Consult other driver teams before changing this.
|
||||
//
|
||||
|
||||
struct DeviceUUID {
|
||||
uint16_t vendorID;
|
||||
uint16_t deviceID;
|
||||
uint16_t revisionID;
|
||||
uint16_t pciDomain;
|
||||
uint8_t pciBus;
|
||||
uint8_t pciDev;
|
||||
uint8_t pciFunc;
|
||||
uint8_t reserved[4];
|
||||
uint8_t subDeviceID;
|
||||
};
|
||||
|
||||
auto &hwInfo = getParentSysmanDeviceImp()->getHardwareInfo();
|
||||
DeviceUUID deviceUUID = {};
|
||||
deviceUUID.vendorID = 0x8086; // Intel
|
||||
deviceUUID.deviceID = hwInfo.platform.usDeviceID;
|
||||
deviceUUID.revisionID = hwInfo.platform.usRevId;
|
||||
deviceUUID.pciDomain = static_cast<uint16_t>(pciBusInfo.pciDomain);
|
||||
deviceUUID.pciBus = static_cast<uint8_t>(pciBusInfo.pciBus);
|
||||
deviceUUID.pciDev = static_cast<uint8_t>(pciBusInfo.pciDevice);
|
||||
deviceUUID.pciFunc = static_cast<uint8_t>(pciBusInfo.pciFunction);
|
||||
deviceUUID.subDeviceID = subDeviceID;
|
||||
|
||||
static_assert(sizeof(DeviceUUID) == NEO::ProductHelper::uuidSize);
|
||||
|
||||
memcpy_s(uuid.data(), NEO::ProductHelper::uuidSize, &deviceUUID, sizeof(DeviceUUID));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxSysmanImp::getUuidFromSubDeviceInfo(uint32_t subDeviceID, std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid) {
|
||||
auto subDeviceCount = getSubDeviceCount();
|
||||
if (uuidVec.size() == 0) {
|
||||
constexpr uint32_t rootDeviceCount = 1;
|
||||
uuidVec.resize(subDeviceCount + rootDeviceCount);
|
||||
}
|
||||
if (getParentSysmanDeviceImp()->getRootDeviceEnvironment().osInterface != nullptr) {
|
||||
auto driverModel = getParentSysmanDeviceImp()->getRootDeviceEnvironment().osInterface->getDriverModel();
|
||||
auto &gfxCoreHelper = getParentSysmanDeviceImp()->getRootDeviceEnvironment().getHelper<NEO::GfxCoreHelper>();
|
||||
auto &productHelper = getParentSysmanDeviceImp()->getRootDeviceEnvironment().getHelper<NEO::ProductHelper>();
|
||||
if (NEO::debugManager.flags.EnableChipsetUniqueUUID.get() != 0) {
|
||||
if (gfxCoreHelper.isChipsetUniqueUUIDSupported()) {
|
||||
auto hwDeviceId = getSysmanHwDeviceIdInstance();
|
||||
this->uuidVec[subDeviceID].isValid = productHelper.getUuid(driverModel, subDeviceCount, subDeviceID, this->uuidVec[subDeviceID].id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->uuidVec[subDeviceID].isValid) {
|
||||
NEO::PhysicalDevicePciBusInfo pciBusInfo = driverModel->getPciBusInfo();
|
||||
this->uuidVec[subDeviceID].isValid = generateUuidFromPciAndSubDeviceInfo(subDeviceID, pciBusInfo, this->uuidVec[subDeviceID].id);
|
||||
}
|
||||
|
||||
if (this->uuidVec[subDeviceID].isValid) {
|
||||
uuid = this->uuidVec[subDeviceID].id;
|
||||
}
|
||||
}
|
||||
|
||||
return this->uuidVec[subDeviceID].isValid;
|
||||
}
|
||||
|
||||
OsSysman *OsSysman::create(SysmanDeviceImp *pParentSysmanDeviceImp) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = new LinuxSysmanImp(pParentSysmanDeviceImp);
|
||||
return static_cast<OsSysman *>(pLinuxSysmanImp);
|
||||
|
|
|
@ -50,6 +50,7 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableAndNonMovableClass {
|
|||
SysmanDeviceImp *getSysmanDeviceImp();
|
||||
SysmanProductHelper *getSysmanProductHelper();
|
||||
uint32_t getSubDeviceCount() override;
|
||||
void getDeviceUuids(std::vector<std::string> &deviceUuids) override;
|
||||
const NEO::HardwareInfo &getHardwareInfo() const override { return pParentSysmanDeviceImp->getHardwareInfo(); }
|
||||
std::string getPciCardBusDirectoryPath(std::string realPciPath);
|
||||
uint32_t getMemoryType();
|
||||
|
@ -78,6 +79,8 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableAndNonMovableClass {
|
|||
SysmanKmdInterface *getSysmanKmdInterface() { return pSysmanKmdInterface.get(); }
|
||||
static ze_result_t getResult(int err);
|
||||
bool getTelemData(uint32_t subDeviceId, std::string &telemDir, std::string &guid, uint64_t &telemOffset);
|
||||
bool getUuidFromSubDeviceInfo(uint32_t subDeviceID, std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid);
|
||||
bool generateUuidFromPciAndSubDeviceInfo(uint32_t subDeviceID, const NEO::PhysicalDevicePciBusInfo &pciBusInfo, std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SysmanProductHelper> pSysmanProductHelper;
|
||||
|
@ -94,6 +97,11 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableAndNonMovableClass {
|
|||
std::map<uint32_t, std::unique_ptr<PlatformMonitoringTech::TelemData>> mapOfSubDeviceIdToTelemData;
|
||||
std::map<uint32_t, std::string> telemNodesInPciPath;
|
||||
std::unique_ptr<PlatformMonitoringTech::TelemData> pTelemData = nullptr;
|
||||
struct Uuid {
|
||||
bool isValid = false;
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> id;
|
||||
};
|
||||
std::vector<Uuid> uuidVec;
|
||||
|
||||
private:
|
||||
LinuxSysmanImp() = delete;
|
||||
|
|
|
@ -114,6 +114,83 @@ KmdSysManager &WddmSysmanImp::getKmdSysManager() {
|
|||
return *pKmdSysManager;
|
||||
}
|
||||
|
||||
void WddmSysmanImp::getDeviceUuids(std::vector<std::string> &deviceUuids) {
|
||||
deviceUuids.clear();
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> deviceUuid;
|
||||
bool uuidValid = this->getUuid(deviceUuid);
|
||||
if (uuidValid) {
|
||||
uint8_t uuid[ZE_MAX_DEVICE_UUID_SIZE] = {};
|
||||
std::copy_n(std::begin(deviceUuid), ZE_MAX_DEVICE_UUID_SIZE, std::begin(uuid));
|
||||
std::string uuidString(reinterpret_cast<char const *>(uuid));
|
||||
deviceUuids.push_back(uuidString);
|
||||
}
|
||||
}
|
||||
|
||||
bool WddmSysmanImp::getUuid(std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid) {
|
||||
if (getSysmanDeviceImp()->getRootDeviceEnvironment().osInterface != nullptr) {
|
||||
auto driverModel = getSysmanDeviceImp()->getRootDeviceEnvironment().osInterface->getDriverModel();
|
||||
if (!this->uuid.isValid) {
|
||||
NEO::PhysicalDevicePciBusInfo pciBusInfo = driverModel->getPciBusInfo();
|
||||
this->uuid.isValid = generateUuidFromPciBusInfo(pciBusInfo, this->uuid.id);
|
||||
}
|
||||
|
||||
if (this->uuid.isValid) {
|
||||
uuid = this->uuid.id;
|
||||
}
|
||||
}
|
||||
|
||||
return this->uuid.isValid;
|
||||
}
|
||||
|
||||
bool WddmSysmanImp::generateUuidFromPciBusInfo(const NEO::PhysicalDevicePciBusInfo &pciBusInfo, std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid) {
|
||||
if (pciBusInfo.pciDomain != NEO::PhysicalDevicePciBusInfo::invalidValue) {
|
||||
uuid.fill(0);
|
||||
|
||||
// Device UUID uniquely identifies a device within a system.
|
||||
// We generate it based on device information along with PCI information
|
||||
// This guarantees uniqueness of UUIDs on a system even when multiple
|
||||
// identical Intel GPUs are present.
|
||||
//
|
||||
|
||||
// We want to have UUID matching between different GPU APIs (including outside
|
||||
// of compute_runtime project - i.e. other than L0 or OCL). This structure definition
|
||||
// has been agreed upon by various Intel driver teams.
|
||||
//
|
||||
// Consult other driver teams before changing this.
|
||||
//
|
||||
|
||||
struct DeviceUUID {
|
||||
uint16_t vendorID;
|
||||
uint16_t deviceID;
|
||||
uint16_t revisionID;
|
||||
uint16_t pciDomain;
|
||||
uint8_t pciBus;
|
||||
uint8_t pciDev;
|
||||
uint8_t pciFunc;
|
||||
uint8_t reserved[4];
|
||||
uint8_t subDeviceID;
|
||||
};
|
||||
auto &hwInfo = getSysmanDeviceImp()->getHardwareInfo();
|
||||
DeviceUUID deviceUUID = {};
|
||||
deviceUUID.vendorID = 0x8086; // Intel
|
||||
deviceUUID.deviceID = hwInfo.platform.usDeviceID;
|
||||
deviceUUID.revisionID = hwInfo.platform.usRevId;
|
||||
deviceUUID.pciDomain = static_cast<uint16_t>(pciBusInfo.pciDomain);
|
||||
deviceUUID.pciBus = static_cast<uint8_t>(pciBusInfo.pciBus);
|
||||
deviceUUID.pciDev = static_cast<uint8_t>(pciBusInfo.pciDevice);
|
||||
deviceUUID.pciFunc = static_cast<uint8_t>(pciBusInfo.pciFunction);
|
||||
deviceUUID.subDeviceID = 0;
|
||||
|
||||
static_assert(sizeof(DeviceUUID) == NEO::ProductHelper::uuidSize);
|
||||
|
||||
memcpy_s(uuid.data(), NEO::ProductHelper::uuidSize, &deviceUUID, sizeof(DeviceUUID));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
OsSysman *OsSysman::create(SysmanDeviceImp *pParentSysmanDeviceImp) {
|
||||
WddmSysmanImp *pWddmSysmanImp = new WddmSysmanImp(pParentSysmanDeviceImp);
|
||||
return static_cast<OsSysman *>(pWddmSysmanImp);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#pragma once
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/os_interface/driver_info.h"
|
||||
#include "shared/source/os_interface/product_helper.h"
|
||||
|
||||
#include "level_zero/sysman/source/device/os_sysman.h"
|
||||
#include "level_zero/sysman/source/device/sysman_device.h"
|
||||
|
@ -36,11 +38,14 @@ class WddmSysmanImp : public OsSysman, NEO::NonCopyableAndNonMovableClass {
|
|||
void releaseFwUtilInterface();
|
||||
|
||||
uint32_t getSubDeviceCount() override;
|
||||
void getDeviceUuids(std::vector<std::string> &deviceUuids) override;
|
||||
SysmanDeviceImp *getSysmanDeviceImp();
|
||||
const NEO::HardwareInfo &getHardwareInfo() const override { return pParentSysmanDeviceImp->getHardwareInfo(); }
|
||||
PRODUCT_FAMILY getProductFamily() const { return pParentSysmanDeviceImp->getProductFamily(); }
|
||||
SysmanProductHelper *getSysmanProductHelper();
|
||||
PlatformMonitoringTech *getSysmanPmt();
|
||||
bool getUuid(std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid);
|
||||
bool generateUuidFromPciBusInfo(const NEO::PhysicalDevicePciBusInfo &pciBusInfo, std::array<uint8_t, NEO::ProductHelper::uuidSize> &uuid);
|
||||
|
||||
protected:
|
||||
FirmwareUtil *pFwUtilInterface = nullptr;
|
||||
|
@ -48,6 +53,10 @@ class WddmSysmanImp : public OsSysman, NEO::NonCopyableAndNonMovableClass {
|
|||
SysmanDevice *pDevice = nullptr;
|
||||
std::unique_ptr<PlatformMonitoringTech> pPmt;
|
||||
std::unique_ptr<SysmanProductHelper> pSysmanProductHelper;
|
||||
struct {
|
||||
bool isValid = false;
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> id;
|
||||
} uuid;
|
||||
|
||||
private:
|
||||
SysmanDeviceImp *pParentSysmanDeviceImp = nullptr;
|
||||
|
|
|
@ -14,6 +14,7 @@ if(UNIX)
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_driver.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_hw_device_id.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysman_hw_device_id.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_core_handle_support.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "shared/test/common/mocks/mock_driver_info.h"
|
||||
#include "shared/test/common/mocks/mock_driver_model.h"
|
||||
#include "shared/test/common/mocks/mock_product_helper.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
#include "level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface.h"
|
||||
|
@ -277,7 +278,7 @@ TEST_F(SysmanDeviceFixture, GivenInvalidPathnameWhenCallingSysFsAccessScanDirEnt
|
|||
|
||||
std::string path = "noSuchDirectory";
|
||||
std::vector<std::string> listFiles;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pSysFsAccess->scanDirEntries(path, listFiles));
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, pSysFsAccess->scanDirEntries(path, listFiles));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndIntegerWhenCallingReadOnMultipleFilesThenSuccessIsReturned) {
|
||||
|
@ -531,6 +532,85 @@ TEST(SysmanErrorCodeTest, GivenDifferentErrorCodesWhenCallingGetResultThenVerify
|
|||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, LinuxSysmanImp::getResult(EEXIST));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWithInvalidPciDomainWhenCallingGenerateUuidFromPciBusInfoThenFalseIsReturned) {
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> uuid;
|
||||
NEO::PhysicalDevicePciBusInfo pciBusInfo = {};
|
||||
pciBusInfo.pciDomain = std::numeric_limits<uint32_t>::max();
|
||||
uint32_t subDeviceId = 0;
|
||||
bool result = pLinuxSysmanImp->generateUuidFromPciAndSubDeviceInfo(subDeviceId, pciBusInfo, uuid);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenNullOsInterfaceObjectWhenRetrievingUuidsOfDeviceThenNoUuidsAreReturned) {
|
||||
auto execEnv = new NEO::ExecutionEnvironment();
|
||||
execEnv->prepareRootDeviceEnvironments(1);
|
||||
execEnv->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(NEO::defaultHwInfo.get());
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface = std::make_unique<NEO::OSInterface>();
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<NEO::MockDriverModel>());
|
||||
|
||||
auto pSysmanDeviceImp = std::make_unique<L0::Sysman::SysmanDeviceImp>(execEnv, 0);
|
||||
auto pLinuxSysmanImp = static_cast<PublicLinuxSysmanImp *>(pSysmanDeviceImp->pOsSysman);
|
||||
|
||||
auto &rootDeviceEnvironment = (pLinuxSysmanImp->getSysmanDeviceImp()->getRootDeviceEnvironmentRef());
|
||||
rootDeviceEnvironment.osInterface = nullptr;
|
||||
|
||||
std::vector<std::string> uuids;
|
||||
pLinuxSysmanImp->getDeviceUuids(uuids);
|
||||
EXPECT_EQ(0u, uuids.size());
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenInvalidPciBusInfoWhenRetrievingUuidThenFalseIsReturned) {
|
||||
DebugManagerStateRestore restore;
|
||||
auto execEnv = new NEO::ExecutionEnvironment();
|
||||
execEnv->prepareRootDeviceEnvironments(1);
|
||||
execEnv->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(NEO::defaultHwInfo.get());
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface = std::make_unique<NEO::OSInterface>();
|
||||
|
||||
auto driverModel = std::make_unique<NEO::MockDriverModel>();
|
||||
driverModel->pciSpeedInfo = {1, 1, 1};
|
||||
PhysicalDevicePciBusInfo pciBusInfo = {};
|
||||
pciBusInfo.pciDomain = std::numeric_limits<uint32_t>::max();
|
||||
driverModel->pciBusInfo = pciBusInfo;
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(driverModel));
|
||||
|
||||
auto pSysmanDeviceImp = std::make_unique<L0::Sysman::SysmanDeviceImp>(execEnv, 0);
|
||||
auto pLinuxSysmanImp = static_cast<PublicLinuxSysmanImp *>(pSysmanDeviceImp->pOsSysman);
|
||||
|
||||
debugManager.flags.EnableChipsetUniqueUUID.set(0);
|
||||
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> uuid;
|
||||
uint32_t subDeviceId = 0;
|
||||
bool result = pLinuxSysmanImp->getUuidFromSubDeviceInfo(subDeviceId, uuid);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
struct MockSysmanLinuxProductHelper : public ProductHelperHw<IGFX_UNKNOWN> {
|
||||
MockSysmanLinuxProductHelper() = default;
|
||||
bool getUuid(DriverModel *driverModel, const uint32_t subDeviceCount, const uint32_t deviceIndex, std::array<uint8_t, ProductHelper::uuidSize> &uuid) const override {
|
||||
auto pDrm = driverModel->as<Drm>();
|
||||
if (pDrm->getFileDescriptor() >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenValidDeviceWhenRetrievingUuidThenValidFdIsVerifiedInProductHelper) {
|
||||
std::unique_ptr<ProductHelper> mockProductHelper = std::make_unique<MockSysmanLinuxProductHelper>();
|
||||
auto pSysmanDeviceImp = std::make_unique<L0::Sysman::SysmanDeviceImp>(execEnv, 0);
|
||||
auto pLinuxSysmanImp = static_cast<PublicLinuxSysmanImp *>(pSysmanDeviceImp->pOsSysman);
|
||||
|
||||
auto &rootDeviceEnvironment = (pLinuxSysmanImp->getSysmanDeviceImp()->getRootDeviceEnvironmentRef());
|
||||
std::swap(rootDeviceEnvironment.productHelper, mockProductHelper);
|
||||
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> uuid;
|
||||
uint32_t subDeviceId = 0;
|
||||
bool result = pLinuxSysmanImp->getUuidFromSubDeviceInfo(subDeviceId, uuid);
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
std::swap(rootDeviceEnvironment.productHelper, mockProductHelper);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
namespace ult {
|
||||
|
||||
class SysmanDeviceFixtureWithCore : public SysmanDeviceFixture, public L0::ult::DeviceFixture {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SysmanDeviceFixture::SetUp();
|
||||
L0::ult::DeviceFixture::setUp();
|
||||
}
|
||||
void TearDown() override {
|
||||
L0::ult::DeviceFixture::tearDown();
|
||||
SysmanDeviceFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
HWTEST2_F(SysmanDeviceFixtureWithCore, GivenValidCoreHandleWhenRetrievingSysmanDeviceThenNonNullHandleIsReturned, IsPVC) {
|
||||
auto coreDeviceHandle = L0::Device::fromHandle(device->toHandle());
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(coreDeviceHandle);
|
||||
EXPECT_NE(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDeviceFixtureWithCore, GivenNullCoreHandleWhenSysmanHandleIsQueriedThenNullPtrIsReturned, IsPVC) {
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(nullptr);
|
||||
EXPECT_EQ(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDeviceFixtureWithCore, GivenValidCoreHandleWhenSysmanHandleIsQueriedAndNotFoundInLookUpThenNullPtrIsReturned, IsPVC) {
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsRealpath)> mockRealPath(&NEO::SysCalls::sysCallsRealpath, [](const char *path, char *buf) -> char * {
|
||||
constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:02.0");
|
||||
strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:02.0");
|
||||
return buf;
|
||||
});
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
|
||||
std::string str = "../../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/drm/renderD128";
|
||||
std::memcpy(buf, str.c_str(), str.size());
|
||||
return static_cast<int>(str.size());
|
||||
});
|
||||
|
||||
class MockSysmanDriverHandleImp : public SysmanDriverHandleImp {
|
||||
public:
|
||||
MockSysmanDriverHandleImp() {
|
||||
SysmanDriverHandleImp();
|
||||
}
|
||||
void clearUuidDeviceMap() {
|
||||
uuidDeviceMap.clear();
|
||||
}
|
||||
};
|
||||
std::unique_ptr<MockSysmanDriverHandleImp> pSysmanDriverHandleImp = std::make_unique<MockSysmanDriverHandleImp>();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, pSysmanDriverHandleImp->initialize(*(L0::Sysman::ult::SysmanDeviceFixture::execEnv)));
|
||||
pSysmanDriverHandleImp->clearUuidDeviceMap();
|
||||
auto pSysmanDevice = pSysmanDriverHandleImp->getSysmanDeviceFromCoreDeviceHandle(L0::Device::fromHandle(device->toHandle()));
|
||||
EXPECT_EQ(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDeviceFixtureWithCore, GivenValidCoreHandleWhenRetrievingSysmanHandleTwiceThenSuccessAreReturned, IsDG2) {
|
||||
auto coreDeviceHandle = L0::Device::fromHandle(device->toHandle());
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(coreDeviceHandle);
|
||||
EXPECT_NE(pSysmanDevice, nullptr);
|
||||
pSysmanDevice = nullptr;
|
||||
pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(coreDeviceHandle);
|
||||
EXPECT_NE(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
|
@ -15,6 +15,7 @@ if(WIN32)
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_driver.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_core_handle_support.cpp
|
||||
)
|
||||
endif()
|
||||
add_subdirectories()
|
||||
add_subdirectories()
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/mocks/mock_driver_model.h"
|
||||
#include "shared/test/common/mocks/mock_product_helper.h"
|
||||
|
||||
#include "level_zero/sysman/test/unit_tests/sources/windows/mock_sysman_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
|
@ -104,6 +107,59 @@ TEST_F(SysmanDeviceFixture, GivenInvalidSysmanDeviceHandleWhenCallingSysmanDevic
|
|||
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, SysmanDevice::deviceEnumEnabledVF(invalidHandle, &count, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWithInvalidPciDomainWhenCallingGenerateUuidFromPciBusInfoThenFalseIsReturned) {
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> uuid;
|
||||
NEO::PhysicalDevicePciBusInfo pciBusInfo = {};
|
||||
pciBusInfo.pciDomain = std::numeric_limits<uint32_t>::max();
|
||||
bool result = pWddmSysmanImp->generateUuidFromPciBusInfo(pciBusInfo, uuid);
|
||||
EXPECT_EQ(false, result);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenNullOsInterfaceObjectWhenRetrievingUuidsOfDeviceThenNoUuidsAreReturned) {
|
||||
auto execEnv = new NEO::ExecutionEnvironment();
|
||||
execEnv->prepareRootDeviceEnvironments(1);
|
||||
execEnv->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(NEO::defaultHwInfo.get());
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface = std::make_unique<NEO::OSInterface>();
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<NEO::MockDriverModel>());
|
||||
|
||||
auto pSysmanDeviceImp = std::make_unique<L0::Sysman::SysmanDeviceImp>(execEnv, 0);
|
||||
auto pWddmSysmanImp = static_cast<PublicWddmSysmanImp *>(pSysmanDeviceImp->pOsSysman);
|
||||
|
||||
auto &rootDeviceEnvironment = (pWddmSysmanImp->getSysmanDeviceImp()->getRootDeviceEnvironmentRef());
|
||||
rootDeviceEnvironment.osInterface = nullptr;
|
||||
|
||||
std::vector<std::string> uuids;
|
||||
pWddmSysmanImp->getDeviceUuids(uuids);
|
||||
EXPECT_EQ(0u, uuids.size());
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenInvalidPciBusInfoWhenRetrievingUuidThenFalseIsReturned) {
|
||||
auto execEnv = new NEO::ExecutionEnvironment();
|
||||
execEnv->prepareRootDeviceEnvironments(1);
|
||||
execEnv->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(NEO::defaultHwInfo.get());
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface = std::make_unique<NEO::OSInterface>();
|
||||
|
||||
auto driverModel = std::make_unique<NEO::MockDriverModel>();
|
||||
driverModel->pciSpeedInfo = {1, 1, 1};
|
||||
PhysicalDevicePciBusInfo pciBusInfo = {};
|
||||
pciBusInfo.pciDomain = std::numeric_limits<uint32_t>::max();
|
||||
driverModel->pciBusInfo = pciBusInfo;
|
||||
execEnv->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(driverModel));
|
||||
|
||||
auto pSysmanDeviceImp = std::make_unique<L0::Sysman::SysmanDeviceImp>(execEnv, 0);
|
||||
auto pWddmSysmanImp = static_cast<PublicWddmSysmanImp *>(pSysmanDeviceImp->pOsSysman);
|
||||
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> uuid;
|
||||
bool result = pWddmSysmanImp->getUuid(uuid);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenValidWddmSysmanImpWhenRetrievingUuidThenTrueIsReturned) {
|
||||
std::array<uint8_t, NEO::ProductHelper::uuidSize> uuid;
|
||||
bool result = pWddmSysmanImp->getUuid(uuid);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (C) 2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/sysman/test/unit_tests/sources/windows/mock_sysman_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
namespace ult {
|
||||
|
||||
class SysmanDeviceFixtureWithCore : public SysmanDeviceFixture, public L0::ult::DeviceFixture {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SysmanDeviceFixture::SetUp();
|
||||
L0::ult::DeviceFixture::setUp();
|
||||
}
|
||||
void TearDown() override {
|
||||
L0::ult::DeviceFixture::tearDown();
|
||||
SysmanDeviceFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanDeviceFixtureWithCore, GivenValidCoreHandleWhenRetrievingSysmanDeviceThenNonNullHandleIsReturned) {
|
||||
auto coreDeviceHandle = L0::Device::fromHandle(device->toHandle());
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(coreDeviceHandle);
|
||||
EXPECT_NE(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixtureWithCore, GivenNullCoreHandleWhenSysmanHandleIsQueriedThenNullPtrIsReturned) {
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(nullptr);
|
||||
EXPECT_EQ(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixtureWithCore, GivenValidCoreHandleWhenSysmanHandleIsQueriedAndNotFoundInLookUpThenNullPtrIsReturned) {
|
||||
class MockSysmanDriverHandleImp : public SysmanDriverHandleImp {
|
||||
public:
|
||||
MockSysmanDriverHandleImp() {
|
||||
SysmanDriverHandleImp();
|
||||
}
|
||||
void clearUuidDeviceMap() {
|
||||
uuidDeviceMap.clear();
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<MockSysmanDriverHandleImp> pSysmanDriverHandleImp = std::make_unique<MockSysmanDriverHandleImp>();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, pSysmanDriverHandleImp->initialize(*(L0::Sysman::ult::SysmanDeviceFixture::execEnv)));
|
||||
pSysmanDriverHandleImp->clearUuidDeviceMap();
|
||||
auto pSysmanDevice = pSysmanDriverHandleImp->getSysmanDeviceFromCoreDeviceHandle(L0::Device::fromHandle(device->toHandle()));
|
||||
EXPECT_EQ(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixtureWithCore, GivenValidCoreHandleWhenRetrievingSysmanHandleTwiceThenSuccessAreReturned) {
|
||||
auto coreDeviceHandle = L0::Device::fromHandle(device->toHandle());
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(coreDeviceHandle);
|
||||
EXPECT_NE(pSysmanDevice, nullptr);
|
||||
pSysmanDevice = nullptr;
|
||||
pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(coreDeviceHandle);
|
||||
EXPECT_NE(pSysmanDevice, nullptr);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
Loading…
Reference in New Issue