Skip to content

Commit 8851359

Browse files
authored
Merge pull request #2353 from nrspruit/zesInit_default_support
[L0] Enable zesInit by default given newer L0 IP version
2 parents 78ec89d + 6602480 commit 8851359

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
/**
80119
* @brief Initializes the platforms by querying Level Zero drivers and devices.
81120
*
@@ -282,11 +321,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
282321
return;
283322
}
284323

324+
uint32_t UserForcedSysManInit = 0;
285325
// Check if the user has disabled the default L0 Env initialization.
286-
const int UrSysManEnvInitEnabled = [] {
326+
const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
287327
const char *UrRet = std::getenv("UR_L0_ENABLE_SYSMAN_ENV_DEFAULT");
288328
if (!UrRet)
289329
return 1;
330+
UserForcedSysManInit &= 1;
290331
return std::atoi(UrRet);
291332
}();
292333

@@ -419,16 +460,25 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
419460
#endif
420461

421462
// Check if the user has enabled the default L0 SysMan initialization.
422-
const int UrSysmanZesinitEnable = [] {
463+
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
423464
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");
424465
if (!UrRet)
425466
return 0;
467+
UserForcedSysManInit &= 2;
426468
return std::atoi(UrRet);
427469
}();
428470

429-
// Enable zesInit by default only if ZES_ENABLE_SYSMAN has not been set by
430-
// default and UrSysmanZesinitEnable is true.
431-
if (UrSysmanZesinitEnable && !UrSysManEnvInitEnabled) {
471+
bool ZesInitNeeded = UrSysmanZesinitEnable && !UrSysManEnvInitEnabled;
472+
// Unless the user has forced the SysMan init, we will check the device
473+
// version to see if the zesInit is needed.
474+
if (UserForcedSysManInit == 0 &&
475+
checkDeviceIntelGPUIpVersionOrNewer(0x05004000) == UR_RESULT_SUCCESS) {
476+
if (UrSysManEnvInitEnabled) {
477+
setEnvVar("ZES_ENABLE_SYSMAN", "0");
478+
}
479+
ZesInitNeeded = true;
480+
}
481+
if (ZesInitNeeded) {
432482
GlobalAdapter->getDeviceByUUIdFunctionPtr =
433483
(zes_pfnDriverGetDeviceByUuidExp_t)
434484
ur_loader::LibLoader::getFunctionPtr(

0 commit comments

Comments
 (0)