Go · Executors

Executors

import "github.com/unum-cloud/uform" 4.0.0-rc.1 · c58749fe

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/uform/go/executors.md' | claude -p "How would this fit my code?"

An executor owns host threads or device streams, the activation scratch, and the pinned buffers staging passes through, grown to a high-water mark. One executor serves any number of models of its residency.

threads, err := uform.ExecutorForRam(nil, uform.CPUClassUnknown, 8)                  // eight threads, where zero takes 7/8 of the cores
nearby, err := uform.ExecutorForRam([]int32{1}, uform.CPUClassUnknown, 0)            // threads spawned near NUMA node 1
serial, err := uform.ExecutorForRam(nil, uform.CPUClassSerial, 0)                    // dispatches as the portable floor
streams, err := uform.ExecutorForVram([]int32{0, 1}, uform.GPUClassUnknown, nil, uform.CPUClassUnknown, nil, 0)
var local *uform.Executor                                                            // owns nothing, runs on the calling goroutine

err = threads.Drain(uform.MoodSpinning) // waits until no call holds it, then keeps spinning

The class arguments are ceilings: calls dispatch as the best class under them the hardware runs, and the zero class sets none. Naming one memory domain spawns the threads near it, while none or several interleave them across the machine. ExecutorForVram opens one stream per device, or adopts the caller’s streams, one per named device, and Close destroys them; naming no devices drives every listed device of the first vendor with a known class. uform.GPUDevices(devices) fills a slice of GPUDevice and answers how many GPUs the process can drive, and a device’s position there is the ordinal ExecutorForVram and ModelLoadVram name it by. An executor runs one call at a time, so two goroutines that genuinely overlap take one apiece. Close waits until no call holds the executor, and a closed one refuses every later verb with StatusUninitialized.

API

Types

MeshDescriptionMeshDescription is what a mesh reports about itself.
types.go:343 ↗
type MeshDescription struct {
    GPUsPerHostDomain      uint
    GPUsPerMultimemDomain  uint
    GPUsPerColocatedDomain uint
    HostDomainIndex        uint
    FirstGPUIndex          uint
    MultimemTier           MultimemTier
    GPUClass               GPUClass
}

Mirrors uform_mesh_description_t field for field, so the library writes it in place.

MeshOptionsMeshOptions is where this process sits among the processes of a run, and how they meet.
types.go:325 ↗
type MeshOptions struct {
    HostDomainIndex uint
    HostDomainCount uint
    GPUsPerMultimemDomain uint
    Directory string
    Job string
    TimeoutSeconds float64
}

Mirrors uform_mesh_options_t.

Fields

HostDomainIndexuintHostDomainIndex is this process's index among HostDomainCount.
HostDomainCountuintHostDomainCount is the processes in the run; zero derives one.
GPUsPerMultimemDomainuintGPUsPerMultimemDomain is the GPUs one NVLink multicast domain spans; zero derives the host.
DirectorystringDirectory is the path every host sees, where processes exchange their facts.
JobstringJob is the run's unique name, naming one directory inside Directory.
TimeoutSecondsfloat64TimeoutSeconds is how long any wait for a peer lasts; zero derives 120.
EnumCPUClassCPUClass is a CPU family UForm ships tuned variants for, numbered as USearch numbers it; a RAM placement or executor may cap dispatch at one, and the zero value sets no ceiling.2
types.go:614 ↗
type CPUClass int32

Values

CPUClassUnknownCPUClassUnknown sets no ceiling, so dispatch may pick any class the machine runs.
CPUClassSerialCPUClassSerial is the portable floor, with no SIMD assumptions.
CPUClassMonoversionedCPUClassMonoversioned is the one class of a monoversioned build.
CPUClassIntelHaswellCPUClassIntelHaswell is Haswell-class x86: AVX2 and FMA.
CPUClassIntelSierraCPUClassIntelSierra is Sierra Forest-class x86: AVX-VNNI without AVX-512.
CPUClassIntelSkylakeCPUClassIntelSkylake is Skylake-class x86: the AVX-512 foundation.
CPUClassIntelIcelakeCPUClassIntelIcelake is Icelake-class x86: AVX-512 VNNI and VPOPCNT.
CPUClassAMDGenoaCPUClassAMDGenoa is Genoa-class x86: native bf16 dot products over AVX-512.
CPUClassIntelSapphireCPUClassIntelSapphire is Sapphire Rapids-class x86: AVX-512 FP16 and the AMX tiles.
CPUClassIntelGraniteCPUClassIntelGranite is Granite Rapids-class x86: the AMX-FP16 tiles.
CPUClassIntelDiamondCPUClassIntelDiamond is Diamond Rapids-class x86: AVX10.2's FP8 conversions.
CPUClassAWSG2CPUClassAWSG2 is Graviton2-class Arm: the bare NEON floor.
CPUClassAppleM2CPUClassAppleM2 is Armv8.6 NEON with dot products and bf16.
CPUClassAppleM4CPUClassAppleM4 is Apple M4-class Arm: the SME outer-product tiles.
CPUClassAWSG5CPUClassAWSG5 is Graviton5-class Arm: Armv9.2.
CPUClassNVIDIAVeraCPUClassNVIDIAVera is Vera-class Arm: FP8 dot products.
CPUClassAlibabaC930CPUClassAlibabaC930 is Alibaba C930-class RISC-V: RVA23 vectors.
CPUClassIBMPower10CPUClassIBMPower10 is IBM POWER10-class Power: VSX vectors and MMA accumulators.
CPUClassWasm32V128CPUClassWasm32V128 is WebAssembly with fixed-width simd128.
CPUClassWasm64ExtendedCPUClassWasm64Extended is WebAssembly with relaxed SIMD, threads and 64-bit addressing.
CPUClassFromNameCPUClassFromName reads a CPU class back from the spelling CPUClass.String renders.
types.go:665 ↗
func CPUClassFromName(name string) (CPUClass, error)
*String× 2String renders the class as the library spells it.
types.go:660 ↗
func (class CPUClass) String() string
StructExecutorExecutor owns the host threads or device streams a call runs on, the activation scratch, and the pinned buffers staging passes through, apart from any model.4
types.go:559 ↗
type Executor struct {
    // contains filtered or unexported fields
}

One executor serves any number of models of its residency, while a model owns only its weights, which is what lets one pool serve several models and keeps the cost of spawning visible at the line that spawns it. Its kind is fixed by the constructor that produced it.

A nil *Executor is the null executor: it owns nothing, and every call handed it runs on the calling goroutine. One call holds an executor at a time; a second call finding it held finishes StatusContended, and nothing queues.

ExecutorForRamExecutorForRam spawns host threads for RAM-resident models near the one memory domain memoryDomains names, or interleaved across the machine for none or several; the list is the one the models were loaded with, and an empty list derives it from the machine.
types.go:789 ↗
func ExecutorForRam(
    memoryDomains []int32,
    cpuClassCeiling CPUClass,
    threads uint,
) (*Executor, error)

Zero threads takes seven eighths of the cores those domains carry. A cpuClassCeiling intersects with what the machine runs, so a class the machine lacks narrows rather than refuses.

ExecutorForVramExecutorForVram opens one submission stream on every named device, all driven by the one host thread that calls the verbs, beside host threads on memoryDomains for the decoding the devices leave to the host.
types.go:810 ↗
func ExecutorForVram(
    devices []int32,
    gpuClassCeiling GPUClass,
    memoryDomains []int32,
    cpuClassCeiling CPUClass,
    streams []unsafe.Pointer,
    scratchLimit uint,
) (*Executor, error)

Streams is empty, or holds one stream per device in devices order: a CUDA or HIP stream becomes the executor's, which synchronizes and destroys it; a Metal queue is retained, the executor releasing its own reference while the caller keeps and releases theirs. Zero scratchLimit lets scratch grow as batches ask.

CloseClose waits out the call holding the executor, then releases its threads, rings or streams; every arena it made must be closed first, or it fails with StatusContended and frees nothing, so a later Close retries.
types.go:1168 ↗
func (executor *Executor) Close() error

It is idempotent; a closed executor must not be used again.

DrainDrain waits until no call holds this executor, then adopts mood until the next call; it only waits and never runs a call itself.
types.go:844 ↗
func (executor *Executor) Drain(mood Mood) error

A failure is the executor's own, such as a lost device, never one of a drained call.

EnumGPUClassGPUClass is a GPU family UForm ships tuned variants for, numbered as USearch numbers it; a VRAM placement or executor may cap dispatch at one, and the zero value sets no ceiling.1
types.go:673 ↗
type GPUClass int32

Values

GPUClassUnknownGPUClassUnknown sets no ceiling, so dispatch may pick any class every named device loads.
GPUClassNVIDIAAmpereGPUClassNVIDIAAmpere is Ampere-class NVIDIA, and every newer GPU whose driver compiles its PTX.
GPUClassNVIDIAAdaGPUClassNVIDIAAda is Ada-class NVIDIA: the fp8 conversions.
GPUClassNVIDIAHopperGPUClassNVIDIAHopper is Hopper-class NVIDIA.
GPUClassNVIDIABlackwellGPUClassNVIDIABlackwell is Blackwell-class NVIDIA.
GPUClassNVIDIABlackwellRTXGPUClassNVIDIABlackwellRTX is Consumer Blackwell NVIDIA.
GPUClassNVIDIARubinGPUClassNVIDIARubin is Rubin-class NVIDIA.
GPUClassAMDCDNA3GPUClassAMDCDNA3 is CDNA3 AMD: gfx942.
GPUClassAMDCDNA4GPUClassAMDCDNA4 is CDNA4 AMD: gfx950.
GPUClassAMDCDNA5GPUClassAMDCDNA5 is CDNA5 AMD: gfx1250.
GPUClassAppleMetal7GPUClassAppleMetal7 is Apple7-family GPUs, and every Apple GPU without a class of its own.
GPUClassAppleMetal9GPUClassAppleMetal9 is Apple9-family GPUs.
GPUClassAppleMetal10GPUClassAppleMetal10 is Apple10-family GPUs.
GPUClassFromNameGPUClassFromName reads a GPU class back from the spelling GPUClass.String renders.
types.go:710 ↗
func GPUClassFromName(name string) (GPUClass, error)
StructGPUDeviceGPUDevice is one GPU as UForm numbers it: its position in what GPUDevices fills is the ordinal every VRAM call names.1
types.go:739 ↗
type GPUDevice struct {
    Vendor GPUVendor
    VendorOrdinal uint32
    GPUClass GPUClass
    ComputeUnits uint32
    MemoryBytes uint64
    // contains filtered or unexported fields
}

Mirrors uform_gpu_device_t field for field, so the library writes it in place.

Fields

VendorGPUVendorVendor is the runtime that drives the device.
VendorOrdinaluint32VendorOrdinal is the device's ordinal in its vendor's runtime.
GPUClassGPUClassGPUClass is the newest class whose code runs on it, or GPUClassUnknown where none does.
ComputeUnitsuint32ComputeUnits counts streaming multiprocessors or compute units.
MemoryBytesuint64MemoryBytes is the device memory.
NameName reports the vendor's own name for the device.
types.go:754 ↗
func (device GPUDevice) Name() string
EnumGPUVendorGPUVendor is the runtime that drives a GPU.1
types.go:717 ↗
type GPUVendor int32

Values

GPUVendorUnknownGPUVendorUnknown names no vendor.
GPUVendorNVIDIAGPUVendorNVIDIA drives the device through the CUDA driver.
GPUVendorAMDGPUVendorAMD drives the device through the HIP runtime.
GPUVendorAppleGPUVendorApple drives the device through Metal.
StringString renders the vendor as the library spells it.
types.go:731 ↗
func (vendor GPUVendor) String() string
StructMeshMesh is one process's place among the processes of a run, made once and referred to by every trainer, which must be closed first.3
train.go:500 ↗
type Mesh struct {
    // contains filtered or unexported fields
}

Mirrors uform_mesh_t; Close calls uform_mesh_free.

MeshBootstrapMeshBootstrap joins this process to the run's mesh over executor, a VRAM executor whose devices are this process's members; every process of the run calls it with the same options.
train.go:508 ↗
func MeshBootstrap(
    executor *Executor,
    config *MeshOptions,
) (*Mesh, error)

Calls uform_mesh_bootstrap, blocking.

CloseClose leaves the mesh.
train.go:557 ↗
func (mesh *Mesh) Close() error

It is idempotent, and every trainer made over the mesh must be closed first.

DescribeDescribe reports the mesh's shape and this process's place in it.
train.go:540 ↗
func (mesh *Mesh) Describe() (MeshDescription, error)

Calls uform_mesh_describe.

EnumMultimemTierMultimemTier is how a mesh's NVLink domains reduce.2
train.go:166 ↗
type MultimemTier int32

Values

MultimemTierSwitchReducedMultimemTierSwitchReduced reduces through the NVLink switch's multicast memory.
MultimemTierPeerReadMultimemTierPeerRead reads every peer in a fixed order, where multicast is absent.
MultimemTierFromNameMultimemTierFromName reads a multimem tier back from the spelling MultimemTier.String renders.
train.go:181 ↗
func MultimemTierFromName(name string) (MultimemTier, error)
StringString renders the tier as the library spells it.
train.go:176 ↗
func (tier MultimemTier) String() string

Functions

CapabilitiesAvailableCapabilitiesAvailable lists the hardware capabilities the current machine offers at runtime, comma separated.
uform.go:1273 ↗
func CapabilitiesAvailable() string
CapabilitiesCompiledCapabilitiesCompiled lists the hardware capabilities the linked binary was compiled with, comma separated.
uform.go:1265 ↗
func CapabilitiesCompiled() string
GPUDevicesGPUDevices fills devices with the GPUs this process can drive, NVIDIA first, then AMD, then Apple, and reports how many there are, which may exceed len(devices).
uform.go:770 ↗
func GPUDevices(devices []GPUDevice) (uint, error)