1 /**
2 * Copyright (C) NVIDIA Corporation. 2019.  ALL RIGHTS RESERVED.
3 *
4 * See file LICENSE for terms.
5 */
6 
7 #ifndef UCS_TOPO_H
8 #define UCS_TOPO_H
9 
10 #include <ucs/type/status.h>
11 #include <limits.h>
12 #include <stdio.h>
13 #include <stdint.h>
14 
15 BEGIN_C_DECLS
16 
17 #define UCS_SYS_DEVICE_ID_UNKNOWN UINT_MAX /* Indicate that the ucs_sys_device_t
18                                               for the device has no real bus_id
19                                               E.g. virtual devices like CMA/knem
20                                             */
21 
22 
23 /** @file topo.h */
24 
25 typedef struct ucs_sys_bus_id {
26     uint16_t domain;   /* range: 0 to ffff */
27     uint8_t  bus;      /* range: 0 to ff */
28     uint8_t  slot;     /* range: 0 to 1f */
29     uint8_t  function; /* range: 0 to 7 */
30 } ucs_sys_bus_id_t;
31 
32 
33 /**
34  * @ingroup UCS_RESOURCE
35  * System Device Index
36  * Obtained from a translation of the device bus id into an unsigned int
37  * Refer ucs_topo_find_device_by_bus_id()
38  */
39 typedef unsigned ucs_sys_device_t;
40 
41 
42 /*
43  * Capture the estimated latency, bandwidth between two system devices
44  * referred by ucs_sys_device_t handle
45  */
46 typedef struct ucs_sys_dev_distance {
47     double latency;   /**< in seconds */
48     double bandwidth; /**< in bytes/second */
49 } ucs_sys_dev_distance_t;
50 
51 
52 /**
53  * Find system device by pci bus id
54  *
55  * @param [in]  bus_id  pointer to bus id of the device of interest
56  * @param [out] sys_dev system device index associated with the bus_id
57  *
58  * @return UCS_OK or error in case device cannot be found
59  */
60 ucs_status_t ucs_topo_find_device_by_bus_id(const ucs_sys_bus_id_t *bus_id,
61                                             ucs_sys_device_t *sys_dev);
62 
63 
64 /**
65  * Find the distance between two system devices (in terms of latency,
66  * bandwidth, hops, etc)
67  *
68  * @param [in]  device1  system device index of the first device
69  * @param [in]  device2  system device index of the second device
70  * @param [out] distance result populated with distance details between the two
71  *                       devices
72  *
73  * @return UCS_OK or error in case distance cannot be determined
74  */
75 ucs_status_t ucs_topo_get_distance(ucs_sys_device_t device1,
76                                    ucs_sys_device_t device2,
77                                    ucs_sys_dev_distance_t *distance);
78 
79 
80 /**
81  * Print a map indicating the topology information between system
82  * devices discovered
83  */
84 void ucs_topo_print_info(FILE *stream);
85 
86 /**
87  * Initialize UCS topology subsystem.
88  */
89 void ucs_topo_init();
90 
91 /**
92  * Cleanup UCS topology subsystem.
93  */
94 void ucs_topo_cleanup();
95 
96 END_C_DECLS
97 
98 #endif
99