Pure-Go Backend ("go")

100% pure-Go, CGO-free CPU and WebAssembly backend with SIMD acceleration, native dynamic shapes, and quantized execution.

Importing

  • Included by default in backends/default? Yes — always included on all platforms when importing _ "github.com/gomlx/gomlx/backends/default".
  • Standalone blank import (links only the pure-Go backend, no CGo required):
    import _ "github.com/gomlx/compute/gobackend"
    

Overview

The "go" backend (github.com/gomlx/compute/gobackend) is a pure Go implementation of compute.Backend. It requires no CGo (CGO_ENABLED=0) and no external C/C++ libraries.

  • Pros: 100% portable across OSes and architectures. Compiles cleanly to WebAssembly (GOOS=js GOARCH=wasm) to run models directly in the browser, and natively supports dynamic shapes (DynamicShapesNative) without recompilation.
  • Cons: Slower than dedicated GPU/TPU accelerators or XLA whole-graph compilation for heavy model training.

Performance Enhancements

  • SIMD & Hardware Matrix Acceleration (AMD64 & ARM64): When built with GOEXPERIMENT=simd (Go 1.27+), utilizes Go’s simd and simd/archsimd packages alongside handwritten assembly microkernels for:
    • AMD64: AVX2 and AVX-512 (including AVX-512 VNNI) microkernels for DotGeneral, FusedDense, FusedQuantizedDense, FusedScaledDotProductAttention (SDPA), FusedLayerNorm, FusedSoftmax, reductions, and activations.
    • ARM64 (darwin/arm64 & linux/arm64): NEON (FEAT_ASIMD) and Scalable Matrix Extension (FEAT_SME, e.g., on Apple M4/M5/M6) assembly microkernels across DotGeneral/FusedDense (Float32, Float16, BFloat16, Float64), FusedScaledDotProductAttention, reductions, trailing-axis binary broadcasts, Where, and hardware Float16/BFloat16 conversions—with asymmetric CPU cluster probing and hybrid SME + NEON co-execution across Super, Performance, and Efficiency cores (reaching up to 2.51 TFlops/s on Apple M6).
  • Hierarchical 3-Level Parallel Scheduler: Prioritizes Inter-Call > Intra-Op > Inter-Op parallelism using persistent workers, deadlock-free work-helping, dynamic graph execution, and Guided Self-Scheduling (GSS).
  • Fused Operations & Constant Weight Caching: Implements fused attention, layer normalization, softmax, dense/activation operations, and one-time GEMM constant weight panel pre-packing with automatic raw buffer eviction to minimize memory allocations and bandwidth.
  • Quantization: Supports quantized operations (FusedQuantizedDense, FusedQuantizedDenseVJP, QuantizedEmbeddingLookup) across all 12 GGML/GGUF block formats (Q4_0–Q8_0, IQ4_NL, Q2_K–Q8_K), QuantLinear (Int8, Uint8, Int4, Uint4, Int2, Uint2), and QuantNF4 for faster inference and QLoRA backpropagation on smaller memory footprints.

Configuration Options

Configure the "go" backend via GOMLX_BACKEND="go:<option1>,<option2>=<value>" or compute.NewWithConfig(...):

  • parallelism=<N>: Sets the maximum number of worker goroutines in the intra-op scheduler pool and throttles concurrent Executable.Execute() calls to at most N (when N > 0; parallelism=1 disables intra-op multi-threading; parallelism=0 disables parallelism; parallelism=-1 is unlimited).
    • Default: Uses physical CPU cores (min(PhysicalCores(), runtime.GOMAXPROCS(0))) when AVX-512 is active (since 512-bit AVX-512 kernels saturate each physical core’s FMA/VNNI/BF16 units and private L1/L2 caches with a single thread), and runtime.GOMAXPROCS(0) otherwise (AVX2, ARM64, or non-SIMD builds).
    • Note on heterogeneous and high-core-count CPUs: Modern CPUs are very heterogeneous — with asymmetric Performance/Efficiency core clusters (e.g., Intel hybrid P+E cores where P-cores have Hyper-Threading and E-cores do not, or Apple Silicon Super/Performance/Efficiency clusters), SMT/Hyper-Threading, multi-CCD/V-Cache L3 layouts, and varying SIMD widths — so the automatic default will not always be optimal for every CPU and workload.
    • High-core-count server CPUs (AMD EPYC / Intel Xeon, 64–192+ cores): While high core counts scale well for inter-call concurrency (many simultaneous Execute() calls), single-stream intra-op / inter-op parallelism often hits diminishing returns or slows down beyond ~32–64 cores due to cross-CCD/cross-socket synchronization overhead, NUMA memory latency, and per-socket DDR5 bandwidth saturation. On very large EPYC/Xeon machines, use intra_call_parallelism=<N> (see below) to cap per-call fan-out while keeping full inter-call concurrency, lower parallelism=<N> for single-stream inference, or pin one process per NUMA node (e.g., via numactl). For performance-critical deployments, benchmark a few explicit values.
  • intra_call_parallelism=<N>: Optional upper bound on the number of workers (intra-op + inter-op) used within any single Executable.Execute() call, without reducing the inter-call concurrency cap set by parallelism (defaults to 0, meaning the same limit as parallelism). Useful on high-core-count AMD EPYC and Intel Xeon servers (e.g., GOMLX_BACKEND="go:parallelism=192,intra_call_parallelism=32"): up to 192 concurrent requests can still run simultaneously across all physical cores, while each individual call avoids fanning out across 100+ cores and paying cross-CCD/NUMA synchronization overhead.
  • num_executors=<N>: Sets the maximum number of concurrent graph-node executor goroutines launched during parallel graph execution (defaults to 8, capped at the effective parallelism).
  • ops_sequential / ops_parallel: Forces independent graph operations to execute sequentially or in parallel where possible (by default, runs dynamically: parallel when a single execution is live, sequential when multiple concurrent calls are active).
  • dependency_order / creation_order: Selects the topological node scheduling strategy for sequential execution:
    • dependency_order (default): Critical-path topological order (schedules nodes with the longest dependency path to an output first, breaking ties by creation order).
    • creation_order: Executes nodes in monotonically increasing creation order.
  • quantized_cache=<always|balanced|never> (default balanced): Controls constant weight and supporting-tensor (scale, zero_point, bias) caching for FusedQuantizedDense (accepts aliases true/1 or bare quantized_cache for always, and false/none/0 for never):
    • balanced (default): Decides once per constant at compile time, caching a tensor only when its cached representation is <= 4 MiB and its net extra memory (cached - freed_raw) is <= 2× its raw size. Automatically caches 4-bit to 8-bit Mode B (quantized_matmul=true) weights in small/medium L3-resident models (such as MiniLM / BGE embedders) as well as small Float16/BFloat16 scales and biases—improving throughput and reducing pooled scratch duplication under concurrent inference—while leaving large LLM layers (> 4 MiB), ultra-low-bit (Q2_K/Q3_K), and Mode A (float32 panels) uncached to preserve low RAM and DRAM bandwidth.
    • always (or true, 1, or bare quantized_cache): Caches every eligible constant quantized weight (both Mode B K4 panels and Mode A float32 GEMM panels) and supporting constant tensor regardless of size or expansion ratio. Donated raw buffers are freed once cached; non-donated constants are still cached and shared across graphs while keeping the caller’s raw buffer intact.
    • never (or none, false, 0): Disables quantized constant caching completely; all quantized weights and supporting tensors are unpacked or converted on the fly in bounded pooled chunks (<= 2–4 MiB).
    • See GoBackendMemoryUsage.md for a full breakdown of Go backend memory management, expansion ratios, and caching behavior.
  • constant_arena[=<true|false>] (default true): Allocates pre-packed/cached constant weight panels into 2 MiB-aligned off-heap mmap chunks advised with MADV_HUGEPAGE on Linux, reference-counted per compiled Builder/Executable so chunks are immediately unmapped back to the OS once all referencing executables (or the backend) are finalized. Also configurable via GOMLX_GO_CONSTANT_ARENA.
  • no_ops: Debugging and benchmarking option that allocates output buffers and runs full graph scheduling without executing kernel math, useful for measuring pure framework and scheduler overhead.
Passing an unknown option such as GOMLX_BACKEND="go:help" returns an error listing all valid configuration options.

Environment Variables

The "go" backend also accepts the following environment variables for fine-grained tuning and profiling:

  • GOMLX_GO_SIMD_AVX512: Set to 0 or false to disable AVX-512 SIMD implementations (enabled by default when supported by the CPU).
  • GOMLX_GO_SIMD_AVX512_BF16: Set to 0 or false to disable native AVX512_BF16 (VDPBF16PS) BFloat16 matmul kernels and fall back to AVX-512 FP32-unpack kernels (enabled by default when supported by the CPU).
  • GOMLX_GO_CONSTANT_ARENA: Set to 0 or false to disable the off-heap MADV_HUGEPAGE constant arena (enabled by default).
  • GOMLX_GO_SIMD_AVX2: Set to 0 or false to disable AVX2 SIMD implementations (enabled by default when supported by the CPU).
  • GOMLX_GO_SIMD_NEON: Set to 0 or false to disable ARM64 NEON (FEAT_ASIMD) SIMD implementations (enabled by default when supported by the CPU).
  • GOMLX_GO_SIMD_SVE: Set to 0 or false to disable ARM64 SVE SIMD implementations (enabled by default when supported by the CPU).
  • GOMLX_GO_SIMD_SME: Set to 0 or false to disable ARM64 Scalable Matrix Extension (FEAT_SME) implementations (enabled by default when supported by the CPU).
  • GOMLX_GO_AVX512_ASM, GOMLX_GO_AVX2_ASM, GOMLX_GO_NEON_ASM: Set to 0 or false to disable handwritten assembly GEMM microkernels and fall back to Go SIMD kernels.
  • GOMLX_GO_AVX512_KC, GOMLX_GO_AVX512_MC, GOMLX_GO_AVX512_NC (and corresponding GOMLX_GO_AVX2_*, GOMLX_GO_NEON_*, GOMLX_GO_NOSIMD_*): Override cache blocking parameters (KC, MC, NC) for matrix multiplication.
  • GOMLX_GO_DOT_MATMUL: Set to 0 or false to disable the tiled matmul implementation in DotGeneral (enabled by default).
  • GOMLX_GO_FUSION: Set to 0 or false to disable fused operations (enabled by default).
  • GOMLX_OP_PROFILE: Enables per-operator timing summaries in the Go backend. Set to 1 (or true) to print a per-op wall/CPU time breakdown every 5 timed runs (after 1 warm-up run), or set to <N> (N > 1) to print every N runs (combine with GOMLX_BACKEND="go:ops_sequential" for isolated per-op wall and CPU times).

Contributing Specialized Kernels

It is relatively straightforward to add specialized fused operations or SIMD kernels for specific CPUs in github.com/gomlx/compute. Open an issue in the GoMLX repository or reach out in our Slack channel with questions!

Last updated December 1, 2026