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