Skip to content

Commit a5790be

Browse files
committed
Regenerate UR
1 parent c1e3348 commit a5790be

File tree

6 files changed

+183
-180
lines changed

6 files changed

+183
-180
lines changed

unified-runtime/include/ur_api.h

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 165 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -371,204 +371,201 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
371371
setEnvVar("ZEL_ENABLE_BASIC_LEAK_CHECKER", "1");
372372
}
373373

374-
uint32_t UserForcedSysManInit = 0;
375-
// Check if the user has disabled the default L0 Env initialization.
376-
const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
377-
const char *UrRet = std::getenv("UR_L0_ENABLE_SYSMAN_ENV_DEFAULT");
378-
if (!UrRet)
379-
return 1;
380-
UserForcedSysManInit &= 1;
381-
return std::atoi(UrRet);
382-
}();
383-
384-
// Dynamically load the new L0 apis separately.
385-
// This must be done to avoid attempting to use symbols that do
386-
// not exist in older loader runtimes.
374+
uint32_t UserForcedSysManInit = 0;
375+
// Check if the user has disabled the default L0 Env initialization.
376+
const int UrSysManEnvInitEnabled = [&UserForcedSysManInit] {
377+
const char *UrRet = std::getenv("UR_L0_ENABLE_SYSMAN_ENV_DEFAULT");
378+
if (!UrRet)
379+
return 1;
380+
UserForcedSysManInit &= 1;
381+
return std::atoi(UrRet);
382+
}();
383+
384+
// Dynamically load the new L0 apis separately.
385+
// This must be done to avoid attempting to use symbols that do
386+
// not exist in older loader runtimes.
387387
#ifndef UR_STATIC_LEVEL_ZERO
388388
#ifdef _WIN32
389-
processHandle = GetModuleHandle(NULL);
389+
processHandle = GetModuleHandle(NULL);
390390
#else
391-
processHandle = nullptr;
391+
processHandle = nullptr;
392392
#endif
393393
#endif
394394

395-
// Setting these environment variables before running zeInit will enable
396-
// the validation layer in the Level Zero loader.
397-
if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
398-
setEnvVar("ZE_ENABLE_VALIDATION_LAYER", "1");
399-
setEnvVar("ZE_ENABLE_PARAMETER_VALIDATION", "1");
400-
}
401-
402-
if (getenv("SYCL_ENABLE_PCI") != nullptr) {
403-
UR_LOG(
404-
WARN,
405-
"WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n");
406-
}
395+
// Setting these environment variables before running zeInit will enable
396+
// the validation layer in the Level Zero loader.
397+
if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
398+
setEnvVar("ZE_ENABLE_VALIDATION_LAYER", "1");
399+
setEnvVar("ZE_ENABLE_PARAMETER_VALIDATION", "1");
400+
}
407401

408-
// TODO: We can still safely recover if something goes wrong during the
409-
// init. Implement handling segfault using sigaction.
402+
if (getenv("SYCL_ENABLE_PCI") != nullptr) {
403+
UR_LOG(WARN,
404+
"WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n");
405+
}
410406

411-
// We must only initialize the driver once, even if urPlatformGet() is
412-
// called multiple times. Declaring the return value as "static" ensures
413-
// it's only called once.
407+
// TODO: We can still safely recover if something goes wrong during the
408+
// init. Implement handling segfault using sigaction.
414409

415-
// Set ZES_ENABLE_SYSMAN by default if the user has not set it.
416-
if (UrSysManEnvInitEnabled) {
417-
setEnvVar("ZES_ENABLE_SYSMAN", "1");
418-
}
410+
// We must only initialize the driver once, even if urPlatformGet() is
411+
// called multiple times. Declaring the return value as "static" ensures
412+
// it's only called once.
419413

420-
// Init with all flags set to enable for all driver types to be init in
421-
// the application.
422-
ze_init_flags_t L0InitFlags = ZE_INIT_FLAG_GPU_ONLY;
423-
if (UrL0InitAllDrivers) {
424-
L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
425-
}
426-
UR_LOG(DEBUG, "\nzeInit with flags value of {}\n",
427-
static_cast<int>(L0InitFlags));
428-
ZeInitResult = ZE_CALL_NOCHECK(zeInit, (L0InitFlags));
429-
if (ZeInitResult != ZE_RESULT_SUCCESS) {
430-
const char *ErrorString = "Unknown";
431-
zeParseError(ZeInitResult, ErrorString);
432-
UR_LOG(ERR, "\nzeInit failed with {}\n", ErrorString);
433-
}
414+
// Set ZES_ENABLE_SYSMAN by default if the user has not set it.
415+
if (UrSysManEnvInitEnabled) {
416+
setEnvVar("ZES_ENABLE_SYSMAN", "1");
417+
}
434418

435-
bool useInitDrivers = false;
436-
zel_version_t loader_version = {};
437-
size_t num_components;
438-
auto result = zelLoaderGetVersions(&num_components, nullptr);
439-
if (result == ZE_RESULT_SUCCESS) {
440-
zel_component_version_t *versions =
441-
new zel_component_version_t[num_components];
442-
result = zelLoaderGetVersions(&num_components, versions);
443-
if (result == ZE_RESULT_SUCCESS) {
444-
for (size_t i = 0; i < num_components; ++i) {
445-
if (strncmp(versions[i].component_name, "loader",
446-
strlen("loader")) == 0) {
447-
loader_version = versions[i].component_lib_version;
448-
UR_LOG(DEBUG, "\nLevel Zero Loader Version: {}.{}.{}\n",
449-
loader_version.major, loader_version.minor,
450-
loader_version.patch);
451-
break;
452-
}
453-
}
454-
}
455-
delete[] versions;
456-
if (loader_version.major > 1 ||
457-
(loader_version.major == 1 && loader_version.minor > 19) ||
458-
(loader_version.major == 1 && loader_version.minor == 19 &&
459-
loader_version.patch >= 2)) {
460-
useInitDrivers = true;
461-
}
419+
// Init with all flags set to enable for all driver types to be init in
420+
// the application.
421+
ze_init_flags_t L0InitFlags = ZE_INIT_FLAG_GPU_ONLY;
422+
if (UrL0InitAllDrivers) {
423+
L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
424+
}
425+
UR_LOG(DEBUG, "\nzeInit with flags value of {}\n",
426+
static_cast<int>(L0InitFlags));
427+
ZeInitResult = ZE_CALL_NOCHECK(zeInit, (L0InitFlags));
428+
if (ZeInitResult != ZE_RESULT_SUCCESS) {
429+
const char *ErrorString = "Unknown";
430+
zeParseError(ZeInitResult, ErrorString);
431+
UR_LOG(ERR, "\nzeInit failed with {}\n", ErrorString);
432+
}
462433

463-
if ((loader_version.major == 1 && loader_version.minor < 21) ||
464-
(loader_version.major == 1 && loader_version.minor == 21 &&
465-
loader_version.patch < 2)) {
466-
UR_LOG(
467-
WARN,
468-
"WARNING: Level Zero Loader version is older than 1.21.2. "
469-
"Please update to the latest version for API logging support.\n");
434+
bool useInitDrivers = false;
435+
zel_version_t loader_version = {};
436+
size_t num_components;
437+
auto result = zelLoaderGetVersions(&num_components, nullptr);
438+
if (result == ZE_RESULT_SUCCESS) {
439+
zel_component_version_t *versions =
440+
new zel_component_version_t[num_components];
441+
result = zelLoaderGetVersions(&num_components, versions);
442+
if (result == ZE_RESULT_SUCCESS) {
443+
for (size_t i = 0; i < num_components; ++i) {
444+
if (strncmp(versions[i].component_name, "loader", strlen("loader")) ==
445+
0) {
446+
loader_version = versions[i].component_lib_version;
447+
UR_LOG(DEBUG, "\nLevel Zero Loader Version: {}.{}.{}\n",
448+
loader_version.major, loader_version.minor,
449+
loader_version.patch);
450+
break;
470451
}
471452
}
453+
}
454+
delete[] versions;
455+
if (loader_version.major > 1 ||
456+
(loader_version.major == 1 && loader_version.minor > 19) ||
457+
(loader_version.major == 1 && loader_version.minor == 19 &&
458+
loader_version.patch >= 2)) {
459+
useInitDrivers = true;
460+
}
461+
462+
if ((loader_version.major == 1 && loader_version.minor < 21) ||
463+
(loader_version.major == 1 && loader_version.minor == 21 &&
464+
loader_version.patch < 2)) {
465+
UR_LOG(WARN,
466+
"WARNING: Level Zero Loader version is older than 1.21.2. "
467+
"Please update to the latest version for API logging support.\n");
468+
}
469+
}
472470

473-
if (useInitDrivers) {
471+
if (useInitDrivers) {
474472
#ifdef UR_STATIC_LEVEL_ZERO
475-
initDriversFunctionPtr = zeInitDrivers;
473+
initDriversFunctionPtr = zeInitDrivers;
476474
#else
477-
initDriversFunctionPtr =
478-
(ze_pfnInitDrivers_t)ur_loader::LibLoader::getFunctionPtr(
479-
processHandle, "zeInitDrivers");
475+
initDriversFunctionPtr =
476+
(ze_pfnInitDrivers_t)ur_loader::LibLoader::getFunctionPtr(
477+
processHandle, "zeInitDrivers");
480478
#endif
481-
if (initDriversFunctionPtr) {
482-
UR_LOG(DEBUG, "\nzeInitDrivers with flags value of {}\n",
483-
static_cast<int>(InitDriversDesc.flags));
484-
ZeInitDriversResult =
485-
ZE_CALL_NOCHECK(initDriversFunctionPtr,
486-
(&ZeInitDriversCount, nullptr, &InitDriversDesc));
487-
if (ZeInitDriversResult == ZE_RESULT_SUCCESS) {
488-
InitDriversSupported = true;
489-
} else {
490-
const char *ErrorString = "Unknown";
491-
zeParseError(ZeInitDriversResult, ErrorString);
492-
UR_LOG(ERR, "\nzeInitDrivers failed with {}\n", ErrorString);
493-
}
494-
}
479+
if (initDriversFunctionPtr) {
480+
UR_LOG(DEBUG, "\nzeInitDrivers with flags value of {}\n",
481+
static_cast<int>(InitDriversDesc.flags));
482+
ZeInitDriversResult =
483+
ZE_CALL_NOCHECK(initDriversFunctionPtr,
484+
(&ZeInitDriversCount, nullptr, &InitDriversDesc));
485+
if (ZeInitDriversResult == ZE_RESULT_SUCCESS) {
486+
InitDriversSupported = true;
487+
} else {
488+
const char *ErrorString = "Unknown";
489+
zeParseError(ZeInitDriversResult, ErrorString);
490+
UR_LOG(ERR, "\nzeInitDrivers failed with {}\n", ErrorString);
495491
}
492+
}
493+
}
496494

497-
if (ZeInitResult != ZE_RESULT_SUCCESS &&
498-
ZeInitDriversResult != ZE_RESULT_SUCCESS) {
499-
// Absorb the ZE_RESULT_ERROR_UNINITIALIZED and just return 0 Platforms.
500-
UR_LOG(ERR, "Level Zero Uninitialized\n");
501-
return;
502-
}
495+
if (ZeInitResult != ZE_RESULT_SUCCESS &&
496+
ZeInitDriversResult != ZE_RESULT_SUCCESS) {
497+
// Absorb the ZE_RESULT_ERROR_UNINITIALIZED and just return 0 Platforms.
498+
UR_LOG(ERR, "Level Zero Uninitialized\n");
499+
return;
500+
}
503501

504-
PlatformVec platforms;
502+
PlatformVec platforms;
505503

506504
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
507-
auto [useV2, reason] = shouldUseV2Adapter();
508-
if (!useV2) {
509-
UR_LOG(INFO, "Skipping L0 V2 adapter: {}", reason);
510-
return;
511-
}
505+
auto [useV2, reason] = shouldUseV2Adapter();
506+
if (!useV2) {
507+
UR_LOG(INFO, "Skipping L0 V2 adapter: {}", reason);
508+
return;
509+
}
512510
#else
513-
auto [useV1, reason] = shouldUseV1Adapter();
514-
if (!useV1) {
515-
UR_LOG(INFO, "Skipping L0 V1 adapter: {}", reason);
516-
return;
517-
}
511+
auto [useV1, reason] = shouldUseV1Adapter();
512+
if (!useV1) {
513+
UR_LOG(INFO, "Skipping L0 V1 adapter: {}", reason);
514+
return;
515+
}
518516
#endif
519517

520-
// Check if the user has enabled the default L0 SysMan initialization.
521-
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
522-
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");
523-
if (!UrRet)
524-
return 0;
525-
UserForcedSysManInit &= 2;
526-
return std::atoi(UrRet);
527-
}();
528-
529-
bool ZesInitNeeded = UrSysmanZesinitEnable && !UrSysManEnvInitEnabled;
530-
// Unless the user has forced the SysMan init, we will check the device
531-
// version to see if the zesInit is needed.
532-
if (UserForcedSysManInit == 0 && checkDeviceIntelGPUIpVersionOrNewer(
533-
0x05004000) == UR_RESULT_SUCCESS) {
534-
if (UrSysManEnvInitEnabled) {
535-
setEnvVar("ZES_ENABLE_SYSMAN", "0");
536-
}
537-
ZesInitNeeded = true;
538-
}
539-
if (ZesInitNeeded) {
518+
// Check if the user has enabled the default L0 SysMan initialization.
519+
const int UrSysmanZesinitEnable = [&UserForcedSysManInit] {
520+
const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT");
521+
if (!UrRet)
522+
return 0;
523+
UserForcedSysManInit &= 2;
524+
return std::atoi(UrRet);
525+
}();
526+
527+
bool ZesInitNeeded = UrSysmanZesinitEnable && !UrSysManEnvInitEnabled;
528+
// Unless the user has forced the SysMan init, we will check the device
529+
// version to see if the zesInit is needed.
530+
if (UserForcedSysManInit == 0 &&
531+
checkDeviceIntelGPUIpVersionOrNewer(0x05004000) == UR_RESULT_SUCCESS) {
532+
if (UrSysManEnvInitEnabled) {
533+
setEnvVar("ZES_ENABLE_SYSMAN", "0");
534+
}
535+
ZesInitNeeded = true;
536+
}
537+
if (ZesInitNeeded) {
540538
#ifdef UR_STATIC_LEVEL_ZERO
541-
getDeviceByUUIdFunctionPtr = zesDriverGetDeviceByUuidExp;
542-
getSysManDriversFunctionPtr = zesDriverGet;
543-
sysManInitFunctionPtr = zesInit;
539+
getDeviceByUUIdFunctionPtr = zesDriverGetDeviceByUuidExp;
540+
getSysManDriversFunctionPtr = zesDriverGet;
541+
sysManInitFunctionPtr = zesInit;
544542
#else
545-
getDeviceByUUIdFunctionPtr = (zes_pfnDriverGetDeviceByUuidExp_t)
546-
ur_loader::LibLoader::getFunctionPtr(processHandle,
547-
"zesDriverGetDeviceByUuidExp");
548-
getSysManDriversFunctionPtr =
549-
(zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr(
550-
processHandle, "zesDriverGet");
551-
sysManInitFunctionPtr =
552-
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle,
553-
"zesInit");
543+
getDeviceByUUIdFunctionPtr =
544+
(zes_pfnDriverGetDeviceByUuidExp_t)ur_loader::LibLoader::getFunctionPtr(
545+
processHandle, "zesDriverGetDeviceByUuidExp");
546+
getSysManDriversFunctionPtr =
547+
(zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr(
548+
processHandle, "zesDriverGet");
549+
sysManInitFunctionPtr = (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(
550+
processHandle, "zesInit");
554551
#endif
555-
}
556-
if (getDeviceByUUIdFunctionPtr && getSysManDriversFunctionPtr &&
557-
sysManInitFunctionPtr) {
558-
ze_init_flags_t L0ZesInitFlags = 0;
559-
UR_LOG(DEBUG, "\nzesInit with flags value of {}\n",
560-
static_cast<int>(L0ZesInitFlags));
561-
ZesResult = ZE_CALL_NOCHECK(sysManInitFunctionPtr, (L0ZesInitFlags));
562-
} else {
563-
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
564-
}
552+
}
553+
if (getDeviceByUUIdFunctionPtr && getSysManDriversFunctionPtr &&
554+
sysManInitFunctionPtr) {
555+
ze_init_flags_t L0ZesInitFlags = 0;
556+
UR_LOG(DEBUG, "\nzesInit with flags value of {}\n",
557+
static_cast<int>(L0ZesInitFlags));
558+
ZesResult = ZE_CALL_NOCHECK(sysManInitFunctionPtr, (L0ZesInitFlags));
559+
} else {
560+
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
561+
}
565562

566-
ur_result_t err = initPlatforms(this, platforms, ZesResult);
567-
if (err == UR_RESULT_SUCCESS) {
568-
Platforms = std::move(platforms);
569-
} else {
570-
throw err;
571-
}
563+
ur_result_t err = initPlatforms(this, platforms, ZesResult);
564+
if (err == UR_RESULT_SUCCESS) {
565+
Platforms = std::move(platforms);
566+
} else {
567+
throw err;
568+
}
572569
}
573570

574571
void globalAdapterOnDemandCleanup() {

0 commit comments

Comments
 (0)