Skip to content

Open a device on the CPU

Call device.Open with the absolute path of a PJRT CPU plugin and the number of devices you want:

d, err := device.Open("/opt/pjrt/pjrt_c_api_cpu_v0.117.2_plugin.so", 2)
if err != nil {
    return err
}
defer d.Close()

Open runs a small program on the plugin before it returns. A plugin that loads but cannot compute is reported there, not at the first training step.

Get the plugin

scatha never downloads the plugin. Take the pjrt_cpu_linux_amd64.tar.gz asset from a gomlx/pjrt-cpu-binaries release and unpack it wherever you like. It holds one .so file of about 220 MB. scatha is tested with v0.114.0 and v0.117.2.

Build with no C compiler

A program that uses scatha needs nothing beyond go get gitlab.com/phpboyscout/scatha. It builds with CGO_ENABLED=0, needs no C compiler, and needs no replace line in your go.mod. scatha reaches the plugin through purego, not cgo.

Only linux/amd64 is supported so far.

The binary still loads the plugin and the C library at run time, so it is linked dynamically. Go writes the build machine's dynamic loader into it. A binary built on Alpine, whose C library is musl, names musl's loader and will not start on a glibc system. To build there for glibc, name glibc's loader:

CGO_ENABLED=0 go build -ldflags="-I /lib64/ld-linux-x86-64.so.2" ./cmd/train

When Open refuses

Message says Because
must be absolute the plugin path is relative; scatha does not search for plugins
may not hold a comma the path holds a comma, which the backend's configuration string cannot carry
at least one device the device count is below one
loaded but could not run a program the plugin opened, but the check program failed or computed a wrong answer