Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.7.2

  |   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 
17 #ifndef HWLOC_GL_H
18 #define HWLOC_GL_H
19 
20 #include <hwloc.h>
21 
22 #include <stdio.h>
23 #include <string.h>
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 
49 static __hwloc_inline hwloc_obj_t
51  unsigned port, unsigned device)
52 {
53  unsigned x = (unsigned) -1, y = (unsigned) -1;
54  hwloc_obj_t osdev = NULL;
55  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
56  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
57  && osdev->name
58  && sscanf(osdev->name, ":%u.%u", &x, &y) == 2
59  && port == x && device == y)
60  return osdev;
61  }
62  errno = EINVAL;
63  return NULL;
64 }
65 
80 static __hwloc_inline hwloc_obj_t
82  const char *name)
83 {
84  hwloc_obj_t osdev = NULL;
85  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
86  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
87  && osdev->name
88  && !strcmp(name, osdev->name))
89  return osdev;
90  }
91  errno = EINVAL;
92  return NULL;
93 }
94 
106 static __hwloc_inline int
107 hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused,
108  hwloc_obj_t osdev,
109  unsigned *port, unsigned *device)
110 {
111  unsigned x = -1, y = -1;
112  if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
113  && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) {
114  *port = x;
115  *device = y;
116  return 0;
117  }
118  errno = EINVAL;
119  return -1;
120 }
121 
125 #ifdef __cplusplus
126 } /* extern "C" */
127 #endif
128 
129 
130 #endif /* HWLOC_GL_H */
131