Skip to content

Commit 0ccd144

Browse files
committed
[L0] Enable zesInit by default given newer L0 IP version
- If the user has not overwritten the sysman init type, then the adapter will check the device ip version to determine if zesInit should be used and the env disabled. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent e9d94b1 commit 0ccd144

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

source/adapters/level_zero/adapter.cpp

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ ur_result_t getZesDeviceHandle(zes_uuid_t coreDeviceUuid,
7676
return UR_RESULT_ERROR_INVALID_ARGUMENT;
7777
}
7878

79+
ur_result_t checkDeviceIntelGPUIpVersionOrNewer(uint32_t ipVersion) {
80+
uint32_t ZeDriverCount = 0;
81+
ZE2UR_CALL(zeDriverGet, (&ZeDriverCount, nullptr));
82+
if (ZeDriverCount == 0) {
83+
return UR_RESULT_SUCCESS;
84+
}
85+
86+
std::vector<ze_driver_handle_t> ZeDrivers;
87+
std::vector<ze_device_handle_t> ZeDevices;
88+
ZeDrivers.resize(ZeDriverCount);
89+
90+
ZE2UR_CALL(zeDriverGet, (&ZeDriverCount, ZeDrivers.data()));
91+
for (uint32_t I = 0; I < ZeDriverCount; ++I) {
92+
ze_device_properties_t device_properties{};
93+
ze_device_ip_version_ext_t ipVersionExt{};
94+
ipVersionExt.stype = ZE_STRUCTURE_TYPE_DEVICE_IP_VERSION_EXT;
95+
ipVersionExt.pNext = nullptr;
96+
device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
97+
device_properties.pNext = &ipVersionExt;
98+
uint32_t ZeDeviceCount = 0;
99+
ZE2UR_CALL(zeDeviceGet, (ZeDrivers[I], &ZeDeviceCount, nullptr));
100+
ZeDevices.resize(ZeDeviceCount);
101+
ZE2UR_CALL(zeDeviceGet, (ZeDrivers[I], &ZeDeviceCount, ZeDevices.data()));
102+
// Check if this driver has GPU Devices that have this IP Version or newer.
103+
for (uint32_t D = 0; D < ZeDeviceCount; ++D) {
104+
ZE2UR_CALL(zeDeviceGetProperties, (ZeDevices[D], &device_properties));
105+
if (device_properties.type == ZE_DEVICE_TYPE_GPU &&
106+
device_properties.vendorId == 0x8086) {
107+
ze_device_ip_version_ext_t *ipVersionExt =
108+
(ze_device_ip_version_ext_t *)device_properties.pNext;
109+
if (ipVersionExt->ipVersion >= ipVersion) {
110+
return UR_RESULT_SUCCESS;
111+
}
112+
}
113+
}
114+
}
115+
return UR_RESULT_ERROR_UNSUPPORTED_VERSION;
116+
}
117+
79118
ur_result_t initPlatforms(PlatformVec &platforms,
80119
ze_result_t ZesResult) noexcept try {
81120
uint32_t ZeDriverCount = 0;
@@ -206,11 +245,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
206245
return;
207246
}
208247

248+
uint32_t UserForcedSysManInit = 0;
209249
// Check if the user has disabled the default L0 Env initialization.
210-
const int UrSysManEnvInitEnabled = [] {
250+
const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
211251
const char *UrRet = std::getenv("UR_L0_ENABLE_SYSMAN_ENV_DEFAULT");
212252
if (!UrRet)
213253
return 1;
254+
UserForcedSysManInit &= 1;
214255
return std::atoi(UrRet);
215256
}();
216257

@@ -275,16 +316,25 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
275316
#endif
276317

277318
// Check if the user has enabled the default L0 SysMan initialization.
278-
const int UrSysmanZesinitEnable = [] {
319+
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
279320
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");
280321
if (!UrRet)
281322
return 0;
323+
UserForcedSysManInit &= 2;
282324
return std::atoi(UrRet);
283325
}();
284326

285-
// Enable zesInit by default only if ZES_ENABLE_SYSMAN has not been set by
286-
// default and UrSysmanZesinitEnable is true.
287-
if (UrSysmanZesinitEnable && !UrSysManEnvInitEnabled) {
327+
bool ZesInitNeeded = UrSysmanZesinitEnable && !UrSysManEnvInitEnabled;
328+
// Unless the user has forced the SysMan init, we will check the device
329+
// version to see if the zesInit is needed.
330+
if (UserForcedSysManInit == 0 &&
331+
checkDeviceIntelGPUIpVersionOrNewer(0x05004000) == UR_RESULT_SUCCESS) {
332+
if (UrSysManEnvInitEnabled) {
333+
setEnvVar("ZES_ENABLE_SYSMAN", "0");
334+
}
335+
ZesInitNeeded = true;
336+
}
337+
if (ZesInitNeeded) {
288338
GlobalAdapter->getDeviceByUUIdFunctionPtr =
289339
(zes_pfnDriverGetDeviceByUuidExp_t)
290340
ur_loader::LibLoader::getFunctionPtr(

0 commit comments

Comments
 (0)