diff --git a/hwloc/topology-levelzero.c b/hwloc/topology-levelzero.c index b2a75d14a6..0b6a1f8edd 100644 --- a/hwloc/topology-levelzero.c +++ b/hwloc/topology-levelzero.c @@ -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); @@ -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 @@ -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) { diff --git a/hwloc/topology.c b/hwloc/topology.c index db51ad7292..e3471a42c0 100644 --- a/hwloc/topology.c +++ b/hwloc/topology.c @@ -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 @@ -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) diff --git a/tests/hwloc/levelzero.c b/tests/hwloc/levelzero.c index db0334e77f..04fe6e9bbe 100644 --- a/tests/hwloc/levelzero.c +++ b/tests/hwloc/levelzero.c @@ -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); diff --git a/tests/hwloc/ports/include/levelzero/level_zero/ze_api.h b/tests/hwloc/ports/include/levelzero/level_zero/ze_api.h index da042819fa..5fefd9bcd1 100644 --- a/tests/hwloc/ports/include/levelzero/level_zero/ze_api.h +++ b/tests/hwloc/ports/include/levelzero/level_zero/ze_api.h @@ -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