From f04d4625a29a3a8fe61918b76244ecb36c50f21a Mon Sep 17 00:00:00 2001 From: Brice Goglin Date: Mon, 12 Jun 2023 11:43:53 +0200 Subject: [PATCH] levelzero: remove the setting of ZES_ENABLE_SYSMAN=1 Now that zesInit() is widely available, remove all the stuff trying to set ZES_ENABLE_SYSMAN=1 in the environment early. If people really cannot use a recent runtime with zesInit(), they should take care of setting ZES_ENABLE_SYSMAN=1. Signed-off-by: Brice Goglin --- hwloc/topology-levelzero.c | 18 -------------- hwloc/topology.c | 51 -------------------------------------- 2 files changed, 69 deletions(-) diff --git a/hwloc/topology-levelzero.c b/hwloc/topology-levelzero.c index 7aeac46679..5958b9af8e 100644 --- a/hwloc/topology-levelzero.c +++ b/hwloc/topology-levelzero.c @@ -533,24 +533,6 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status } return 0; } -#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. - */ - { - char *env = getenv("ZES_ENABLE_SYSMAN"); - if (!env) { - /* setenv() is safer than putenv() but not available on Windows */ -#ifdef HWLOC_WIN_SYS - putenv("ZES_ENABLE_SYSMAN=1"); -#else - setenv("ZES_ENABLE_SYSMAN", "1", 1); -#endif - } - } #endif /* !HWLOC_HAVE_ZESINIT */ res = zeInit(0); diff --git a/hwloc/topology.c b/hwloc/topology.c index b71d71c016..9bef2588b3 100644 --- a/hwloc/topology.c +++ b/hwloc/topology.c @@ -54,57 +54,6 @@ #endif -#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 - * an external levelzero plugin in a hwloc library built without levelzero (unlikely), - * he may have to manually set ZES_ENABLE_SYSMAN=1. - * - * Use the constructor if supported and/or the Windows DllMain callback. - * Do it in the main hwloc library instead of the levelzero component because - * the latter could be loaded later as a plugin. - * - * L0 seems to be using getenv() to check this variable on Windows - * (at least in the Intel Compute-Runtime of March 2021), - * but setenv() doesn't seem to exist on Windows, hence use putenv() to set the variable. - * - * For the record, Get/SetEnvironmentVariable() is not exactly the same as getenv/putenv(): - * - getenv() doesn't see what was set with SetEnvironmentVariable() - * - GetEnvironmentVariable() doesn't see putenv() in cygwin (while it does in MSVC and MinGW). - * Hence, if L0 ever switches from getenv() to GetEnvironmentVariable(), - * it will break in cygwin, we'll have to use both putenv() and SetEnvironmentVariable(). - * Hopefully L0 will provide a way to enable Sysman without env vars before it happens. - */ -#if HWLOC_HAVE_ATTRIBUTE_CONSTRUCTOR -static void hwloc_constructor(void) __attribute__((constructor)); -static void hwloc_constructor(void) -{ - if (!getenv("ZES_ENABLE_SYSMAN")) -#ifdef HWLOC_WIN_SYS - putenv("ZES_ENABLE_SYSMAN=1"); -#else - setenv("ZES_ENABLE_SYSMAN", "1", 1); -#endif -} -#endif -#ifdef HWLOC_WIN_SYS -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) -{ - if (fdwReason == DLL_PROCESS_ATTACH) { - if (!getenv("ZES_ENABLE_SYSMAN")) - /* Windows does not have a setenv, so use putenv. */ - putenv((char *) "ZES_ENABLE_SYSMAN=1"); - } - return TRUE; -} -#endif -#endif /* HWLOC_HAVE_LEVELZERO && !HWLOC_HAVE_ZESINIT */ - - unsigned hwloc_get_api_version(void) { return HWLOC_API_VERSION;