Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:16

0001 /*
0002  * Copyright © 2012 Blue Brain Project, EPFL. All rights reserved.
0003  * Copyright © 2012-2023 Inria.  All rights reserved.
0004  * See COPYING in top-level directory.
0005  */
0006 
0007 /** \file
0008  * \brief Macros to help interaction between hwloc and OpenGL displays.
0009  *
0010  * Applications that use both hwloc and OpenGL may want to include
0011  * this file so as to get topology information for OpenGL displays.
0012  */
0013 
0014 #ifndef HWLOC_GL_H
0015 #define HWLOC_GL_H
0016 
0017 #include "hwloc.h"
0018 
0019 #include <stdio.h>
0020 #include <string.h>
0021 
0022 
0023 #ifdef __cplusplus
0024 extern "C" {
0025 #endif
0026 
0027 
0028 /** \defgroup hwlocality_gl Interoperability with OpenGL displays
0029  *
0030  * This interface offers ways to retrieve topology information about
0031  * OpenGL displays.
0032  *
0033  * Only the NVIDIA display locality information is currently available,
0034  * using the NV-CONTROL X11 extension and the NVCtrl library.
0035  *
0036  * @{
0037  */
0038 
0039 /** \brief Get the hwloc OS device object corresponding to the
0040  * OpenGL display given by port and device index.
0041  *
0042  * \return The hwloc OS device object describing the OpenGL display
0043  * whose port (server) is \p port and device (screen) is \p device.
0044  * \return \c NULL if none could be found.
0045  *
0046  * The topology \p topology does not necessarily have to match the current
0047  * machine. For instance the topology may be an XML import of a remote host.
0048  * I/O devices detection and the GL component must be enabled in the topology.
0049  *
0050  * \note The corresponding PCI device object can be obtained by looking
0051  * at the OS device parent object (unless PCI devices are filtered out).
0052  */
0053 static __hwloc_inline hwloc_obj_t
0054 hwloc_gl_get_display_osdev_by_port_device(hwloc_topology_t topology,
0055                       unsigned port, unsigned device)
0056 {
0057         unsigned x = (unsigned) -1, y = (unsigned) -1;
0058         hwloc_obj_t osdev = NULL;
0059         while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
0060                 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
0061                     && osdev->name
0062                     && sscanf(osdev->name, ":%u.%u", &x, &y) == 2
0063                     && port == x && device == y)
0064                         return osdev;
0065         }
0066     errno = EINVAL;
0067         return NULL;
0068 }
0069 
0070 /** \brief Get the hwloc OS device object corresponding to the
0071  * OpenGL display given by name.
0072  *
0073  * \return The hwloc OS device object describing the OpenGL display
0074  * whose name is \p name, built as ":port.device" such as ":0.0" .
0075  * \return \c NULL if none could be found.
0076  *
0077  * The topology \p topology does not necessarily have to match the current
0078  * machine. For instance the topology may be an XML import of a remote host.
0079  * I/O devices detection and the GL component must be enabled in the topology.
0080  *
0081  * \note The corresponding PCI device object can be obtained by looking
0082  * at the OS device parent object (unless PCI devices are filtered out).
0083  */
0084 static __hwloc_inline hwloc_obj_t
0085 hwloc_gl_get_display_osdev_by_name(hwloc_topology_t topology,
0086                    const char *name)
0087 {
0088         hwloc_obj_t osdev = NULL;
0089         while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
0090                 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
0091                     && osdev->name
0092                     && !strcmp(name, osdev->name))
0093                         return osdev;
0094         }
0095     errno = EINVAL;
0096         return NULL;
0097 }
0098 
0099 /** \brief Get the OpenGL display port and device corresponding
0100  * to the given hwloc OS object.
0101  *
0102  * Retrieves the OpenGL display port (server) in \p port and device (screen)
0103  * in \p screen that correspond to the given hwloc OS device object.
0104  *
0105  * \return 0 on success.
0106  * \return -1 if none could be found.
0107  *
0108  * The topology \p topology does not necessarily have to match the current
0109  * machine. For instance the topology may be an XML import of a remote host.
0110  * I/O devices detection and the GL component must be enabled in the topology.
0111  */
0112 static __hwloc_inline int
0113 hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused,
0114                   hwloc_obj_t osdev,
0115                   unsigned *port, unsigned *device)
0116 {
0117     unsigned x = -1, y = -1;
0118     if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
0119         && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) {
0120         *port = x;
0121         *device = y;
0122         return 0;
0123     }
0124     errno = EINVAL;
0125     return -1;
0126 }
0127 
0128 /** @} */
0129 
0130 
0131 #ifdef __cplusplus
0132 } /* extern "C" */
0133 #endif
0134 
0135 
0136 #endif /* HWLOC_GL_H */
0137