Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v2.8.0

  |   Home   |   Support   |   FAQ   |  
gl.h
1 /*
2  * Copyright © 2012 Blue Brain Project, EPFL. All rights reserved.
3  * Copyright © 2012-2021 Inria. All rights reserved.
4  * See COPYING in top-level directory.
5  */
6 
14 #ifndef HWLOC_GL_H
15 #define HWLOC_GL_H
16 
17 #include "hwloc.h"
18 
19 #include <stdio.h>
20 #include <string.h>
21 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 
53 static __hwloc_inline hwloc_obj_t
55  unsigned port, unsigned device)
56 {
57  unsigned x = (unsigned) -1, y = (unsigned) -1;
58  hwloc_obj_t osdev = NULL;
59  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
60  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
61  && osdev->name
62  && sscanf(osdev->name, ":%u.%u", &x, &y) == 2
63  && port == x && device == y)
64  return osdev;
65  }
66  errno = EINVAL;
67  return NULL;
68 }
69 
84 static __hwloc_inline hwloc_obj_t
86  const char *name)
87 {
88  hwloc_obj_t osdev = NULL;
89  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
90  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
91  && osdev->name
92  && !strcmp(name, osdev->name))
93  return osdev;
94  }
95  errno = EINVAL;
96  return NULL;
97 }
98 
111 static __hwloc_inline int
112 hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused,
113  hwloc_obj_t osdev,
114  unsigned *port, unsigned *device)
115 {
116  unsigned x = -1, y = -1;
117  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
118  && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) {
119  *port = x;
120  *device = y;
121  return 0;
122  }
123  errno = EINVAL;
124  return -1;
125 }
126 
130 #ifdef __cplusplus
131 } /* extern "C" */
132 #endif
133 
134 
135 #endif /* HWLOC_GL_H */
136 
@ HWLOC_OBJ_OSDEV_GPU
Operating system GPU device. For instance ":0.0" for a GL display, "card0" for a Linux DRM device.
Definition: hwloc.h:342
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:692
static hwloc_obj_t hwloc_get_next_osdev(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next OS device in the system.
Definition: helper.h:1194
static hwloc_obj_t hwloc_gl_get_display_osdev_by_name(hwloc_topology_t topology, const char *name)
Get the hwloc OS device object corresponding to the OpenGL display given by name.
Definition: gl.h:85
static hwloc_obj_t hwloc_gl_get_display_osdev_by_port_device(hwloc_topology_t topology, unsigned port, unsigned device)
Get the hwloc OS device object corresponding to the OpenGL display given by port and device index.
Definition: gl.h:54
static int hwloc_gl_get_display_by_osdev(hwloc_topology_t topology, hwloc_obj_t osdev, unsigned *port, unsigned *device)
Get the OpenGL display port and device corresponding to the given hwloc OS object.
Definition: gl.h:112
Structure of a topology object.
Definition: hwloc.h:396
char * name
Object-specific name if any. Mostly used for identifying OS devices and Misc objects where a name str...
Definition: hwloc.h:408
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:415
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev
hwloc_obj_osdev_type_t type
Definition: hwloc.h:666