Hardware Locality (hwloc)
v2.0-20191027.0400.gite37e7d8
|
00001 /* 00002 * Copyright © 2012 Blue Brain Project, EPFL. All rights reserved. 00003 * Copyright © 2012-2013 Inria. All rights reserved. 00004 * See COPYING in top-level directory. 00005 */ 00006 00014 #ifndef HWLOC_GL_H 00015 #define HWLOC_GL_H 00016 00017 #include <hwloc.h> 00018 00019 #include <stdio.h> 00020 #include <string.h> 00021 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 00053 static __hwloc_inline hwloc_obj_t 00054 hwloc_gl_get_display_osdev_by_port_device(hwloc_topology_t topology, 00055 unsigned port, unsigned device) 00056 { 00057 unsigned x = (unsigned) -1, y = (unsigned) -1; 00058 hwloc_obj_t osdev = NULL; 00059 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) { 00060 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type 00061 && osdev->name 00062 && sscanf(osdev->name, ":%u.%u", &x, &y) == 2 00063 && port == x && device == y) 00064 return osdev; 00065 } 00066 errno = EINVAL; 00067 return NULL; 00068 } 00069 00084 static __hwloc_inline hwloc_obj_t 00085 hwloc_gl_get_display_osdev_by_name(hwloc_topology_t topology, 00086 const char *name) 00087 { 00088 hwloc_obj_t osdev = NULL; 00089 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) { 00090 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type 00091 && osdev->name 00092 && !strcmp(name, osdev->name)) 00093 return osdev; 00094 } 00095 errno = EINVAL; 00096 return NULL; 00097 } 00098 00110 static __hwloc_inline int 00111 hwloc_gl_get_display_by_osdev(hwloc_topology_t topology __hwloc_attribute_unused, 00112 hwloc_obj_t osdev, 00113 unsigned *port, unsigned *device) 00114 { 00115 unsigned x = -1, y = -1; 00116 if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type 00117 && sscanf(osdev->name, ":%u.%u", &x, &y) == 2) { 00118 *port = x; 00119 *device = y; 00120 return 0; 00121 } 00122 errno = EINVAL; 00123 return -1; 00124 } 00125 00129 #ifdef __cplusplus 00130 } /* extern "C" */ 00131 #endif 00132 00133 00134 #endif /* HWLOC_GL_H */ 00135