Files
magpie/internal/pii/arch.go
T
yetone 4179cf2d8f pii: a CPU without AVX2 runs pf-serve-base, and Rosetta Apple silicon's pf-serve
echo_yip on X: Settings → Privacy's model never started, "pf-serve
(Metal): signal: illegal instruction" and the same on the CPU. x86's
pf-serve needs AVX2, FMA, F16C and BMI2, which a Celeron, a Pentium or
a Mac before Haswell lacks, and so does Rosetta before macOS 15, where
the Intel DMG on Apple silicon ran the Intel pf-serve.

- arch.go: target() is darwin-arm64 for magpie's Intel build under
  Rosetta (sysctl.proc_translated, rosetta_darwin.go), so Apple
  silicon's pf-serve, with Metal, is fetched and run. The Intel one
  already on disk is kept until the arm64 one is (tagDirs; start
  fetches it first, for at most 5 minutes, and falls back), then
  removed with the old tags.
- fullX86 asks golang.org/x/sys/cpu for AVX, AVX2, FMA and BMI2. Where
  one is missing, candidates() runs only pf-serve-base, the SSE4.2
  build the previous commit adds, when it is on disk.
- pf-v3 (privacy-filter run 41256502056 at 697335d8e) is pinned;
  pf-v2 and pf-v1 are old tags, so pf-v2 runs until pf-v3 is
  downloaded. On a CPU without AVX2 that first start still fails, and
  the retry after the download runs pf-serve-base.

Run at this commit: go test ./internal/pii/... on mote, ok; go build
./... ok; go vet ./internal/pii/... for linux, windows and darwin/amd64
ok; gofmt -l clean. Broken by hand: with candidates()'s fullX86 branch
and start()'s fetch turned off, TestBaseWhereTheCPULacksAVX2 ("starts =
[start pf-serve-vulkan MTL0]") and TestRosettaRunsAppleSiliconsServe
("started from [path pf-v9-darwin-amd64]") go red.

pf-v3's five zips, downloaded from the release and hashed here, match
its SHA256SUMS and the pins. A throwaway probe (not committed) set a
temp dir as pii's folder with the pinned model, fetched pf-v3 through
ensureServe from GitHub and masked an English and a Chinese text:
  Linux (magpie-desktop), x86 with AVX2: pf-v3-linux-amd64, Vulkan
    first, name/email/phone found
  mote, Apple M5 Pro: pf-v3-darwin-arm64, Metal, the same spans
  this Mac under Rosetta (arch -x86_64, the darwin/amd64 test binary,
    sysctl.proc_translated 1): target darwin-arm64, fetched
    pf-v3-darwin-arm64 and masked with Metal, the same scores as mote
  Windows (xiaomi-gpu): pf-v3-windows-amd64, Vulkan, name/email/phone
    found
The previous commit's qemu -cpu Nehalem run is where pf-serve-base
starts and pf-serve dies with SIGILL.

Not tried: the full go test ./... (only internal/pii changed); a real
CPU without AVX2; a Mac before macOS 15, where Rosetta has no AVX;
the GUI's Settings → Privacy page on a pf-v2 to pf-v3 upgrade.
2026-11-01 08:46:20 +08:00

35 lines
1.1 KiB
Go

package pii
import (
"runtime"
"golang.org/x/sys/cpu"
)
// osArch is the system magpie was built for.
var osArch = runtime.GOOS + "-" + runtime.GOARCH
// target is this system's name in serveSHA: the one magpie was built
// for, but Apple silicon's where an Intel magpie runs under Rosetta.
// Rosetta before macOS 15 has no AVX, so the Intel pf-serve ended with
// SIGILL on its first instruction of it, on Metal and on the CPU alike
// (echo_yip on X); Apple silicon's runs there natively, on Metal.
func target() string {
if osArch == "darwin-amd64" && translated() {
return "darwin-arm64"
}
return osArch
}
// fullX86 says the CPU has what pf-serve is built for on x86 (build.sh's
// x86): AVX, AVX2, FMA and BMI2, with F16C, which every CPU with AVX2
// has. Without them pf-serve ends with SIGILL (a Celeron, a Pentium, a
// Mac before Haswell), and pf-serve-base, built for SSE4.2 alone, is run
// instead. Off x86 it is true: no other system has a pf-serve-base.
var fullX86 = func() bool {
if runtime.GOARCH != "amd64" {
return true
}
return cpu.X86.HasAVX && cpu.X86.HasAVX2 && cpu.X86.HasFMA && cpu.X86.HasBMI2
}