Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP DNM] levelzero: use zesInit() when available #594

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions hwloc/topology-levelzero.c
Expand Up @@ -604,8 +604,7 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
uint32_t nbdrivers, i, k, zeidx;
struct hwloc_osdev_array oarray;
struct hwloc_levelzero_ports hports;
int sysman_maybe_missing = 0; /* 1 if ZES_ENABLE_SYSMAN=1 was NOT set early, 2 if ZES_ENABLE_SYSMAN=0 */
char *env;
int sysman_maybe_missing = 0; /* 1 if ZES_ENABLE_SYSMAN=1 was NOT set early and zesInit() isn't available, 2 if ZES_ENABLE_SYSMAN=0 */

assert(dstatus->phase == HWLOC_DISC_PHASE_IO);

Expand All @@ -620,18 +619,22 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
#ifdef HWLOC_HAVE_ZESINIT
res = zesInit(0);
if (res != ZE_RESULT_SUCCESS) {
hwloc_debug("hwloc/levelzero: Failed to initialize LevelZero Sysman in zesInit(): 0x%x\n", (unsigned)res);
hwloc_debug("hwloc/levelzero: Continuing. Hopefully ZES_ENABLE_SYSMAN=1\n");
if (res == ZE_RESULT_ERROR_UNSUPPORTED_FEATURE) {
fprintf(stderr, "hwloc/levelzero: Unsupported zesInit(), please either an older or a more recent level-zero runtime.\n");
} else if (HWLOC_SHOW_ALL_ERRORS()) {
fprintf(stderr, "hwloc/levelzero: Failed to initialize LevelZero in zesInit(): 0x%x\n", (unsigned)res);
}
return 0;
}
#endif /* HWLOC_HAVE_ZESINIT */

#else /* !HWLOC_HAVE_ZESINIT */
/* Tell L0 to create sysman devices.
* If somebody already initialized L0 without Sysman,
* zesDeviceGetProperties() will fail and warn in hwloc__levelzero_properties_get().
* The lib constructor and Windows DllMain tried to set ZES_ENABLE_SYSMAN=1 early (see topology.c),
* we try again in case they didn't.
*/
env = getenv("ZES_ENABLE_SYSMAN");
{
char *env = getenv("ZES_ENABLE_SYSMAN");
if (!env) {
/* setenv() is safer than putenv() but not available on Windows */
#ifdef HWLOC_WIN_SYS
Expand All @@ -644,6 +647,8 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
} else if (!atoi(env)) {
sysman_maybe_missing = 2;
}
}
#endif /* !HWLOC_HAVE_ZESINIT */

res = zeInit(0);
if (res != ZE_RESULT_SUCCESS) {
Expand Down
5 changes: 3 additions & 2 deletions hwloc/topology.c
Expand Up @@ -54,9 +54,10 @@
#endif


#ifdef HWLOC_HAVE_LEVELZERO
#if (defined HWLOC_HAVE_LEVELZERO) && !(defined HWLOC_HAVE_ZESINIT)
/*
* Define ZES_ENABLE_SYSMAN=1 early so that the LevelZero backend gets Sysman enabled.
* This is only for old releases (<1.5) without zesInit().
*
* Only if the levelzero was enabled in this build so that we don't enable sysman
* for external levelzero users when hwloc doesn't need it. If somebody ever loads
Expand Down Expand Up @@ -101,7 +102,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
return TRUE;
}
#endif
#endif /* HWLOC_HAVE_LEVELZERO */
#endif /* HWLOC_HAVE_LEVELZERO && !HWLOC_HAVE_ZESINIT */


unsigned hwloc_get_api_version(void)
Expand Down
10 changes: 5 additions & 5 deletions tests/hwloc/levelzero.c
Expand Up @@ -26,19 +26,19 @@ int main(void)
#ifdef HWLOC_HAVE_ZESINIT
res = zesInit(0);
if (res != ZE_RESULT_SUCCESS) {
fprintf(stderr, "Failed to initialize LevelZero Sysman in zesInit(): %d\n", (int)res);
/* continuing, assuming ZES_ENABLE_SYSMAN=1 will be enough */
fprintf(stderr, "Failed to initialize LevelZero in zesInit(): %d\n", (int)res);
return 0;
}
#endif

#else
putenv((char *) "ZES_ENABLE_SYSMAN=1");
#endif

res = zeInit(0);
if (res != ZE_RESULT_SUCCESS) {
fprintf(stderr, "Failed to initialize LevelZero in zeInit(): %d\n", (int)res);
return 0;
}

hwloc_topology_init(&topology);
hwloc_topology_set_io_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_IMPORTANT);
hwloc_topology_load(topology);
Expand Down
1 change: 1 addition & 0 deletions tests/hwloc/ports/include/levelzero/level_zero/ze_api.h
Expand Up @@ -8,6 +8,7 @@

typedef int ze_result_t;
#define ZE_RESULT_SUCCESS 0
#define ZE_RESULT_ERROR_UNSUPPORTED_FEATURE 0x78000003

#define ZE_MAX_DEVICE_NAME 64

Expand Down