Debian Codegraph @

third-party/tbb/rfcs/proposed/numa_support/tbbbind-link-static-hwloc.org

raw
1 # -*- fill-column: 80; -*-
2
3 #+title: Link ~tbbbind~ with Static HWLOC for NUMA API predictability
4
5 *Note:* This document is a sub-RFC of the [[file:README.md][umbrella RFC about improving NUMA
6 support]]. Specifically, the "Increased availability of NUMA support" section.
7
8 * Introduction
9 oneTBB has a soft dependency on several variants of ~tbbbind~, which the library
10 loads during the initialization stage. Each ~tbbbind~, in turn, has a hard
11 dependency on a specific version of the HWLOC library [1, 2]. The soft
12 dependency means that the library continues the execution even if the system
13 loader fails to resolve the hard dependency on HWLOC for ~tbbbind~. In this
14 case, oneTBB does not discover the hardware topology. Instead, it defaults to
15 viewing all CPU cores as uniform, consistent with TBB behavior when NUMA
16 constraints are not used. As a result, the following code returns the irrelevant
17 values that do not reflect the actual topology:
18
19 #+begin_src C++
20 std::vector<oneapi::tbb::numa_node_id> numa_nodes = oneapi::tbb::info::numa_nodes();
21 std::vector<oneapi::tbb::core_type_id> core_types = oneapi::tbb::info::core_types();
22 #+end_src
23
24 This lack of valid HW topology, caused by the absence of a third-party library,
25 is the major problem with the current oneTBB behavior. The problem lies in the
26 lack of diagnostics making it difficult for developers to detect. As a result,
27 the code continues to run but fails to use NUMA as intended.
28
29 Dependency on a shared HWLOC library has the following benefits:
30 1. Code reuse with all of the positive consequences out of this, including
31 relying on the same code that has been tested and debugged, allowing the OS
32 to share it among different processes, which consequently improves on cache
33 locality and memory footprint. That's the primary purpose of shared
34 libraries.
35 2. A drop-in replacement. Users are able to use their own version of HWLOC
36 without recompilation of oneTBB. This specific version of HWLOC could include
37 a hotfix to support a particular and/or new hardware that a customer has, but
38 whose support is not yet upstreamed to HWLOC project. It is also possible
39 that such support won't be upstreamed at all if that hardware is not going to
40 be available for massive users. It could also be a development version of
41 HWLOC that someone wants to test on their systems first. Of course, they can
42 do it with the static version as well, but that's more cumbersome as it
43 requires recompilation of every dependent component.
44
45 The only disadvantage from depending on HWLOC library dynamically is that the
46 developers that use oneTBB's NUMA support API need to make sure the library is
47 available and can be found by oneTBB. Depending on the distribution model of a
48 developer's code, this is achieved either by:
49 1. Asking the end user to have necessary version of a dependency pre-installed.
50 2. Bundling necessary HWLOC version together with other pieces of a product
51 release.
52
53 However, the requirement to fulfill one of the above steps for the NUMA API to
54 start paying off may be considered as an incovenience and, what is more
55 important, it is not always obvious that one of these steps is needed.
56 Especially, due to silent behavior in case HWLOC library cannot be found in the
57 environment.
58
59 The proposal is to reduce the effect of the disadvantage of relying on a dynamic
60 HWLOC library. The improvements involve statically linking HWLOC with one of the
61 ~tbbbind~ libraries distributed together with oneTBB. At the same time, you
62 retain the flexibility to specify different version of HWLOC library if needed.
63
64 Since HWLOC 1.x is an older version and modern operating systems install HWLOC
65 2.x by default, the probability of users being restricted to HWLOC 1.x is
66 relatively small. Thus, we can reuse the filename of the ~tbbbind~ library
67 linked to HWLOC 1.x for the library linked against a static HWLOC 2.x.
68
69 * Proposal
70 1. Replace the dynamic link of ~tbbbind~ library currently linked
71 against HWLOC 1.x with a link to a static HWLOC library version 2.x.
72 2. Add loading of that ~tbbbind~ variant as the last attempt to resolve the
73 dependency on functionality provided by the ~tbbbind~ layer.
74 3. Update the oneTBB documentation, including
75 [[https://uxlfoundation.github.io/oneTBB/search.html?q=tbb%3A%3Ainfo][these
76 pages]], to detail the steps for identifying which ~tbbbind~ is being used.
77
78 ** Advantages
79 1. The proposed behavior introduces a fallback mechanism for resolving the HWLOC
80 library dependency when it is not in the environment, while still preferring
81 user-provided versions. As a result, the problematic oneTBB API usage works
82 as expected, returning an enumerated list of actual NUMA nodes and core types
83 on the system the code is running on, provided that the loaded HWLOC library
84 works on that system and that an application properly distributes all
85 binaries of oneTBB, sets the environment so that the necessary variant of
86 ~tbbbind~ library can be found and loaded.
87 2. Dropping support for HWLOC 1.x, does not introduce an additional ~tbbbind~
88 variant while maintaining support for widely used versions of HWLOC.
89
90 ** Disadvantages
91 By default, there is still no diagnostics if you fail to correctly setup an
92 environment with your version of HWLOC. Although, specifying the ~TBB_VERSION=1~
93 environment variable helps identify configuration issues quickly.
94
95 * Alternative Handling for Missing System Topology
96 The other behavior in case HWLOC library cannot be found is to be more explicit
97 about the problem of a missing component and to either issue a warning or to
98 refuse working requiring one of the ~tbbbind~ variant to be loaded (e.g., throw
99 an exception).
100
101 Comparing these alternative approaches to the one proposed.
102 ** Common Advantages
103 - Explicitly indicates that the functionality being used does not work, instead
104 of failing silently.
105 - Avoids the need to distribute an additional variant of ~tbbbind~ library.
106
107 ** Common Disadvantages
108 - Requires additional step from the user side to resolve the problem. In other
109 words, it does not provide complete solution to the problem.
110
111 *** Disadvantages of Issuing a Warning
112 - The warning may be unnoticed, especially if standard streams are closed.
113
114 *** Disadvantages of Throwing an Exception
115 - May break existing code that does not expect an exception to be thrown.
116 - Requires introduction of an additional exception hierarchy.
117
118 * References
119 1. [[https://www.open-mpi.org/projects/hwloc/][HWLOC project main page]]
120 2. [[https://github.com/open-mpi/hwloc][HWLOC project repository on GitHub]]