Hardware Locality (hwloc): gl.h Source File

Hardware Locality (hwloc) 2.14.0rc1

gl.h
1/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright © 2012 Blue Brain Project, EPFL. All rights reserved.
4 * Copyright © 2012-2023 Inria. All rights reserved.
5 * See COPYING in top-level directory.
6 */
7
14
15#ifndef HWLOC_GL_H
16#define HWLOC_GL_H
17
18#include "hwloc.h"
19
20#include <stdio.h>
21#include <string.h>
22
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
42
61static __hwloc_inline hwloc_obj_t
62hwloc_gl_get_display_osdev_by_port_device(hwloc_topology_t topology,
63 unsigned port, unsigned device)
64{
65 unsigned x = (unsigned) -1, y = (unsigned) -1;
66 hwloc_obj_t osdev = NULL;
67 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
68 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
69 && osdev->name
70 && sscanf(osdev->name, ":%u.%u", &x, &y) == 2
71 && port == x && device == y)
72 return osdev;
73 }
74 errno = EINVAL;
75 return NULL;
76}
77
96static __hwloc_inline hwloc_obj_t
97hwloc_gl_get_display_osdev_by_name(hwloc_topology_t topology,
98 const char *name)
99{
100 hwloc_obj_t osdev = NULL;
101 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
102 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
103 && osdev->name
104 && !strcmp(name, osdev->name))
105 return osdev;
106 }
107 errno = EINVAL;
108 return NULL;
109}
110
128static __hwloc_inline int
129hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused,
130 hwloc_obj_t osdev,
131 unsigned *port, unsigned *device)
132{
133 unsigned x = -1, y = -1;
134 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
135 && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) {
136 *port = x;
137 *device = y;
138 return 0;
139 }
140 errno = EINVAL;
141 return -1;
142}
143
145
146
147#ifdef __cplusplus
148} /* extern "C" */
149#endif
150
151
152#endif /* HWLOC_GL_H */
153
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:380
hwloc_obj_t
struct hwloc_obj * hwloc_obj_t
Convenience typedef; a pointer to a struct hwloc_obj.
Definition hwloc.h:637
hwloc_topology_t
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition hwloc.h:748
hwloc_get_next_osdev
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:1291
hwloc_gl_get_display_osdev_by_port_device
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:62
hwloc_gl_get_display_by_osdev
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:129
hwloc_gl_get_display_osdev_by_name
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:97
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:449
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:456
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:722