1/*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2020 Inria.  All rights reserved.
4 * Copyright © 2009-2013 Université Bordeaux
5 * Copyright © 2009-2020 Cisco Systems, Inc.  All rights reserved.
6 * Copyright © 2020 Hewlett Packard Enterprise.  All rights reserved.
7 * See COPYING in top-level directory.
8 */
9
10/*! \page hwloc_intro Hardware Locality (hwloc) Introduction
11
12<h1 class="sub">Portable abstraction of hierarchical architectures for high-performance computing</h1>
13
14<hr>
15
16\htmlonly
17<div class="section">
18\endhtmlonly
19See also \ref further_reading
20\htmlonly
21or the Related pages tab above
22\endhtmlonly
23for links to more sections about hwloc concepts.
24\htmlonly
25</div>
26\endhtmlonly
27
28\htmlonly
29<div class="section" id="hwloc_summary">
30\endhtmlonly
31\section hwloc_summary hwloc Summary
32
33hwloc provides command line tools and a C API to obtain the
34hierarchical map of key computing elements within a node, such as: NUMA memory
35nodes, shared caches, processor packages, dies and cores,
36processing units (logical processors or "threads")
37and even I/O devices.
38hwloc also gathers various attributes such as
39cache and memory information, and is portable across a variety of
40different operating systems and platforms.
41
42hwloc primarily aims at helping high-performance computing (HPC)
43applications, but is also applicable to any project seeking to exploit
44code and/or data locality on modern computing platforms.
45
46hwloc supports the following operating systems:
47
48<ul>
49<li>Linux (including old kernels not having sysfs topology
50information, with knowledge of cpusets, ScaleMP vSMP support, etc.)
51on all supported hardware, including Intel Xeon Phi
52and NumaScale NumaConnect.</li>
53<li>Solaris (with support for processor sets and logical domains)</li>
54<li>AIX</li>
55<li>Darwin / OS X</li>
56<li>FreeBSD and its variants (such as kFreeBSD/GNU)</li>
57<li>NetBSD</li>
58<li>HP-UX</li>
59<li>Microsoft Windows</li>
60<li>IBM BlueGene/Q Compute Node Kernel (CNK)</li>
61</ul>
62
63Since it uses standard Operating System information, hwloc's support is mostly
64independant from the processor type (x86, powerpc, ...) and just relies on the
65Operating System support. The main exception is BSD operating systems (NetBSD, FreeBSD, etc.)
66because they do not provide support topology information, hence hwloc uses an x86-only CPUID-based
67backend (which can be used for other OSes too, see the \ref plugins section).
68
69To check whether hwloc works on a particular machine, just try to build it
70and run <tt>lstopo</tt> or <tt>lstopo-no-graphics</tt>. If some things do not look right
71(e.g. bogus or missing cache information), see \ref bugs.
72
73hwloc only reports the number of processors on unsupported operating
74systems; no topology information is available.
75
76For development and debugging purposes, hwloc also offers the ability to
77work on "fake" topologies:
78
79<ul>
80  <li> Symmetrical tree of resources generated from a list of level arities,
81  see \ref synthetic.</li>
82  <li> Remote machine simulation through the gathering of topology as XML files,
83  see \ref xml.</li>
84</ul>
85
86hwloc can display the topology in a human-readable format, either in
87graphical mode (X11), or by exporting in one of several different
88formats, including: plain text, LaTeX tikzpicture, PDF, PNG, and FIG (see \ref cli_examples
89below).  Note that some of the export formats require additional
90support libraries.
91
92hwloc offers a programming interface for manipulating topologies and
93objects. It also brings a powerful CPU bitmap API that is used to
94describe topology objects location on physical/logical processors. See
95the \ref interface below. It may also be used to binding applications
96onto certain cores or memory nodes. Several utility programs are also
97provided to ease command-line manipulation of topology objects,
98binding of processes, and so on.
99
100Perl bindings are available from Bernd Kallies on
101<a href=http://search.cpan.org/~bka/Sys-Hwloc-0.10/>CPAN</a>.
102
103Python bindings are available from Guy Streeter:
104<ul>
105<li><a href=http://people.redhat.com/streeter/>Fedora RPM and tarball</a>.</li>
106<li><a href=git://git.fedorahosted.org/python-hwloc.git>git tree</a>
107(<a href=http://git.fedorahosted.org/git/python-hwloc.git>html</a>).</li>
108</ul>
109
110
111\htmlonly
112</div><div class="section" id="hwloc_installation">
113\endhtmlonly
114\section hwloc_installation hwloc Installation
115
116The generic installation procedure for both hwloc and netloc
117is described in \ref common_installation.
118
119The hwloc command-line tool "lstopo" produces human-readable topology
120maps, as mentioned above.  It can also export maps to the "fig" file
121format.  Support for PDF, Postscript, and PNG exporting is provided if
122the "Cairo" development package (usually <tt>cairo-devel</tt> or
123<tt>libcairo2-dev</tt>) can be found in "lstopo" when hwloc
124is configured and build.
125
126The hwloc core may also benefit from the following development packages:
127<ul>
128<li>libpciaccess for full I/O device discovery
129    (<tt>libpciaccess-devel</tt> or <tt>libpciaccess-dev</tt> package).
130    On Linux, PCI discovery may still be performed (without vendor/device names)
131    even if libpciaccess cannot be used.
132</li>
133
134<li>AMD or NVIDIA OpenCL implementations for OpenCL device discovery.
135</li>
136<li>the NVIDIA CUDA Toolkit for CUDA device discovery.
137</li>
138<li>the NVIDIA Management Library (NVML) for NVML device discovery.
139  It is included in CUDA since version 8.0.
140  Older NVML releases were available within the NVIDIA GPU Deployment Kit
141  from https://developer.nvidia.com/gpu-deployment-kit .
142</li>
143<li>the NV-CONTROL X extension library (NVCtrl) for NVIDIA display discovery.
144  The relevant development package is usually <tt>libXNVCtrl-devel</tt>
145  or <tt>libxnvctrl-dev</tt>.
146  It is also available within nvidia-settings from ftp://download.nvidia.com/XFree86/nvidia-settings/
147  and https://github.com/NVIDIA/nvidia-settings/ .
148</li>
149<li>the AMD ROCm SMI library for RSMI device discovery.
150  The relevant development package is usually <tt>rocm-smi-lib64</tt>
151  or <tt>librocm-smi-dev</tt>.
152</li>
153<li>libxml2 for full XML import/export support (otherwise, the
154    internal minimalistic parser will only be able to import
155    XML files that were exported by the same hwloc release).
156    See \ref xml for details.
157    The relevant development package is usually <tt>libxml2-devel</tt>
158    or <tt>libxml2-dev</tt>.
159</li>
160<li>libudev on Linux for easier discovery of OS device information
161    (otherwise hwloc will try to manually parse udev raw files).
162    The relevant development package is usually <tt>libudev-devel</tt>
163    or <tt>libudev-dev</tt>.
164</li>
165<li>libtool's ltdl library for dynamic plugin loading if the native dlopen cannot be used.
166  The relevant development package is usually <tt>libtool-ltdl-devel</tt>
167  or <tt>libltdl-dev</tt>.
168</li>
169</ul>
170
171PCI and XML support may be statically built inside the main hwloc
172library, or as separate dynamically-loaded plugins (see the
173\ref plugins section).
174
175Note that because of the possibility of GPL taint, the
176<tt>pciutils</tt> library <tt>libpci</tt> will not be used (remember
177that hwloc is BSD-licensed).
178
179
180\htmlonly
181</div><div class="section" id="cli_examples">
182\endhtmlonly
183\section cli_examples Command-line Examples
184
185On a 4-package 2-core machine with hyper-threading, the \c lstopo tool
186may show the following graphical output:
187
188\image html dudley.png
189\image latex dudley.png "" width=\textwidth
190
191Here's the equivalent output in textual form:
192
193\verbatim
194Machine
195  NUMANode L#0 (P#0)
196  Package L#0 + L3 L#0 (4096KB)
197    L2 L#0 (1024KB) + L1 L#0 (16KB) + Core L#0
198      PU L#0 (P#0)
199      PU L#1 (P#8)
200    L2 L#1 (1024KB) + L1 L#1 (16KB) + Core L#1
201      PU L#2 (P#4)
202      PU L#3 (P#12)
203  Package L#1 + L3 L#1 (4096KB)
204    L2 L#2 (1024KB) + L1 L#2 (16KB) + Core L#2
205      PU L#4 (P#1)
206      PU L#5 (P#9)
207    L2 L#3 (1024KB) + L1 L#3 (16KB) + Core L#3
208      PU L#6 (P#5)
209      PU L#7 (P#13)
210  Package L#2 + L3 L#2 (4096KB)
211    L2 L#4 (1024KB) + L1 L#4 (16KB) + Core L#4
212      PU L#8 (P#2)
213      PU L#9 (P#10)
214    L2 L#5 (1024KB) + L1 L#5 (16KB) + Core L#5
215      PU L#10 (P#6)
216      PU L#11 (P#14)
217  Package L#3 + L3 L#3 (4096KB)
218    L2 L#6 (1024KB) + L1 L#6 (16KB) + Core L#6
219      PU L#12 (P#3)
220      PU L#13 (P#11)
221    L2 L#7 (1024KB) + L1 L#7 (16KB) + Core L#7
222      PU L#14 (P#7)
223      PU L#15 (P#15)
224\endverbatim
225
226Note that there is also an equivalent output in XML that is meant for
227exporting/importing topologies but it is hardly readable to human-beings
228(see \ref xml for details).
229
230On a 4-package 2-core Opteron NUMA machine
231(with two core cores disallowed by the administrator),
232the \c lstopo tool may show the following graphical output
233(with <tt>\--disallowed</tt> for displaying disallowed objects):
234
235\image html hagrid.png
236\image latex hagrid.png "" width=\textwidth
237
238Here's the equivalent output in textual form:
239
240\verbatim
241Machine (32GB total)
242  Package L#0
243    NUMANode L#0 (P#0 8190MB)
244    L2 L#0 (1024KB) + L1 L#0 (64KB) + Core L#0 + PU L#0 (P#0)
245    L2 L#1 (1024KB) + L1 L#1 (64KB) + Core L#1 + PU L#1 (P#1)
246  Package L#1
247    NUMANode L#1 (P#1 8192MB)
248    L2 L#2 (1024KB) + L1 L#2 (64KB) + Core L#2 + PU L#2 (P#2)
249    L2 L#3 (1024KB) + L1 L#3 (64KB) + Core L#3 + PU L#3 (P#3)
250  Package L#2
251    NUMANode L#2 (P#2 8192MB)
252    L2 L#4 (1024KB) + L1 L#4 (64KB) + Core L#4 + PU L#4 (P#4)
253    L2 L#5 (1024KB) + L1 L#5 (64KB) + Core L#5 + PU L#5 (P#5)
254  Package L#3
255    NUMANode L#3 (P#3 8192MB)
256    L2 L#6 (1024KB) + L1 L#6 (64KB) + Core L#6 + PU L#6 (P#6)
257    L2 L#7 (1024KB) + L1 L#7 (64KB) + Core L#7 + PU L#7 (P#7)
258\endverbatim
259
260On a 2-package quad-core Xeon (pre-Nehalem, with 2 dual-core dies into
261each package):
262
263\image html emmett.png
264\image latex emmett.png "" width=\textwidth
265
266Here's the same output in textual form:
267
268\verbatim
269Machine (total 16GB)
270  NUMANode L#0 (P#0 16GB)
271  Package L#0
272    L2 L#0 (4096KB)
273      L1 L#0 (32KB) + Core L#0 + PU L#0 (P#0)
274      L1 L#1 (32KB) + Core L#1 + PU L#1 (P#4)
275    L2 L#1 (4096KB)
276      L1 L#2 (32KB) + Core L#2 + PU L#2 (P#2)
277      L1 L#3 (32KB) + Core L#3 + PU L#3 (P#6)
278  Package L#1
279    L2 L#2 (4096KB)
280      L1 L#4 (32KB) + Core L#4 + PU L#4 (P#1)
281      L1 L#5 (32KB) + Core L#5 + PU L#5 (P#5)
282    L2 L#3 (4096KB)
283      L1 L#6 (32KB) + Core L#6 + PU L#6 (P#3)
284      L1 L#7 (32KB) + Core L#7 + PU L#7 (P#7)
285\endverbatim
286
287
288\htmlonly
289</div><div class="section" id="interface">
290\endhtmlonly
291\section interface Programming Interface
292
293The basic interface is available in hwloc.h.
294Some higher-level functions are available in hwloc/helper.h to reduce
295the need to manually manipulate objects and follow links between them.
296Documentation for all these is provided later in this document.
297Developers may also want to look at hwloc/inlines.h which contains the
298actual inline code of some hwloc.h routines, and at this document,
299which provides good higher-level topology traversal examples.
300
301To precisely define the vocabulary used by hwloc, a \ref termsanddefs
302section is available and should probably be read first.
303
304Each hwloc object contains a cpuset describing the list of processing
305units that it contains.  These bitmaps may be used for
306\ref hwlocality_cpubinding and \ref hwlocality_membinding.
307hwloc offers an extensive
308bitmap manipulation interface in hwloc/bitmap.h.
309
310Moreover, hwloc also comes with additional helpers for
311interoperability with several commonly used environments.
312See the \ref interoperability section for details.
313
314The complete API documentation is available in a full set of HTML
315pages, man pages, and self-contained PDF files (formatted for both
316both US letter and A4 formats) in the source tarball in
317doc/doxygen-doc/.
318
319<strong>NOTE:</strong> If you are building the documentation from a
320Git clone, you will need to have Doxygen and pdflatex
321installed -- the documentation will be built during the normal "make"
322process.  The documentation is installed during "make install" to
323$prefix/share/doc/hwloc/ and your systems default man page tree (under
324$prefix, of course).
325
326\subsection portability Portability
327
328Operating System have varying support for CPU and memory binding,
329e.g. while some Operating Systems provide interfaces for all kinds of CPU and
330memory bindings, some others provide only interfaces for a limited number of
331kinds of CPU and memory binding, and some do not provide any binding interface
332at all.  Hwloc's binding functions would then simply return the ENOSYS error
333(Function not implemented), meaning that the underlying Operating System
334does not provide any interface for them. \ref hwlocality_cpubinding and
335\ref hwlocality_membinding provide more information on which hwloc binding functions
336should be preferred because interfaces for them are usually available on the
337supported Operating Systems.
338
339Similarly, the ability of reporting topology information varies from
340one platform to another.
341As shown in \ref cli_examples, hwloc can obtain information on a wide
342variety of hardware topologies.  However, some platforms and/or
343operating system versions will only report a subset of this
344information.  For example, on an PPC64-based system with 8 cores
345(each with 2 hardware threads) running a default 2.6.18-based kernel
346from RHEL 5.4, hwloc is only able to glean information about NUMA
347nodes and processor units (PUs).  No information about caches,
348packages, or cores is available.
349
350Here's the graphical output from lstopo on this platform when
351Simultaneous Multi-Threading (SMT) is enabled:
352
353\image html ppc64-with-smt.png
354\image latex ppc64-with-smt.png "" width=\textwidth
355
356And here's the graphical output from lstopo on this platform when SMT is
357disabled:
358
359\image html ppc64-without-smt.png
360\image latex ppc64-without-smt.png "" width=.5\textwidth
361
362Notice that hwloc only sees half the PUs when SMT is disabled.
363PU L#6, for example, seems to change location from NUMA node #0 to #1.
364In reality, no PUs "moved" -- they were simply re-numbered when hwloc
365only saw half as many (see also Logical index in \ref termsanddefs_indexes).
366Hence, PU L#6 in the SMT-disabled picture probably corresponds to
367PU L#12 in the SMT-enabled picture.
368
369This same "PUs have disappeared" effect can be seen on other platforms
370-- even platforms / OSs that provide much more information than the
371above PPC64 system.  This is an unfortunate side-effect of how
372operating systems report information to hwloc.
373
374Note that upgrading the Linux kernel on the same PPC64 system
375mentioned above to 2.6.34, hwloc is able to discover all the topology
376information.  The following picture shows the entire topology layout
377when SMT is enabled:
378
379\image html ppc64-full-with-smt.png
380\image latex ppc64-full-with-smt.png "" width=\textwidth
381
382Developers using the hwloc API or XML output for portable applications
383should therefore be extremely careful to not make any assumptions
384about the structure of data that is returned.  For example, per the
385above reported PPC topology, it is not safe to assume that PUs will
386always be descendants of cores.
387
388Additionally, future hardware may insert new topology elements that
389are not available in this version of hwloc.  Long-lived applications
390that are meant to span multiple different hardware platforms should
391also be careful about making structure assumptions.  For example,
392a new element may someday exist between a core and a PU.
393
394
395\subsection interface_example API Example
396
397The following small C example (available in the source tree as ``doc/examples/hwloc-hello.c'')
398prints the topology of the machine and performs some thread and memory binding.
399More examples are available in the doc/examples/ directory of the source
400tree.
401
402\include examples/hwloc-hello.c
403
404hwloc provides a \c pkg-config executable to obtain relevant compiler
405and linker flags.  For example, it can be used thusly to compile
406applications that utilize the hwloc library (assuming GNU Make):
407
408\verbatim
409CFLAGS += $(shell pkg-config --cflags hwloc)
410LDLIBS += $(shell pkg-config --libs hwloc)
411
412hwloc-hello: hwloc-hello.c
413        $(CC) hwloc-hello.c $(CFLAGS) -o hwloc-hello $(LDLIBS)
414\endverbatim
415
416On a machine 2 processor packages -- each package of
417which has two processing cores -- the output from running \c
418hwloc-hello could be something like the following:
419
420\verbatim
421shell$ ./hwloc-hello
422*** Objects at level 0
423Index 0: Machine
424*** Objects at level 1
425Index 0: Package#0
426Index 1: Package#1
427*** Objects at level 2
428Index 0: Core#0
429Index 1: Core#1
430Index 2: Core#3
431Index 3: Core#2
432*** Objects at level 3
433Index 0: PU#0
434Index 1: PU#1
435Index 2: PU#2
436Index 3: PU#3
437*** Printing overall tree
438Machine
439  Package#0
440    Core#0
441      PU#0
442    Core#1
443      PU#1
444  Package#1
445    Core#3
446      PU#2
447    Core#2
448      PU#3
449*** 2 package(s)
450*** Logical processor 0 has 0 caches totaling 0KB
451shell$
452\endverbatim
453
454
455
456\htmlonly
457</div><div class="section" id="history">
458\endhtmlonly
459\section history History / Credits
460
461hwloc is the evolution and merger of the libtopology project and the Portable
462Linux Processor Affinity (PLPA) (https://www.open-mpi.org/projects/plpa/)
463project. Because of functional and ideological overlap, these two code bases
464and ideas were merged and released under the name "hwloc" as an Open MPI
465sub-project.
466
467libtopology was initially developed by the Inria Runtime Team-Project.
468PLPA was initially developed by
469the Open MPI development team as a sub-project. Both are now deprecated
470in favor of hwloc, which is distributed as an Open MPI sub-project.
471
472\htmlonly
473</div><div class="section" id="further_reading">
474\endhtmlonly
475\section further_reading Further Reading
476
477The documentation chapters include
478
479<ul>
480<li> \ref termsanddefs
481<li> \ref tools
482<li> \ref envvar
483<li> \ref cpu_mem_bind
484<li> \ref iodevices
485<li> \ref miscobjs
486<li> \ref attributes
487<li> \ref topoattrs
488<li> \ref xml
489<li> \ref synthetic
490<li> \ref interoperability
491<li> \ref threadsafety
492<li> \ref plugins
493<li> \ref embed
494<li> \ref faq
495<li> \ref upgrade_to_api_2x
496</ul>
497
498Make sure to have had a look at those too!
499
500\htmlonly
501</div>
502\endhtmlonly
503
504
505
506\page termsanddefs Terms and Definitions
507
508
509\htmlonly
510<div class="section" id="termsanddefs_objects">
511\endhtmlonly
512\section termsanddefs_objects Objects
513
514<dl>
515
516<dt>Object</dt>
517  <dd>Interesting kind of part of the system, such as a Core, a L2Cache,
518  a NUMA memory node, etc. The different types detected by hwloc are
519  detailed in the ::hwloc_obj_type_t enumeration.
520
521  There are four kinds of Objects: Memory (NUMA nodes and Memory-side caches), I/O (Bridges, PCI and OS devices),
522  Misc, and Normal (everything else, including Machine, Package, Die, Core, PU, CPU Caches, etc.).
523  Normal and Memory objects have (non-NULL) CPU sets and nodesets, while I/O and Misc don't.
524
525  Objects are topologically sorted by locality (CPU and node sets)
526  into a tree (see \ref termsanddefs_tree).
527  </dd>
528
529<dt>Processing Unit (PU)</dt>
530  <dd>The smallest processing element that can be represented by a hwloc
531  object. It may be a single-core processor, a core of a multicore
532  processor, or a single thread in a SMT processor
533  (also sometimes called "Logical processor",
534   not to be confused with "Logical index of a processor").
535  hwloc's PU acronym stands for Processing Unit.
536  </dd>
537
538<dt>Package</dt>
539  <dd>A processor Package is the physical package that usually gets
540  inserted into a socket on the motherboard.
541  It is also often called a physical processor or a CPU even if these
542  names bring confusion with respect to cores and processing units.
543  A processor package usually contains multiple cores
544  (and may also be composed of multiple dies).
545  hwloc Package objects were called Sockets up to hwloc 1.10.
546  </dd>
547
548<dt>NUMA Node</dt>
549  <dd>
550  An object that contains memory that is directly and byte-accessible
551  to the host processors.
552  It is usually close to some cores as specified by its CPU set.
553  Hence it is attached as a memory child of the object that groups
554  those cores together, for instance a Package objects with 4 Core children
555  (see \ref termsanddefs_tree).
556  </dd>
557
558<dt>Memory-side Cache</dt>
559  <dd>
560  A cache in front of a specific memory region (e.g. a range of physical addresses).
561  It caches all accesses to that region without caring about which core issued the request.
562  This is the opposite of usual CPU caches where only accesses from the local cores
563  are cached, without caring about the target memory.
564
565  In hwloc, memory-side caches are memory objects placed between their local CPU objects
566  (parent) and the target NUMA node memory (child).
567  </dd>
568</dl>
569
570
571\htmlonly
572</div><div class="section" id="termsanddefs_indexes">
573\endhtmlonly
574\section termsanddefs_indexes Indexes and Sets
575
576<dl>
577
578<dt>OS or physical index</dt>
579  <dd>The index that the operating system (OS) uses to identify the
580  object.  This may be completely arbitrary, non-unique, non-contiguous, not
581  representative of logical proximity, and may depend on the BIOS
582  configuration. That is why hwloc almost never uses them, only in the default
583  lstopo output (<tt>P\#x</tt>) and cpuset masks.
584  See also \ref faq_indexes.</dd>
585
586<dt>Logical index</dt>
587  <dd>Index to uniquely identify objects of the same type and depth,
588  automatically computed by hwloc according to the topology.  It expresses
589  logical proximity in a generic way, i.e. objects which have adjacent logical
590  indexes are adjacent in the topology. That is why hwloc almost always uses
591  it in its API, since it expresses logical proximity. They can be shown (as
592  <tt>L\#x</tt>) by <tt>lstopo</tt> thanks to the <tt>-l</tt> option.  This index
593  is always linear and in
594  the range [0, num_objs_same_type_same_level-1].  Think of it as ``cousin
595  rank.'' The ordering is based on topology first, and then on OS CPU numbers,
596  so it is stable across everything except firmware CPU renumbering.
597  "Logical index" should not be confused with "Logical processor". A "Logical
598  processor" (which in hwloc we rather call "processing unit" to avoid the
599  confusion) has both a physical index (as chosen arbitrarily by BIOS/OS) and a logical
600  index (as computed according to logical proximity by hwloc).
601  See also \ref faq_indexes.</dd>
602
603<dt>CPU set</dt>
604  <dd>The set of processing units (PU) logically included in an object
605  (if it makes sense).  They are always expressed using physical
606  processor numbers (as announced by the OS).  They are implemented as the
607  ::hwloc_bitmap_t opaque structure.  hwloc CPU sets are just masks, they
608  do \em not have any relation with an operating system actual binding notion like
609  Linux' cpusets.
610  I/O and Misc objects do not have CPU sets while all Normal and Memory objects have non-NULL CPU sets.</dd>
611
612<dt>Node set</dt>
613  <dd>The set of NUMA memory nodes logically included in an object
614  (if it makes sense).  They are always expressed using physical node
615  numbers (as announced by the OS).  They are implemented with the
616  ::hwloc_bitmap_t opaque structure.
617  as bitmaps.
618  I/O and Misc objects do not have Node sets while all Normal and Memory objects have non-NULL nodesets.</dd>
619
620<dt>Bitmap</dt>
621  <dd>A possibly-infinite set of bits used for describing sets of objects
622  such as CPUs (CPU sets) or memory nodes (Node sets). They are implemented
623  with the ::hwloc_bitmap_t opaque structure.
624</dd>
625
626</dl>
627
628
629\htmlonly
630</div><div class="section" id="termsanddefs_tree">
631\endhtmlonly
632\section termsanddefs_tree Hierarchy, Tree and Levels
633
634<dl>
635
636<dt>Parent object</dt>
637  <dd>The object logically containing the current object, for example
638  because its CPU set includes the CPU set of the current object.
639  All objects have a non-NULL parent, except the root of the topology (Machine object).
640  </dd>
641
642<dt>Ancestor object</dt>
643  <dd>The parent object, or its own parent, and so on.</dd>
644
645<dt>Children object(s)</dt>
646  <dd>The object (or objects) contained in the current object because
647  their CPU set is included in the CPU set of the current object.
648  Each object may also contain separated lists for Memory, I/O and Misc object children.
649  </dd>
650
651<dt>Arity</dt>
652  <dd>The number of normal children of an object.
653  There are also specific arities for Memory, I/O and Misc children.
654  </dd>
655
656<dt>Sibling objects</dt>
657  <dd>Objects in the same children list, which all of them are normal
658  children of the same parent, or all of them are Memory children of
659  the same parent, or I/O children, or Misc.
660  They usually have the same type (and hence are cousins, as well).
661  But they may not if the topology is asymmetric.
662  </dd>
663
664<dt>Sibling rank</dt>
665  <dd>Index to uniquely identify objects which have
666  the same parent, and is always in the range [0, arity-1]
667  (respectively memory_arity, io_arity or misc_arity for Memory, I/O
668  and Misc children of a parent).</dd>
669
670<dt>Cousin objects</dt>
671  <dd>Objects of the same type (and depth) as the current object,
672  even if they do not have the same parent.</dd>
673
674<dt>Level</dt>
675  <dd>Set of objects of the same type and depth. All these objects
676  are cousins.
677
678  Memory, I/O and Misc objects also have their own specific levels and (virtual) depth.
679  </dd>
680
681<dt>Depth</dt>
682  <dd>Nesting level in the object tree, starting from the root object.
683  If the topology is symmetric, the depth of a child is equal to the
684  parent depth plus one, and an object depth is also equal to the number
685  of parent/child links between the root object and the given object.
686  If the topology is asymmetric, the difference between some parent
687  and child depths may be larger than one when some intermediate levels
688  (for instance groups) are missing in only some parts of the machine.
689
690  The depth of the Machine object is always 0 since it is always the
691  root of the topology.
692  The depth of PU objects is equal to the number of levels in the topology
693  minus one.
694
695  Memory, I/O and Misc objects also have their own specific levels and depth.
696  </dd>
697
698</dl>
699
700The following diagram can help to understand the vocabulary of the relationships
701by showing the example of a machine with two dual core packages (with no
702hardware threads); thus, a topology with 5 levels. Each box with rounded corner
703corresponds to one ::hwloc_obj_t, containing the values of the different integer
704fields (depth, logical_index, etc.), and arrows show to which other ::hwloc_obj_t
705pointers point to (first_child, parent, etc.).
706
707The topology always starts with a Machine object as root (depth 0)
708and ends with PU objects at the bottom (depth 4 here).
709
710Objects of the same level (cousins) are listed in red boxes and linked
711with red arrows.
712Children of the same parent (siblings) are linked with blue arrows.
713
714The L2 cache of the last core is intentionally missing to show how asymmetric topologies are handled.
715See \ref faq_asymmetric for more information about such strange topologies.
716
717\image html diagram.png
718\image latex diagram.eps "" width=\textwidth
719
720It should be noted that for PU objects, the logical index -- as
721computed linearly by hwloc -- is not the same as the OS index.
722
723The NUMA node is on the side because it is not part of the main tree
724but rather attached to the object that corresponds to its locality
725(the entire machine here, hence the root object).
726It is attached as a <i>Memory</i> child (in green) and has a virtual depth (negative).
727It could also have siblings if there were multiple local NUMA nodes,
728or cousins if other NUMA nodes were attached somewhere else in the machine.
729
730I/O or Misc objects could be attached in a similar manner.
731
732
733
734\page tools Command-Line Tools
735
736\htmlonly
737<div class="section">
738\endhtmlonly
739
740hwloc comes with an extensive C programming interface and several
741command line utilities. Each of them is fully documented in its own
742manual page; the following is a summary of the available command line
743tools.
744
745
746\htmlonly
747</div><div class="section" id="cli_lstopo">
748\endhtmlonly
749\section cli_lstopo lstopo and lstopo-no-graphics
750
751lstopo (also known as hwloc-ls) displays the
752hierarchical topology map of the current system.  The output may be
753graphical, ascii-art or textual, and can also be exported to numerous file
754formats such as PDF, PNG, XML, and others.
755Advanced graphical outputs require the "Cairo" development package
756(usually <tt>cairo-devel</tt> or <tt>libcairo2-dev</tt>).
757
758lstopo and lstopo-no-graphics accept the same command-line options.
759However, graphical outputs are only available in lstopo.
760Textual outputs (those that do not depend on heavy external libraries
761such as Cairo) are supported in both lstopo and lstopo-no-graphics.
762
763This command can also display the processes currently bound to a part
764of the machine (via the <tt>\--ps</tt> option).
765
766Note that lstopo can read XML files and/or alternate chroot
767filesystems and display topological maps representing those systems
768(e.g., use lstopo to output an XML file on one system, and then use
769lstopo to read in that XML file and display it on a different system).
770
771
772\htmlonly
773</div><div class="section" id="cli_hwloc_bind">
774\endhtmlonly
775\section cli_hwloc_bind hwloc-bind
776
777hwloc-bind binds processes to specific hardware objects through a
778flexible syntax.  A simple example is binding an executable to
779specific cores (or packages or bitmaps or ...).  The hwloc-bind(1) man
780page provides much more detail on what is possible.
781
782hwloc-bind can also be used to retrieve the current process' binding,
783or retrieve the last CPU(s) where a process ran,
784or operate on memory binding.
785
786Just like hwloc-calc, the input locations given to hwloc-bind may be
787either objects or cpusets (bitmaps as reported by hwloc-calc or hwloc-distrib).
788
789
790\htmlonly
791</div><div class="section" id="cli_hwloc_calc">
792\endhtmlonly
793\section cli_hwloc_calc hwloc-calc
794
795hwloc-calc is hwloc's Swiss Army Knife command-line tool for converting things.
796The input may be either objects or cpusets (bitmaps as reported by another hwloc-calc instance or by hwloc-distrib),
797that may be combined by addition, intersection or subtraction.
798The output kinds include:
799<ul>
800<li>a cpuset bitmap: This compact opaque representation of objects is useful for shell scripts etc.
801It may passed to hwloc command-line tools such as hwloc-calc or hwloc-bind,
802or to hwloc command-line options such as <tt>lstopo \--restrict</tt>.</li>
803<li>the amount of the equivalent hwloc objects from a specific type, or the list of their indexes.
804This is useful for iterating over all similar objects (for instance all cores) within a given
805part of a platform.</li>
806<li>a hierarchical description of objects,
807for instance a thread index within a core within a package.
808This gives a better view of the actual location of an object.</li>
809</ul>
810
811Moreover, input and/or output may be use either physical/OS object
812indexes or as hwloc's logical object indexes.
813It eases cooperation with external tools such as taskset or numactl
814by exporting hwloc specifications into list of processor or NUMA node
815physical indexes.
816See also \ref faq_indexes.
817
818
819\htmlonly
820</div><div class="section" id="cli_hwloc_info">
821\endhtmlonly
822\section cli_hwloc_info hwloc-info
823
824hwloc-info dumps information about the given objects, as well as all its specific attributes.
825It is intended to be used with tools such as grep for filtering
826certain attribute lines.
827When no object is specified, or when <tt>\--topology</tt> is passed,
828hwloc-info prints a summary of the topology.
829When <tt>\--support</tt> is passed, hwloc-info lists the supported
830features for the topology.
831
832
833\htmlonly
834</div><div class="section" id="cli_hwloc_distrib">
835\endhtmlonly
836\section cli_hwloc_distrib hwloc-distrib
837
838hwloc-distrib generates a set of cpuset bitmaps that are uniformly
839distributed across the machine for the given number of processes.
840These strings may be used with hwloc-bind to run processes to maximize
841their memory bandwidth by properly distributing them across the
842machine.
843
844
845\htmlonly
846</div><div class="section" id="cli_hwloc_ps">
847\endhtmlonly
848\section cli_hwloc_ps hwloc-ps
849
850hwloc-ps is a tool to display the bindings of processes that are
851currently running on the local machine.  By default, hwloc-ps only
852lists processes that are bound; unbound process (and Linux kernel
853threads) are not displayed.
854
855
856\htmlonly
857</div><div class="section" id="cli_hwloc_annotate">
858\endhtmlonly
859\section cli_hwloc_annotate hwloc-annotate
860
861hwloc-annotate may modify object (and topology) attributes such as string information
862(see \ref attributes_info for details) or Misc children objects.
863It may also add distances, memory attributes, etc. to the topology.
864It reads an input topology from a XML file and outputs
865the annotated topology as another XML file.
866
867
868\htmlonly
869</div><div class="section" id="cli_hwloc_diffpatchcompress">
870\endhtmlonly
871\section cli_hwloc_diffpatchcompress hwloc-diff, hwloc-patch and hwloc-compress-dir
872
873hwloc-diff computes the difference between two topologies
874and outputs it to another XML file.
875
876hwloc-patch reads such a difference file and applies to
877another topology.
878
879hwloc-compress-dir compresses an entire directory of XML
880files by using hwloc-diff to save the differences between
881topologies instead of entire topologies.
882
883
884\htmlonly
885</div><div class="section" id="cli_hwloc_dump_hwdata">
886\endhtmlonly
887\section cli_hwloc_dump_hwdata hwloc-dump-hwdata
888
889hwloc-dump-hwdata is a Linux and x86-specific tool that dumps
890(during boot, privileged) some topology and locality information
891from raw hardware files (SMBIOS and ACPI tables) to human-readable
892and world-accessible files that the hwloc library will later reuse.
893
894Currently only used on Intel Xeon Phi processor platforms.
895See \ref faq_knl_dump.
896
897See <tt>HWLOC_DUMPED_HWDATA_DIR</tt> in \ref envvar for details
898about the location of dumped files.
899
900
901\htmlonly
902</div><div class="section" id="cli_hwloc_gather">
903\endhtmlonly
904\section cli_hwloc_gather hwloc-gather-topology and hwloc-gather-cpuid
905
906hwloc-gather-topology is a Linux-specific tool that saves the
907relevant topology files of the current machine into a tarball
908(and the corresponding lstopo outputs).
909
910hwloc-gather-cpuid is a x86-specific tool that dumps the
911result of CPUID instructions on the current machine into
912a directory.
913
914The output of hwloc-gather-cpuid is included in the tarball
915saved by hwloc-gather-topology when running on Linux/x86.
916
917These files may be used later (possibly offline) for simulating
918or debugging a machine without actually running on it.
919
920
921
922
923\page envvar Environment Variables
924
925\htmlonly
926<div class="section">
927\endhtmlonly
928
929The behavior of the hwloc library and tools may be tuned thanks to the
930following environment variables.
931
932<dl>
933
934<dt>HWLOC_XMLFILE=/path/to/file.xml</dt>
935  <dd>enforces the discovery from the given XML file as if
936  hwloc_topology_set_xml() had been called.
937  This file may have been generated earlier with lstopo file.xml.
938  For convenience, this backend provides empty binding hooks which just
939  return success.  To have hwloc still actually call OS-specific hooks,
940  HWLOC_THISSYSTEM should be set 1 in the environment too, to assert that
941  the loaded file is really the underlying system.
942  See also \ref xml.
943  </dd>
944
945<dt>HWLOC_SYNTHETIC=synthetic_description</dt>
946  <dd>enforces the discovery through a synthetic description string
947  as if hwloc_topology_set_synthetic() had been called.
948  For convenience, this backend provides empty binding hooks which just
949  return success.
950  See also \ref synthetic.
951  </dd>
952
953<dt>HWLOC_XML_VERBOSE=1</dt>
954<dt>HWLOC_SYNTHETIC_VERBOSE=1</dt>
955  <dd>enables verbose messages in the XML or synthetic topology backends.
956  hwloc XML backends (see \ref xml) can emit some error messages to
957  the error output stream.
958  Enabling these verbose messages within hwloc can be useful for
959  understanding failures to parse input XML topologies.
960  Similarly, enabling verbose messages in the synthetic topology
961  backend can help understand why the description string is invalid.
962  See also \ref synthetic.
963  </dd>
964
965<dt>HWLOC_THISSYSTEM=1</dt>
966  <dd>enforces the return value of hwloc_topology_is_thissystem(), as if
967  ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM was set with hwloc_topology_set_flags().
968  It means that it makes hwloc assume that the selected backend provides the
969  topology for the system on which we are running, even if it is not the
970  OS-specific backend but the XML backend for instance.
971  This means making the binding functions actually call the OS-specific
972  system calls and really do binding, while the XML backend would otherwise
973  provide empty hooks just returning success.
974  This can be used for efficiency reasons to first detect the topology once,
975  save it to a XML file, and quickly reload it later through the XML
976  backend, but still having binding functions actually do bind.
977  This also enables support for the variable HWLOC_THISSYSTEM_ALLOWED_RESOURCES.
978  </dd>
979
980<dt>HWLOC_THISSYSTEM_ALLOWED_RESOURCES=1</dt>
981  <dd>Get the set of allowed resources from the native operating system
982  even if the topology was loaded from XML or synthetic description,
983  as if ::HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES was set
984  with hwloc_topology_set_flags().
985  This variable requires the topology to match the current system
986  (see the variable HWLOC_THISSYSTEM).
987  This is useful when the topology is not loaded directly from the
988  local machine (e.g. for performance reason) and it comes with all
989  resources, but the running process is restricted to only a part
990  of the machine (for instance because of Linux Cgroup/Cpuset).
991  </dd>
992
993<dt>HWLOC_ALLOW=all</dt>
994  <dd>Totally ignore administrative restrictions such as Linux Cgroups
995  and consider all resources (PUs and NUMA nodes) as allowed.
996  This is different from setting HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED
997  which gathers all resources but marks the unavailable ones as disallowed.
998  </dt>
999
1000<dt>HWLOC_HIDE_ERRORS=0</dt>
1001  <dd>enables or disables verbose reporting of errors.
1002  The hwloc library may issue warnings to the standard error stream
1003  when it detects a problem during topology discovery, for instance
1004  if the operating system (or user) gives contradictory topology
1005  information.   Setting this environment variable to 1 removes the
1006  actual displaying of these error messages.
1007  </dd>
1008
1009<dt>HWLOC_USE_NUMA_DISTANCES=7</dt>
1010  <dd>enables or disables the use of NUMA distances.
1011  NUMA distances and memory target/initiator information may be used
1012  to improve the locality of NUMA nodes, especially CPU-less nodes.
1013  Bits in the value of this environment variable enable different features:
1014  Bit 0 enables the gathering of NUMA distances from the operating system.
1015  Bit 1 further enables the use of NUMA distances to improve the
1016  locality of CPU-less nodes.
1017  Bit 2 enables the use of target/initiator information.
1018  </dd>
1019
1020<dt>HWLOC_GROUPING=1</dt>
1021  <dd>enables or disables objects grouping based on distances.
1022  By default, hwloc uses distance matrices between objects (either read
1023  from the OS or given by the user) to find groups of close objects.
1024  These groups are described by adding intermediate Group objects in the topology.
1025  Setting this environment variable to 0 will disable this grouping.
1026  This variable supersedes the obsolete HWLOC_IGNORE_DISTANCES variable.
1027  </dd>
1028
1029<dt>HWLOC_GROUPING_ACCURACY=0.05</dt>
1030  <dd>relaxes distance comparison during grouping.
1031  By default, objects may be grouped if their distances form a minimal
1032  distance graph. When setting this variable to 0.02, and when
1033  ::HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE is given, these distances
1034  do not have to be strictly equal anymore, they may just be equal
1035  with a 2% error.
1036  If set to <tt>try</tt> instead of a numerical value, hwloc will try
1037  to group with perfect accuracy (0, the default), then with 0.01, 0.02,
1038  0.05 and finally 0.1.
1039  Numbers given in this environment variable should always use a dot
1040  as a decimal mark (for instance 0.01 instead of 0,01).</dd>
1041
1042<dt>HWLOC_GROUPING_VERBOSE=0</dt>
1043  <dd>enables or disables some verbose messages during grouping.
1044  If this variable is set to 1, some debug messages will be displayed
1045  during distance-based grouping of objects even if debug was not specific
1046  at configure time.
1047  This is useful when trying to find an interesting distance grouping
1048  accuracy.</dd>
1049
1050<dt>HWLOC_CPUKINDS_RANKING=default</dt>
1051  <dd>change the ranking policy for CPU kinds.
1052  By default, the OS-provided efficiency is used for ranking.
1053  If not available, the frequency is used on ARM processors,
1054  or core type and frequency on other architectures.
1055  <br/>
1056  This environment variable may be set to
1057  <tt>coretype+frequency</tt>, <tt>coretype</tt>,
1058  <tt>frequency</tt>, <tt>frequency_base</tt>, <tt>frequency_max</tt>,
1059  <tt>forced_efficiency</tt>, <tt>no_forced_efficiency</tt>,
1060  <tt>default</tt>, or <tt>none</tt>.
1061  </dd>
1062
1063<dt>HWLOC_PCI_LOCALITY=&lt;domain/bus&gt; &lt;cpuset&gt;;...</dt>
1064<dt>HWLOC_PCI_LOCALITY=/path/to/pci/locality/file</dt>
1065<dd>changes the locality of I/O devices behing the specified PCI buses.
1066  If no I/O locality information is available or if the BIOS reports
1067  incorrect information, it is possible to move a I/O device tree
1068  (OS and/or PCI devices with optional bridges)
1069  near a custom set of processors.
1070  <br/>
1071  Localities are given either inside the environment variable itself,
1072  or in the pointed file.
1073  They may be separated either by semi-colons or by line-breaks.
1074  <br/>
1075  Each locality contains a domain/bus specification (in hexadecimal numbers as usual)
1076  followed by a whitespace and a cpuset:
1077  <ul>
1078  <li><tt>0001 &lt;cpuset&gt;</tt> specifies the locality of all buses in PCI domain 0000.</li>
1079  <li><tt>0000:0f &lt;cpuset&gt;</tt> specifies only PCI bus 0f in domain 0000.</li>
1080  <li><tt>0002:04-0a &lt;cpuset&gt;</tt> specifies a range of buses (from 04 to 0a) within domain 0002.</li>
1081  </ul>
1082  Domain/bus specifications should usually match entire hierarchies of buses
1083  behind a bridge (including primary, secondary and subordinate buses).
1084  For instance, if hostbridge 0000:00 is above other bridges/switches with buses 0000:01 to 0000:09,
1085  the variable should be HWLOC_PCI_LOCALITY="0000:00-09 <cpuset>".
1086  It supersedes the old HWLOC_PCI_0000_00_LOCALCPUS=&lt;cpuset&gt;
1087  which only works when hostbridges exist in the topology.
1088  <br/>
1089  If the variable is defined to empty or invalid, no forced PCI locality is applied
1090  but hwloc's internal automatic locality quirks are disabled, which means the exact
1091  PCI locality reported by the platform is used.
1092  </dd>
1093
1094<dt>HWLOC_X86_TOPOEXT_NUMANODES=0</dt>
1095  <dd>use AMD topoext CPUID leaf in the x86 backend to detect NUMA nodes.
1096  When using the x86 backend, setting this variable to 1 enables the building
1097  of NUMA nodes from AMD processor CPUID instructions.
1098  However this strategy does not always reflect BIOS configuration such as NUMA interleaving.
1099  And node indexes may be different from those of the operating system.
1100  Hence this should only be used when OS backends are wrong
1101  and the user is sure that CPUID returns correct NUMA information.
1102  </dd>
1103
1104<dt>HWLOC_KEEP_NVIDIA_GPU_NUMA_NODES=0</dt>
1105  <dd>show or hide NUMA nodes that correspond to NVIDIA GPU memory.
1106  By default they are ignored to avoid interleaved memory being allocated
1107  on GPU by mistake.
1108  Setting this environment variable to 1 exposes these NUMA nodes.
1109  They may be recognized by the <em>GPUMemory</em> subtype.
1110  They also have a <em>PCIBusID</em> info attribute to identify the
1111  corresponding GPU.
1112  </dd>
1113
1114<dt>HWLOC_KNL_MSCACHE_L3=0</dt>
1115  <dd>Expose the KNL MCDRAM in cache mode as a Memory-side Cache instead of a L3.
1116  hwloc releases prior to 2.1 exposed the MCDRAM cache as a CPU-side L3 cache.
1117  Now that Memory-side caches are supported by hwloc, it is still exposed
1118  as a L3 by default to avoid breaking existing applications.
1119  Setting this environment variable to 1 will expose it as a proper Memory-side cache.
1120  </dd>
1121
1122<dt>HWLOC_ANNOTATE_GLOBAL_COMPONENTS=0</dt>
1123  <dd>Allow components to annotate the topology even if they are
1124  usually excluded by global components by default.
1125  Setting this variable to 1 and also setting <tt>HWLOC_COMPONENTS=xml,pci,stop</tt>
1126  enables the addition of PCI vendor and model info attributes to a XML topology
1127  that was generated without those names (if pciaccess was missing).
1128  </dd>
1129
1130<dt>HWLOC_FSROOT=/path/to/linux/filesystem-root/</dt>
1131  <dd>switches to reading the topology from the specified
1132  Linux filesystem root instead of the main file-system root.
1133  This directory may have been saved previously from another machine
1134  with <tt>hwloc-gather-topology</tt>.
1135  <br/>
1136  One should likely also set <tt>HWLOC_COMPONENTS=linux,stop</tt>
1137  so that non-Linux backends are disabled
1138  (the <tt>-i</tt> option of command-line tools takes care of both).
1139  <br/>
1140  Not using the main file-system root causes hwloc_topology_is_thissystem()
1141  to return 0.
1142  For convenience, this backend provides empty binding hooks which just
1143  return success.  To have hwloc still actually call OS-specific hooks,
1144  HWLOC_THISSYSTEM should be set 1 in the environment too, to assert that
1145  the loaded file is really the underlying system.
1146  </dd>
1147
1148<dt>HWLOC_CPUID_PATH=/path/to/cpuid/</dt>
1149  <dd>forces the x86 backend to read dumped CPUIDs from the given directory
1150  instead of executing actual x86 CPUID instructions.
1151  This directory may have been saved previously from another machine
1152  with <tt>hwloc-gather-cpuid</tt>.
1153  <br/>
1154  One should likely also set <tt>HWLOC_COMPONENTS=x86,stop</tt>
1155  so that non-x86 backends are disabled
1156  (the <tt>-i</tt> option of command-line tools takes care of both).
1157  <br/>
1158  It causes hwloc_topology_is_thissystem() to return 0.
1159  For convenience, this backend provides empty binding hooks which just
1160  return success.  To have hwloc still actually call OS-specific hooks,
1161  HWLOC_THISSYSTEM should be set 1 in the environment too, to assert that
1162  the loaded CPUID dump is really the underlying system.
1163  </dd>
1164
1165<dt>HWLOC_DUMPED_HWDATA_DIR=/path/to/dumped/files/</dt>
1166  <dd>loads files dumped by <tt>hwloc-dump-hwdata</tt> (on Linux)
1167  from the given directory.
1168  The default dump/load directory is configured during build based
1169  on \--runstatedir, \--localstatedir, and \--prefix options.
1170  It usually points to <tt>/var/run/hwloc/</tt> in Linux distribution
1171  packages, but it may also point to <tt>$prefix/var/run/hwloc/</tt>
1172  when manually installing and only specifying \--prefix.
1173  </dd>
1174
1175<dt>HWLOC_COMPONENTS=list,of,components</dt>
1176  <dd>forces a list of components to enable or disable.
1177  Enable or disable the given comma-separated list of components
1178  (if they do not conflict with each other). Component names prefixed with
1179  <tt>-</tt> are disabled (a single phase may also be disabled).
1180
1181  Once the end of the list is reached, hwloc falls back to
1182  enabling the remaining components (sorted by priority) that do not
1183  conflict with the already enabled ones, and unless explicitly disabled in the
1184  list.
1185  If <tt>stop</tt> is met, the enabling loop immediately stops, no
1186  more component is enabled.
1187
1188  If <tt>xml</tt> or <tt>synthetic</tt> components are selected,
1189  the corresponding XML filename or synthetic description string
1190  should be pass in <tt>HWLOC_XMLFILE</tt> or <tt>HWLOC_SYNTHETIC</tt>
1191  respectively.
1192
1193  Since this variable is the low-level and more generic way to
1194  select components, it takes precedence over environment variables
1195  for selecting components.
1196
1197  If the variable is set to an empty string (or set to a single comma),
1198  no specific component is loaded first, all components are loaded
1199  in priority order.
1200
1201  See \ref plugins_select for details.
1202  </dd>
1203
1204<dt>HWLOC_COMPONENTS_VERBOSE=1</dt>
1205  <dd>displays verbose information about components.
1206  Display messages when components are registered or enabled.
1207  This is the recommended way to list the available components
1208  with their priority
1209  (all of them are <em>registered</em> at startup).
1210  </dd>
1211
1212<dt>HWLOC_PLUGINS_PATH=/path/to/hwloc/plugins/:...</dt>
1213  <dd>changes the default search directory for plugins.
1214  By default, <tt>$libdir/hwloc</tt> is used.
1215  The variable may contain several colon-separated directories.
1216  </dd>
1217
1218<dt>HWLOC_PLUGINS_VERBOSE=1</dt>
1219  <dd>displays verbose information about plugins.
1220  List which directories are scanned, which files are loaded,
1221  and which components are successfully loaded.
1222  </dd>
1223
1224<dt>HWLOC_PLUGINS_BLACKLIST=filename1,filename2,...</dt>
1225  <dd>prevents plugins from being loaded if their filename
1226  (without path) is listed.
1227  Plugin filenames may be found in verbose messages outputted
1228  when HWLOC_PLUGINS_VERBOSE=1.
1229  </dd>
1230
1231<dt>HWLOC_DEBUG_VERBOSE=0</dt>
1232  <dd>disables all verbose messages that are enabled by default
1233  when <tt>--enable-debug</tt> is passed to configure.
1234  When set to more than 1, even more verbose messages are displayed.
1235  The default is 1.
1236  </dd>
1237
1238</dl>
1239
1240<!-- not documented:
1241 HWLOC_USE_DT
1242  enables the use of the POWER Device-Tree on Linux (disabled by default since 2.1)
1243 HWLOC_KNL_NUMA_QUIRK
1244  disables the KNL NUMA Cluster quirk in the linux backend
1245 HWLOC_KNL_HDH_FALLBACK
1246  if 1, ignore KNL info from hwloc-dump-hwdata and fallback to heuristic
1247  if 0, never fallback to the hardwired heuristic, useful if the heuristic is wrong
1248 HWLOC_DEBUG_ALLOW_OVERLAPPING_NODE_CPUSETS
1249  don't ignore linux numa nodes with overlapping cpusets
1250 HWLOC_DEBUG_SORT_CHILDREN
1251  sort osdev I/O children by name to make sure the topology doesn't depend
1252  on the ordering of dentries in the local filesystem (for Linux fsroot tests)
1253 HWLOC_DEBUG_CHECK
1254  runs sanity checks during discovery, as if \--enable-debug was passed but
1255  without debug messages
1256  may be useful in the doc for debugging?
1257 HWLOC_HIDE_DEPRECATED
1258  hides some warnings about deprecated features.
1259  listed in those warnings so no need to document it
1260 HWLOC_TEST_GATHER_TOPOLOGY=0
1261  disable the hwloc-gather-topology test when too long on large servers
1262 HWLOC_FORCE_BGQ
1263  makes the bgq component run even if it doesn't recognize the running platform as a BGQ/CNK
1264 HWLOC_PICL_HETEROGENEOUS
1265  don't apply PICL info from a single CPU to all CPUs since the machine isn't homogeneous
1266 HWLOC_DEBUG_FAKE_COMPONENT
1267  enables debugging message to check that the fake component gets loaded
1268 HWLOC_DONT_ADD_VERSION_INFO
1269  do not add hwlocVersion and processName info attributes (to facilitate comparing outputs)
1270 HWLOC_LIBXML=0
1271 HWLOC_LIBXML_EXPORT=0
1272 HWLOC_LIBXML_IMPORT=0
1273  forces the use of the nolibxml XML backend instead of libxml2 if available,
1274  for both import and export, or only one
1275 HWLOC_LIBXML_CLEANUP
1276  cleanup libxml when ending import, to make valgrind happy
1277  not enabled by default because somebody else may be using libxml
1278 HWLOC_XML_USERDATA_NOT_DECODED
1279  do not decode base64 userdata on import,
1280  and reexport it the same (used by tools for leaving userdata untouched)
1281 HWLOC_XML_SUPPORT_EXPORT=0
1282  don't export support info to XML.
1283 HWLOC_RSMI_SHUTDOWN
1284  force rsmi_shutdown to make valgrind happy
1285  not enabled by default on rsmi <= 3.3.x because those old libs do not
1286  refcount and somebody else might be using rsmi
1287-->
1288
1289
1290
1291
1292\page cpu_mem_bind CPU and Memory Binding Overview
1293
1294\htmlonly
1295<div class="section">
1296\endhtmlonly
1297
1298Some operating systems do not systematically provide separate
1299functions for CPU and memory binding.  This means that CPU binding
1300functions may have have effects on the memory binding policy.
1301Likewise, changing the memory binding policy may change the CPU
1302binding of the current thread.  This is often not a problem for
1303applications, so by default hwloc will make use of these functions
1304when they provide better binding support.
1305
1306If the application does not want the CPU binding to change when
1307changing the memory policy, it needs to use the
1308::HWLOC_MEMBIND_NOCPUBIND flag to prevent hwloc from using OS functions
1309which would change the CPU binding.  Additionally,
1310::HWLOC_CPUBIND_NOMEMBIND can be passed to CPU binding function to
1311prevent hwloc from using OS functions would change the memory binding
1312policy.  Of course, using these flags will reduce hwloc's overall support for
1313binding, so their use is discouraged.
1314
1315One can avoid using these flags but still closely control both memory
1316and CPU binding by allocating memory, touching each page in the
1317allocated memory, and then changing the CPU binding.  The
1318already-really-allocated memory will then be "locked" to physical
1319memory and will not be migrated.  Thus, even if the memory binding
1320policy gets changed by the CPU binding order, the already-allocated
1321memory will not change with it.  When binding and allocating further
1322memory, the CPU binding should be performed again in case the memory
1323binding altered the previously-selected CPU binding.
1324
1325Not all operating systems support the notion of a "current" memory
1326binding policy for the current process, but such operating systems often still
1327provide a way to allocate data on a given node set.  Conversely, some
1328operating systems support the notion of a "current" memory binding policy and do
1329not permit allocating data on a specific node set without changing the
1330current policy and allocate the data. To provide the most powerful coverage of
1331these facilities, hwloc provides:
1332
1333<ul>
1334<li>functions that set/get the current memory binding policies (if supported):
1335hwloc_set/get_membind() and hwloc_set/get_proc_membind()
1336<li>a function that allocates memory bound to specific node set without changing
1337the current memory binding policy (if supported): hwloc_alloc_membind().
1338<li>a helper which, if needed, changes the current memory binding policy of the
1339process in order to obtain memory binding: hwloc_alloc_membind_policy().
1340</ul>
1341
1342An application can thus use the two first sets of functions if it wants to
1343manage separately the global process binding policy and directed allocation,
1344or use the third set of functions if it does not care about the process memory
1345binding policy.
1346
1347See \ref hwlocality_cpubinding and \ref hwlocality_membinding for
1348hwloc's API functions regarding CPU and memory binding, respectively.
1349There are some examples under doc/examples/ in the source tree.
1350
1351
1352
1353\page iodevices I/O Devices
1354
1355\htmlonly
1356<div class="section">
1357\endhtmlonly
1358
1359hwloc usually manipulates processing units and memory but it can also
1360discover I/O devices and report their locality as well.
1361This is useful for placing I/O intensive applications on cores near the
1362I/O devices they use, or for gathering information about all platform
1363components.
1364
1365
1366\htmlonly
1367</div><div class="section" id="iodevices_enabling">
1368\endhtmlonly
1369\section iodevices_enabling Enabling and requirements
1370
1371I/O discovery is disabled by default (except in lstopo) for performance
1372reasons.
1373It can be enabled by changing the filtering of I/O object types to
1374<tt>::HWLOC_TYPE_FILTER_KEEP_IMPORTANT</tt> or <tt>::HWLOC_TYPE_FILTER_KEEP_ALL</tt>
1375before loading the topology, for instance with <tt>hwloc_topology_set_io_types_filter()</tt>.
1376
1377Note that I/O discovery requires significant help from the operating system.
1378The pciaccess library (the development package is usually <tt>libpciaccess-devel</tt>
1379or <tt>libpciaccess-dev</tt>) is needed to fully detect PCI devices and bridges/switches.
1380On Linux, PCI discovery may still be performed even if <tt>libpciaccess</tt> cannot
1381be used. But it misses PCI device names.
1382Moreover, some operating systems require privileges for probing PCI devices,
1383see \ref faq_privileged for details.
1384
1385The actual locality of I/O devices is only currently detected on Linux.
1386Other operating system will just report I/O devices as being attached
1387to the topology root object.
1388
1389
1390\htmlonly
1391</div><div class="section" id="iodevices_objects">
1392\endhtmlonly
1393\section iodevices_objects I/O objects
1394
1395When I/O discovery is enabled and supported, some additional objects
1396are added to the topology.
1397The corresponding I/O object types are:
1398<ul><li>
1399<tt>::HWLOC_OBJ_OS_DEVICE</tt> describes an operating-system-specific
1400handle such as the <em>sda</em> drive or the <em>eth0</em> network interface.
1401See \ref iodevices_osdev.
1402</li><li>
1403<tt>::HWLOC_OBJ_PCI_DEVICE</tt> and <tt>::HWLOC_OBJ_BRIDGE</tt> build up
1404a PCI hierarchy made of bridges (that may be actually be switches) and devices.
1405See \ref iodevices_pci.
1406</li></ul>
1407Any of these types may be filtered individually with <tt>hwloc_topology_set_type_filter()</tt>.
1408
1409hwloc tries to attach these new objects to normal objects
1410(usually NUMA nodes) to match their actual physical location.
1411For instance, if a I/O hub (or root complex) is physically connected to a package,
1412the corresponding hwloc bridge object (and its PCI bridges and devices children)
1413is inserted as a child of the corresponding hwloc Package object.
1414<b>These children are not in the normal children list but rather in the I/O-specific
1415children list.</b>
1416
1417I/O objects also have neither CPU sets nor node sets (NULL pointers) because
1418they are not directly usable by the user applications for binding.
1419Moreover I/O hierarchies may be highly complex (asymmetric trees of bridges).
1420So I/O objects are placed in specific levels with custom depths.
1421Their lists may still be traversed with regular helpers such as
1422hwloc_get_next_obj_by_type().
1423However, hwloc offers some dedicated helpers such as hwloc_get_next_pcidev()
1424and hwloc_get_next_osdev() for convenience (see \ref hwlocality_advanced_io).
1425
1426
1427\htmlonly
1428</div><div class="section" id="iodevices_osdev">
1429\endhtmlonly
1430\section iodevices_osdev OS devices
1431
1432Although each PCI device is uniquely identified by its bus ID
1433(e.g. 0000:01:02.3), a user-space application can hardly find out which
1434PCI device it is actually using.
1435Applications rather use software handles
1436(such as the <em>eth0</em> network interface,
1437 the <em>sda</em> hard drive,
1438 or the <em>mlx4_0</em> OpenFabrics HCA).
1439Therefore hwloc tries to add software devices
1440(<tt>::HWLOC_OBJ_OS_DEVICE</tt>, also known as OS devices).
1441
1442OS devices may be attached below PCI devices, but they may also be
1443attached directly to normal objects.
1444Indeed some OS devices are not related to PCI.
1445For instance, NVDIMM block devices (such as <em>pmem0s</em> on Linux)
1446are directly attached near their NUMA node
1447(I/O child of the parent whose memory child is the NUMA node).
1448Also, if hwloc could not discover PCI for some reason, PCI-related
1449OS devices may also be attached directly to normal objects.
1450
1451hwloc first tries to discover OS devices from the operating system,
1452e.g. <em>eth0</em>, <em>sda</em> or <em>mlx4_0</em>.
1453However, this ability is currently only available on Linux for some
1454classes of devices.
1455
1456hwloc then tries to discover software devices through additional
1457I/O components using external libraries.
1458For instance proprietary graphics drivers do not expose any named OS device,
1459but hwloc may still create one OS object per software handle when
1460supported.
1461For instance the <tt>opencl</tt> and <tt>cuda</tt> components may
1462add some <em>opencl0d0</em> and <em>cuda0</em> OS device objects.
1463
1464Here is a list of OS device objects commonly created by hwloc
1465components when I/O discovery is enabled and supported.
1466
1467<ul>
1468<li>Hard disks or non-volatile memory devices (::HWLOC_OBJ_OSDEV_BLOCK)
1469 <ul>
1470 <li><em>sda</em> or <em>dax2.0</em> (Linux component)</li>
1471 </ul>
1472</li>
1473<li>Network interfaces (::HWLOC_OBJ_OSDEV_NETWORK)
1474 <ul>
1475 <li><em>eth0</em>, <em>wlan0</em>, <em>ib0</em> (Linux component)</li>
1476 </ul>
1477</li>
1478<li>OpenFabrics (InfiniBand, Omni-Path, usNIC, etc) HCAs (::HWLOC_OBJ_OSDEV_OPENFABRICS)
1479 <ul>
1480 <li><em>mlx5_0</em>, <em>hfi1_0</em>, <em>qib0</em>, <em>usnic_0</em> (Linux component)</li>
1481 </ul>
1482</li>
1483<li>GPUs (::HWLOC_OBJ_OSDEV_GPU)
1484 <ul>
1485 <li><em>rsmi0</em> for the first RSMI device
1486  (RSMI component, using the AMD ROCm SMI library)</li>
1487 <li><em>nvml0</em> for the first NVML device
1488  (NVML component, using the NVIDIA Management Library)</li>
1489 <li><em>:0.0</em> for the first display
1490  (GL component, using the NV-CONTROL X extension library, NVCtrl)</li>
1491 </ul>
1492</li>
1493<li>Co-Processors (::HWLOC_OBJ_OSDEV_COPROC)
1494 <ul>
1495 <li><em>opencl0d0</em> for the first device of the first OpenCL platform,
1496  <em>opencl1d3</em> for the fourth device of the second OpenCL platform
1497  (OpenCL component)</li>
1498 <li><em>cuda0</em> for the first NVIDIA CUDA device
1499  (CUDA component, using the NVIDIA CUDA Library)</li>
1500</li>
1501<li>DMA engine channel (::HWLOC_OBJ_OSDEV_DMA)
1502 <ul>
1503 <li><em>dma0chan0</em> (Linux component) when all OS devices are enabled (::HWLOC_TYPE_FILTER_KEEP_ALL)</li>
1504 </ul>
1505</li>
1506</ul>
1507
1508Note that some PCI devices may contain multiple software devices
1509(see the example below).
1510
1511See also \ref interoperability for managing these devices without
1512considering them as hwloc objects.
1513
1514
1515\htmlonly
1516</div><div class="section" id="iodevices_pci">
1517\endhtmlonly
1518\section iodevices_pci PCI devices and bridges
1519
1520A PCI hierarchy is usually organized as follows:
1521A hostbridge object ( <tt>::HWLOC_OBJ_BRIDGE</tt> object with upstream
1522type <em>Host</em> and downstream type <em>PCI</em>) is attached below
1523a normal object (usually the entire machine or a NUMA node).
1524There may be multiple hostbridges in the machine, attached to
1525different places, but all PCI devices are below one of them
1526(unless the Bridge object type is filtered-out).
1527
1528Each hostbridge contains one or several children, either other bridges
1529(usually PCI to PCI switches) or PCI devices (<tt>::HWLOC_OBJ_PCI_DEVICE</tt>).
1530The number of bridges between the hostbridge and a PCI device depends
1531on the machine.
1532
1533
1534\htmlonly
1535</div><div class="section" id="iodevices_consult">
1536\endhtmlonly
1537\section iodevices_consult Consulting I/O devices and binding
1538
1539I/O devices may be consulted by traversing the topology manually
1540(with usual routines such as hwloc_get_obj_by_type()) or by using
1541dedicated helpers (such as hwloc_get_pcidev_by_busid(), see
1542\ref hwlocality_advanced_io).
1543
1544I/O objects do not actually contain any locality information because
1545their CPU sets and node sets are NULL.
1546Their locality must be retrieved by walking up the object tree
1547(through the <tt>parent</tt> link) until a non-I/O object is found
1548(see hwloc_get_non_io_ancestor_obj()).
1549This normal object should have non-NULL CPU sets and node sets
1550which describe the processing units and memory that are immediately
1551close to the I/O device.
1552For instance the path from a OS device to its locality may go
1553across a PCI device parent, one or several bridges, up to
1554a Package node with the same locality.
1555
1556Command-line tools are also aware of I/O devices.
1557lstopo displays the interesting ones by default
1558(passing <tt>\--no-io</tt> disables it).
1559
1560hwloc-calc and hwloc-bind may manipulate I/O devices specified
1561by PCI bus ID or by OS device name.
1562<ul>
1563<li>
1564 <tt>pci=0000:02:03.0</tt> is replaced by the set
1565 of CPUs that are close to the PCI device whose bus ID is given.
1566</li>
1567<li>
1568 <tt>os=eth0</tt> is replaced by CPUs that are close to the I/O
1569 device whose software handle is called <tt>eth0</tt>.
1570</li>
1571</ul>
1572This enables easy binding of I/O-intensive applications near the
1573device they use.
1574
1575
1576\htmlonly
1577</div><div class="section" id="iodevices_examples">
1578\endhtmlonly
1579\section iodevices_examples Examples
1580
1581The following picture shows a dual-package dual-core host whose
1582PCI bus is connected to the first package and NUMA node.
1583
1584\image html devel09-pci.png
1585\image latex devel09-pci.png "" width=\textwidth
1586
1587Six interesting PCI devices were discovered.
1588However, hwloc found some corresponding software devices
1589(<em>eth0</em>, <em>eth1</em>, <em>sda</em>, <em>mlx4_0</em>,
1590<em>ib0</em>, and <em>ib1</em>) for only four of these physical
1591devices.
1592The other ones (<em>PCI 102b:0532</em> and <em>PCI 8086:3a20</em>)
1593are an unused IDE controller (no disk attached)
1594and a graphic card (no corresponding software device reported
1595to the user by the operating system).
1596
1597On the contrary, it should be noted that three different software
1598devices were found for the last PCI device (<em>PCI 15b3:634a</em>).
1599Indeed this OpenFabrics HCA PCI device object contains one
1600one OpenFabrics software device (<em>mlx4_0</em>) and two virtual
1601network interface software devices (<em>ib0</em> and <em>ib1</em>).
1602
1603
1604Here is the corresponding textual output:
1605
1606\verbatim
1607Machine (24GB total)
1608  Package L#0
1609    NUMANode L#0 (P#0 12GB)
1610    L3 L#0 (8192KB)
1611      L2 L#0 (256KB) + L1 L#0 (32KB) + Core L#0 + PU L#0 (P#0)
1612      L2 L#1 (256KB) + L1 L#1 (32KB) + Core L#1 + PU L#1 (P#2)
1613    HostBridge
1614      PCIBridge
1615        PCI 01:00.0 (Ethernet)
1616          Net "eth0"
1617        PCI 01:00.1 (Ethernet)
1618          Net "eth1"
1619      PCIBridge
1620        PCI 03:00.0 (RAID)
1621          Block "sda"
1622      PCIBridge
1623        PCI 04:03.0 (VGA)
1624      PCI 00:1f.2 (IDE)
1625      PCI 51:00.0 (InfiniBand)
1626        Net "ib0"
1627        Net "ib1"
1628        Net "mlx4_0"
1629  Package L#1
1630    NUMANode L#1 (P#1 12GB)
1631    L3 L#1 (8192KB)
1632      L2 L#2 (256KB) + L1 L#2 (32KB) + Core L#2 + PU L#2 (P#1)
1633      L2 L#3 (256KB) + L1 L#3 (32KB) + Core L#3 + PU L#3 (P#3)
1634\endverbatim
1635
1636
1637
1638
1639\page miscobjs Miscellaneous objects
1640
1641\htmlonly
1642<div class="section">
1643\endhtmlonly
1644
1645hwloc topologies may be annotated with Misc objects
1646(of type <tt>::HWLOC_OBJ_MISC</tt>)
1647either automatically or by the user.
1648This is a flexible way to annotate topologies with
1649large sets of information since Misc objects may be inserted
1650anywhere in the topology (to annotate specific objects or
1651parts of the topology), even below other Misc objects, and each
1652of them may contain multiple attributes (see also \ref faq_annotate).
1653
1654These Misc objects may have a <tt>subtype</tt> field
1655to replace <tt>Misc</tt> with something else in the lstopo
1656output.
1657
1658
1659\htmlonly
1660</div><div class="section" id="miscobjs_auto">
1661\endhtmlonly
1662\section miscobjs_auto Misc objects added by hwloc
1663
1664hwloc only uses Misc objects when other object types are not sufficient,
1665and when the Misc object type is not filtered-out anymore.
1666This currently includes:
1667<ul>
1668<li>
1669Memory modules (DIMMs), on Linux when privileged and when
1670<tt>dmi-sysfs</tt> is supported by the kernel.
1671These objects have a <tt>subtype</tt> field of value <tt>MemoryModule</tt>.
1672They are currently always attached to the root object.
1673Their attributes describe the DIMM vendor, model, etc.
1674<tt>lstopo -v</tt> displays them as:
1675\code
1676Misc(MemoryModule) (P#1 DeviceLocation="Bottom-Slot 2(right)" BankLocation="BANK 2" Vendor=Elpida SerialNumber=21733667 AssetTag=9876543210 PartNumber="EBJ81UG8EFU0-GN-F ")
1677\endcode
1678</li>
1679<li>
1680Displaying process binding in <tt>lstopo \--top</tt>.
1681These objects have a <tt>subtype</tt> field of value <tt>Process</tt>
1682and a name attribute made of their PID and program name.
1683They are attached below the object they are bound to.
1684The textual <tt>lstopo</tt> displays them as:
1685\code
1686  PU L#0 (P#0)
1687    Misc(Process) 4445 myprogram
1688\endcode
1689</li>
1690</ul>
1691
1692
1693\htmlonly
1694</div><div class="section" id="miscobjs_annotate">
1695\endhtmlonly
1696\section miscobjs_annotate Annotating topologies with Misc objects
1697
1698The user may annotate hwloc topologies with its own Misc objects.
1699This can be achieved with <tt>hwloc_topology_insert_misc_object()</tt>
1700as well as hwloc-annotate command-line tool.
1701
1702
1703
1704
1705\page attributes Object attributes
1706
1707\htmlonly
1708<div class="section" id="attributes_normal">
1709\endhtmlonly
1710\section attributes_normal Normal attributes
1711
1712hwloc objects have many generic attributes in the ::hwloc_obj structure,
1713for instance their <tt>logical_index</tt> or <tt>os_index</tt>
1714(see \ref faq_indexes), <tt>depth</tt> or <tt>name</tt>.
1715
1716The kind of object is first described by the <tt>obj->type</tt>
1717generic attribute (an integer).
1718OS devices also have a specific <tt>obj->attr->osdev.type</tt> integer
1719for distinguishing between NICs, GPUs, etc.
1720Objects may also have an optional <tt>obj->subtype</tt> pointing
1721to a better description string.
1722For instance subtype is useful to say what Group objects are actually
1723made of (e.g. <em>Book</em> for Linux S/390 books).
1724It may also specify that a Block OS device is a <em>Disk</em>,
1725or that a CoProcessor OS device is a <em>CUDA</em> device.
1726This subtype is displayed by lstopo either in place or after the
1727main <tt>obj->type</tt> attribute.
1728NUMA nodes that correspond GPU memory may also have <em>GPUMemory</em>
1729as subtype.
1730
1731Each object also contains an <tt>attr</tt> field that, if non NULL,
1732points to a union ::hwloc_obj_attr_u of type-specific attribute
1733structures.
1734For instance, a L2Cache object <tt>obj</tt> contains cache-specific
1735information in <tt>obj->attr->cache</tt>, such as its size and
1736associativity, cache type.
1737See ::hwloc_obj_attr_u for details.
1738
1739
1740\htmlonly
1741</div><div class="section" id="attributes_info">
1742\endhtmlonly
1743\section attributes_info Custom string infos
1744
1745Aside os these generic attribute fields, hwloc annotates
1746many objects with string attributes that are made of a key and a
1747value.
1748Each object contains a list of such pairs that may be consulted
1749manually (looking at the object <tt>infos</tt> array field)
1750or using the hwloc_obj_get_info_by_name().
1751The user may additionally add new key-value pairs to any object using
1752hwloc_obj_add_info() or the \ref cli_hwloc_annotate program.
1753
1754Here is a non-exhaustive list of attributes that may be automatically
1755added by hwloc.
1756Note that these attributes heavily depend on the ability of the
1757operating system to report them.
1758Many of them will therefore be missing on some OS.
1759
1760\htmlonly
1761</div><div class="subsection" id="attributes_info_platform">
1762\endhtmlonly
1763\subsection attributes_info_platform Hardware Platform Information
1764
1765These info attributes are attached to the root object (Machine).
1766
1767<dl>
1768<dt>PlatformName, PlatformModel, PlatformVendor, PlatformBoardID, PlatformRevision,</dt>
1769<dt> SystemVersionRegister, ProcessorVersionRegister (Machine)</dt>
1770<dd>Some POWER/PowerPC-specific attributes describing the platform
1771and processor.
1772Currently only available on Linux.
1773Usually added to Package objects, but can be in Machine instead if
1774hwloc failed to discover any package.
1775</dd>
1776<dt>DMIBoardVendor, DMIBoardName, etc.</dt>
1777<dd>DMI hardware information such as the motherboard and chassis
1778models and vendors, the BIOS revision, etc.,
1779as reported by Linux under <tt>/sys/class/dmi/id/</tt>.
1780</dd>
1781<dt>MemoryMode, ClusterMode</dt>
1782<dd>
1783Intel Xeon Phi processor configuration modes.
1784Available if hwloc-dump-hwdata was used (see \ref faq_knl_dump)
1785or if hwloc managed to guess them from the NUMA configuration.
1786
1787The memory mode may be <em>Cache</em>, <em>Flat</em>,
1788<em>Hybrid50</em> (half the MCDRAM is used as a cache)
1789or <em>Hybrid25</em> (25% of MCDRAM as cache).
1790The cluster mode may be <em>Quadrant</em>, <em>Hemisphere</em>, <em>All2All</em>,
1791<em>SNC2</em> or <em>SNC4</em>.
1792See doc/examples/get-knl-modes.c in the source directory for an example of retrieving these attributes.
1793</dd>
1794</dl>
1795
1796
1797\htmlonly
1798</div><div class="subsection" id="attributes_info_os">
1799\endhtmlonly
1800\subsection attributes_info_os Operating System Information
1801
1802These info attributes are attached to the root object (Machine).
1803
1804<dl>
1805<dt>OSName, OSRelease, OSVersion, HostName, Architecture</dt>
1806<dd>The operating system name, release, version, the hostname and the
1807architecture name, as reported by the Unix <tt>uname</tt> command.
1808</dd>
1809<dt>LinuxCgroup</dt>
1810<dd>The name the Linux control group where the calling process is
1811placed.
1812</dd>
1813<dt>WindowsBuildEnvironment</dt>
1814<dd>Either MinGW or Cygwin when one of these environments was used during build.
1815</dd>
1816</dl>
1817
1818
1819\htmlonly
1820</div><div class="subsection" id="attributes_info_hwloc">
1821\endhtmlonly
1822\subsection attributes_info_hwloc hwloc Information
1823
1824Unless specified, these info attributes are attached to the root object (Machine).
1825
1826<dl>
1827<dt>Backend (topology root, or specific object added by that backend)</dt>
1828<dd>The name of the hwloc backend/component that filled the topology.
1829If several components were combined, multiple Backend keys may exist,
1830with different values, for instance <tt>x86</tt> and <tt>Linux</tt> in the root
1831object and <tt>CUDA</tt> in CUDA OS device objects.
1832</dd>
1833<dt>SyntheticDescription</dt>
1834<dd>The description string that was given to hwloc to build this
1835synthetic topology.
1836</dd>
1837<dt>hwlocVersion</dt>
1838<dd>The version number of the hwloc library that was used to generate
1839the topology. If the topology was loaded from XML, this is not the hwloc
1840version that loaded it, but rather the first hwloc instance that exported
1841the topology to XML earlier.
1842</dd>
1843<dt>ProcessName</dt>
1844<dd>The name of the process that contains the hwloc library that was used
1845to generate the topology. If the topology was from XML, this is not the
1846hwloc process that loaded it, but rather the first process that exported
1847the topology to XML earlier.
1848</dd>
1849</dl>
1850
1851
1852\htmlonly
1853</div><div class="subsection" id="attributes_info_cpu">
1854\endhtmlonly
1855\subsection attributes_info_cpu CPU Information
1856
1857These info attributes are attached to Package objects,
1858or to the root object (Machine) if package locality information is missing.
1859
1860<dl>
1861<dt>CPUModel</dt>
1862<dd>The processor model name.</dd>
1863<dt>CPUVendor, CPUModelNumber, CPUFamilyNumber, CPUStepping</dt>
1864<dd>The processor vendor name, model number, family number, and stepping number.
1865Currently available for x86 and Xeon Phi processors on most systems,
1866and for ia64 processors on Linux (except CPUStepping).
1867</dd>
1868<dt>CPURevision</dt>
1869<dd>
1870A POWER/PowerPC-specific general processor revision number,
1871currently only available on Linux.
1872</dd>
1873<dt>CPUType</dt>
1874<dd>
1875A Solaris-specific general processor type name, such as "i86pc".
1876</dd>
1877</dl>
1878
1879
1880\htmlonly
1881</div><div class="subsection" id="attributes_info_osdev">
1882\endhtmlonly
1883\subsection attributes_info_osdev OS Device Information
1884
1885These info attributes are attached to OS device objects specified in parentheses.
1886
1887<dl>
1888<dt>Vendor, Model, Revision, SerialNumber, Size, SectorSize (Block OS devices)</dt>
1889<dd>The vendor and model names, revision, serial number, size (in kB)
1890and SectorSize (in bytes).
1891</dd>
1892<dt>LinuxDeviceID (Block OS devices)</dt>
1893<dd>The major/minor device number such as 8:0 of Linux device.
1894</dd>
1895<dt>GPUVendor, GPUModel (GPU or Co-Processor OS devices)</dt>
1896<dd>The vendor and model names of the GPU device.
1897</dd>
1898<dt>OpenCLDeviceType, OpenCLPlatformIndex,</dt>
1899<dt>OpenCLPlatformName, OpenCLPlatformDeviceIndex (OpenCL OS devices)</dt>
1900<dd>The type of OpenCL device,
1901 the OpenCL platform index and name,
1902 and the index of the device within the platform.
1903</dd>
1904<dt>OpenCLComputeUnits, OpenCLGlobalMemorySize (OpenCL OS devices)</dt>
1905<dd>The number of compute units and global memory size (in kB) of an OpenCL device.
1906</dd>
1907<dt>AMDUUID, AMDSerial (RSMI GPU OS devices)</dt>
1908<dd>The UUID and serial number of AMD GPUs.
1909</dd>
1910<dt>XGMIHiveID (RSMI GPU OS devices)</dt>
1911<dd>The ID of the group of GPUs (Hive) interconnected by XGMI links
1912</dd>
1913<dt>XGMIPeers (RSMI GPU OS devices)</dt>
1914<dd>The list of RSMI OS devices that are directly connected
1915  to the current device through XGMI links.
1916  They are given as a space-separated list of object names,
1917  for instance <em>rsmi2 rsmi3</em>.
1918</dd>
1919<dt>NVIDIAUUID, NVIDIASerial (NVML GPU OS devices)</dt>
1920<dd>The UUID and serial number of NVIDIA GPUs.
1921</dd>
1922<dt>CUDAMultiProcessors, CUDACoresPerMP,</dt>
1923<dt>CUDAGlobalMemorySize, CUDAL2CacheSize, CUDASharedMemorySizePerMP (CUDA OS devices)</dt>
1924<dd>
1925 The number of shared multiprocessors, the number of cores per
1926 multiprocessor, the global memory size, the (global) L2 cache size,
1927 and size of the shared memory in each multiprocessor of a CUDA device.
1928 Sizes are in kB.
1929</dd>
1930<dt>Address, Port (Network interface OS devices)</dt>
1931<dd>The MAC address and the port number of a software network
1932interface, such as <tt>eth4</tt> on Linux.
1933</dd>
1934<dt>NodeGUID, SysImageGUID, Port1State, Port2LID, Port2LMC, Port3GID1
1935(OpenFabrics OS devices)</dt>
1936<dd>The node GUID and GUID mask,
1937the state of a port #1 (value is 4 when active),
1938the LID and LID mask count of port #2,
1939and GID #1 of port #3.
1940</dd>
1941</dl>
1942
1943
1944\htmlonly
1945</div><div class="subsection" id="attributes_info_otherobjs">
1946\endhtmlonly
1947\subsection attributes_info_otherobjs Other Object-specific Information
1948
1949These info attributes are attached to objects specified in parentheses.
1950
1951<dl>
1952<dt>DAXDevice (NUMA Nodes)</dt>
1953<dd>The name of the Linux DAX device that was used to expose a non-volatile
1954memory region as a volatile NUMA node.
1955</dd>
1956<dt>PCIBusID (GPUMemory NUMA Nodes)</dt>
1957<dd>The PCI bus ID of the GPU whose memory is exposed in this NUMA node.
1958</dd>
1959<dt>Inclusive (Caches)</dt>
1960<dd>The inclusiveness of a cache (1 if inclusive, 0 otherwise).
1961Currently only available on x86 processors.
1962</dd>
1963<dt>SolarisProcessorGroup (Group)</dt>
1964<dd>
1965The Solaris kstat processor group name that was used to build this Group object.
1966</dd>
1967<dt>PCIVendor, PCIDevice (PCI devices and bridges)</dt>
1968<dd>The vendor and device names of the PCI device.
1969</dd>
1970<dt>PCISlot (PCI devices or Bridges)</dt>
1971<dd>The name/number of the physical slot where the device is plugged.
1972 If the physical device contains PCI bridges above the actual PCI device,
1973 the attribute may be attached to the highest bridge
1974 (i.e. the first object that actually appears below the physical slot).
1975</dd>
1976<dt>Vendor, AssetTag, PartNumber, DeviceLocation, BankLocation (MemoryModule Misc objects)</dt>
1977<dd>
1978Information about memory modules (DIMMs) extracted from SMBIOS.
1979</dd>
1980</dl>
1981
1982
1983\htmlonly
1984</div><div class="subsection" id="attributes_info_user">
1985\endhtmlonly
1986\subsection attributes_info_user User-Given Information
1987
1988Here is a non-exhaustive list of user-provided info attributes
1989that have a special meaning:
1990<dl>
1991<dt>lstopoStyle</dt>
1992<dd>Enforces the style of an object (background and text colors)
1993 in the graphical output of lstopo.
1994 See CUSTOM COLORS in the lstopo(1) manpage for details.
1995</dd>
1996</dl>
1997
1998
1999
2000
2001\page topoattrs Topology Attributes: Distances, Memory Attributes and CPU Kinds
2002
2003\htmlonly
2004<div class="section">
2005\endhtmlonly
2006
2007Besides the hierarchy of objects and individual object attributes
2008(see \ref attributes), hwloc may also expose finer information about
2009the hardware organization.
2010
2011
2012\htmlonly
2013</div><div class="section" id="topoattrs_distances">
2014\endhtmlonly
2015\section topoattrs_distances Distances
2016
2017A machine with 4 CPUs may have identical links between every pairs of CPUs,
2018or those CPUs could also only be connected through a ring.
2019In the ring case, accessing the memory of nearby CPUs is slower than local
2020memory, but it is also faster than accessing the memory of CPU on the
2021opposite side of the ring.
2022These deep details cannot be exposed in the hwloc hierarchy,
2023that is why hwloc also exposes distances.
2024
2025Distances are matrices of values between sets of objects,
2026usually latencies or bandwidths.
2027By default, hwloc tries to get a matrix of relative latencies
2028between NUMA nodes when exposed by the hardware.
2029
2030In the aforementioned ring case, the matrix could report 10
2031for latency between a NUMA node and itself, 20 for nearby nodes,
2032and 30 for nodes that are opposites on the ring.
2033Those are theoretical values exposed by hardware vendors
2034(in the System Locality Distance Information Table (SLIT) in the ACPI)
2035rather than physical latencies.
2036They are mostly meant for comparing node relative distances.
2037
2038Distances structures currently created by hwloc are:
2039<dl>
2040<dt>NUMALatency (Linux, Solaris, FreeBSD)</dt>
2041<dd>This is the matrix of theoretical latencies described above.
2042</dd>
2043</dl>
2044
2045Users may also specify their own matrices between any set of objects,
2046even if these objects are of different types (e.g. bandwidths between GPUs and CPUs).
2047
2048The entire API is located in hwloc/distances.h.
2049See also \ref hwlocality_distances_get,
2050as well as \ref hwlocality_distances_consult
2051and \ref hwlocality_distances_add.
2052
2053
2054\htmlonly
2055</div><div class="section" id="topoattrs_memattrs">
2056\endhtmlonly
2057\section topoattrs_memattrs Memory Attributes
2058
2059Machines with heterogeneous memory, for instance high-bandwidth memory (HBM),
2060normal memory (DDR), and/or high-capacity slow memory (such as non-volatile
2061memory DIMMs, NVDIMMs) require applications to allocate buffers
2062in the appropriate target memory depending on performance and capacity needs.
2063Those target nodes may be exposed in the hwloc hierarchy as different
2064memory children but there is a need for performance information to select
2065the appropriate one.
2066
2067hwloc memory attributes are designed to expose memory
2068information such as latency, bandwidth, etc.
2069Users may also specify their own attributes and values.
2070
2071The memory attributes API is located in hwloc/memattrs.h,
2072see \ref hwlocality_memattrs and \ref hwlocality_memattrs_manage for details.
2073
2074\htmlonly
2075</div><div class="section" id="topoattrs_cpukinds">
2076\endhtmlonly
2077\section topoattrs_cpukinds CPU Kinds
2078
2079Hybrid CPUs may contain different kinds of cores.
2080The CPU kinds API in hwloc/cpukinds.h provides a way to list the sets
2081of PUs in each kind and get some optional information about their
2082hardware characteristics and efficiency.
2083
2084If the operating system provides efficiency information (e.g. Windows 10),
2085it is used to rank hwloc CPU kinds by efficiency.
2086Otherwise, hwloc implements several heuristics based on frequencies
2087and core types (see HWLOC_CPUKINDS_RANKING in \ref envvar).
2088
2089Attributes include:
2090<dl>
2091<dt>FrequencyMaxMHz (Linux)</dt>
2092<dd>The maximal operating frequency of the core,
2093as reported by <tt>cpufreq</tt> drivers on Linux.
2094</dd>
2095<dt>FrequencyBaseMHz (Linux)</dt>
2096<dd>The base operating frequency of the core,
2097as reported by some <tt>cpufreq</tt> drivers on Linux (e.g. <tt>intel_pstate</tt>).
2098</dd>
2099<dt>CoreType (x86, Linux)</dt>
2100<dd>A string describing the kind of core,
2101currently <tt>IntelAtom</tt> or <tt>IntelCore</tt>,
2102as reported by the x86 CPUID instruction and future Linux kernels
2103on some Intel processors.
2104</dd>
2105<dt>LinuxCPUType (Linux)</dt>
2106<dd>The Linux-specific CPU type found in sysfs,
2107such as <tt>intel_atom_0</tt>,
2108as reported by future Linux kernels on some Intel processors.
2109</dd>
2110</dl>
2111
2112See \ref hwlocality_cpukinds for details.
2113
2114
2115
2116
2117\page xml Importing and exporting topologies from/to XML files
2118
2119\htmlonly
2120<div class="section">
2121\endhtmlonly
2122
2123hwloc offers the ability to export topologies to XML files and reload
2124them later. This is for instance useful for loading topologies faster
2125(see \ref faq_xml), manipulating other nodes' topology, or avoiding
2126the need for privileged processes (see \ref faq_privileged).
2127
2128Topologies may be exported to XML files thanks to hwloc_topology_export_xml(),
2129or to a XML memory buffer with hwloc_topology_export_xmlbuffer().
2130The lstopo program can also serve as a XML topology export tool.
2131
2132XML topologies may then be reloaded later with hwloc_topology_set_xml()
2133and hwloc_topology_set_xmlbuffer().
2134The HWLOC_XMLFILE environment variable also tells hwloc to load the topology
2135from the given XML file (see \ref envvar).
2136
2137\note Loading XML topologies disables binding because the loaded
2138topology may not correspond to the physical machine that loads it.
2139This behavior may be reverted by asserting that loaded file really
2140matches the underlying system with the HWLOC_THISSYSTEM environment
2141variable or the ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM topology flag.
2142
2143\note The topology flag ::HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES
2144may be used to load a XML topology that contains the entire machine
2145and restrict it to the part that is actually available to the current
2146process (e.g. when Linux Cgroup/Cpuset are used to restrict the set
2147of resources).
2148
2149\note hwloc also offers the ability to export/import \ref hwlocality_diff.
2150
2151\note XML topology files are not localized. They use a dot as a
2152decimal separator. Therefore any exported topology can be
2153reloaded on any other machine without requiring to change the
2154locale.
2155
2156\note XML exports contain all details about the platform. It means
2157that two very similar nodes still have different XML exports
2158(e.g. some serial numbers or MAC addresses are different).
2159If a less precise exporting/importing is required, one may want to
2160look at \ref synthetic instead.
2161
2162
2163\htmlonly
2164</div><div class="section" id="xml_backends">
2165\endhtmlonly
2166\section xml_backends libxml2 and minimalistic XML backends
2167
2168hwloc offers two backends for importing/exporting XML.
2169
2170First, it can use the libxml2 library for importing/exporting XML
2171files. It features full XML support, for instance when those files
2172have to be manipulated by non-hwloc software (e.g. a XSLT parser).
2173The libxml2 backend is enabled by default if libxml2 development
2174headers are available (the relevant development package is usually
2175<tt>libxml2-devel</tt> or <tt>libxml2-dev</tt>).
2176
2177If libxml2 is not available at configure time,
2178or if <tt>\--disable-libxml2</tt> is passed, hwloc falls back to a
2179custom backend.
2180Contrary to the aforementioned full XML backend with libxml2, this
2181minimalistic XML backend cannot be guaranteed to work with external
2182programs.
2183It should only be assumed to be compatible with the same hwloc
2184release (even if using the libxml2 backend).
2185Its advantage is, however, to always be available without requiring
2186any external dependency.
2187
2188If libxml2 is available but the core hwloc library should not directly
2189depend on it, the libxml2 support may be built as a dynamicall-loaded
2190plugin.
2191One should pass <tt>\--enable-plugins</tt> to enable plugin support
2192(when supported) and build as plugins all component that support it.
2193Or pass <tt>\--enable-plugins=xml_libxml</tt> to only build this
2194libxml2 support as a plugin.
2195
2196
2197\htmlonly
2198</div><div class="section" id="xml_errors">
2199\endhtmlonly
2200\section xml_errors XML import error management
2201
2202Importing XML files can fail at least because of file access errors,
2203invalid XML syntax, non-hwloc-valid XML contents,
2204or incompatibilities between hwloc releases (see \ref faq_version_xml).
2205
2206Both backend cannot detect all these errors when the input XML
2207file or buffer is selected (when hwloc_topology_set_xml() or
2208hwloc_topology_set_xmlbuffer() is called).
2209Some errors such non-hwloc-valid contents can only be detected
2210later when loading the topology with hwloc_topology_load().
2211
2212It is therefore strongly recommended to check the return value of
2213both hwloc_topology_set_xml() (or hwloc_topology_set_xmlbuffer())
2214and hwloc_topology_load() to handle all these errors.
2215
2216
2217
2218
2219\page synthetic Synthetic topologies
2220
2221\htmlonly
2222<div class="section">
2223\endhtmlonly
2224
2225hwloc may load fake or remote topologies so as to consult them
2226without having the underlying hardware available.
2227Aside from loading XML topologies, hwloc also enables the building of
2228<em>synthetic</em> topologies that are described by a single string
2229listing the arity of each levels.
2230
2231For instance, lstopo may create a topology made of 2 packages,
2232containing a single NUMA node and a L2 cache above two
2233single-threaded cores:
2234
2235\verbatim
2236$ lstopo -i "pack:2 node:1 l2:1 core:2 pu:1" -
2237Machine (2048MB)
2238  Package L#0
2239    NUMANode L#0 (P#0 1024MB)
2240    L2 L#0 (4096KB)
2241      Core L#0 + PU L#0 (P#0)
2242      Core L#1 + PU L#1 (P#1)
2243  Package L#1
2244    NUMANode L#1 (P#1 1024MB)
2245    L2 L#1 (4096KB)
2246      Core L#2 + PU L#2 (P#2)
2247      Core L#3 + PU L#3 (P#3)
2248\endverbatim
2249
2250Replacing <tt>-</tt> with <tt>file.xml</tt> in this command line
2251will export this topology to XML as usual.
2252
2253\note Synthetic topologies offer a very basic way to export a
2254topology and reimport it on another machine. It is a lot less
2255precise than XML but may still be enough when only the hierarchy
2256of resources matters.
2257
2258
2259\htmlonly
2260</div><div class="section" id="synthetic_string">
2261\endhtmlonly
2262\section synthetic_string Synthetic description string
2263
2264Each item in the description string gives the type of the level and
2265the number of such children under each object of the previous level.
2266That is why the above topology contains 4 cores (2 cores times 2 nodes).
2267
2268These type names must be written as
2269<tt>numanode</tt>, <tt>package</tt>, <tt>core</tt>,
2270<tt>l2u</tt>, <tt>l1i</tt>, <tt>pu</tt>, <tt>group</tt>
2271(hwloc_obj_type_sscanf() is used for parsing the type names).
2272They do not need to be written case-sensitively, nor entirely
2273(as long as there is no ambiguity, 2 characters such as <tt>ma</tt>
2274 select a Machine level).
2275Note that I/O and Misc objects are not available.
2276
2277Instead of specifying the type of each level, it is possible to
2278just specify the arities and let hwloc choose all types
2279according to usual topologies. The following examples are therefore
2280equivalent:
2281\verbatim
2282$ lstopo -i "2 3 4 5 6"
2283$ lstopo -i "Package:2 NUMANode:3 L2Cache:4 Core:5 PU:6"
2284\endverbatim
2285
2286NUMA nodes are handled in a special way since they are not part of the
2287main CPU hierarchy but rather attached below it as memory children.
2288Thus, <tt>NUMANode:3</tt> actually means <tt>Group:3</tt> where one
2289NUMA node is attached below each group.
2290These groups are merged back into the parent when possible
2291(typically when a single NUMA node is requested below each parent).
2292
2293It is also possible the explicitly attach NUMA nodes to specific levels.
2294For instance, a topology similar to a Intel Xeon Phi processor
2295(with 2 NUMA nodes per 16-core group) may be created with:
2296\verbatim
2297$ lstopo -i "package:1 group:4 [numa] [numa] core:16 pu:4"
2298\endverbatim
2299
2300The root object does not appear in the synthetic description string
2301since it is always a Machine object.
2302Therefore the Machine type is disallowed in the description as well.
2303
2304A NUMA level (with a single NUMA node) is automatically added if needed.
2305
2306Each item may be followed parentheses containing a list of
2307space-separated attributes. For instance:
2308<ul>
2309<li>
2310 <tt>L2iCache:2(size=32kB)</tt> specifies 2 children
2311 of 32kB level-2 instruction caches.
2312 The size may be specified in bytes (without any unit suffix) or as TB, GB, MB or kB.
2313</li>
2314<li>
2315 <tt>NUMANode:3(memory=16MB)</tt> specifies 3 NUMA nodes with 16MB each.
2316 The size may be specified in bytes (without any unit suffix) or as TB, GB, MB or kB.
2317</li>
2318<li>
2319 <tt>PU:2(indexes=0,2,1,3)</tt> specifies 2 PU children and the
2320 full list of OS indexes among the entire set of 4 PU objects.
2321</li>
2322<li>
2323 <tt>PU:2(indexes=numa:core)</tt> specifies 2 PU children whose
2324 OS indexes are interleaved by NUMA node first and then by package.
2325</li>
2326<li>
2327 Attributes in parentheses at the very beginning of the description
2328 apply to the root object.
2329</li>
2330</ul>
2331
2332
2333\htmlonly
2334</div><div class="section" id="synthetic_use">
2335\endhtmlonly
2336\section synthetic_use Loading a synthetic topology
2337
2338Aside from lstopo, the hwloc programming interface offers the same
2339ability by passing the synthetic description string to
2340hwloc_topology_set_synthetic() before hwloc_topology_load().
2341
2342Synthetic topologies are created by the <tt>synthetic</tt> component.
2343This component may be enabled by force by setting the HWLOC_SYNTHETIC
2344environment variable to something such as
2345<tt>node:2 core:3 pu:4</tt>.
2346
2347Loading a synthetic topology disables binding support since the
2348topology usually does not match the underlying hardware.
2349Binding may be reenabled as usual by setting HWLOC_THISSYSTEM=1 in the
2350environment or by setting the ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM
2351topology flag.
2352
2353
2354\htmlonly
2355</div><div class="section" id="synthetic_export">
2356\endhtmlonly
2357\section synthetic_export Exporting a topology as a synthetic string
2358
2359The function hwloc_topology_export_synthetic() may export
2360a topology as a synthetic string.
2361It offers a convenient way to quickly describe the contents of a machine.
2362The lstopo tool may also perform such an export by forcing the output format.
2363
2364\verbatim
2365$ lstopo --of synthetic --no-io
2366Package:1 L3Cache:1 L2Cache:2 L1dCache:1 L1iCache:1 Core:1 PU:2
2367\endverbatim
2368
2369The exported string may be passed back to hwloc for recreating
2370another similar topology (see also \ref faq_version_synthetic).
2371The entire tree will be similar, but some attributes such as
2372the processor model will be missing.
2373
2374Such an export is only possible if the topology is totally symmetric.
2375It means that the <tt>symmetric_subtree</tt> field of the root object
2376is set.
2377Also memory children should be attached in a symmetric way
2378(e.g. the same number of memory children below each Package object, etc.).
2379However, I/O devices and Misc objects are ignored when looking at
2380symmetry and exporting the string.
2381
2382
2383
2384
2385\page interoperability Interoperability With Other Software
2386
2387\htmlonly
2388<div class="section">
2389\endhtmlonly
2390
2391Although hwloc offers its own portable interface, it still may have to
2392interoperate with specific or non-portable libraries that manipulate
2393similar kinds of objects.  hwloc therefore offers several specific
2394"helpers" to assist converting between those specific interfaces and
2395hwloc.
2396
2397Some external libraries may be specific to a particular OS; others may
2398not always be available.  The hwloc core therefore generally does not
2399explicitly depend on these types of libraries.  However, when a custom
2400application uses or otherwise depends on such a library, it may
2401optionally include the corresponding hwloc helper to extend the hwloc
2402interface with dedicated helpers.
2403
2404Most of these helpers use structures that are specific to these external
2405libraries and only meaningful on the local machine. If so, the helper
2406requires the input topology to match the current machine.
2407Some helpers also require I/O device discovery to be supported and
2408enabled for the current topology.
2409
2410<dl>
2411
2412<dt>Linux specific features</dt>
2413 <dd>
2414  hwloc/linux.h offers Linux-specific helpers that utilize some
2415  non-portable features of the Linux system, such as binding threads
2416  through their thread ID ("tid") or parsing kernel CPU mask files.
2417 </dd>
2418
2419<dt>Linux libnuma</dt>
2420 <dd>
2421  hwloc/linux-libnuma.h provides conversion helpers between hwloc CPU
2422  sets and libnuma-specific types, such as  bitmasks.  It
2423  helps you use libnuma memory-binding functions with hwloc CPU sets.
2424 </dd>
2425
2426<dt>Glibc</dt>
2427 <dd>
2428  hwloc/glibc-sched.h offers conversion routines between Glibc and
2429  hwloc CPU sets in order to use hwloc with functions such as
2430  sched_getaffinity() or pthread_attr_setaffinity_np().
2431 </dd>
2432
2433<dt>OpenFabrics Verbs</dt>
2434 <dd>
2435  hwloc/openfabrics-verbs.h helps interoperability with the
2436  OpenFabrics Verbs interface.  For example, it can return a list of
2437  processors near an OpenFabrics device.
2438  It may also return the corresponding OS device hwloc object for further
2439  information (if I/O device discovery is enabled).
2440 </dd>
2441
2442<dt>OpenCL</dt>
2443 <dd>
2444  hwloc/opencl.h enables interoperability with the OpenCL interface.
2445  Only the AMD and NVIDIA implementations currently offer locality information.
2446  It may return the list of processors near a GPU given as
2447  a <tt>cl_device_id</tt>.
2448  It may also return the corresponding OS device hwloc object for further
2449  information (if I/O device discovery is enabled).
2450 </dd>
2451
2452<dt>AMD ROCm SMI Library (RSMI)</dt>
2453 <dd>
2454  hwloc/rsmi.h enables interoperability with the AMD ROCm SMI interface.
2455  It may return the list of processors near an AMD GPU.
2456  It may also return the corresponding OS device hwloc object for further
2457  information (if I/O device discovery is enabled).
2458 </dd>
2459
2460<dt>NVIDIA CUDA</dt>
2461 <dd>
2462  hwloc/cuda.h and hwloc/cudart.h enable interoperability with
2463  NVIDIA CUDA Driver and Runtime interfaces. For instance, it may
2464  return the list of processors near NVIDIA GPUs.
2465  It may also return the corresponding OS device hwloc object for further
2466  information (if I/O device discovery is enabled).
2467 </dd>
2468
2469<dt>NVIDIA Management Library (NVML)</dt>
2470 <dd>
2471  hwloc/nvml.h enables interoperability with the NVIDIA NVML interface.
2472  It may return the list of processors near a NVIDIA GPU given as
2473  a <tt>nvmlDevice_t</tt>.
2474  It may also return the corresponding OS device hwloc object for further
2475  information (if I/O device discovery is enabled).
2476 </dd>
2477
2478<dt>NVIDIA displays</dt>
2479 <dd>
2480  hwloc/gl.h enables interoperability with NVIDIA displays
2481  using the NV-CONTROL X extension (NVCtrl library).
2482  If I/O device discovery is enabled, it may return the OS device
2483  hwloc object that corresponds to a display
2484  given as a name such as <em>:0.0</em>
2485  or given as a port/device pair (server/screen).
2486 </dd>
2487
2488<dt>Taskset command-line tool</dt>
2489 <dd>
2490  The taskset command-line tool is widely used for binding
2491  processes. It manipulates CPU set strings in a format that
2492  is slightly different from hwloc's one (it does not divide the
2493  string in fixed-size subsets and separates them with commas).
2494  To ease interoperability, hwloc offers routines to convert
2495  hwloc CPU sets from/to taskset-specific string format.
2496  Most hwloc command-line tools also support the <tt>\--taskset</tt>
2497  option to manipulate taskset-specific strings.
2498 </dd>
2499
2500</dl>
2501
2502
2503
2504\page threadsafety Thread Safety
2505
2506\htmlonly
2507<div class="section">
2508\endhtmlonly
2509
2510Like most libraries that mainly fill data structures, hwloc is not
2511thread safe but rather reentrant: all state is held in a
2512::hwloc_topology_t instance without mutex protection.  That means, for
2513example, that two threads can safely operate on and modify two
2514different ::hwloc_topology_t instances, but they should not
2515simultaneously invoke functions that modify the <em>same</em>
2516instance.  Similarly, one thread should not modify a
2517::hwloc_topology_t instance while another thread is reading or
2518traversing it.  However, two threads can safely read or traverse the
2519same ::hwloc_topology_t instance concurrently.
2520
2521When running in multiprocessor environments, be aware that proper thread
2522synchronization and/or memory coherency protection is needed to pass hwloc
2523data (such as ::hwloc_topology_t pointers) from one processor
2524to another (e.g., a mutex, semaphore, or a memory barrier).
2525Note that this is not a hwloc-specific requirement, but it is worth
2526mentioning.
2527
2528For reference, ::hwloc_topology_t modification operations include
2529(but may not be limited to):
2530
2531<dl>
2532
2533<dt>Creation and destruction</dt>
2534  <dd><tt>hwloc_topology_init(), hwloc_topology_load(),
2535  hwloc_topology_destroy()</tt> (see \ref hwlocality_creation) imply
2536  major modifications of the structure, including freeing some
2537  objects.  No other thread cannot access the topology or any of its
2538  objects at the same time.
2539
2540  Also references to objects inside the topology are not valid anymore
2541  after these functions return.  </dd>
2542
2543<dt>Runtime topology modifications</dt>
2544  <dd><tt>hwloc_topology_insert_misc_object()</tt>,
2545  <tt>hwloc_topology_alloc_group_object()</tt>,
2546  and <tt>hwloc_topology_insert_group_object()</tt>
2547  (see \ref hwlocality_tinker) may modify the topology significantly by adding
2548  objects inside the tree, changing the topology depth, etc.
2549
2550  <tt>hwloc_distances_add()</tt> and <tt>hwloc_distances_remove()</tt>
2551  (see \ref hwlocality_distances_add) modify the list of distance structures
2552  in the topology, and the former may even insert new Group objects.
2553
2554  <tt>hwloc_memattr_register()</tt> and <tt>hwloc_memattr_set_value()</tt>
2555  (see \ref hwlocality_memattrs_manage) modify the memory attributes
2556  of the topology.
2557
2558  <tt>hwloc_topology_restrict()</tt> modifies the topology even more
2559  dramatically by removing some objects.
2560
2561  <tt>hwloc_topology_refresh()</tt> updates some internal cached structures.
2562  (see below).
2563
2564  Although references to former objects <em>may</em> still be valid
2565  after insertion or restriction, it is strongly advised to not rely on any such
2566  guarantee and always re-consult the topology to reacquire new
2567  instances of objects.  </dd>
2568
2569<dt>Consulting distances</dt>
2570  <dd>
2571  <tt>hwloc_distances_get()</tt> and its variants are thread-safe
2572  except if the topology was recently modified
2573  (because distances may involve objects that were removed).
2574
2575  Whenever the topology is modified (see above), <tt>hwloc_topology_refresh()</tt>
2576  should be called in the same thread-safe context to force the refresh
2577  of internal distances structures.
2578  A call to <tt>hwloc_distances_get()</tt> may also refresh
2579  distances-related structures.
2580
2581  Once this refresh has been performed, multiple <tt>hwloc_distances_get()</tt>
2582  may then be performed concurrently by multiple threads.
2583  </dd>
2584
2585<dt>Consulting memory attributes</dt>
2586  <dd>
2587  Functions consulting memory attributes in hwloc/memattrs.h
2588  are thread-safe except if the topology was recently modified
2589  (because memory attributes may involve objects that were removed).
2590
2591  Whenever the topology is modified (see above), <tt>hwloc_topology_refresh()</tt>
2592  should be called in the same thread-safe context to force the refresh
2593  of internal memory attribute structures.
2594  A call to <tt>hwloc_memattr_get_value()</tt> or
2595  <tt>hwloc_memattr_get_targets()</tt> may also refresh internal
2596  structures for a given memory attribute.
2597
2598  Once this refresh has been performed, multiple functions consulting
2599  memory attributes may then be performed concurrently by multiple threads.
2600  </dd>
2601
2602<dt>Locating topologies</dt>
2603
2604  <dd><tt>hwloc_topology_set_*</tt>
2605  (see \ref hwlocality_configuration) do not modify the topology
2606  directly, but they do modify internal structures describing the
2607  behavior of the upcoming invocation of <tt>hwloc_topology_load()</tt>.
2608  Hence, all of these functions should not be used concurrently.
2609  </dd>
2610
2611</dl>
2612
2613
2614
2615\page plugins Components and plugins
2616
2617\htmlonly
2618<div class="section">
2619\endhtmlonly
2620
2621hwloc is organized in components that are responsible for discovering
2622objects.
2623Depending on the topology configuration, some components will be used,
2624some will be ignored.
2625The usual default is to enable the native operating system component,
2626(e.g. <tt>linux</tt> or <tt>solaris</tt>) and the
2627<tt>pci</tt> miscellaneous component.
2628If available, an architecture-specific component (such as <tt>x86</tt>)
2629may also improve the topology detection.
2630
2631If a XML topology is loaded, the <tt>xml</tt> discovery  component
2632will be used instead of all other components.
2633It internally uses a specific class of components for the actual XML
2634import/export routines (<tt>xml_libxml</tt> and <tt>xml_nolibxml</tt>)
2635but these will not be discussed here (see \ref xml_backends).
2636
2637
2638\htmlonly
2639</div><div class="section" id="plugins_default">
2640\endhtmlonly
2641\section plugins_default Components enabled by default
2642
2643The hwloc core contains a list of components sorted by priority.
2644Each one is enabled as long as it does not conflict with the
2645previously enabled ones.
2646This includes native operating system components,
2647architecture-specific ones, and if available, I/O components
2648such as <tt>pci</tt>.
2649
2650Usually the native operating system component
2651(when it exists, e.g. <tt>linux</tt> or <tt>aix</tt>)
2652is enabled first.
2653Then hwloc looks for an architecture specific component
2654(e.g. <tt>x86</tt>).
2655Finally there also exist a basic component (<tt>no_os</tt>)
2656that just tries to discover the number of PUs in the system.
2657
2658Each component discovers as much topology information as possible.
2659Most of them, including most native OS components, do nothing
2660unless the topology is still empty.
2661Some others, such as <tt>x86</tt> and <tt>pci</tt>,
2662can complete and annotate what other backends found earlier.
2663Discovery is performed by phases: CPUs are first discovered,
2664then memory is attached, then PCI, etc.
2665
2666Default priorities ensure that clever components are invoked first.
2667Native operating system components have higher priorities,
2668and are therefore invoked first, because they likely offer
2669very detailed topology information.
2670If needed, it will be later extended by architecture-specific
2671information (e.g. from the <tt>x86</tt> component).
2672
2673If any configuration function such as hwloc_topology_set_xml()
2674is used before loading the topology, the corresponding component
2675is enabled first.
2676Then, as usual, hwloc enables any other component (based on
2677priorities) that does not conflict.
2678
2679Certain components that manage a virtual topology, for instance XML
2680topology import or synthetic topology description,
2681conflict with all other components.
2682Therefore, one of them may only be loaded
2683(e.g. with <tt>hwloc_topology_set_xml()</tt>)
2684if no other component is enabled.
2685
2686The environment variable <tt>HWLOC_COMPONENTS_VERBOSE</tt>
2687may be set to get verbose messages about component registration
2688(including their priority) and enabling.
2689
2690
2691\htmlonly
2692</div><div class="section" id="plugins_select">
2693\endhtmlonly
2694\section plugins_select Selecting which components to use
2695
2696If no topology configuration functions such as
2697<tt>hwloc_topology_set_synthetic()</tt> have been called,
2698plugins may be selected with environment variables such as
2699<tt>HWLOC_XMLFILE</tt>, <tt>HWLOC_SYNTHETIC</tt>,
2700<tt>HWLOC_FSROOT</tt>, or <tt>HWLOC_CPUID_PATH</tt> (see \ref envvar).
2701
2702Finally, the environment variable <tt>HWLOC_COMPONENTS</tt>
2703resets the list of selected components.
2704If the variable is set and empty (or set to a single comma separating nothing,
2705since some operating systems do not accept empty variables),
2706the normal plugin priority order is used.
2707
2708If the variable is set to <tt>x86</tt> in this variable will cause
2709the <tt>x86</tt> component to take precedence over any other component,
2710including the native operating system component.
2711It is therefore loaded first, before hwloc tries to load all remaining
2712non-conflicting components.
2713In this case, <tt>x86</tt> would take care of discovering everything
2714it supports, instead of only completing what the native OS information.
2715This may be useful if the native component is buggy on some platforms.
2716
2717It is possible to prevent some components from being loaded by prefixing their
2718name with <tt>-</tt> in the list. For instance <tt>x86,-pci</tt> will load the
2719<tt>x86</tt> component, then let hwloc load all the usual components except
2720<tt>pci</tt>.
2721A single component phase may also be blacklisted, for instance with <tt>-linux:io</tt>.
2722hwloc_topology_set_components() may also be used inside the program
2723to prevent the loading of a specific component (or phases) for the target topology.
2724
2725It is possible to prevent all remaining components from being loaded
2726by placing <tt>stop</tt> in the environment variable.
2727Only the components listed before this keyword will be enabled.
2728
2729
2730\htmlonly
2731</div><div class="section" id="plugins_load">
2732\endhtmlonly
2733\section plugins_load Loading components from plugins
2734
2735Components may optionally be built as plugins so that the hwloc core
2736library does not directly depend on their dependencies (for instance
2737the <tt>libpciaccess</tt> library).
2738Plugin support may be enabled with the <tt>\--enable-plugins</tt>
2739configure option.
2740All components buildable as plugins will then be built as plugins.
2741The configure option may be given a comma-separated list of component
2742names to specify the exact list of components to build as plugins.
2743
2744Plugins are built as independent dynamic libraries that are installed
2745in <tt>$libdir/hwloc</tt>.
2746All plugins found in this directory are loaded during
2747<tt>topology_init()</tt>
2748(unless blacklisted in <tt>HWLOC_PLUGINS_BLACKLIST</tt>, see \ref envvar).
2749A specific list of directories (colon-separated) to scan may be
2750specified in the <tt>HWLOC_PLUGINS_PATH</tt> environment variable.
2751
2752Note that loading a plugin just means that the corresponding component
2753is registered to the hwloc core.
2754Components are then only enabled if the topology configuration
2755requests it, as explained in the previous sections.
2756
2757Also note that plugins should carefully be enabled and used when
2758embedding hwloc in another project, see \ref embed for details.
2759
2760
2761\htmlonly
2762</div><div class="section" id="plugins_list">
2763\endhtmlonly
2764\section plugins_list Existing components and plugins
2765
2766All components distributed within hwloc are listed below.
2767The list of actually available components may be listed
2768at running with the <tt>HWLOC_COMPONENTS_VERBOSE</tt>
2769environment variable (see \ref envvar).
2770
2771<dl>
2772
2773<dt>linux</dt>
2774<dd>
2775 The official component for discovering CPU, memory and I/O devices on Linux.
2776 It discovers PCI devices without the help of external libraries such as libpciaccess,
2777 but requires the pci component for adding vendor/device names to PCI objects.
2778 It also discovers many kinds of Linux-specific OS devices.
2779</dd>
2780<dt>aix, darwin, freebsd, hpux, netbsd, solaris, windows</dt>
2781<dd>
2782 Each officially supported operating system has its own native component,
2783 which is statically built when supported, and which is used by default.
2784</dd>
2785<dt>x86</dt>
2786<dd>
2787 The x86 architecture (either 32 or 64 bits) has its own component
2788 that may complete or replace the previously-found CPU information.
2789 It is statically built when supported.
2790</dd>
2791<dt>bgq</dt>
2792<dd>
2793 This component is specific to IBM BlueGene/Q compute node (running CNK).
2794 It is built and enabled by default when <tt>\--host=powerpc64-bgq-linux</tt>
2795 is passed to configure (see \ref faq_bgq).
2796</dd>
2797<dt>no_os</dt>
2798<dd>
2799 A basic component that just tries to detect the number of processing
2800 units in the system. It mostly serves on operating systems that are
2801 not natively supported.
2802 It is always statically built.
2803</dd>
2804<dt>pci</dt>
2805<dd>
2806 PCI object discovery uses the external pciaccess library (aka libpciaccess);
2807 see \ref iodevices. It may also annotate existing PCI devices with vendor
2808 and device names.
2809 <b>It may be built as a plugin</b>.
2810</dd>
2811<dt>opencl</dt>
2812<dd>
2813 The OpenCL component creates co-processor OS device objects such as
2814 <em>opencl0d0</em> (first device of the first OpenCL platform)
2815 or <em>opencl1d3</em> (fourth device of the second platform).
2816 Only the AMD and NVIDIA OpenCL implementations currently offer locality
2817 information.
2818 <b>It may be built as a plugin</b>.
2819</dd>
2820<dt>rsmi</dt>
2821<dd>
2822 This component creates GPU OS device objects such as
2823 <em>rsmi0</em> for describing AMD GPUs.
2824 <b>It may be built as a plugin</b>.
2825</dd>
2826<dt>cuda</dt>
2827<dd>
2828 This component creates co-processor OS device objects such as <em>cuda0</em>
2829 that correspond to NVIDIA GPUs used with CUDA library.
2830 <b>It may be built as a plugin</b>.
2831</dd>
2832<dt>nvml</dt>
2833<dd>
2834 Probing the NVIDIA Management Library creates OS device objects
2835 such as <em>nvml0</em> that are useful for batch schedulers.
2836 It also detects the actual PCIe link bandwidth without depending
2837 on power management state and without requiring administrator
2838 privileges.
2839 <b>It may be built as a plugin</b>.
2840</dd>
2841<dt>gl</dt>
2842<dd>
2843 Probing the NV-CONTROL X extension (NVCtrl library) creates OS
2844 device objects such as <em>:0.0</em> corresponding to NVIDIA
2845 displays.
2846 They are useful for graphical applications that need to place
2847 computation and/or data near a rendering GPU.
2848 <b>It may be built as a plugin</b>.
2849</dd>
2850<dt>synthetic</dt>
2851<dd>
2852 Synthetic topology support (see \ref synthetic) is always built statically.
2853</dd>
2854<dt>xml</dt>
2855<dd>
2856 XML topology import (see \ref xml) is always built statically.
2857 It internally uses one of the XML backends (see \ref xml_backends).
2858 <ul>
2859 <li><b>xml_nolibxml</b> is a basic and hwloc-specific XML import/export.
2860  It is always statically built.
2861 </li>
2862 <li><b>xml_libxml</b> relies on the external libxml2 library for
2863  provinding a feature-complete XML import/export.
2864  <b>It may be built as a plugin</b>.
2865 </li>
2866</dd>
2867<dt>fake</dt>
2868<dd>
2869 A dummy plugin that does nothing but is used for debugging plugin support.
2870</dd>
2871</dl>
2872
2873
2874
2875
2876\page embed Embedding hwloc in Other Software
2877
2878\htmlonly
2879<div class="section">
2880\endhtmlonly
2881
2882It can be desirable to include hwloc in a larger software package (be
2883sure to check out the LICENSE file) so that users don't have to
2884separately download and install it before installing your software.
2885This can be advantageous to ensure that your software uses a
2886known-tested/good version of hwloc, or for use on systems that do not
2887have hwloc pre-installed.
2888
2889When used in "embedded" mode, hwloc will:
2890
2891- not install any header files
2892- not build any documentation files
2893- not build or install any executables or tests
2894- not build <tt>libhwloc.*</tt> -- instead, it will build
2895  <tt>libhwloc_embedded.*</tt>
2896
2897There are two ways to put hwloc into "embedded" mode.  The first is
2898directly from the configure command line:
2899
2900\verbatim
2901shell$ ./configure --enable-embedded-mode ...
2902\endverbatim
2903
2904The second requires that your software project uses the GNU Autoconf /
2905Automake / Libtool tool chain to build your software.  If you do this,
2906you can directly integrate hwloc's m4 configure macro into your
2907configure script.  You can then invoke hwloc's configuration tests and
2908build setup by calling a m4 macro (see below).
2909
2910Although hwloc dynamic shared object plugins may be used in embedded
2911mode, the embedder project will have to manually setup dlopen or libltdl in its
2912build system so that hwloc can load its plugins at run time.
2913Also, embedders should be aware of complications that can arise due to
2914public and private linker namespaces (e.g., if the embedder project is
2915loaded into a private namespace and then hwloc tries to dynamically
2916load its plugins, such loading may fail since the hwloc plugins can't
2917find the hwloc symbols they need).
2918The embedder project is <b>strongly</b> advised not to use hwloc's
2919dynamically loading plugins / dlopen / libltdl capability.
2920
2921
2922\htmlonly
2923</div><div class="section" id="embedding_m4">
2924\endhtmlonly
2925\section embedding_m4 Using hwloc's M4 Embedding Capabilities
2926
2927Every project is different, and there are many different ways of
2928integrating hwloc into yours.  What follows is <em>one</em> example of
2929how to do it.
2930
2931If your project uses recent versions Autoconf, Automake, and Libtool
2932to build, you can use hwloc's embedded m4 capabilities.  We have
2933tested the embedded m4 with projects that use Autoconf 2.65, Automake
29341.11.1, and Libtool 2.2.6b.  Slightly earlier versions of may also
2935work but are untested.  Autoconf versions prior to 2.65 are almost
2936certain to not work.
2937
2938You can either copy all the config/hwloc*m4 files from the hwloc
2939source tree to the directory where your project's m4 files reside, or
2940you can tell aclocal to find more m4 files in the embedded hwloc's
2941"config" subdirectory (e.g., add "-Ipath/to/embedded/hwloc/config" to
2942your Makefile.am's ACLOCAL_AMFLAGS).
2943
2944The following macros can then be used from your configure script (only
2945HWLOC_SETUP_CORE <em>must</em> be invoked if using the m4 macros):
2946
2947- HWLOC_SETUP_CORE(config-dir-prefix, action-upon-success,
2948  action-upon-failure, print_banner_or_not): Invoke the hwloc
2949  configuration tests and setup the hwloc tree to build.  The first
2950  argument is the prefix to use for AC_OUTPUT files -- it's where the
2951  hwloc tree is located relative to <tt>$top_srcdir</tt>.  Hence, if
2952  your embedded hwloc is located in the source tree at contrib/hwloc,
2953  you should pass <tt>[contrib/hwloc]</tt> as the first argument.  If
2954  HWLOC_SETUP_CORE and the rest of <tt>configure</tt> completes
2955  successfully, then "make" traversals of the hwloc tree with standard
2956  Automake targets (all, clean, install, etc.) should behave as
2957  expected.  For example, it is safe to list the hwloc directory in
2958  the SUBDIRS of a higher-level Makefile.am.  The last argument, if
2959  not empty, will cause the macro to display an announcement banner
2960  that it is starting the hwloc core configuration tests.
2961
2962  HWLOC_SETUP_CORE will set the following environment variables and
2963  AC_SUBST them: HWLOC_EMBEDDED_CFLAGS, HWLOC_EMBEDDED_CPPFLAGS, and
2964  HWLOC_EMBEDDED_LIBS.  These flags are filled with the values
2965  discovered in the hwloc-specific m4 tests, and can be used in your
2966  build process as relevant.  The _CFLAGS, _CPPFLAGS, and _LIBS
2967  variables are necessary to build libhwloc (or libhwloc_embedded)
2968  itself.
2969
2970  HWLOC_SETUP_CORE also sets HWLOC_EMBEDDED_LDADD environment variable
2971  (and AC_SUBSTs it) to contain the location of the
2972  libhwloc_embedded.la convenience Libtool archive.  It can be used in
2973  your build process to link an application or other library against
2974  the embedded hwloc library.
2975
2976  <strong>NOTE: If the HWLOC_SET_SYMBOL_PREFIX macro is used, it must
2977  be invoked <em>before</em> HWLOC_SETUP_CORE.</strong>
2978
2979- HWLOC_BUILD_STANDALONE: HWLOC_SETUP_CORE defaults to building hwloc
2980  in an "embedded" mode (described above).  If HWLOC_BUILD_STANDALONE
2981  is invoked *before* HWLOC_SETUP_CORE, the embedded definitions will
2982  not apply (e.g., libhwloc.la will be built, not
2983  libhwloc_embedded.la).
2984
2985- HWLOC_SET_SYMBOL_PREFIX(foo_): Tells the hwloc to prefix all of
2986  hwloc's types and public symbols with "foo_"; meaning that function
2987  hwloc_init() becomes foo_hwloc_init().  Enum values are prefixed
2988  with an upper-case translation if the prefix supplied;
2989  HWLOC_OBJ_CORE becomes FOO_hwloc_OBJ_CORE.  This is recommended
2990  behavior if you are including hwloc in middleware -- it is possible
2991  that your software will be combined with other software that links
2992  to another copy of hwloc.  If both uses of hwloc utilize different
2993  symbol prefixes, there will be no type/symbol clashes, and
2994  everything will compile, link, and run successfully.  If you both
2995  embed hwloc without changing the symbol prefix and also link against
2996  an external hwloc, you may get multiple symbol definitions when
2997  linking your final library or application.
2998
2999- HWLOC_SETUP_DOCS, HWLOC_SETUP_UTILS, HWLOC_SETUP_TESTS: These three
3000  macros only apply when hwloc is built in "standalone" mode (i.e.,
3001  they should NOT be invoked unless HWLOC_BUILD_STANDALONE has already
3002  been invoked).
3003
3004- HWLOC_DO_AM_CONDITIONALS: If you embed hwloc in a larger project and
3005  build it conditionally with Automake (e.g., if HWLOC_SETUP_CORE is
3006  invoked conditionally), you must unconditionally invoke
3007  HWLOC_DO_AM_CONDITIONALS to avoid warnings from Automake (for the
3008  cases where hwloc is not selected to be built).  This macro is
3009  necessary because hwloc uses some AM_CONDITIONALs to build itself,
3010  and AM_CONDITIONALs cannot be defined conditionally.  Note that it
3011  is safe (but unnecessary) to call HWLOC_DO_AM_CONDITIONALS even if
3012  HWLOC_SETUP_CORE is invoked unconditionally.  If you are not using
3013  Automake to build hwloc, this macro is unnecessary (and will actually
3014  cause errors because it invoked AM_* macros that will be undefined).
3015
3016<strong>NOTE:</strong> When using the HWLOC_SETUP_CORE m4 macro, it may
3017be necessary to explicitly invoke AC_CANONICAL_TARGET (which requires
3018config.sub and config.guess) and/or AC_USE_SYSTEM_EXTENSIONS macros
3019early in the configure script (e.g., after AC_INIT but before
3020AM_INIT_AUTOMAKE).  See the Autoconf documentation for further
3021information.
3022
3023Also note that hwloc's top-level configure.ac script uses exactly the
3024macros described above to build hwloc in a standalone mode (by
3025default).  You may want to examine it for one example of how these
3026macros are used.
3027
3028
3029\htmlonly
3030</div><div class="section" id="embedding_example">
3031\endhtmlonly
3032\section embedding_example Example Embedding hwloc
3033
3034Here's an example of integrating with a larger project named sandbox
3035that already uses Autoconf, Automake, and Libtool to build itself:
3036
3037\verbatim
3038# First, cd into the sandbox project source tree
3039shell$ cd sandbox
3040shell$ cp -r /somewhere/else/hwloc-<version> my-embedded-hwloc
3041shell$ edit Makefile.am
3042  1. Add "-Imy-embedded-hwloc/config" to ACLOCAL_AMFLAGS
3043  2. Add "my-embedded-hwloc" to SUBDIRS
3044  3. Add "$(HWLOC_EMBEDDED_LDADD)" and "$(HWLOC_EMBEDDED_LIBS)" to
3045     sandbox's executable's LDADD line.  The former is the name of the
3046     Libtool convenience library that hwloc will generate.  The latter
3047     is any dependent support libraries that may be needed by
3048     $(HWLOC_EMBEDDED_LDADD).
3049  4. Add "$(HWLOC_EMBEDDED_CFLAGS)" to AM_CFLAGS
3050  5. Add "$(HWLOC_EMBEDDED_CPPFLAGS)" to AM_CPPFLAGS
3051shell$ edit configure.ac
3052  1. Add "HWLOC_SET_SYMBOL_PREFIX(sandbox_hwloc_)" line
3053  2. Add "HWLOC_SETUP_CORE([my-embedded-hwloc], [happy=yes], [happy=no])" line
3054  3. Add error checking for happy=no case
3055shell$ edit sandbox.c
3056  1. Add #include <hwloc.h>
3057  2. Add calls to sandbox_hwloc_init() and other hwloc API functions
3058\endverbatim
3059
3060Now you can bootstrap, configure, build, and run the sandbox as normal
3061-- all calls to "sandbox_hwloc_*" will use the embedded hwloc rather
3062than any system-provided copy of hwloc.
3063
3064
3065
3066
3067
3068
3069\page faq Frequently Asked Questions
3070
3071
3072\htmlonly
3073<div class="section" id="faq1">
3074\endhtmlonly
3075\section faq1 Concepts
3076
3077
3078\subsection faq_why I only need binding, why should I use hwloc ?
3079
3080hwloc is its portable API that works on a variety of operating
3081systems.
3082It supports binding of threads, processes and memory buffers
3083(see \ref hwlocality_cpubinding and \ref hwlocality_membinding).
3084Even if some features are not supported on some systems,
3085using hwloc is much easier than reimplementing your own portability layer.
3086
3087Moreover, hwloc provides knowledge of cores and hardware threads.
3088It offers easy ways to bind tasks to individual hardware threads,
3089or to entire multithreaded cores, etc.
3090See \ref faq_smt.
3091Most alternative software for binding do not even know whether each
3092core is single-threaded, multithreaded or hyper-threaded.
3093They would bind to individual threads without any way to know whether
3094multiple tasks are in the same physical core.
3095
3096However, using hwloc comes with an overhead since a topology must
3097be loaded before gathering information and binding tasks or memory.
3098Fortunately this overhead may be significantly reduced by filtering
3099non-interesting information out of the topology.
3100For instance the following code builds a topology that only contains
3101Cores (explicitly filtered-in below),
3102hardware threads (PUs, cannot be filtered-out),
3103NUMA nodes (cannot be filtered-out),
3104and the root object (usually a Machine; the root cannot be removed without breaking the tree).
3105
3106\verbatim
3107hwloc_topology_t topology;
3108hwloc_topology_init(&topology);
3109/* filter everything out */
3110hwloc_topology_set_all_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_NONE);
3111/* filter Cores back in */
3112hwloc_topology_set_type_filter(topology, HWLOC_OBJ_CORE, HWLOC_TYPE_FILTER_KEEP_ALL);
3113hwloc_topology_load(topology);
3114\endverbatim
3115
3116However, one should remember that filtering such objects out removes
3117locality information from the hwloc tree.
3118For instance, we do not know anymore which PU is close to which NUMA
3119node.
3120This would be useful to applications that explicitly want to
3121place specific memory buffers close to specific tasks.
3122Those applications just need to tell hwloc to keep Group objects that
3123bring structure information:
3124\verbatim
3125hwloc_topology_set_type_filter(topology, HWLOC_OBJ_GROUP, HWLOC_TYPE_FILTER_KEEP_STRUCTURE);
3126\endverbatim
3127
3128Note that the default configuration is to keep all objects enabled,
3129except I/Os and instruction caches.
3130
3131
3132\subsection faq_indexes Should I use logical or physical/OS indexes? and how?
3133
3134One of the original reasons why hwloc was created is that <b>physical/OS indexes</b>
3135(<tt>obj->os_index</tt>) are often crazy and unpredictable:
3136processors numbers are usually
3137non-contiguous (processors 0 and 1 are not physically close), they vary from
3138one machine to another, and may even change after a BIOS or system update.
3139This numbers make task placement hardly portable.
3140Moreover some objects have no physical/OS numbers (caches), and some objects
3141have non-unique numbers (core numbers are only unique within a socket).
3142Physical/OS indexes are only guaranteed to exist and be unique for PU
3143and NUMA nodes.
3144
3145hwloc therefore introduces <b>logical indexes</b> (<tt>obj->logical_index</tt>)
3146which are portable, contiguous and logically ordered
3147(based on the resource organization in the locality tree).
3148In general, one should only use logical indexes and just let hwloc do the
3149internal conversion when really needed (when talking to the OS and hardware).
3150
3151hwloc developers recommends that users do not use physical/OS indexes
3152unless they really know what they are doing.
3153The main reason for still using physical/OS indexes is when interacting with
3154non-hwloc tools such as numactl or taskset, or when reading hardware information
3155from raw sources such as /proc/cpuinfo.
3156
3157lstopo options <tt>-l</tt> and <tt>-p</tt> may be used to switch between
3158logical indexes (prefixed with <tt>L#</tt>) and physical/OS indexes (<tt>P#</tt>).
3159Converting one into the other may also be achieved with hwloc-calc which may
3160manipulate either logical or physical indexes as input or output.
3161See also \ref cli_hwloc_calc.
3162
3163\verbatim
3164# Convert PU with physical number 3 into logical number
3165$ hwloc-calc -I pu --physical-input --logical-output pu:3
31665
3167
3168# Convert a set of NUMA nodes from logical to physical
3169# (beware that the output order may not match the input order)
3170$ hwloc-calc -I numa --logical-input --physical-output numa:2-3 numa:7
31710,2,5
3172\endverbatim
3173
3174
3175\subsection faq_structural hwloc is only a structural model, it ignores performance models, memory bandwidth, etc.?
3176
3177hwloc is indeed designed to provide applications with a structural model
3178of the platform. This is an orthogonal approach to describing the
3179machine with performance models, for instance using memory bandwidth
3180or latencies measured by benchmarks.
3181We believe that both approaches are important for helping application
3182make the most of the hardware.
3183
3184For instance, on a dual-processor host with four cores each, hwloc
3185clearly shows which four cores are together.
3186Latencies between all pairs of cores of the same processor are likely
3187identical, and also likely lower than the latency between cores of
3188different processors.
3189However, the structural model cannot guarantee such implementation
3190details.
3191On the other side, performance models would reveal such details
3192without always clearly identifying which cores are in the same
3193processor.
3194
3195The focus of hwloc is mainly of the structural modeling side.
3196However, hwloc lets user adds performance information to the topology
3197through distances
3198(see \ref topoattrs_distances),
3199memory attributes
3200(see \ref topoattrs_memattrs)
3201or even custom annotations (see \ref faq_annotate).
3202hwloc may also use such distance information for grouping objects
3203together (see \ref faq_onedim and \ref faq_groups).
3204
3205
3206\subsection faq_onedim hwloc only has a one-dimensional view of the architecture, it ignores distances?
3207
3208hwloc places all objects in a tree. Each level is a one-dimensional
3209view of a set of similar objects. All children of the same object (siblings)
3210are assumed to be equally interconnected (same distance between any of them),
3211while the distance between children of different objects (cousins) is supposed
3212to be larger.
3213
3214Modern machines exhibit complex hardware interconnects, so this tree
3215may miss some information about the actual physical distances between objects.
3216The hwloc topology may therefore be annotated with distance information that
3217may be used to build a more realistic representation (multi-dimensional)
3218of each level.
3219For instance, there can be a distance matrix that representing the latencies
3220between any pair of NUMA nodes if the BIOS and/or operating system reports them.
3221
3222For more information about the hwloc distances, see \ref topoattrs_distances.
3223
3224
3225\subsection faq_groups What are these Group objects in my topology?
3226
3227hwloc comes with a set of predefined object types (Core, Package, NUMA node, Caches)
3228that match the vast majority of hardware platforms.
3229The ::HWLOC_OBJ_GROUP type was designed for cases where this set is not sufficient.
3230Groups may be used anywhere to add more structure information to the topology,
3231for instance to show that 2 out of 4 NUMA nodes are actually closer than the others.
3232When applicable, the <tt>subtype</tt> field describes why a Group
3233was actually added (see also \ref attributes_normal).
3234
3235hwloc currently uses Groups for the following reasons:
3236<ul>
3237<li>NUMA parents when memory locality does not match any existing object.</li>
3238<li>I/O parents when I/O locality does not match any existing object.</li>
3239<li>Distance-based groups made of close objects.</li>
3240<li>AMD Bulldozer dual-core compute units (<tt>subtype</tt> is <tt>ComputeUnit</tt>, in the x86 backend),
3241 but these objects are usually merged with the L2 caches.</li>
3242<li>Intel Extended Topology Enumeration levels (in the x86 backend).</li>
3243<li>Windows processor groups (unless they contain a single NUMA node, or a single Package, etc.).</li>
3244<li>IBM S/390 "Books" on Linux (<tt>subtype</tt> is <tt>Book</tt>).</li>
3245<li>AIX unknown hierarchy levels.</li>
3246</ul>
3247
3248hwloc Groups are only kept if no other object has the same
3249locality information.
3250It means that a Group containing a single child is merged
3251into that child.
3252And a Group is merged into its parent if it is its only child.
3253For instance a Windows processor group containing a single NUMA node
3254would be merged with that NUMA node since it already contains the
3255relevant hierarchy information.
3256
3257When inserting a custom Group with hwloc_hwloc_topology_insert_group_object(),
3258this merging may be disabled by setting its <tt>dont_merge</tt> attribute.
3259
3260
3261\subsection faq_asymmetric What happens if my topology is asymmetric?
3262
3263hwloc supports asymmetric topologies even if most platforms are usually
3264symmetric. For example, there could be different types of processors
3265in a single machine, each with different numbers of cores, symmetric
3266multithreading, or levels of caches.
3267
3268In practice, asymmetric topologies mostly appear when intermediate groups
3269are added for I/O affinity: on a 4-package machine, an I/O bus may be
3270connected to 2 packages. These packages are below an additional Group
3271object, while the other packages are not (see also \ref faq_groups).
3272
3273To understand how hwloc manages such cases, one should first remember
3274the meaning of levels and cousin objects. All objects of the same type
3275are gathered as horizontal levels with a given depth. They are also
3276connected through the cousin pointers of the ::hwloc_obj structure.
3277Object attribute (cache depth and type, group depth) are also taken
3278in account when gathering objects as horizontal levels.
3279To be clear: there will be one level for L1i
3280caches, another level for L1d caches, another one for L2, etc.
3281
3282If the topology is asymmetric (e.g., if a group is missing above some
3283processors), a given horizontal level will still exist if there
3284exist any objects of that type.  However, some branches of the overall
3285tree may not have an object located in that horizontal level.  Note
3286that this specific hole within one horizontal level does not imply
3287anything for other levels.  All objects of the same type are gathered
3288in horizontal levels even if their parents or children have different
3289depths and types.
3290
3291See the diagram in \ref termsanddefs for a graphical representation
3292of such topologies.
3293
3294Moreover, it is important to understand that a same parent object may
3295have children of different types (and therefore, different
3296depths). <strong>These children are therefore siblings (because they
3297have the same parent), but they are <em>not</em> cousins (because they
3298do not belong to the same horizontal level).</strong>
3299
3300
3301\subsection faq_nosmt What happens to my topology if I disable symmetric multithreading, hyper-threading, etc. in the system?
3302
3303hwloc creates one PU (processing unit) object per hardware thread.
3304If your machine supports symmetric multithreading, for instance Hyper-Threading,
3305each Core object may contain multiple PU objects:
3306\verbatim
3307$ lstopo -
3308...
3309  Core L#0
3310    PU L#0 (P#0)
3311    PU L#1 (P#2)
3312  Core L#1
3313    PU L#2 (P#1)
3314    PU L#3 (P#3)
3315\endverbatim
3316
3317x86 machines usually offer the ability to disable hyper-threading in the BIOS.
3318Or it can be disabled on the Linux kernel command-line at boot time,
3319or later by writing in sysfs virtual files.
3320
3321If you do so, the hwloc topology structure does not significantly change,
3322but some PU objects will not appear anymore.
3323No level will disappear, you will see the same number of Core objects,
3324but each of them will contain a single PU now.
3325The PU level does not disappear either
3326(remember that hwloc topologies always contain a PU level at the bottom of the topology)
3327even if there is a single PU object per Core parent.
3328\verbatim
3329$ lstopo -
3330...
3331  Core L#0
3332    PU L#0 (P#0)
3333  Core L#1
3334    PU L#1 (P#1)
3335\endverbatim
3336
3337
3338\subsection faq_smt How may I ignore symmetric multithreading, hyper-threading, etc. in hwloc?
3339
3340First, see \ref faq_nosmt for more information about multithreading.
3341
3342If you need to ignore symmetric multithreading in software,
3343you should likely manipulate hwloc Core objects directly:
3344\verbatim
3345/* get the number of cores */
3346unsigned nbcores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
3347...
3348/* get the third core below the first package */
3349hwloc_obj_t package, core;
3350package = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 0);
3351core = hwloc_get_obj_inside_cpuset_by_type(topology, package->cpuset,
3352                                           HWLOC_OBJ_CORE, 2);
3353\endverbatim
3354
3355Whenever you want to bind a process or thread to a core, make sure you
3356singlify its cpuset first, so that the task is actually bound to a single
3357thread within this core (to avoid useless migrations).
3358\verbatim
3359/* bind on the second core */
3360hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, 1);
3361hwloc_cpuset_t set = hwloc_bitmap_dup(core->cpuset);
3362hwloc_bitmap_singlify(set);
3363hwloc_set_cpubind(topology, set, 0);
3364hwloc_bitmap_free(set);
3365\endverbatim
3366
3367With hwloc-calc or hwloc-bind command-line tools, you may specify that
3368you only want a single-thread within each core by asking for their first
3369PU object:
3370\verbatim
3371$ hwloc-calc core:4-7
33720x0000ff00
3373$ hwloc-calc core:4-7.pu:0
33740x00005500
3375\endverbatim
3376
3377When binding a process on the command-line, you may either specify
3378the exact thread that you want to use, or ask hwloc-bind to singlify
3379the cpuset before binding
3380\verbatim
3381$ hwloc-bind core:3.pu:0 -- echo "hello from first thread on core #3"
3382hello from first thread on core #3
3383...
3384$ hwloc-bind core:3 --single -- echo "hello from a single thread on core #3"
3385hello from a single thread on core #3
3386\endverbatim
3387
3388
3389
3390\htmlonly
3391</div><div class="section" id="faq2">
3392\endhtmlonly
3393\section faq2 Advanced
3394
3395
3396
3397\subsection faq_xml I do not want hwloc to rediscover my enormous machine topology every time I rerun a process
3398
3399Although the topology discovery is not expensive on common machines,
3400its overhead may become significant when multiple processes repeat
3401the discovery on large machines (for instance when starting one process
3402per core in a parallel application).
3403The machine topology usually does not vary much, except if some cores
3404are stopped/restarted or if the administrator restrictions are modified.
3405Thus rediscovering the whole topology again and again may look useless.
3406
3407For this purpose, hwloc offers XML import/export and shared memory features.
3408
3409XML lets you
3410save the discovered topology to a file (for instance with the lstopo program)
3411and reload it later by setting the HWLOC_XMLFILE environment variable.
3412The HWLOC_THISSYSTEM environment variable should also be set to 1 to
3413assert that loaded file is really the underlying system.
3414
3415Loading a XML topology is usually much faster than querying multiple
3416files or calling multiple functions of the operating system.
3417It is also possible to manipulate such XML files with the C programming
3418interface, and the import/export may also be directed to memory buffer
3419(that may for instance be transmitted between applications through a package).
3420See also \ref xml.
3421
3422\note The environment variable HWLOC_THISSYSTEM_ALLOWED_RESOURCES
3423may be used to load a XML topology that contains the entire machine
3424and restrict it to the part that is actually available to the current
3425process (e.g. when Linux Cgroup/Cpuset are used to restrict the set
3426of resources). See \ref envvar.
3427
3428Shared-memory topologies consist in one process exposing its topology
3429in a shared-memory buffer so that other processes (running on the same machine)
3430may use it directly.
3431This has the advantage of reducing the memory footprint since a single
3432topology is stored in physical memory for multiple processes.
3433However, it requires all processes to map this shared-memory buffer
3434at the same virtual address, which may be difficult in some cases.
3435This API is described in \ref hwlocality_shmem.
3436
3437
3438\subsection faq_multitopo How many topologies may I use in my program?
3439
3440hwloc lets you manipulate multiple topologies at the same time.
3441However, these topologies consume memory and system resources
3442(for instance file descriptors) until they are destroyed.
3443It is therefore discouraged to open the same topology multiple
3444times.
3445
3446Sharing a single topology between threads is easy (see \ref threadsafety)
3447since the vast majority of accesses are read-only.
3448
3449If multiple topologies of different (but similar) nodes are needed
3450in your program, have a look at \ref faq_diff.
3451
3452
3453\subsection faq_diff How to avoid memory waste when manipulating multiple similar topologies?
3454
3455hwloc does not share information between topologies.
3456If multiple similar topologies are loaded in memory, for instance
3457the topologies of different identical nodes of a cluster,
3458lots of information will be duplicated.
3459
3460hwloc/diff.h (see also \ref hwlocality_diff) offers the ability to
3461compute topology differences, apply or unapply them, or export/import
3462to/from XML.
3463However, this feature is limited to basic differences such as attribute changes.
3464It does not support complex modifications such as adding or removing some objects.
3465
3466
3467\subsection faq_annotate How do I annotate the topology with private notes?
3468
3469Each hwloc object contains a <tt>userdata</tt> field that may be used by
3470applications to store private pointers. This field is only valid
3471during the lifetime of these container object and topology.
3472It becomes invalid as soon the topology is destroyed,
3473or as soon as the object disappears, for instance when restricting
3474the topology.
3475The userdata field is not exported/imported to/from XML by default since
3476hwloc does not know what it contains.
3477This behavior may be changed by specifying application-specific callbacks
3478with <tt>hwloc_topology_set_userdata_export_callback()</tt>
3479and <tt>hwloc_topology_set_userdata_import_callback()</tt>.
3480
3481Each object may also contain some <em>info</em> attributes
3482(key name and value) that are setup by hwloc during discovery
3483and that may be extended by the user with
3484<tt>hwloc_obj_add_info()</tt> (see also \ref attributes).
3485Contrary to the <tt>userdata</tt> field which is unique, multiple info
3486attributes may exist for each object, even with the same name.
3487These attributes are always exported to XML.
3488However, only character strings may be used as key names and values.
3489
3490It is also possible to insert Misc objects with a custom name
3491anywhere as a leaf of the topology (see \ref miscobjs).
3492And Misc objects may have their own userdata and info attributes
3493just like any other object.
3494
3495The hwloc-annotate command-line tool may be used for adding
3496Misc objects and info attributes.
3497
3498There is also a topology-specific userdata pointer that can be used
3499to recognize different topologies by storing a custom pointer.
3500It may be manipulated with <tt>hwloc_topology_set_userdata()</tt>
3501and <tt>hwloc_topology_get_userdata()</tt>.
3502
3503
3504
3505\htmlonly
3506</div><div class="section" id="faq3">
3507\endhtmlonly
3508\section faq3 Caveats
3509
3510
3511
3512\subsection faq_slow_lstopo Why is hwloc slow?
3513
3514Building a hwloc topology on a large machine may be slow because
3515the discovery of hundreds of hardware cores or threads takes time
3516(especially when reading thousands of sysfs files on Linux).
3517Ignoring some objects (for instance caches) that aren't useful
3518to the current application may improve this overhead (see \ref faq_why).
3519One should also consider using XML (see \ref faq_xml) to work
3520around such issues.
3521
3522Additionally, lstopo enables most hwloc objects and discovery flags
3523by default so that the output topology is as precise as possible
3524(while hwloc disables many of them by default).
3525This includes I/O device discovery through PCI libraries as well as external
3526libraries such as NVML.
3527To speed up lstopo, you may disable such features with command-line
3528options such as <tt>\--no-io</tt>.
3529
3530When NVIDIA GPU probing is enabled with CUDA or NVML, one should make sure that
3531the <em>Persistent</em> mode is enabled (with <tt>nvidia-smi -pm 1</tt>)
3532to avoid significant GPU initialization overhead.
3533
3534When AMD GPU discovery is enabled with OpenCL and hwloc is used remotely
3535over ssh, some spurious round-trips on the network may significantly
3536increase the discovery time.
3537Forcing the <tt>DISPLAY</tt> environment variable to the remote X server
3538display (usually <tt>:0</tt>) instead of only setting the <tt>COMPUTE</tt>
3539variable may avoid this.
3540
3541Also remember that these components may be disabled at build-time with
3542configure flags such as <tt>\--disable-opencl</tt>, <tt>\--disable-cuda</tt> or <tt>\--disable-nvml</tt>,
3543and at runtime with the environment variable
3544<tt>HWLOC_COMPONENTS=-opencl,-cuda,-nvml</tt>
3545or with hwloc_topology_set_components().
3546
3547
3548\subsection faq_privileged Does hwloc require privileged access?
3549
3550hwloc discovers the topology by querying the operating system.
3551Some minor features may require privileged access to the operation
3552system.
3553For instance memory module discovery on Linux is reserved to root,
3554and the entire PCI discovery on Solaris and BSDs requires access to
3555some special files that are usually restricted to root
3556(/dev/pci* or /devices/pci*).
3557
3558To workaround this limitation, it is recommended to export the
3559topology as a XML file generated by the administrator (with the
3560lstopo program) and make it available to all users
3561(see \ref xml).
3562It will offer all discovery information to any application without
3563requiring any privileged access anymore.
3564Only the necessary hardware characteristics will be exported, no
3565sensitive information will be disclosed through this XML export.
3566
3567This XML-based model also has the advantage of speeding up the
3568discovery because reading a XML topology is usually much faster
3569than querying the operating system again.
3570
3571The utility <tt>hwloc-dump-hwdata</tt> is also involved in gathering
3572privileged information at boot time and making it available to
3573non-privileged users (note that this may require a specific SELinux
3574MLS policy module). However, it only applies to Intel Xeon Phi processors
3575for now (see \ref faq_knl_dump).
3576See also <tt>HWLOC_DUMPED_HWDATA_DIR</tt> in \ref envvar for details
3577about the location of dumped files.
3578
3579
3580\subsection faq_os_error What should I do when hwloc reports "operating system" warnings?
3581
3582When the operating system reports invalid locality information (because
3583of either software or hardware bugs), hwloc may fail to insert some objects
3584in the topology because they cannot fit in the already built tree of resources.
3585If so, hwloc will report a warning like the following.
3586The object causing this error is ignored, the discovery continues but the
3587resulting topology will miss some objects and may be asymmetric
3588(see also \ref faq_asymmetric).
3589
3590\verbatim
3591****************************************************************************
3592* hwloc received invalid information from the operating system.
3593*
3594* L3 (cpuset 0x000003f0) intersects with NUMANode (P#0 cpuset 0x0000003f) without inclusion!
3595* Error occurred in topology.c line 940
3596*
3597* Please report this error message to the hwloc user's mailing list,
3598* along with the files generated by the hwloc-gather-topology script.
3599*
3600* hwloc will now ignore this invalid topology information and continue.
3601****************************************************************************
3602\endverbatim
3603
3604These errors are common on large AMD platforms because of BIOS and/or Linux
3605kernel bugs causing invalid L3 cache information.
3606In the above example, the hardware reports
3607a L3 cache that is shared by 2 cores in the first NUMA node and 4 cores
3608in the second NUMA node. That's wrong, it should actually be shared by all 6
3609cores in a single NUMA node.
3610The resulting topology will miss some L3 caches.
3611
3612If your application does not care about cache sharing, or if you do not plan to
3613request cache-aware binding in your process launcher, you may likely ignore
3614this error (and hide it by setting HWLOC_HIDE_ERRORS=1 in your environment).
3615
3616Some platforms report similar warnings about conflicting Packages and NUMANodes.
3617
3618On x86 hosts, passing <tt>HWLOC_COMPONENTS=x86</tt> in the environment may
3619workaround some of these issues by switching to a different way to discover the topology.
3620
3621Upgrading the BIOS and/or the operating system may help.
3622Otherwise, as explained in the message, reporting this issue to the hwloc developers
3623(by sending the tarball that is generated by the hwloc-gather-topology script
3624 on this platform) is a good way to make sure that this is a software
3625(operating system) or hardware bug (BIOS, etc).
3626
3627See also \ref bugs. Opening an issue on GitHub automatically displays hints
3628on what information you should provide when reporting such bugs.
3629
3630
3631\subsection faq_valgrind Why does Valgrind complain about hwloc memory leaks?
3632
3633If you are debugging your application with Valgrind, you want to
3634avoid memory leak reports that are caused by hwloc and not by your
3635program.
3636
3637hwloc itself is often checked with Valgrind to make sure it does
3638not leak memory.
3639However, some global variables in hwloc dependencies are never freed.
3640For instance libz allocates its global state once at startup and
3641never frees it so that it may be reused later.
3642Some libxml2 global state is also never freed because hwloc does not
3643know whether it can safely ask libxml2 to free it (the application may
3644also be using libxml2 outside of hwloc).
3645
3646These unfreed variables cause leak reports in Valgrind.
3647hwloc installs a Valgrind <em>suppressions</em> file to hide them.
3648You should pass the following command-line option to Valgrind to use it:
3649\verbatim
3650  --suppressions=/path/to/hwloc-valgrind.supp
3651\endverbatim
3652
3653
3654
3655
3656\htmlonly
3657</div><div class="section" id="faq4">
3658\endhtmlonly
3659\section faq4 Platform-specific
3660
3661
3662\subsection faq_knl_numa How do I find the local MCDRAM NUMA node on Intel Xeon Phi processor?
3663
3664Intel Xeon Phi processors introduced a new memory architecture by
3665possibly having two distinct local memories:
3666some normal memory (DDR) and some high-bandwidth on-package memory (MCDRAM).
3667Processors can be configured in various clustering modes to have up to 4 <em>Clusters</em>.
3668Moreover, each <em>Cluster</em> (quarter, half or whole processor) of the processor may have its own local
3669parts of the DDR and of the MCDRAM.
3670This memory and clustering configuration may be probed by looking at MemoryMode
3671and ClusterMode attributes, see \ref attributes_info_platform and doc/examples/get-knl-modes.c
3672in the source directory.
3673
3674Starting with version 2.0, hwloc properly exposes this memory
3675configuration.
3676DDR and MCDRAM are attached as two memory children of the same parent,
3677DDR first, and MCDRAM second if any.
3678Depending on the processor configuration, that parent may be a Package,
3679a Cache, or a Group object of type <tt>Cluster</tt>.
3680
3681Hence cores may have one or two local NUMA nodes, listed by the core nodeset.
3682An application may allocate local memory from a core by using that nodeset.
3683The operating system will actually allocate from the DDR when
3684possible, or fallback to the MCDRAM.
3685
3686To allocate specifically on one of these memories,
3687one should walk up the parent pointers until finding an object with
3688some memory children.
3689Looking at these memory children will give the DDR first,
3690then the MCDRAM if any.
3691Their nodeset may then be used for allocating or binding memory buffers.
3692
3693One may also traverse the list of NUMA nodes until finding some whose
3694cpuset matches the target core or PUs.
3695The MCDRAM NUMA nodes may be identified thanks to the <tt>subtype</tt> field
3696which is set to <tt>MCDRAM</tt>.
3697
3698Command-line tools such as <tt>hwloc-bind</tt> may bind memory on the MCDRAM by
3699using the <i>hbm</i> keyword. For instance, to bind on the first MCDRAM NUMA node:
3700
3701\verbatim
3702$ hwloc-bind --membind --hbm numa:0 -- myprogram
3703$ hwloc-bind --membind numa:0 -- myprogram
3704\endverbatim
3705
3706
3707\subsection faq_knl_dump Why do I need hwloc-dump-hwdata for memory on Intel Xeon Phi processor?
3708
3709Intel Xeon Phi processors may use the on-package memory (MCDRAM)
3710as either memory or a memory-side cache
3711(reported as a L3 cache by hwloc by default,
3712see <tt>HWLOC_KNL_MSCACHE_L3</tt> in \ref envvar).
3713There are also several clustering modes that significantly affect the memory organization
3714(see \ref faq_knl_numa for more information about these modes).
3715Details about these are currently only available to privileged users.
3716Without them, hwloc relies on a heuristic for guessing the modes.
3717
3718The hwloc-dump-hwdata utility may be used to dump this privileged binary information
3719into human-readable and world-accessible files that the hwloc library will later load.
3720The utility should usually run as root once during boot, in order to update dumped
3721information (stored under /var/run/hwloc by default) in case the MCDRAM or clustering configuration
3722changed between reboots.
3723
3724When SELinux MLS policy is enabled, a specific hwloc policy module may be required
3725so that all users get access to the dumped files (in /var/run/hwloc by default).
3726One may use hwloc policy files from the SELinux Reference Policy at
3727https://github.com/TresysTechnology/refpolicy-contrib
3728(see also the documentation at https://github.com/TresysTechnology/refpolicy/wiki/GettingStarted).
3729
3730hwloc-dump-hwdata requires <tt>dmi-sysfs</tt> kernel module loaded.
3731
3732The utility is currently unneeded on platforms without Intel Xeon Phi processors.
3733
3734See <tt>HWLOC_DUMPED_HWDATA_DIR</tt> in \ref envvar for details
3735about the location of dumped files.
3736
3737
3738\subsection faq_bgq How do I build hwloc for BlueGene/Q?
3739
3740IBM BlueGene/Q machines run a standard Linux on the login/frontend nodes
3741and a custom CNK (<em>Compute Node Kernel</em>) on the compute nodes.
3742
3743To discover the topology of a login/frontend node, hwloc should be
3744configured as usual, without any BlueGene/Q-specific option.
3745
3746However, one would likely rather discover the topology of the compute nodes
3747where parallel jobs are actually running.
3748If so, hwloc must be cross-compiled with the following configuration line:
3749\verbatim
3750./configure --host=powerpc64-bgq-linux --disable-shared --enable-static \
3751  CPPFLAGS='-I/bgsys/drivers/ppcfloor -I/bgsys/drivers/ppcfloor/spi/include/kernel/cnk/'
3752\endverbatim
3753
3754CPPFLAGS may have to be updated if your platform headers are installed
3755in a different directory.
3756
3757
3758\subsection faq_windows How do I build hwloc for Windows?
3759
3760hwloc releases are available as pre-built ZIPs for Windows on both 32bits and
376164bits x86 platforms.
3762They are built using MSYS2 and MinGW on a Windows host.
3763Such an environment allows using the Unix-like <tt>configure</tt>, <tt>make</tt>
3764and <tt>make install</tt> steps without having to tweak too many variables or options.
3765One may look at <tt>contrib/ci.inria.fr/job-3-mingw.sh</tt> in the hwloc
3766repository for an example used for nightly testing.
3767
3768hwloc releases also contain a basic Microsoft Visual Studio solution
3769under <tt>contrib/windows/</tt>.
3770
3771
3772\subsection faq_netbsd_bind How to get useful topology information on NetBSD?
3773
3774The NetBSD (and FreeBSD) backend uses x86-specific topology discovery
3775(through the x86 component).
3776This implementation requires CPU binding so as to query topology
3777information from each individual processor.
3778This means that hwloc cannot find any useful topology information
3779unless user-level process binding is allowed by the NetBSD kernel.
3780The <tt>security.models.extensions.user_set_cpu_affinity</tt>
3781sysctl variable must be set to 1 to do so.
3782Otherwise, only the number of processors will be detected.
3783
3784
3785\subsection faq_aix_bind Why does binding fail on AIX?
3786
3787The AIX operating system requires specific user capabilities for
3788attaching processes to resource sets (CAP_NUMA_ATTACH).
3789Otherwise functions such as hwloc_set_cpubind() fail (return -1 with errno set to EPERM).
3790
3791This capability must also be inherited (through the additional CAP_PROPAGATE capability)
3792if you plan to bind a process before forking another process,
3793for instance with <tt>hwloc-bind</tt>.
3794
3795These capabilities may be given by the administrator with:
3796\verbatim
3797chuser "capabilities=CAP_PROPAGATE,CAP_NUMA_ATTACH" <username>
3798\endverbatim
3799
3800
3801\htmlonly
3802</div><div class="section" id="faq5">
3803\endhtmlonly
3804\section faq5 Compatibility between hwloc versions
3805
3806\subsection faq_version_api How do I handle API changes?
3807
3808The hwloc interface is extended with every new major release.
3809Any application using the hwloc API should be prepared to check at
3810compile-time whether some features are available in the currently
3811installed hwloc distribution.
3812
3813For instance, to check whether the hwloc version is at least 2.0, you should use:
3814\verbatim
3815#include <hwloc.h>
3816#if HWLOC_API_VERSION >= 0x00020000
3817...
3818#endif
3819\endverbatim
3820
3821To check for the API of release X.Y.Z at build time,
3822you may compare ::HWLOC_API_VERSION with <tt>(X<<16)+(Y<<8)+Z</tt>.
3823
3824For supporting older releases that do not have <tt>HWLOC_OBJ_NUMANODE</tt>
3825and <tt>HWLOC_OBJ_PACKAGE</tt> yet, you may use:
3826
3827\verbatim
3828#include <hwloc.h>
3829#if HWLOC_API_VERSION < 0x00010b00
3830#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
3831#define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET
3832#endif
3833\endverbatim
3834
3835Once a program is built against a hwloc library, it may also dynamically
3836link with compatible libraries from other hwloc releases.
3837The version of that runtime library may be queried with hwloc_get_api_version().
3838See \ref faq_version_abi for using this function for testing ABI compatibility.
3839
3840
3841
3842\subsection faq_version What is the difference between API and library version numbers?
3843
3844::HWLOC_API_VERSION is the version of the API.
3845It changes when functions are added, modified, etc.
3846However it does not necessarily change from one release to another.
3847For instance, two releases of the same series (e.g. 2.0.3 and 2.0.4)
3848usually have the same ::HWLOC_API_VERSION (<tt>0x00020000</tt>).
3849However their HWLOC_VERSION strings are different
3850(<tt>\"2.0.3\"</tt> and <tt>\"2.0.4\"</tt> respectively).
3851
3852
3853
3854\subsection faq_version_abi How do I handle ABI breaks?
3855
3856The hwloc interface was deeply modified in release 2.0
3857to fix several issues of the 1.x interface
3858(see \ref upgrade_to_api_2x and the NEWS file in the source directory for details).
3859The ABI was broken, which means
3860<b>applications must be recompiled against the new 2.0 interface</b>.
3861
3862To check that you are not mixing old/recent headers with a recent/old runtime library,
3863check the major revision number in the API version:
3864\verbatim
3865#include <hwloc.h>
3866  unsigned version = hwloc_get_api_version();
3867  if ((version >> 16) != (HWLOC_API_VERSION >> 16)) {
3868    fprintf(stderr,
3869           "%s compiled for hwloc API 0x%x but running on library API 0x%x.\n"
3870           "You may need to point LD_LIBRARY_PATH to the right hwloc library.\n"
3871           "Aborting since the new ABI is not backward compatible.\n",
3872           callname, HWLOC_API_VERSION, version);
3873    exit(EXIT_FAILURE);
3874  }
3875\endverbatim
3876To specifically detect v2.0 issues:
3877\verbatim
3878#include <hwloc.h>
3879#if HWLOC_API_VERSION >= 0x00020000
3880  /* headers are recent */
3881  if (hwloc_get_api_version() < 0x20000)
3882    ... error out, the hwloc runtime library is older than 2.0 ...
3883#else
3884  /* headers are pre-2.0 */
3885  if (hwloc_get_api_version() >= 0x20000)
3886    ... error out, the hwloc runtime library is more recent than 2.0 ...
3887#endif
3888\endverbatim
3889
3890In theory, library sonames prevent linking with incompatible libraries.
3891However custom hwloc installations or improperly configured build environments
3892may still lead to such issues.
3893Hence running one of the above (cheap) checks before initializing hwloc topology
3894may be useful.
3895
3896
3897
3898\subsection faq_version_xml Are XML topology files compatible between hwloc releases?
3899
3900XML topology files are forward-compatible:
3901a XML file may be loaded by a hwloc library that is more recent
3902than the hwloc release that exported that file.
3903
3904However, hwloc XMLs are not always backward-compatible:
3905Topologies exported by hwloc 2.x cannot be imported by 1.x by default
3906(see \ref upgrade_to_api_2x_xml for working around such issues).
3907There are also some corner cases where backward compatibility
3908is not guaranteed because of changes between major releases
3909(for instance 1.11 XMLs could not be imported in 1.10).
3910
3911XMLs are exchanged at runtime between some components of the HPC software stack
3912(for instance the resource managers and MPI processes).
3913Building all these components on the same (cluster-wide)
3914hwloc installation is a good way to avoid such incompatibilities.
3915
3916
3917
3918\subsection faq_version_synthetic Are synthetic strings compatible between hwloc releases?
3919
3920Synthetic strings (see \ref synthetic) are forward-compatible:
3921a synthetic string generated by a release may be imported by future hwloc libraries.
3922
3923However they are often not backward-compatible because new details may have been
3924added to synthetic descriptions in recent releases.
3925Some flags may be given to hwloc_topology_export_synthetic() to avoid such details
3926and stay backward compatible.
3927
3928
3929
3930\subsection faq_version_shmem Is it possible to share a shared-memory topology between different hwloc releases?
3931
3932Shared-memory topologies (see \ref hwlocality_shmem) have strong
3933requirements on compatibility between hwloc libraries.
3934Adopting a shared-memory topology fails
3935if it was exported by a non-compatible hwloc release.
3936Releases with same major revision are usually compatible
3937(e.g. hwloc 2.0.4 may adopt a topology exported by 2.0.3)
3938but different major revisions may be incompatible
3939(e.g. hwloc 2.1.0 cannot adopt from 2.0.x).
3940
3941Topologies are shared at runtime between some components of the HPC software stack
3942(for instance the resource managers and MPI processes).
3943Building all these components on the same (system-wide) hwloc installation
3944is a good way to avoid such incompatibilities.
3945
3946
3947
3948\page upgrade_to_api_2x Upgrading to the hwloc 2.0 API
3949
3950\htmlonly
3951<div class="section">
3952\endhtmlonly
3953
3954See \ref faq5 for detecting the hwloc version that you are compiling
3955and/or running against.
3956
3957
3958\htmlonly
3959</div><div class="section" id="upgrade_to_api_2x_memory">
3960\endhtmlonly
3961\section upgrade_to_api_2x_memory New Organization of NUMA nodes and Memory
3962
3963\subsection upgrade_to_api_2x_memory_children Memory children
3964
3965In hwloc v1.x, NUMA nodes were inside the tree, for instance Packages
3966contained 2 NUMA nodes which contained a L3 and several cache.
3967
3968Starting with hwloc v2.0, NUMA nodes are not in the main tree anymore.
3969They are attached under objects as <i>Memory Children</i> on the side
3970of normal children.
3971This memory children list starts at <code>obj->memory_first_child</code>
3972and its size is <code>obj->memory_arity</code>.
3973Hence there can now exist two local NUMA nodes,
3974for instance on Intel Xeon Phi processors.
3975
3976The normal list of children (starting at <code>obj->first_child</code>,
3977ending at <code>obj->last_child</code>, of size <code>obj->arity</code>,
3978and available as the array <code>obj->children</code>)
3979now only contains CPU-side objects:
3980PUs, Cores, Packages, Caches, Groups, Machine and System.
3981hwloc_get_next_child() may still be used to iterate over all children of all lists.
3982
3983Hence the CPU-side hierarchy is built using normal children,
3984while memory is attached to that hierarchy depending on its affinity.
3985
3986\subsection upgrade_to_api_2x_memory_examples Examples
3987
3988<ul>
3989<li>a UMA machine with 2 packages and a single NUMA node is now modeled
3990 as a "Machine" object with two "Package" children
3991 and one "NUMANode" memory children (displayed first in lstopo below):
3992\verbatim
3993Machine (1024MB total)
3994  NUMANode L#0 (P#0 1024MB)
3995  Package L#0
3996    Core L#0 + PU L#0 (P#0)
3997    Core L#1 + PU L#1 (P#1)
3998  Package L#1
3999    Core L#2 + PU L#2 (P#2)
4000    Core L#3 + PU L#3 (P#3)
4001\endverbatim
4002</li>
4003
4004<li>a machine with 2 packages with one NUMA node and 2 cores in each is now:
4005\verbatim
4006Machine (2048MB total)
4007  Package L#0
4008    NUMANode L#0 (P#0 1024MB)
4009    Core L#0 + PU L#0 (P#0)
4010    Core L#1 + PU L#1 (P#1)
4011  Package L#1
4012    NUMANode L#1 (P#1 1024MB)
4013    Core L#2 + PU L#2 (P#2)
4014    Core L#3 + PU L#3 (P#3)
4015\endverbatim
4016</li>
4017
4018<li>if there are two NUMA nodes per package, a Group object may be added to keep
4019cores together with their local NUMA node:
4020\verbatim
4021Machine (4096MB total)
4022  Package L#0
4023    Group0 L#0
4024      NUMANode L#0 (P#0 1024MB)
4025      Core L#0 + PU L#0 (P#0)
4026      Core L#1 + PU L#1 (P#1)
4027    Group0 L#1
4028      NUMANode L#1 (P#1 1024MB)
4029      Core L#2 + PU L#2 (P#2)
4030      Core L#3 + PU L#3 (P#3)
4031  Package L#1
4032    [...]
4033\endverbatim
4034</li>
4035
4036<li>if the platform has L3 caches whose localities are identical to NUMA nodes, Groups aren't needed:
4037\verbatim
4038Machine (4096MB total)
4039  Package L#0
4040    L3 L#0 (16MB)
4041      NUMANode L#0 (P#0 1024MB)
4042      Core L#0 + PU L#0 (P#0)
4043      Core L#1 + PU L#1 (P#1)
4044    L3 L#1 (16MB)
4045      NUMANode L#1 (P#1 1024MB)
4046      Core L#2 + PU L#2 (P#2)
4047      Core L#3 + PU L#3 (P#3)
4048  Package L#1
4049    [...]
4050\endverbatim
4051</li>
4052</ul>
4053
4054
4055\subsection upgrade_to_api_2x_numa_level NUMA level and depth
4056
4057NUMA nodes are not in "main" tree of normal objects anymore.
4058Hence, they don't have a meaningful depth anymore (like I/O and Misc objects).
4059They have a virtual (negative) depth (::HWLOC_TYPE_DEPTH_NUMANODE)
4060so that functions manipulating depths and level still work,
4061and so that we can still iterate over the level of NUMA nodes just like for any other level.
4062
4063For instance we can still use lines such as
4064\verbatim
4065int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
4066hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 4);
4067hwloc_obj_t node = hwloc_get_next_obj_by_depth(topology, HWLOC_TYPE_DEPTH_NUMANODE, prev);
4068\endverbatim
4069
4070The NUMA depth should not be compared with others.
4071An unmodified code that still compares NUMA and Package depths
4072(to find out whether Packages contain NUMA or the contrary)
4073would now always assume Packages contain NUMA (because the NUMA depth is negative).
4074
4075However, the depth of the Normal parents of NUMA nodes may be used instead.
4076In the last example above, NUMA nodes are attached to L3 caches,
4077hence one may compare the depth of Packages and L3 to find out
4078that NUMA nodes are contained in Packages.
4079This depth of parents may be retrieved with hwloc_get_memory_parents_depth().
4080However, this function may return ::HWLOC_TYPE_DEPTH_MULTIPLE
4081on future platforms if NUMA nodes are attached to different levels.
4082
4083
4084\subsection upgrade_to_api_2x_memory_find Finding Local NUMA nodes and looking at Children and Parents
4085
4086Applications that walked up/down to find NUMANode parent/children must
4087now be updated.
4088Instead of looking directly for a NUMA node, one should now look for
4089an object that has some memory children.
4090NUMA node(s) will be attached there.
4091For instance, when looking for a NUMA node above a given core <tt>core</tt>:
4092\verbatim
4093hwloc_obj_t parent = core->parent;
4094while (parent && !parent->memory_arity)
4095  parent = parent->parent; /* no memory child, walk up */
4096if (parent)
4097  /* use parent->memory_first_child (and its siblings if there are multiple local NUMA nodes) */
4098\endverbatim
4099
4100The list of local NUMA nodes (usually a single one) is also described
4101by the <tt>nodeset</tt> attribute of each object (which contains the
4102physical indexes of these nodes).
4103Iterating over the NUMA level is also an easy way to find local NUMA nodes:
4104\verbatim
4105hwloc_obj_t tmp = NULL;
4106while ((tmp = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, tmp)) != NULL) {
4107  if (hwloc_bitmap_isset(obj->nodeset, tmp->os_index))
4108    /* tmp is a NUMA node local to obj, use it */
4109}
4110\endverbatim
4111
4112Similarly finding objects that are close to a given NUMA nodes
4113should be updated too.
4114Instead of looking at the NUMA node parents/children, one should
4115now find a Normal parent above that NUMA node, and then look
4116at its parents/children as usual:
4117\verbatim
4118hwloc_obj_t tmp = obj->parent;
4119while (hwloc_obj_type_is_memory(tmp))
4120  tmp = tmp->parent;
4121/* now use tmp instead of obj */
4122\endverbatim
4123
4124To avoid such hwloc v2.x-specific and NUMA-specific cases in the code,
4125a <b>generic lookup for any kind of object, including NUMA nodes</b>,
4126might also be implemented by iterating over a level.
4127For instance finding an object of type <tt>type</tt> which either
4128contains or is included in object <tt>obj</tt> can be
4129performed by traversing the level of that type and comparing CPU sets:
4130\verbatim
4131hwloc_obj_t tmp = NULL;
4132while ((tmp = hwloc_get_next_obj_by_type(topology, type, tmp)) != NULL) {
4133  if (hwloc_bitmap_intersects(tmp->cpuset, obj->cpuset))
4134    /* tmp matches, use it */
4135}
4136\endverbatim
4137<b>
4138This generic lookup works whenever <tt>type</tt> or <tt>obj</tt>
4139are Normal or Memory objects since both have CPU sets.
4140Moreover, it is compatible with the hwloc v1.x API.
4141</b>
4142
4143
4144
4145
4146\htmlonly
4147</div><div class="section" id="upgrade_to_api_2x_children">
4148\endhtmlonly
4149\section upgrade_to_api_2x_children 4 Kinds of Objects and Children
4150
4151\subsection upgrade_to_api_2x_io_misc_children I/O and Misc children
4152
4153I/O children are not in the main object children list anymore either.
4154They are in the list starting at <code>obj->io_first_child</code>
4155and its size is <code>obj->io_arity</code>.
4156
4157Misc children are not in the main object children list anymore.
4158They are in the list starting at <code>obj->misc_first_child</code>
4159and its size is <code>obj->misc_arity</code>.
4160
4161See hwloc_obj for details about children lists.
4162
4163hwloc_get_next_child() may still be used to iterate over all children of all lists.
4164
4165
4166\subsection upgrade_to_api_2x_kinds_subsec Kinds of objects
4167
4168Given the above, objects may now be of 4 kinds:
4169<ul>
4170<li>Normal (everything not listed below, including Machine, Package, Core, PU, CPU Caches, etc);</li>
4171<li>Memory (currently NUMA nodes or Memory-side Caches), attached to parents as Memory children;</li>
4172<li>I/O (Bridges, PCI and OS devices), attached to parents as I/O children;</li>
4173<li>Misc objects, attached to parents as Misc children.</li>
4174</ul>
4175See hwloc_obj for details about children lists.
4176
4177For a given object type, the kind may be found with hwloc_obj_type_is_normal(),
4178hwloc_obj_type_is_memory(), hwloc_obj_type_is_normal(),
4179or comparing with ::HWLOC_OBJ_MISC.
4180
4181Normal and Memory objects have (non-NULL) CPU sets and nodesets,
4182while I/O and Misc objects don't have any sets (they are NULL).
4183
4184
4185\htmlonly
4186</div><div class="section" id="upgrade_to_api_2x_cache">
4187\endhtmlonly
4188\section upgrade_to_api_2x_cache HWLOC_OBJ_CACHE replaced
4189
4190Instead of a single HWLOC_OBJ_CACHE, there are now 8 types
4191::HWLOC_OBJ_L1CACHE, ..., ::HWLOC_OBJ_L5CACHE,
4192::HWLOC_OBJ_L1ICACHE, ..., ::HWLOC_OBJ_L3ICACHE.
4193
4194Cache object attributes are unchanged.
4195
4196hwloc_get_cache_type_depth() is not needed to disambiguate cache types anymore
4197since new types can be passed to hwloc_get_type_depth()
4198without ever getting ::HWLOC_TYPE_DEPTH_MULTIPLE anymore.
4199
4200hwloc_obj_type_is_cache(), hwloc_obj_type_is_dcache() and hwloc_obj_type_is_icache()
4201may be used to check whether a given type is a cache, data/unified cache or instruction cache.
4202
4203
4204\htmlonly
4205</div><div class="section" id="upgrade_to_api_2x_allowed">
4206\endhtmlonly
4207\section upgrade_to_api_2x_allowed allowed_cpuset and allowed_nodeset only in the main topology
4208
4209Objects do not have <code>allowed_cpuset</code> and <code>allowed_nodeset</code> anymore.
4210They are only available for the entire topology using
4211hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset().
4212
4213As usual, those are only needed when the INCLUDE_DISALLOWED topology flag is given,
4214which means disallowed objects are kept in the topology.
4215If so, one may find out whether some PUs inside an object is allowed by checking
4216\verbatim
4217hwloc_bitmap_intersects(obj->cpuset, hwloc_topology_get_allowed_cpuset(topology))
4218\endverbatim
4219Replace cpusets with nodesets for NUMA nodes.
4220To find out which ones, replace intersects() with and() to get the actual intersection.
4221
4222
4223\htmlonly
4224</div><div class="section" id="upgrade_to_api_2x_depth">
4225\endhtmlonly
4226\section upgrade_to_api_2x_depth Object depths are now signed int
4227
4228<code>obj->depth</code> as well as depths given to functions
4229such as hwloc_get_obj_by_depth() or returned by hwloc_topology_get_depth() are now
4230<b>signed int</b>.
4231
4232Other depth such as cache-specific depth attribute are still unsigned.
4233
4234
4235\htmlonly
4236</div><div class="section" id="upgrade_to_api_2x_memory_attrs">
4237\endhtmlonly
4238\section upgrade_to_api_2x_memory_attrs Memory attributes become NUMANode-specific
4239
4240Memory attributes such as <code>obj->memory.local_memory</code>
4241are now only available in NUMANode-specific attributes
4242in <code>obj->attr->numanode.local_memory</code>.
4243
4244<code>obj->memory.total_memory</code> is available
4245in all objects as <code>obj->total_memory</code>.
4246
4247See hwloc_obj_attr_u::hwloc_numanode_attr_s and hwloc_obj for details.
4248
4249
4250\htmlonly
4251</div><div class="section" id="upgrade_to_api_2x_config">
4252\endhtmlonly
4253\section upgrade_to_api_2x_config Topology configuration changes
4254
4255The old ignoring API as well as several configuration flags
4256are replaced with the new filtering API,
4257see hwloc_topology_set_type_filter() and its variants,
4258and ::hwloc_type_filter_e for details.
4259
4260<ul>
4261
4262<li>
4263hwloc_topology_ignore_type(), hwloc_topology_ignore_type_keep_structure()
4264and hwloc_topology_ignore_all_keep_structure() are respectively superseded by
4265\verbatim
4266hwloc_topology_set_type_filter(topology, type, HWLOC_TYPE_FILTER_KEEP_NONE);
4267hwloc_topology_set_type_filter(topology, type, HWLOC_TYPE_FILTER_KEEP_STRUCTURE);
4268hwloc_topology_set_all_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_STRUCTURE);
4269\endverbatim
4270
4271Also, the meaning of KEEP_STRUCTURE has changed (only entire levels may be ignored, instead of single objects), the old behavior is not available anymore.
4272</li>
4273
4274<li>
4275HWLOC_TOPOLOGY_FLAG_ICACHES is superseded by
4276\verbatim
4277hwloc_topology_set_icache_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_ALL);
4278\endverbatim
4279</li>
4280
4281<li>
4282HWLOC_TOPOLOGY_FLAG_WHOLE_IO, HWLOC_TOPOLOGY_FLAG_IO_DEVICES and HWLOC_TOPOLOGY_FLAG_IO_BRIDGES replaced.
4283
4284To keep all I/O devices (PCI, Bridges, and OS devices), use:
4285\verbatim
4286hwloc_topology_set_io_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_ALL);
4287\endverbatim
4288
4289To only keep important devices (Bridges with children, common PCI devices and OS devices):
4290\verbatim
4291hwloc_topology_set_io_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_IMPORTANT);
4292\endverbatim
4293</li>
4294
4295</ul>
4296
4297
4298\htmlonly
4299</div><div class="section" id="upgrade_to_api_2x_xml">
4300\endhtmlonly
4301\section upgrade_to_api_2x_xml XML changes
4302
43032.0 XML files are not compatible with 1.x
4304
43052.0 can load 1.x files, but only NUMA distances are imported. Other distance matrices are ignored
4306 (they were never used by default anyway).
4307
43082.0 can export 1.x-compatible files, but only distances attached to the root object are exported
4309(i.e. distances that cover the entire machine).
4310Other distance matrices are dropped (they were never used by default anyway).
4311
4312<b>Users are advised to negociate hwloc versions between exporter and importer:</b>
4313If the importer isn't 2.x, the exporter should export to 1.x.
4314Otherwise, things should work by default.
4315
4316Hence hwloc_topology_export_xml() and hwloc_topology_export_xmlbuffer() have a new flags argument.
4317to force a hwloc-1.x-compatible XML export.
4318<ul>
4319<li>
4320 If both always support 2.0, don't pass any flag.
4321</li>
4322<li>
4323 When the importer uses hwloc 1.x, export with ::HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1.
4324 Otherwise the importer will fail to import.
4325</li>
4326<li>
4327 When the exporter uses hwloc 1.x, it cannot pass any flag,
4328 and a 2.0 importer can import without problem.
4329</li>
4330</ul>
4331
4332\verbatim
4333#if HWLOC_API_VERSION >= 0x20000
4334   if (need 1.x compatible XML export)
4335      hwloc_topology_export_xml(...., HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1);
4336   else /* need 2.x compatible XML export */
4337      hwloc_topology_export_xml(...., 0);
4338#else
4339   hwloc_topology_export_xml(....);
4340#endif
4341\endverbatim
4342
4343Additionally, hwloc_topology_diff_load_xml(), hwloc_topology_diff_load_xmlbuffer(),
4344hwloc_topology_diff_export_xml(), hwloc_topology_diff_export_xmlbuffer()
4345and hwloc_topology_diff_destroy() lost the topology argument:
4346The first argument (topology) isn't needed anymore.
4347
4348
4349\htmlonly
4350</div><div class="section" id="upgrade_to_api_2x_distances">
4351\endhtmlonly
4352\section upgrade_to_api_2x_distances Distances API totally rewritten
4353
4354The new distances API is in hwloc/distances.h.
4355
4356Distances are not accessible directly from objects anymore.
4357One should first call hwloc_distances_get() (or a variant)
4358to retrieve distances (possibly with one call to get the
4359number of available distances structures, and another call
4360to actually get them).
4361Then it may consult these structures, and finally release them.
4362
4363The set of object involved in a distances structure is specified
4364by an array of objects, it may not always cover the entire machine or so.
4365
4366
4367\htmlonly
4368</div><div class="section" id="upgrade_to_api_2x_return">
4369\endhtmlonly
4370\section upgrade_to_api_2x_return Return values of functions
4371
4372Bitmap functions (and a couple other functions) can return errors (in theory).
4373
4374Most bitmap functions may have to reallocate the internal bitmap storage.
4375In v1.x, they would silently crash if realloc failed.
4376In v2.0, they now return an int that can be negative on error.
4377However, the preallocated storage is 512 bits,
4378hence realloc will not even be used unless you run
4379hwloc on machines with larger PU or NUMAnode indexes.
4380
4381hwloc_obj_add_info(), hwloc_cpuset_from_nodeset() and hwloc_cpuset_from_nodeset()
4382also return an int, which would be -1 in case of allocation errors.
4383
4384
4385\htmlonly
4386</div><div class="section" id="upgrade_to_api_2x_misc">
4387\endhtmlonly
4388\section upgrade_to_api_2x_misc Misc API changes
4389
4390<ul>
4391
4392<li>
4393hwloc_type_sscanf() extends hwloc_obj_type_sscanf()
4394by passing a union hwloc_obj_attr_u which may receive
4395Cache, Group, Bridge or OS device attributes.
4396</li>
4397
4398<li>
4399hwloc_type_sscanf_as_depth() is also added to
4400directly return the corresponding level depth within a topology.
4401</li>
4402
4403<li>
4404hwloc_topology_insert_misc_object_by_cpuset() is replaced
4405with hwloc_topology_alloc_group_object() and hwloc_topology_insert_group_object().
4406</li>
4407
4408<li>
4409hwloc_topology_insert_misc_object_by_parent() is replaced
4410with hwloc_topology_insert_misc_object().
4411</li>
4412
4413</ul>
4414
4415
4416\htmlonly
4417</div><div class="section" id="upgrade_to_api_2x_removals">
4418\endhtmlonly
4419\section upgrade_to_api_2x_removals API removals and deprecations
4420
4421<ul>
4422
4423<li>
4424HWLOC_OBJ_SYSTEM removed:
4425The root object is always ::HWLOC_OBJ_MACHINE
4426</li>
4427
4428<li>
4429*_membind_nodeset() memory binding interfaces deprecated:
4430One should use the variant without _nodeset suffix and pass the ::HWLOC_MEMBIND_BYNODESET flag.
4431</li>
4432
4433<li>
4434HWLOC_MEMBIND_REPLICATE removed:
4435no supported operating system supports it anymore.
4436</li>
4437
4438<li>
4439hwloc_obj_snprintf() removed because it was long-deprecated
4440by hwloc_obj_type_snprintf() and hwloc_obj_attr_snprintf().
4441</li>
4442
4443<li>
4444hwloc_obj_type_sscanf() deprecated, hwloc_obj_type_of_string() removed.
4445</li>
4446
4447<li>
4448hwloc_cpuset_from/to_nodeset_strict() deprecated:
4449Now useless since all topologies are NUMA. Use the variant without the _strict suffix
4450</li>
4451
4452<li>
4453hwloc_distribute() and hwloc_distributev() removed,
4454deprecated by hwloc_distrib().
4455</li>
4456
4457<li>
4458The Custom interface (hwloc_topology_set_custom(), etc.)
4459was removed, as well as the corresponding command-line tools (hwloc-assembler, etc.).
4460Topologies always start with object with valid cpusets and nodesets.
4461</li>
4462
4463<li>
4464<code>obj->online_cpuset</code> removed:
4465Offline PUs are simply listed in the <code>complete_cpuset</code> as previously.
4466</li>
4467
4468<li>
4469<code>obj->os_level</code> removed.
4470</li>
4471
4472</ul>
4473
4474
4475
4476*/
4477