Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.8

  |   Home   |   Support   |   FAQ   |  
gl.h
1 /*
2  * Copyright © 2012 Blue Brain Project, EPFL. All rights reserved.
3  * Copyright © 2012-2013 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 
110 static __hwloc_inline int
111 hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused,
112  hwloc_obj_t osdev,
113  unsigned *port, unsigned *device)
114 {
115  unsigned x = -1, y = -1;
116  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
117  && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) {
118  *port = x;
119  *device = y;
120  return 0;
121  }
122  errno = EINVAL;
123  return -1;
124 }
125 
129 #ifdef __cplusplus
130 } /* extern "C" */
131 #endif
132 
133 
134 #endif /* HWLOC_GL_H */
135 
static __hwloc_inline int hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused, 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:111
static __hwloc_inline 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
Structure of a topology object.
Definition: hwloc.h:331
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev
hwloc_obj_osdev_type_t type
Definition: hwloc.h:520
static __hwloc_inline 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
Operating system GPU device. For instance &quot;:0.0&quot; for a GL display, &quot;card0&quot; for a Linux DRM device...
Definition: hwloc.h:261
char * name
Object description if any.
Definition: hwloc.h:335
static __hwloc_inline 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:1175
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:339
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:577