Skip to content

Commit 93fbfa3

Browse files
committed
levelzero: use zesInit() when available
When zesInit() is available (starting in specs 1.5), call it to further reduce problems with ZES_ENABLE_SYSMAN=1 not being set in the environment. The current implementation of zesInit() in the oneAPI compute runtime returns an "unsupported feature" 0x78000003 error (or return success and do nothing if ZES_ENABLE_SYSMAN=1) but hopefully things will improve quickly. Once zesInit() will be widely available/implemented, we'll consider disabling the ZES_ENABLE_SYSMAN=1 stuff if zesInit() is found at configure time, and later remove it. Signed-off-by: Brice Goglin <[email protected]>
1 parent fd66701 commit 93fbfa3

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

config/hwloc.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ return clGetDeviceIDs(0, 0, 0, NULL, NULL);
14091409
HWLOC_PKG_CHECK_MODULES([LEVELZERO], [libze_loader], [zesDevicePciGetProperties], [level_zero/zes_api.h],
14101410
[hwloc_levelzero_happy=yes
14111411
HWLOC_LEVELZERO_REQUIRES=libze_loader
1412+
AC_CHECK_LIB([ze_loader], [zesInit], [AC_DEFINE(HWLOC_HAVE_ZESINIT, 1, [Define to 1 if zesInit is available])])
14121413
AC_CHECK_LIB([ze_loader], [zeDevicePciGetPropertiesExt], [AC_DEFINE(HWLOC_HAVE_ZEDEVICEPCIGETPROPERTIESEXT, 1, [Define to 1 if zeDevicePciGetPropertiesExt is available])])
14131414
], [hwloc_levelzero_happy=no])
14141415
if test x$hwloc_levelzero_happy = xno; then
@@ -1419,6 +1420,7 @@ return clGetDeviceIDs(0, 0, 0, NULL, NULL);
14191420
AC_CHECK_LIB([ze_loader],
14201421
[zesDevicePciGetProperties],
14211422
[HWLOC_LEVELZERO_LIBS="-lze_loader"
1423+
AC_CHECK_LIB([ze_loader], [zesInit], [AC_DEFINE(HWLOC_HAVE_ZESINIT, 1, [Define to 1 if zesInit is available])])
14221424
AC_CHECK_LIB([ze_loader], [zeDevicePciGetPropertiesExt], [AC_DEFINE(HWLOC_HAVE_ZEDEVICEPCIGETPROPERTIESEXT, 1, [Define to 1 if zeDevicePciGetPropertiesExt is available])])
14231425
], [hwloc_levelzero_happy=no])
14241426
], [hwloc_levelzero_happy=no])

hwloc/topology-levelzero.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,14 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
617617

618618
hwloc__levelzero_ports_init(&hports);
619619

620+
#ifdef HWLOC_HAVE_ZESINIT
621+
res = zesInit(0);
622+
if (res != ZE_RESULT_SUCCESS) {
623+
hwloc_debug("hwloc/levelzero: Failed to initialize LevelZero Sysman in zesInit(): 0x%x\n", (unsigned)res);
624+
hwloc_debug("hwloc/levelzero: Continuing. Hopefully ZES_ENABLE_SYSMAN=1\n");
625+
}
626+
#endif /* HWLOC_HAVE_ZESINIT */
627+
620628
/* Tell L0 to create sysman devices.
621629
* If somebody already initialized L0 without Sysman,
622630
* zesDeviceGetProperties() will fail and warn in hwloc__levelzero_properties_get().

include/hwloc/levelzero.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ extern "C" {
4444
* the Level Zero device \p device.
4545
*
4646
* Topology \p topology and device \p device must match the local machine.
47-
* The Level Zero must have been initialized with Sysman enabled
48-
* (ZES_ENABLE_SYSMAN=1 in the environment).
47+
* The Level Zero library must have been initialized with Sysman enabled
48+
* (by calling zesInit(0) if supported,
49+
* or by setting ZES_ENABLE_SYSMAN=1 in the environment).
4950
* I/O devices detection and the Level Zero component are not needed in the
5051
* topology.
5152
*

tests/hwloc/levelzero.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2021 Inria. All rights reserved.
2+
* Copyright © 2021-2023 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -9,6 +9,7 @@
99
#include <level_zero/ze_api.h>
1010
#include <level_zero/zes_api.h>
1111

12+
#include "private/autogen/config.h" /* for HWLOC_HAVE_ZESINIT */
1213
#include "hwloc.h"
1314
#include "hwloc/levelzero.h"
1415

@@ -22,6 +23,14 @@ int main(void)
2223
ze_result_t res;
2324
int err = 0;
2425

26+
#ifdef HWLOC_HAVE_ZESINIT
27+
res = zesInit(0);
28+
if (res != ZE_RESULT_SUCCESS) {
29+
fprintf(stderr, "Failed to initialize LevelZero Sysman in zesInit(): %d\n", (int)res);
30+
/* continuing, assuming ZES_ENABLE_SYSMAN=1 will be enough */
31+
}
32+
#endif
33+
2534
putenv((char *) "ZES_ENABLE_SYSMAN=1");
2635

2736
res = zeInit(0);

tests/hwloc/ports/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright © 2009-2022 Inria. All rights reserved.
1+
# Copyright © 2009-2023 Inria. All rights reserved.
22
# Copyright © 2009, 2011-2012, 2020 Université Bordeaux
33
# Copyright © 2009-2014 Cisco Systems, Inc. All rights reserved.
44
# See COPYING in top-level directory.
@@ -176,7 +176,8 @@ libhwloc_port_levelzero_la_SOURCES = \
176176
include/levelzero/level_zero/ze_api.h \
177177
include/levelzero/level_zero/zes_api.h
178178
libhwloc_port_levelzero_la_CPPFLAGS = $(common_CPPFLAGS) \
179-
-I$(HWLOC_top_srcdir)/tests/hwloc/ports/include/levelzero
179+
-I$(HWLOC_top_srcdir)/tests/hwloc/ports/include/levelzero \
180+
-DHWLOC_HAVE_ZESINIT=1
180181

181182
nodist_libhwloc_port_gl_la_SOURCES = topology-gl.c
182183
libhwloc_port_gl_la_SOURCES = \

tests/hwloc/ports/include/levelzero/level_zero/zes_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2020-2022 Inria. All rights reserved.
2+
* Copyright © 2020-2023 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -8,6 +8,8 @@
88

99
#include "ze_api.h"
1010

11+
extern ze_result_t zesInit(int);
12+
1113
typedef void * zes_device_handle_t;
1214

1315
typedef struct {

0 commit comments

Comments
 (0)