From b0d84f88d75aa05c50aef581e785c7dca6389f11 Mon Sep 17 00:00:00 2001 From: Maciej Plewka Date: Wed, 11 May 2022 15:40:35 +0000 Subject: [PATCH] Return correct device name in L0 With this commit L0 driver will report the same device name as OpenCL driver Signed-off-by: Maciej Plewka --- level_zero/core/source/device/device_imp.cpp | 3 +++ .../unit_tests/sources/device/test_device.cpp | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index e63f7eb279..6208645d03 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -655,6 +655,9 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties) memset(pDeviceProperties->name, 0, ZE_MAX_DEVICE_NAME); std::string name = getNEODevice()->getDeviceInfo().name; + if (driverInfo) { + name.assign(driverInfo->getDeviceName(name).c_str()); + } memcpy_s(pDeviceProperties->name, name.length(), name.c_str(), name.length()); return ZE_RESULT_SUCCESS; diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index e6ae46ee2d..9c80fcab5e 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -993,6 +993,28 @@ TEST_F(DeviceTest, givenDevicePropertiesStructureWhenDevicePropertiesCalledThenA EXPECT_NE(deviceProperties.maxMemAllocSize, devicePropertiesBefore.maxMemAllocSize); } +TEST_F(DeviceTest, givenDevicePropertiesStructureWhenDriverInfoIsEmptyThenDeviceNameTheSameAsInDeviceInfo) { + auto deviceImp = static_cast(device); + ze_device_properties_t deviceProperties; + auto name = device->getNEODevice()->getDeviceInfo().name; + deviceImp->driverInfo.reset(); + deviceImp->getProperties(&deviceProperties); + EXPECT_STREQ(deviceProperties.name, name.c_str()); +} + +TEST_F(DeviceTest, givenDevicePropertiesStructureWhenDriverInfoIsNotEmptyThenDeviceNameTheSameAsInDriverInfo) { + auto deviceImp = static_cast(device); + ze_device_properties_t deviceProperties; + auto driverInfo = std::make_unique(); + std::string customDevName = "Custom device name"; + auto name = device->getNEODevice()->getDeviceInfo().name; + driverInfo->setDeviceName(customDevName); + deviceImp->driverInfo.reset(driverInfo.release()); + deviceImp->getProperties(&deviceProperties); + EXPECT_STREQ(deviceProperties.name, customDevName.c_str()); + EXPECT_STRNE(deviceProperties.name, name.c_str()); +} + TEST_F(DeviceTest, WhenGettingDevicePropertiesThenSubslicesPerSliceIsBasedOnSubslicesSupported) { ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; deviceProperties.type = ZE_DEVICE_TYPE_GPU;