A taskset-compatible wrapper that safely binds programs to the
A100 "AI" cores (cpu 8-15) of the SpacemiT K3, where the stock taskset
fails with "Invalid argument" or crashes the target with SIGSEGV.
Thin companion to k3_ai, which
provides the aix launcher this tool relies on.
# 1. Install the dependency (k3_ai -> provides `aix`)
make deps # clones + builds brucehoult/k3_ai, installs /usr/local/bin/aix
# 2. Install the wrapper as /usr/local/bin/taskset-k3 (no system change)
make install
# 3. Verify on the device
make checkBy default the wrapper installs as taskset-k3, leaving the system taskset
untouched. Two opt-in modes replace the system /usr/bin/taskset (the original
is preserved via dpkg-divert in both):
make install-system— override/usr/bin/tasksetdirectly. Asks for confirmation first.make install-alt— register withupdate-alternativesso you can toggle between the stocktasksetand this wrapper viasudo update-alternatives --config taskset.
k3_taskset is a transparent replacement for taskset. Use it exactly as you
always have:
# X100 cores (0-7) -- behaves exactly like the stock taskset
taskset -c 0-3 ./my_program
# A100 "AI" cores (8-15) -- transparently "born" on the AI cores
taskset -c 8 ./my_program # single AI core
taskset -c 8-15 ./my_program # all AI cores
taskset -c 8-15 openssl speed -evp aes-256-cbc
# See what it does
DEBUG_TASKSET=1 taskset -c 8 ./my_program
# [A100] born-on-A100 via /usr/local/bin/aix: taskset -c 8 ./my_programAny invocation that does not touch cpu 8-15 is passed straight through to the
real taskset, so existing scripts (and tools like sbc-bench) keep working
unchanged.
| Variable | Effect |
|---|---|
DEBUG_TASKSET=1 |
Print [A100] diagnostics to stderr |
AIX=/path/to/aix |
Override the aix location (else auto-detected) |
K3_TASKSET_ORIG=/path |
Override the real taskset (default /usr/bin/taskset.orig) |
The K3 has two kinds of cores with different vector register lengths:
| Cores | CPUs | Type | Vector length (VLEN) |
|---|---|---|---|
| X100 | 0-7 | fast out-of-order, run all normal Linux code | 256 bit |
| A100 | 8-15 | in-order "AI" cores, huge vector/ALU | 1024 bit |
Two problems make the stock taskset unusable for the A100 cores:
-
The A100 cores are not in a normal process's scheduling mask.
taskset -c 8returnsfailed to set pid …'s affinity: Invalid argument. The only way onto them is to write a PID to/proc/set_ai_thread. -
You cannot move a process to A100 after it has started. The dynamic loader (
ld.so) and libc already execute RVV instructions and cache VLEN-dependent decisions during startup, before yourmain()runs. If the process starts on an X100 core (VLEN 256) and is only then migrated to A100 (VLEN 1024), those cached decisions are wrong and the process corrupts its own pointers.
The naive "start the program, then write its PID to /proc/set_ai_thread"
approach hits problem 2 every time. For example, openssl reliably crashes:
openssl[72448]: unhandled signal 11 code 0x1 at 0x0000002ae050e2a0 in openssl[...]
CPU: 8 UID: 0 PID: 72448 Comm: openssl ... cause: 000000000000000d (load page fault)
hmp_set_ai_thread: pid:72448(openssl), vector has been enabled already!!!
The fix is to make the process born on A100 — it must never execute a single
userspace instruction on an X100 core. Because CPU affinity and the A100 region
are inherited across execve() (same task_struct/PID), this is achieved by
switching region before any RVV runs and then exec-ing the target:
taskset -c 8 CMD
└─> aix /usr/bin/taskset.orig -c 8 CMD
│ │ └─ born on A100, ld.so reads VLEN=1024
│ └─ pins to a specific A100 core *inside* the region (safe: all
│ A100 cores share VLEN=1024)
└─ k3_ai's pure-asm launcher: no libc, no ld.so, no RVV.
Writes its own PID to /proc/set_ai_thread, then execve()s the target.
If aix is not installed, the wrapper falls back to a same-PID exec
(echo $$ > /proc/set_ai_thread; exec taskset.orig …), which is also correct
for the target but relies on the shell not having touched RVV. Installing
aix (make deps) is strongly recommended.
- Binding across the boundary (e.g.
-c 0,8) is rejected — the two core types cannot share a vector context. taskset -p -c 8 <pid>(re-binding an already-running process to A100) is refused: that process has already run RVV on X100 and cannot be moved safely. Relaunch it undertaskset -c 8 <cmd>instead.
make uninstall # removes /usr/local/bin/taskset-k3
make uninstall-system # restores the original system taskset (if you used install-system)
make uninstall-alt # deregisters the alternative and restores the original- SpacemiT K3 with the AI-core kernel driver (
/proc/set_ai_threadpresent). k3_ai— providesaix(install viamake deps).- The original
tasksetfromutil-linux, preserved as/usr/bin/taskset.orig(handled automatically bymake installviadpkg-divert).
The born-on-A100 mechanism and the aix launcher are from Bruce Hoult's
k3_ai. This project packages a
taskset-compatible front-end around it.
MIT — see LICENSE.