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’ssimdandsimd/archsimdpackages alongside handwritten assembly microkernels for:- AMD64:
AVX2andAVX-512(includingAVX-512 VNNI) microkernels forDotGeneral,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 acrossDotGeneral/FusedDense(Float32,Float16,BFloat16,Float64),FusedScaledDotProductAttention, reductions, trailing-axis binary broadcasts,Where, and hardwareFloat16/BFloat16conversions—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).
- AMD64:
- Hierarchical 3-Level Parallel Scheduler: Prioritizes
Inter-Call>Intra-Op>Inter-Opparallelism 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), andQuantNF4for 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 concurrentExecutable.Execute()calls to at mostN(whenN > 0;parallelism=1disables intra-op multi-threading;parallelism=0disables parallelism;parallelism=-1is 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), andruntime.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, useintra_call_parallelism=<N>(see below) to cap per-call fan-out while keeping full inter-call concurrency, lowerparallelism=<N>for single-stream inference, or pin one process per NUMA node (e.g., vianumactl). For performance-critical deployments, benchmark a few explicit values.
- Default: Uses physical CPU cores (
intra_call_parallelism=<N>: Optional upper bound on the number of workers (intra-op + inter-op) used within any singleExecutable.Execute()call, without reducing the inter-call concurrency cap set byparallelism(defaults to0, meaning the same limit asparallelism). 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 to8, capped at the effectiveparallelism).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>(defaultbalanced): Controls constant weight and supporting-tensor (scale,zero_point,bias) caching forFusedQuantizedDense(accepts aliasestrue/1or barequantized_cacheforalways, andfalse/none/0fornever):balanced(default): Decides once per constant at compile time, caching a tensor only when its cached representation is<= 4 MiBand 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 smallFloat16/BFloat16scales 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 (float32panels) uncached to preserve low RAM and DRAM bandwidth.always(ortrue,1, or barequantized_cache): Caches every eligible constant quantized weight (both Mode B K4 panels and Mode Afloat32GEMM 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(ornone,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.mdfor a full breakdown of Go backend memory management, expansion ratios, and caching behavior.
constant_arena[=<true|false>](defaulttrue): Allocates pre-packed/cached constant weight panels into 2 MiB-aligned off-heapmmapchunks advised withMADV_HUGEPAGEon Linux, reference-counted per compiledBuilder/Executableso chunks are immediately unmapped back to the OS once all referencing executables (or the backend) are finalized. Also configurable viaGOMLX_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 to0orfalseto disable AVX-512 SIMD implementations (enabled by default when supported by the CPU).GOMLX_GO_SIMD_AVX512_BF16: Set to0orfalseto disable nativeAVX512_BF16(VDPBF16PS)BFloat16matmul kernels and fall back to AVX-512 FP32-unpack kernels (enabled by default when supported by the CPU).GOMLX_GO_CONSTANT_ARENA: Set to0orfalseto disable the off-heapMADV_HUGEPAGEconstant arena (enabled by default).GOMLX_GO_SIMD_AVX2: Set to0orfalseto disable AVX2 SIMD implementations (enabled by default when supported by the CPU).GOMLX_GO_SIMD_NEON: Set to0orfalseto disable ARM64 NEON (FEAT_ASIMD) SIMD implementations (enabled by default when supported by the CPU).GOMLX_GO_SIMD_SVE: Set to0orfalseto disable ARM64 SVE SIMD implementations (enabled by default when supported by the CPU).GOMLX_GO_SIMD_SME: Set to0orfalseto 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 to0orfalseto 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 correspondingGOMLX_GO_AVX2_*,GOMLX_GO_NEON_*,GOMLX_GO_NOSIMD_*): Override cache blocking parameters (KC,MC,NC) for matrix multiplication.GOMLX_GO_DOT_MATMUL: Set to0orfalseto disable the tiledmatmulimplementation inDotGeneral(enabled by default).GOMLX_GO_FUSION: Set to0orfalseto disable fused operations (enabled by default).GOMLX_OP_PROFILE: Enables per-operator timing summaries in the Go backend. Set to1(ortrue) to print a per-op wall/CPU time breakdown every5timed runs (after1warm-up run), or set to<N>(N > 1) to print everyNruns (combine withGOMLX_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