Christian Kastner: Easy dynamic dispatch using GLIBC Hardware Capabilities
TL;DR With GLIBC 2.33+, you can build a shared library multiple times
targeting various optimization levels, and the dynamic linker/loader will pick
the highest version supported by the current CPU. For example, with the layout
below, on a Ryzen 9 5900X,
Longer Version
GLIBC Hardware Capabilities
or "hwcaps" are an easy, almost trivial way to add
a simple form of dynamic dispatch to any amd64 or POWER build, provided that
either the build target or the compiler's optimizations can make use of
certain CPU extensions.
Mo Zhou pointed me towards this
when I was faced with the challenge of creating a performant Debian package for
ggml,
the tensor library behind
llama.cpp
and
whisper.cpp.
The Challenge
A performant yet universally loadable library needs to make use of some
form of dynamic dispatch to leverage the most effective SIMD extensions
available on any given CPU it may run on. Last January, when I first started
with the packaging of ggml for Debian, ggml did have support for this through
its
Dynamic Dispatch using hwcaps
hwcaps were introduced in GLIBC 2.33 and replace the (now) Legacy Hardware
Capabilities, which were removed in 2.37. The way hwcaps work is delightfully
simple: the dynamic linker/loader will look for a shared library not just in
the standard library paths, but also in subdirectories
thereof of the form
x86-64-v3/libfoo0.so would be loaded:
/usr/lib/glibc-hwcaps/x86-64-v4/libfoo0.so /usr/lib/glibc-hwcaps/x86-64-v3/libfoo0.so /usr/lib/glibc-hwcaps/x86-64-v2/libfoo0.so /usr/lib/libfoo0.so
GGML_CPU_ALL_VARIANTS=ON option, but this was limited to amd64.
This meant that on all the other architectures that Debian supports, I would
need to target some ancient
baseline,
thus effectively crippling the package there.
hwcaps/<level>, starting with the highest <level>
that the current CPU supports. The levels are predefined. I'm using the
amd64 levels
below.
For ggml, this meant that I simply could build the library in multiple passes,
each time targeting a different <level>, and install the result in the
corresponding subdirectory, which resulted in the following
layout (reduced to libggml.so for brevity):
/usr/lib/x86_64-linux-gnu/ggml/glibc-hwcaps/x86-64-v4/libggml.so /usr/lib/x86_64-linux-gnu/ggml/glibc-hwcaps/x86-64-v3/libggml.so /usr/lib/x86_64-linux-gnu/ggml/glibc-hwcaps/x86-64-v2/libggml.so /usr/lib/x86_64-linux-gnu/ggml/libggml.soIn practice, this means that on a CPU supporting AVX512, the linker/loader would load
x86-64-v4/libggml.so if it existed, and otherwise continue to
look for the other levels, all the way down to the lowest one. On a
CPU which supported only SSE4.2, the lookup process would be the same,
ending with picking x86-64-v2/libggml.so.
With QEMU, all of this was quickly
verified.
Note that the lowest-level library, targeting x86-64-v1, is not installed
to a subdirectory, but to the path where the library would normally have been
installed. This has the nice property that on systems not using
GLIBC, and thus not having hwcaps available, package installation will still
result in a loadable library, albeit the version with the worst performance.
And a careful observer might have noticed that in the example above, the
library is installed to a private ggml/ directory, so this mechanism also
works when using RUNPATH or LD_LIBRARY_PATH.
As mentioned above, Debian's ggml package will soon switch to
GGML_CPU_ALL_VARIANTS=ON, but this was still quite the useful feature to
discover.










And this is the time when one realizes that she only has one white
camisole left. And it s summer, so I m wearing a lot of white shirts,
and I always wear a white camisole under a white shirt (unless I m
wearing a full chemise).
Not a problem, I have
At bust level it s now a bit too wide, and it gapes a bit under the
arms, but I don t think that it s going to cause significant problems,
and (other than everybody on the internet) nobody is going to see it, so
it s not a big deal.
I still have some linen, but I don t think I m going to make another one
with the same pattern: maybe I ll try to do something with a front
opening, but I ll see later on, also after I ve been looking for the
missing jersey in a few more potential places.
As for now, the number of white camisoles I have has doubled, and this
is progress enough for today.
After cartridge pleating, the next fabric manipulation technique I
wanted to try was smocking, of the honeycombing variety, on a shirt.
My current go-to pattern for shirts is the
In my stash I had a cut of purple-blue hopefully cotton [#cotton] I had
bought for a cheap price and used for my first attempt at an
Of course I wanted some honeycombing on the front, but I was afraid that
the slit in the middle of it would interfere with the honeycombing and
gape, so I decided to have the shirt open in an horizontal line at the
yoke.
I added instructions
I also used a row of honeycombing on the back and two on the upper part
of the sleeves, instead of the gathering, and of course some rows to
gather the cuffs.
The honeycombing on the back was a bit too far away from the edge, so
it s a bit of an odd combination of honeycombing and pleating that I
don t hate, but don t love either. It s on the back, so I don t mind. On
the sleeves I ve done the honeycombing closer to the edge and I ve
decided to sew the sleeve as if it was a cartridge pleated sleeve, and
that worked better.
Because circumstances are still making access to my sewing machine
more of a hassle than I d want it to be, this was completely sewn by
hand, and at a bit more than a month I have to admit that near the end
it felt like it had been taken forever. I m not sure whether it was the
actual sewing being slow, some interruptions that happened when I had
little time to work on it, or the fact that I ve just gone through a
time when my brain kept throwing new projects at me, and I kept thinking
of how to make those. Thanks brain.
Even when on a hurry to finish it, however, it was still enjoyable
sewing, and I think I ll want to do more honeycombing in the future.
Anyway, it s done! And it s going straight into my daily garment
rotation, because the weather is getting hot, and that means it s
definitely shirt time.
TGV train I rode from Luxembourg to Paris
Pasta I had in Paris
A cycling track in Paris
Luxembourg Museum
A shot of the park near to the Luxembourg Museum
Pantheon, one of the attractions of Paris.
Photo with Joenio and Mari
Notre Dame, another tourist attraction of Paris.
My photo with Eiffel Tower in the background
Items at a bakery in Paris. Items from left to right are: Chocolate Twist, Sugar briochette, Pain au Chocolat, Croissant with almonds, Croissant, Croissant with chocolate hazlenut filling.
The Paris subway
Inside a Paris subway
A random building and road in Paris
A shot near Seine river
A view of Seine river
For a long time I ve been wanting to try GitOps tools, but I haven t had the chance to try them for real on the projects
I was working on.
As now I have some spare time I ve decided I m going to play a little with 
Years ago I made myself a quick dressing gown from a white fleece IKEA
throw and often wore it in the morning between waking up and changing
into day clothes.
One day I want to make myself a fancy victorian wrapper, to use in its
place, but that s still in the early planning stage, and will require
quite some work.
Then last autumn I discovered that the taxes I owed to the local lord (who
provides protection from mice and other small animals) included not just
a certain amount of kibbles, but also some warm textiles, and the
dressing gown (which at this time was definitely no longer pristine) had
to go.
For a while I had to do without a dressing gown, but then in the second
half of this winter I had some time for a quick machine sewing
project. I could not tackle the big victorian thing, but I still had a
second POLARVIDE throw from IKEA (this time in a more sensible dark
grey) I had bought with sewing intents.
The fabric in a throw isn t that much, so I needed something pretty
efficient, and rather than winging it as I had done the first time I
decided I wanted to try the Modular Jacket from
Since I didn t have enough fabric for the belt I also skipped the belt
loops, but I have been wearing this with random belts and I don t feel
the need for them anyway. I ve also been thinking about adding a button
just above the bust and use that to keep it closed, but I m still not
100% sure about it.
Another thing I still need to do is to go through the few scraps of
fleece that are left and see if I can piece together a serviceable
pocket or two.
Because of the size of the fabric, I ended up having quite long sleeves:
I m happy with them because they mean that I can cover my hands when
it s cold, or fold them back to make a nice cuff.
If I ll make a real jacket with this patter I ll have to take this in
consideration, and either make the sleeves shorter or finish the seam in
a way that looks nice when folded back.
Will I make a real jacket? I m not sure, it s not really my style of
outer garment, but as a dressing gown it has already been used quite a
bit (as in, almost every morning since I ve made it :) ) and will
continue to be used until too worn to be useful, and that s a good
thing.
Fun with -fsanitize=undefined and Picolibc
Both GCC and Clang support the -fsanitize=undefined flag which
instruments the generated code to detect places where the program
wanders into parts of the C language specification which are either
undefined or implementation defined. Many of these are also common
programming errors. It would be great if there were sanitizers for
other easily detected bugs, but for now, at least the undefined
sanitizer does catch several useful problems.
Supporting the sanitizer
The sanitizer can be built to either trap on any error or call
handlers. In both modes, the same problems are identified, but when
trap mode is enabled, the compiler inserts a trap instruction and
doesn't expect the program to continue running. When handlers are in
use, each identified issue is tagged with a bunch of useful data and
then a specific sanitizer handling function is called.
The specific functions are not all that well documented, nor are the
parameters they receive. Maybe this is because both compilers provide
an implementation of all of the functions they use and don't really
expect external implementations to exist? However, to make these useful in an
embedded environment, picolibc needs to provide a complete set of
handlers that support all versions both gcc and clang as the
compiler-provided versions depend upon specific C (and C++) libraries.
Of course, programs can be built in trap-on-error mode, but that makes
it much more difficult to figure out what went wrong.
Fixing Sanitizer Issues
Once the sanitizer handlers were implemented, picolibc could be
built with them enabled and all of the picolibc tests run to uncover
issues within the library.
As with the static analyzer adventure from last year, the vast bulk of
sanitizer complaints came from invoking undefined or
implementation-defined behavior in harmless ways:
dmidecode grep -A8 ^System Information
tells me that the Manufacturer is HP and Product Name is OMEN Transcend Gaming Laptop 14-fb0xxx
I m provisioning a new piece of hardware for my eng consultant and it s proving more difficult than I expected. I must admit guilt for some of this difficulty. Instead of installing using the debian installer on my keychain, I dd d the pv block device of the 16 inch 2023 version onto the partition set aside from it. I then rebooted into rescue mode and cleaned up the grub config, corrected the EFI boot partition s path in /etc/fstab, ran the grub installer from the rescue menu, and rebooted.
On the initial boot of the system, X or Wayland or whatever is supposed to be talking to this vast array of GPU hardware in this device, it s unable to do more than create a black screen on vt1. It s easy enough to switch to vt2 and get a shell on the installed system. So I m doing that and investigating what s changed in Trixie. It seems like it s pretty significant. Did they just throw out Keith Packard s and Behdad Esfahbod s work on font rendering? I don t understand what s happening in this effort to abstract to a simpler interface. I ll probably end up reading more about it.
In an effort to have Debian re-configure the system for Desktop use, I have uninstalled as many packages as I could find that were in the display and human interface category, or were firmware/drivers for devices not present in this Laptop s SoC. Some commands I used to clear these packages and re-install connamon follow:
Luxembourg's Findel Airport
Separate cycling tracks in Luxembourg
This is what trains look like in Luxembourg
Conference bag
One of the slides of Italo's talk
Picture of the hall in which talks were held
We encountered such scenic views during our walk
Another view of Luxembourg city area
A few months ago
A couple of years ago, I
However, the sole is still going strong, and the general concept has
proved valid, so when I needed a second pair of slippers I used
Then, my partner also needed new slippers, and I wanted to make his too.
His preference, however, is for open heeled slippers, so I adjusted the
pattern into
He also finds completely flat soles a bit uncomfortable, so I made an
heel with the same braided twine technique: this also seems to be
working fine, and I ve also added