Skip to content

Commit af3dd28

Browse files
Support for L0 to read Device LUID from the WDDM driver using EXT Properties
- Added Support for reading the Device LUID of the given device used in Windows WDDM. - Added inital support for passing back the NodeMask of 1. Signed-off-by: Spruit, Neil R <[email protected]>
1 parent f0888fe commit af3dd28

File tree

16 files changed

+458
-1
lines changed

16 files changed

+458
-1
lines changed

level_zero/core/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(L0_RUNTIME_SOURCES
3737
${CMAKE_CURRENT_SOURCE_DIR}/device/bcs_split.cpp
3838
${CMAKE_CURRENT_SOURCE_DIR}/device/bcs_split.h
3939
${CMAKE_CURRENT_SOURCE_DIR}/device/device.h
40+
${CMAKE_CURRENT_SOURCE_DIR}/device/device_imp_${DRIVER_MODEL}/device_imp.cpp
4041
${CMAKE_CURRENT_SOURCE_DIR}/device/device_imp.cpp
4142
${CMAKE_CURRENT_SOURCE_DIR}/device/device_imp.h
4243
${CMAKE_CURRENT_SOURCE_DIR}/driver/driver_handle.h

level_zero/core/source/device/device_imp.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,19 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties)
725725
}
726726
memcpy_s(pDeviceProperties->name, ZE_MAX_DEVICE_NAME, name.c_str(), name.length() + 1);
727727

728+
if (pDeviceProperties->pNext) {
729+
ze_base_properties_t *extendedProperties = reinterpret_cast<ze_base_properties_t *>(pDeviceProperties->pNext);
730+
if (extendedProperties->stype == ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES) {
731+
ze_device_luid_ext_properties_t *deviceLuidProperties =
732+
reinterpret_cast<ze_device_luid_ext_properties_t *>(extendedProperties);
733+
ze_result_t result = queryDeviceLuid(deviceLuidProperties);
734+
if (result != ZE_RESULT_SUCCESS) {
735+
return result;
736+
}
737+
deviceLuidProperties->nodeMask = 1;
738+
}
739+
}
740+
728741
return ZE_RESULT_SUCCESS;
729742
}
730743

level_zero/core/source/device/device_imp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ struct DeviceImp : public Device {
137137
CmdListCreateFunPtrT getCmdListCreateFunc(const ze_command_list_desc_t *desc);
138138
std::unique_ptr<FabricVertex> fabricVertex;
139139

140+
ze_result_t queryDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties);
141+
ze_result_t setDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties);
142+
140143
protected:
141144
void adjustCommandQueueDesc(uint32_t &ordinal, uint32_t &index);
142145
NEO::EngineGroupType getEngineGroupTypeForOrdinal(uint32_t ordinal) const;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/core/source/device/device_imp.h"
9+
10+
namespace L0 {
11+
12+
ze_result_t DeviceImp::queryDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties) {
13+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
14+
}
15+
16+
} // namespace L0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/core/source/device/device_imp.h"
9+
10+
#include "shared/source/command_stream/command_stream_receiver.h"
11+
#include "shared/source/os_interface/os_interface.h"
12+
#include "shared/source/os_interface/windows/hw_device_id.h"
13+
#include "shared/source/os_interface/windows/os_context_win.h"
14+
#include "shared/source/os_interface/windows/wddm/wddm.h"
15+
16+
namespace L0 {
17+
18+
ze_result_t DeviceImp::queryDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties) {
19+
NEO::Device *activeDevice = getActiveDevice();
20+
if (activeDevice->getRootDeviceEnvironment().osInterface) {
21+
NEO::DriverModelType driverType = neoDevice->getRootDeviceEnvironment().osInterface->getDriverModel()->getDriverModelType();
22+
if (driverType == NEO::DriverModelType::WDDM) {
23+
NEO::CommandStreamReceiver *csr = activeDevice->getDefaultEngine().commandStreamReceiver;
24+
NEO::OsContextWin *context = static_cast<NEO::OsContextWin *>(&csr->getOsContext());
25+
std::vector<uint8_t> luidData;
26+
context->getDeviceLuidArray(luidData, ZE_MAX_DEVICE_LUID_SIZE_EXT);
27+
std::copy_n(luidData.begin(), ZE_MAX_DEVICE_LUID_SIZE_EXT, std::begin(deviceLuidProperties->luid.id));
28+
return ZE_RESULT_SUCCESS;
29+
} else {
30+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
31+
}
32+
}
33+
return ZE_RESULT_ERROR_UNINITIALIZED;
34+
}
35+
36+
} // namespace L0
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/core/source/device/device_imp.h"
9+
10+
#include "shared/source/command_stream/command_stream_receiver.h"
11+
#include "shared/source/os_interface/os_context.h"
12+
#include "shared/source/os_interface/windows/hw_device_id.h"
13+
#include "shared/source/os_interface/windows/os_context_win.h"
14+
#include "shared/source/os_interface/windows/wddm/wddm.h"
15+
16+
namespace L0 {
17+
18+
ze_result_t DeviceImp::queryDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties) {
19+
NEO::Device *activeDevice = getActiveDevice();
20+
NEO::CommandStreamReceiver *csr = activeDevice->getDefaultEngine().commandStreamReceiver;
21+
NEO::OsContextWin *context = static_cast<NEO::OsContextWin *>(&csr->getOsContext());
22+
std::vector<uint8_t> luidData;
23+
context->getDeviceLuidArray(luidData, ZE_MAX_DEVICE_LUID_SIZE_EXT);
24+
std::copy_n(luidData.begin(), ZE_MAX_DEVICE_LUID_SIZE_EXT, std::begin(deviceLuidProperties->luid.id));
25+
return ZE_RESULT_SUCCESS;
26+
}
27+
28+
} // namespace L0

level_zero/core/source/driver/driver_handle_imp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ struct DriverHandleImp : public DriverHandle {
9999
{ZE_DEVICE_MEMORY_PROPERTIES_EXT_NAME, ZE_DEVICE_MEMORY_PROPERTIES_EXT_VERSION_CURRENT},
100100
{ZE_RAYTRACING_EXT_NAME, ZE_RAYTRACING_EXT_VERSION_CURRENT},
101101
{ZE_CONTEXT_POWER_SAVING_HINT_EXP_NAME, ZE_POWER_SAVING_HINT_EXP_VERSION_CURRENT},
102-
{ZE_CACHE_RESERVATION_EXT_NAME, ZE_CACHE_RESERVATION_EXT_VERSION_CURRENT}};
102+
{ZE_CACHE_RESERVATION_EXT_NAME, ZE_CACHE_RESERVATION_EXT_VERSION_CURRENT},
103+
{ZE_DEVICE_LUID_EXT_NAME, ZE_DEVICE_LUID_EXT_VERSION_CURRENT}};
103104

104105
uint64_t uuidTimestamp = 0u;
105106

level_zero/core/test/unit_tests/sources/device/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ target_sources(${TARGET_NAME} PRIVATE
99
${CMAKE_CURRENT_SOURCE_DIR}/test_device.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/test_device_pci_speed_info.cpp
1111
${CMAKE_CURRENT_SOURCE_DIR}/test_device_pci_speed_info.h
12+
${CMAKE_CURRENT_SOURCE_DIR}/device_${DRIVER_MODEL}/test_device.cpp
1213
)
1314
add_subdirectories()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2020-2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/test/common/mocks/mock_device.h"
9+
#include "shared/test/common/mocks/mock_driver_info.h"
10+
#include "shared/test/common/mocks/mock_driver_model.h"
11+
#include "shared/test/common/test_macros/hw_test.h"
12+
13+
#include "level_zero/core/source/driver/driver_handle_imp.h"
14+
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
15+
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
16+
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
17+
18+
#include "gtest/gtest.h"
19+
20+
namespace L0 {
21+
namespace ult {
22+
23+
using LuidDeviceTest = Test<DeviceFixture>;
24+
25+
TEST_F(LuidDeviceTest, givenLuidDevicePropertiesStructureAndDRMDriverTypeThenUnsupportedReturned) {
26+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface());
27+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<NEO::MockDriverModelDRM>());
28+
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
29+
ze_device_luid_ext_properties_t deviceLuidProperties = {ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES};
30+
deviceProperties.pNext = &deviceLuidProperties;
31+
ze_result_t result = device->getProperties(&deviceProperties);
32+
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
33+
}
34+
35+
} // namespace ult
36+
} // namespace L0
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/gdi_interface.h"
9+
#include "shared/source/os_interface/windows/hw_device_id.h"
10+
#include "shared/source/os_interface/windows/os_context_win.h"
11+
#include "shared/source/os_interface/windows/os_environment_win.h"
12+
#include "shared/source/os_interface/windows/wddm/wddm.h"
13+
#include "shared/test/common/helpers/engine_descriptor_helper.h"
14+
#include "shared/test/common/mocks/mock_device.h"
15+
#include "shared/test/common/mocks/mock_driver_info.h"
16+
#include "shared/test/common/mocks/mock_driver_model.h"
17+
#include "shared/test/common/test_macros/hw_test.h"
18+
19+
#include "level_zero/core/source/driver/driver_handle_imp.h"
20+
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
21+
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
22+
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
23+
24+
#include "gtest/gtest.h"
25+
26+
namespace L0 {
27+
namespace ult {
28+
29+
#define ADAPTER_HANDLE_WDDM_FAKE (static_cast<D3DKMT_HANDLE>(0x40001234))
30+
31+
struct CloseAdapterMock {
32+
static NTSTATUS(APIENTRY closeAdapter)(
33+
const D3DKMT_CLOSEADAPTER *closeAdapter) {
34+
return STATUS_SUCCESS;
35+
}
36+
};
37+
38+
struct MockHwDeviceIdWddm : public HwDeviceIdWddm {
39+
using HwDeviceIdWddm::osEnvironment;
40+
MockHwDeviceIdWddm(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn, std::unique_ptr<UmKmDataTranslator> umKmDataTranslator) : HwDeviceIdWddm(adapterIn, adapterLuidIn, osEnvironmentIn, std::move(umKmDataTranslator)) {}
41+
};
42+
43+
class MockDriverModelWDDMLUID : public NEO::Wddm {
44+
public:
45+
MockDriverModelWDDMLUID(std::unique_ptr<HwDeviceIdWddm> &&hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(hwDeviceId), rootDeviceEnvironment) {
46+
}
47+
bool init() {
48+
return true;
49+
}
50+
51+
bool isDriverAvaliable() override {
52+
return false;
53+
}
54+
55+
bool skipResourceCleanup() {
56+
return true;
57+
}
58+
59+
MockDriverModelWDDMLUID(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique<MockHwDeviceIdWddm>(ADAPTER_HANDLE_WDDM_FAKE, LUID{0x12, 0x1234}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get(), std::make_unique<UmKmDataTranslator>()), rootDeviceEnvironment) {
60+
if (!rootDeviceEnvironment.executionEnvironment.osEnvironment.get()) {
61+
rootDeviceEnvironment.executionEnvironment.osEnvironment = std::make_unique<OsEnvironmentWin>();
62+
}
63+
static_cast<MockHwDeviceIdWddm *>(this->hwDeviceId.get())->osEnvironment = rootDeviceEnvironment.executionEnvironment.osEnvironment.get();
64+
OsEnvironmentWin *osEnvWin = reinterpret_cast<OsEnvironmentWin *>(static_cast<MockHwDeviceIdWddm *>(this->hwDeviceId.get())->osEnvironment);
65+
osEnvWin->gdi.get()->closeAdapter.mFunc = CloseAdapterMock::closeAdapter;
66+
}
67+
};
68+
69+
class MockOsContextWin : public OsContextWin {
70+
public:
71+
MockOsContextWin(MockDriverModelWDDMLUID &wddm, uint32_t contextId, const EngineDescriptor &engineDescriptor)
72+
: OsContextWin(wddm, contextId, engineDescriptor) {}
73+
};
74+
75+
using LuidDeviceTest = Test<DeviceFixture>;
76+
77+
TEST_F(LuidDeviceTest, givenOsContextWinAndGetLUIDArrayThenLUIDisValid) {
78+
auto luidMock = new MockDriverModelWDDMLUID(*neoDevice->executionEnvironment->rootDeviceEnvironments[0]);
79+
auto defaultEngine = defaultHwInfo->capabilityTable.defaultEngineType;
80+
OsContextWin osContext(*luidMock, 0u, EngineDescriptorHelper::getDefaultDescriptor({defaultEngine, EngineUsage::Regular}));
81+
std::vector<uint8_t> luidData;
82+
size_t arraySize = 8;
83+
osContext.getDeviceLuidArray(luidData, arraySize);
84+
uint64_t luid = 0;
85+
memcpy_s(&luid, sizeof(uint64_t), luidData.data(), sizeof(uint8_t) * luidData.size());
86+
EXPECT_NE(luid, (uint64_t)0);
87+
delete luidMock;
88+
}
89+
90+
TEST_F(LuidDeviceTest, givenLuidDevicePropertiesStructureAndWDDMDriverTypeThenSuccessReturned) {
91+
auto defaultEngine = defaultHwInfo->capabilityTable.defaultEngineType;
92+
auto luidMock = new MockDriverModelWDDMLUID(*neoDevice->executionEnvironment->rootDeviceEnvironments[0]);
93+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface());
94+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(luidMock));
95+
MockOsContextWin mockContext(*luidMock, 0u, EngineDescriptorHelper::getDefaultDescriptor({defaultEngine, EngineUsage::Regular}));
96+
auto &deviceRegularEngines = neoDevice->getRegularEngineGroups();
97+
auto &deviceEngine = deviceRegularEngines[0].engines[0];
98+
auto csr = deviceEngine.commandStreamReceiver;
99+
csr->setupContext(mockContext);
100+
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
101+
ze_device_luid_ext_properties_t deviceLuidProperties = {ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES};
102+
deviceProperties.pNext = &deviceLuidProperties;
103+
ze_result_t result = device->getProperties(&deviceProperties);
104+
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
105+
uint64_t luid = 0;
106+
LUID adapterLuid{0x12, 0x1234};
107+
memcpy_s(&luid, sizeof(uint64_t), &deviceLuidProperties.luid, sizeof(deviceLuidProperties.luid));
108+
uint32_t lowLUID = luid & 0xFFFFFFFF;
109+
uint32_t highLUID = ((luid & 0xFFFFFFFF00000000) >> 32);
110+
EXPECT_EQ(lowLUID, (uint32_t)adapterLuid.LowPart);
111+
EXPECT_EQ(highLUID, (uint32_t)adapterLuid.HighPart);
112+
EXPECT_NE(deviceLuidProperties.nodeMask, (uint32_t)0);
113+
}
114+
115+
TEST_F(LuidDeviceTest, givenLuidDevicePropertiesStructureAndDRMDriverTypeThenUnsupportedReturned) {
116+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface());
117+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::make_unique<NEO::MockDriverModelDRM>());
118+
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
119+
ze_device_luid_ext_properties_t deviceLuidProperties = {ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES};
120+
deviceProperties.pNext = &deviceLuidProperties;
121+
ze_result_t result = device->getProperties(&deviceProperties);
122+
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
123+
}
124+
125+
TEST_F(LuidDeviceTest, givenLuidDevicePropertiesStructureAndAndNoOsInterfaceThenUninitReturned) {
126+
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(nullptr);
127+
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
128+
ze_device_luid_ext_properties_t deviceLuidProperties = {ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES};
129+
deviceProperties.pNext = &deviceLuidProperties;
130+
ze_result_t result = device->getProperties(&deviceProperties);
131+
EXPECT_EQ(result, ZE_RESULT_ERROR_UNINITIALIZED);
132+
}
133+
134+
} // namespace ult
135+
} // namespace L0

0 commit comments

Comments
 (0)