Hardware Locality (hwloc) 2.9.2

gl.h
1/*
2 * Copyright © 2012 Blue Brain Project, EPFL. All rights reserved.
3 * Copyright © 2012-2023 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
112 static __hwloc_inline int
113 hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused,
114 hwloc_obj_t osdev,
115 unsigned *port, unsigned *device)
116{
117 unsigned x = -1, y = -1;
118 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
119 && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) {
120 *port = x;
121 *device = y;
122 return 0;
123 }
124 errno = EINVAL;
125 return -1;
126}
127
131#ifdef __cplusplus
132} /* extern "C" */
133#endif
134
135
136#endif /* HWLOC_GL_H */
137
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:363
hwloc_topology_t
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:716
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:1280
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_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:113
hwloc_obj
Structure of a topology object.
Definition: hwloc.h:420
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:432
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:439
hwloc_obj_attr_u::osdev
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev
hwloc_obj_attr_u::hwloc_osdev_attr_s::type
hwloc_obj_osdev_type_t type
Definition: hwloc.h:690