Hardware Locality (hwloc) 2.2.0

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
54 hwloc_gl_get_display_osdev_by_port_device(hwloc_topology_t topology,
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
85 hwloc_gl_get_display_osdev_by_name(hwloc_topology_t topology,
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
hwloc_obj_attr_u::hwloc_osdev_attr_s::type
hwloc_obj_osdev_type_t type
Definition: hwloc.h:652
hwloc_obj_attr_u::osdev
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev
hwloc_obj::attr
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:403
hwloc_gl_get_display_osdev_by_name
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
hwloc_topology_t
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:678
hwloc_obj
Structure of a topology object.
Definition: hwloc.h:384
hwloc_obj::name
char * name
Object-specific name if any. Mostly used for identifying OS devices and Misc objects where a name str...
Definition: hwloc.h:396
HWLOC_OBJ_OSDEV_GPU
@ 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:330
hwloc_get_next_osdev
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:1151
hwloc_gl_get_display_osdev_by_port_device
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
hwloc_gl_get_display_by_osdev
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:111