ThreadPinning.jl

Most notably, ThreadPinning.jl allows you

  • to pin Julia threads to specific CPU-threads ("hardware threads") with pinthreads and
  • to obtain a visual overview of the system topology with threadinfo.

What is this about? (10 minutes)

Check out my lightning talk that I gave as part of JuliaCon 2023 at MIT.

Why pin threads?

Installation

The package is registered. Hence, you can simply use

] add ThreadPinning

to add the package to your Julia environment.

Note

While you can install the package on all systems, only Linux is fully supported. Especially the pinning functionality does not work on other operating systems and all basic pinning calls (e.g. pinthreads(:cores)) will turn into no-ops. threadinfo(), and other querying functions, should work on all systems (although the output might be limited).

Terminology

  • CPU: Chip that sits in a socket and (almost always) hosts multiple CPU-cores.
  • CPU-cores: Physical processor cores of the CPU.
  • CPU-threads: Hardware threads (a.k.a. "virtual cores") within the CPU-cores.
  • CPU ID: Unique ID that identifies a specific CPU-thread. (This is somewhat inconsistent but has been chosen for brevity and backwards-compatibility reasons.)

If the system supports SMT ("hyperthreading"), there are more CPU-threads than CPU-cores (most commonly a factor of two more). Independent of the CPU vendor, we refer to all but the first CPU-threads in a core as hyperthreads. The latter are highlighted differently in output, see threadinfo().

Backends

ThreadPinning.jl is based on

Noteworthy Alternatives

  • Simply setting JULIA_EXCLUSIVE=1 will pin Julia threads to CPU-threads in "physical order" (i.e. as specified by lscpu), which might or might not include hyperthreads.
  • pinthreads or likwid-pin (CLI tool) from LIKWID.jl
  • This discourse thread discusses issues with alternatives like numactl