From 91a9b925f7acca998d58afcf35c29df909a47a00 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 13 Jan 2023 08:35:43 +0100 Subject: [PATCH] fix: Append device id to ambigous device names Related-To: NEO-7537 Signed-off-by: Mateusz Jablonski --- .../linux/os_global_operations_imp.cpp | 4 +-- .../linux/test_zes_global_operations.cpp | 2 +- opencl/source/cl_device/cl_device.h | 2 +- opencl/source/cl_device/cl_device_caps.cpp | 4 +-- .../unit_test/device/device_caps_tests.cpp | 4 +-- .../device/get_device_name_tests.cpp | 27 +++++++++---------- shared/source/device/device.h | 2 +- shared/source/device/device_caps.cpp | 2 +- .../source/device/device_get_device_name.cpp | 18 ++++++++++--- .../unit_test/device/neo_device_tests.cpp | 19 +++++++++++++ 10 files changed, 56 insertions(+), 28 deletions(-) diff --git a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp index fb4a0e4ca4..bf1de66feb 100644 --- a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp +++ b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -136,7 +136,7 @@ void LinuxGlobalOperationsImp::getBrandName(char (&brandName)[ZES_STRING_PROPERT void LinuxGlobalOperationsImp::getModelName(char (&modelName)[ZES_STRING_PROPERTY_SIZE]) { NEO::Device *neoDevice = pDevice->getNEODevice(); - std::string deviceModelName = neoDevice->getDeviceName(neoDevice->getHardwareInfo()); + std::string deviceModelName = neoDevice->getDeviceName(); std::strncpy(modelName, deviceModelName.c_str(), ZES_STRING_PROPERTY_SIZE); } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp index 9789cbaa27..a1d78bf7bf 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp @@ -100,7 +100,7 @@ class SysmanGlobalOperationsFixture : public SysmanDeviceFixture { pGlobalOperationsImp = static_cast(pSysmanDeviceImp->pGlobalOperations); pOsGlobalOperationsPrev = pGlobalOperationsImp->pOsGlobalOperations; pGlobalOperationsImp->pOsGlobalOperations = nullptr; - expectedModelName = neoDevice->getDeviceName(neoDevice->getHardwareInfo()); + expectedModelName = neoDevice->getDeviceName(); } void TearDown() override { diff --git a/opencl/source/cl_device/cl_device.h b/opencl/source/cl_device/cl_device.h index 3b2b982f49..7d9e2772af 100644 --- a/opencl/source/cl_device/cl_device.h +++ b/opencl/source/cl_device/cl_device.h @@ -139,7 +139,7 @@ class ClDevice : public BaseObject<_cl_device_id> { void initializeOpenclCAllVersions(); void initializeOsSpecificCaps(); void setupFp64Flags(); - const std::string getClDeviceName(const HardwareInfo &hwInfo) const; + const std::string getClDeviceName() const; Device &device; ClDevice &rootClDevice; diff --git a/opencl/source/cl_device/cl_device_caps.cpp b/opencl/source/cl_device/cl_device_caps.cpp index 1eb9ba0650..f0a5b93dcd 100644 --- a/opencl/source/cl_device/cl_device_caps.cpp +++ b/opencl/source/cl_device/cl_device_caps.cpp @@ -79,7 +79,7 @@ void ClDevice::initializeCaps() { if (DebugManager.flags.OverrideDeviceName.get() != "unk") { name.assign(DebugManager.flags.OverrideDeviceName.get().c_str()); } else { - name = getClDeviceName(hwInfo); + name = getClDeviceName(); if (driverInfo) { name.assign(driverInfo->getDeviceName(name).c_str()); } @@ -449,7 +449,7 @@ void ClDevice::initializeOpenclCAllVersions() { } } -const std::string ClDevice::getClDeviceName(const HardwareInfo &hwInfo) const { +const std::string ClDevice::getClDeviceName() const { return this->getDevice().getDeviceInfo().name; } diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index 735e5726ac..a9a28930d5 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -119,7 +119,7 @@ TEST_F(DeviceGetCapsTest, WhenCreatingDeviceThenCapsArePopulatedCorrectly) { EXPECT_NE(nullptr, caps.builtInKernels); std::string strDriverName = caps.name; - std::string strDeviceName = device->getClDeviceName(*defaultHwInfo.get()); + std::string strDeviceName = device->getClDeviceName(); EXPECT_NE(std::string::npos, strDriverName.find(strDeviceName)); @@ -1230,7 +1230,7 @@ TEST_F(DeviceGetCapsTest, givenSystemWithNoDriverInfoWhenGettingNameAndVersionTh const auto &caps = device->getDeviceInfo(); - std::string tempName = device->getClDeviceName(*defaultHwInfo.get()); + std::string tempName = device->getClDeviceName(); #define QTR(a) #a #define TOSTR(b) QTR(b) diff --git a/opencl/test/unit_test/device/get_device_name_tests.cpp b/opencl/test/unit_test/device/get_device_name_tests.cpp index 40ebc09d15..165033a000 100644 --- a/opencl/test/unit_test/device/get_device_name_tests.cpp +++ b/opencl/test/unit_test/device/get_device_name_tests.cpp @@ -16,21 +16,18 @@ using namespace NEO; using DeviceNameTest = ::testing::Test; -TEST_F(DeviceNameTest, WhenCallingGetClDeviceNameThenReturnDeviceNameWithoutDeviceIdAppendedAtTheEnd) { - auto clDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); +TEST_F(DeviceNameTest, WhenCallingGetClDeviceNameThenReturnDeviceNameFromBaseDevice) { + { + auto clDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); - std::string deviceName = "Intel(R) Graphics"; - EXPECT_STREQ(deviceName.c_str(), clDevice->device.getDeviceName(*defaultHwInfo.get()).c_str()); + EXPECT_STREQ(clDevice->device.getDeviceName().c_str(), clDevice->getClDeviceName().c_str()); + } - EXPECT_STREQ(deviceName.c_str(), clDevice->getClDeviceName(*defaultHwInfo.get()).c_str()); -} - -TEST_F(DeviceNameTest, GivenDeviceWithNameWhenCallingGetClDeviceNameThenReturnCustomDeviceName) { - HardwareInfo localHwInfo = *defaultHwInfo; - localHwInfo.capabilityTable.deviceName = "Custom Device"; - - auto clDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); - - std::string deviceName = "Custom Device"; - EXPECT_STREQ(deviceName.c_str(), clDevice->device.getDeviceName(localHwInfo).c_str()); + { + HardwareInfo localHwInfo = *defaultHwInfo; + localHwInfo.capabilityTable.deviceName = "Custom Device"; + + auto clDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); + EXPECT_STREQ(clDevice->device.getDeviceName().c_str(), clDevice->getClDeviceName().c_str()); + } } diff --git a/shared/source/device/device.h b/shared/source/device/device.h index b497e81e93..963ecfaab1 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -99,7 +99,7 @@ class Device : public ReferenceTrackedObject { NEO::SourceLevelDebugger *getSourceLevelDebugger(); DebuggerL0 *getL0Debugger(); const EnginesT &getAllEngines() const; - const std::string getDeviceName(const HardwareInfo &hwInfo) const; + const std::string getDeviceName() const; ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; } const RootDeviceEnvironment &getRootDeviceEnvironment() const; diff --git a/shared/source/device/device_caps.cpp b/shared/source/device/device_caps.cpp index 54ba2fd692..b06b44a373 100644 --- a/shared/source/device/device_caps.cpp +++ b/shared/source/device/device_caps.cpp @@ -184,7 +184,7 @@ void Device::initializeCaps() { this->preemptionMode = PreemptionMode::Disabled; } - deviceInfo.name = this->getDeviceName(hwInfo); + deviceInfo.name = this->getDeviceName(); size_t maxParameterSizeFromIgc = getMaxParameterSizeFromIGC(); if (maxParameterSizeFromIgc > 0) { diff --git a/shared/source/device/device_get_device_name.cpp b/shared/source/device/device_get_device_name.cpp index 939a28401f..572825ecde 100644 --- a/shared/source/device/device_get_device_name.cpp +++ b/shared/source/device/device_get_device_name.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,11 +8,23 @@ #include "shared/source/device/device.h" #include "shared/source/helpers/hw_info.h" +#include +#include #include namespace NEO { -const std::string Device::getDeviceName(const HardwareInfo &hwInfo) const { - return std::string(hwInfo.capabilityTable.deviceName).empty() ? "Intel(R) Graphics" : hwInfo.capabilityTable.deviceName; +const std::string Device::getDeviceName() const { + auto &hwInfo = this->getHardwareInfo(); + std::string deviceName = hwInfo.capabilityTable.deviceName; + if (!deviceName.empty()) { + return deviceName; + } + + std::stringstream deviceNameDefault; + deviceNameDefault << "Intel(R) Graphics"; + deviceNameDefault << " [0x" << std::hex << std::setw(4) << std::setfill('0') << hwInfo.platform.usDeviceID << "]"; + + return deviceNameDefault.str(); } } // namespace NEO diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 91b27bdeeb..9ed676f23a 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -55,6 +55,25 @@ TEST(Device, givenNoDebuggerWhenGettingDebuggerThenNullptrIsReturned) { EXPECT_EQ(nullptr, device->getSourceLevelDebugger()); } +TEST(Device, givenDeviceWithBrandingStringNameWhenGettingDeviceNameThenBrandingStringIsReturned) { + auto hwInfo = *defaultHwInfo; + + hwInfo.capabilityTable.deviceName = "Custom Device"; + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + + EXPECT_STREQ("Custom Device", device->getDeviceName().c_str()); +} + +TEST(Device, givenDeviceWithoutBrandingStringNameWhenGettingDeviceNameThenGenericNameWithHexadecimalDeviceIdIsReturned) { + auto hwInfo = *defaultHwInfo; + + hwInfo.capabilityTable.deviceName = ""; + hwInfo.platform.usDeviceID = 0x1AB; + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + + EXPECT_STREQ("Intel(R) Graphics [0x01ab]", device->getDeviceName().c_str()); +} + using DeviceTest = Test; TEST_F(DeviceTest, whenInitializeRayTracingIsCalledAndRtBackedBufferIsNullptrThenMemoryBackedBufferIsCreated) {