mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-31 03:20:47 +08:00
Add uuid support using inband information
Added chipset specific uuid retrieving functionality This is used by zeDeviceGetProperties Related-To: LOCI-2636 Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
cf70a57efb
commit
06be26fd1e
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "CL/cl.h"
|
||||
|
||||
static_assert(NEO::HwInfoConfig::uuidSize == ZE_MAX_DEVICE_UUID_SIZE);
|
||||
|
||||
struct _ze_device_handle_t {};
|
||||
namespace NEO {
|
||||
class Device;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "shared/source/built_ins/sip.h"
|
||||
#include "shared/source/command_container/implicit_scaling.h"
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/device/device_info.h"
|
||||
#include "shared/source/device/sub_device.h"
|
||||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
@@ -465,12 +466,18 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties)
|
||||
|
||||
pDeviceProperties->flags = 0u;
|
||||
|
||||
uint32_t rootDeviceIndex = this->neoDevice->getRootDeviceIndex();
|
||||
std::array<uint8_t, NEO::HwInfoConfig::uuidSize> deviceUuid;
|
||||
if (this->neoDevice->getUuid(deviceUuid)) {
|
||||
std::copy_n(std::begin(deviceUuid), ZE_MAX_DEVICE_UUID_SIZE, std::begin(pDeviceProperties->uuid.id));
|
||||
} else {
|
||||
|
||||
memset(pDeviceProperties->uuid.id, 0, ZE_MAX_DEVICE_UUID_SIZE);
|
||||
memcpy_s(pDeviceProperties->uuid.id, sizeof(uint32_t), &pDeviceProperties->vendorId, sizeof(pDeviceProperties->vendorId));
|
||||
memcpy_s(pDeviceProperties->uuid.id + sizeof(uint32_t), sizeof(uint32_t), &pDeviceProperties->deviceId, sizeof(pDeviceProperties->deviceId));
|
||||
memcpy_s(pDeviceProperties->uuid.id + (2 * sizeof(uint32_t)), sizeof(uint32_t), &rootDeviceIndex, sizeof(rootDeviceIndex));
|
||||
uint32_t rootDeviceIndex = this->neoDevice->getRootDeviceIndex();
|
||||
|
||||
memset(pDeviceProperties->uuid.id, 0, ZE_MAX_DEVICE_UUID_SIZE);
|
||||
memcpy_s(pDeviceProperties->uuid.id, sizeof(uint32_t), &deviceInfo.vendorId, sizeof(deviceInfo.vendorId));
|
||||
memcpy_s(pDeviceProperties->uuid.id + sizeof(uint32_t), sizeof(uint32_t), &hardwareInfo.platform.usDeviceID, sizeof(hardwareInfo.platform.usDeviceID));
|
||||
memcpy_s(pDeviceProperties->uuid.id + (2 * sizeof(uint32_t)), sizeof(uint32_t), &rootDeviceIndex, sizeof(rootDeviceIndex));
|
||||
}
|
||||
|
||||
pDeviceProperties->subdeviceId = isSubdevice ? static_cast<NEO::SubDevice *>(neoDevice)->getSubDeviceIndex() : 0;
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# Copyright (C) 2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_device_uuid.cpp
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/device/root_device.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/libult/linux/drm_mock.h"
|
||||
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/ult_device_factory.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
struct TestDeviceUuid : public ::testing::Test {
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
HWTEST2_F(TestDeviceUuid, GivenCorrectTelemetryNodesAreAvailableWhenRetrievingDeviceAndSubDevicePropertiesThenCorrectUuidIsReceived, IsXEHP) {
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int {
|
||||
std::map<std::string, std::string> fileNameLinkMap = {
|
||||
{"/sys/dev/char/226:128", "../../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:01.0/0000:3a:00.0/i915-spi.2.auto/mtd/mtd0/mtd3/"},
|
||||
{"/sys/class/intel_pmt/telem3", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem3/"},
|
||||
{"/sys/class/intel_pmt/telem1", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem1/"},
|
||||
{"/sys/class/intel_pmt/telem2", "./../devices/pci0000:37/0000:37:01.0/0000:38:00.0/0000:39:02.0/0000:3c:00.1/intel-dvsec-2.1.auto/intel_pmt/telem2/"},
|
||||
};
|
||||
|
||||
auto it = fileNameLinkMap.find(std::string(path));
|
||||
if (it != fileNameLinkMap.end()) {
|
||||
std::memcpy(buf, it->second.c_str(), it->second.size());
|
||||
return static_cast<int>(it->second.size());
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
|
||||
std::vector<std::string> supportedFiles = {
|
||||
"/sys/class/intel_pmt/telem1/guid",
|
||||
"/sys/class/intel_pmt/telem1/offset",
|
||||
"/sys/class/intel_pmt/telem1/telem",
|
||||
};
|
||||
|
||||
auto itr = std::find(supportedFiles.begin(), supportedFiles.end(), std::string(pathname));
|
||||
if (itr != supportedFiles.end()) {
|
||||
// skipping "0"
|
||||
return static_cast<int>(std::distance(supportedFiles.begin(), itr)) + 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
|
||||
std::vector<std::pair<std::string, std::string>> supportedFiles = {
|
||||
{"/sys/class/intel_pmt/telem1/guid", "0xfdc76195"},
|
||||
{"/sys/class/intel_pmt/telem1/offset", "0\n"},
|
||||
{"/sys/class/intel_pmt/telem1/telem", "dummy"},
|
||||
};
|
||||
|
||||
fd -= 1;
|
||||
|
||||
if ((fd) < static_cast<int>(supportedFiles.size())) {
|
||||
if (supportedFiles[fd].second == "dummy") {
|
||||
uint64_t data = 0xFEEDBEADDEABDEEF;
|
||||
memcpy(buf, &data, sizeof(data));
|
||||
return sizeof(data);
|
||||
}
|
||||
memcpy(buf, supportedFiles[fd].second.c_str(), supportedFiles[fd].second.size());
|
||||
return supportedFiles[fd].second.size();
|
||||
}
|
||||
|
||||
return -1;
|
||||
});
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
||||
|
||||
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
DrmMockResources *drmMock = nullptr;
|
||||
|
||||
auto executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
auto osInterface = new OSInterface();
|
||||
drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
|
||||
std::vector<std::string> pciPaths = {
|
||||
"0000:3a:00.0"};
|
||||
drmMock->setPciPath(pciPaths[0].c_str());
|
||||
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<Drm>(drmMock));
|
||||
|
||||
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
|
||||
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
uint64_t expectedVal = 0xFEEDBEADDEABDEEF;
|
||||
ze_device_properties_t deviceProps;
|
||||
deviceProps = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, device->getProperties(&deviceProps));
|
||||
EXPECT_TRUE(0 == std::memcmp(deviceProps.uuid.id, &expectedVal, sizeof(expectedVal)));
|
||||
|
||||
uint32_t subdeviceCount = neoDevice->getNumGenericSubDevices();
|
||||
std::vector<ze_device_handle_t> subdevices;
|
||||
subdevices.resize(subdeviceCount);
|
||||
device->getSubDevices(&subdeviceCount, subdevices.data());
|
||||
|
||||
uint8_t expectedUuid[16] = {0};
|
||||
std::memcpy(expectedUuid, &expectedVal, sizeof(uint64_t));
|
||||
expectedUuid[15] = 1;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, static_cast<Device *>(subdevices[0])->getProperties(&deviceProps));
|
||||
EXPECT_TRUE(0 == std::memcmp(deviceProps.uuid.id, expectedUuid, sizeof(expectedUuid)));
|
||||
expectedUuid[15] = 2;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, static_cast<Device *>(subdevices[1])->getProperties(&deviceProps));
|
||||
EXPECT_TRUE(0 == std::memcmp(deviceProps.uuid.id, expectedUuid, sizeof(expectedUuid)));
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user