zero-config-tensor-cluster
Zero-configuration Bonjour + QUIC distributed Metal 4 tensor allreduce cluster demo with P-256 node identity attestation, running purely in Go (//go:build darwin, CGO_ENABLED=0) with zero macOS Keychain or GUI prompts.
What It Composes
github.com/tmc/apple/x/meshdisc:
- Inspects local Thunderbolt, Ethernet, Wi-Fi, and loopback interfaces via
meshdisc.LocalLinks() (net.Interfaces, nw_path_monitor, and /dev/rdma* probing).
- Advertises
_tensormesh._tcp (or _tensormesh._udp via -service) with each rank's dynamically assigned QUIC UDP port (quic_port) and 65-byte ANSI X9.63 P-256 public key (pub) in the Bonjour TXT record — no hardcoded ports.
- Browses for cluster peers via
meshdisc.Browse and computes a deterministic coordinator and rank plan with meshdisc.BuildRendezvousConfig.
github.com/tmc/apple/x/enclave:
- Probes Secure Enclave availability via
enclave.Probe() and generates P-256 node identity keys via enclave.Generate (hardware Secure Enclave when available, with automatic ephemeral software SecKey fallback).
- Executes a mutual challenge-response P-256 ECDSA-SHA256 attestation handshake over a QUIC control stream, binding each peer's cryptographic identity to its Bonjour TXT
pub record.
github.com/tmc/apple/x/nwquic:
- Establishes a headless PSK-bound TLS 1.3 multiplexed QUIC connection (
nwquic.ListenContext / nwquic.Dial) without touching any macOS Keychain.
- Exchanges 16 MiB float32 tensors bidirectionally (32 MiB total wire application payload) across 4 concurrent full-duplex QUIC streams (
NWConnectionGroup) with distinct stream IDs ([8 12 16 20]).
- Exchanges RFC 9221 QUIC control datagrams (
sync:reduced barrier + done:<sha256> reduced-tensor parity confirmation) and collects NWDataTransferReport telemetry (TransferReport).
github.com/tmc/apple/x/metal4:
- Allocates resident buffer-backed
MTLTensor (float32) resources in each rank's metal4.CommandContext (MTL4CommandQueue, MTL4Compiler, MTLResidencySet, AllocatorPool).
- Runs Metal 4 GPU compute kernels (
fill_tensor and reduce_add) via MTL4ComputeCommandEncoder, MTL4ArgumentTable, and metal4.DispatchBarrier, verifying exact analytical values and bit-identical rank0 == rank1 SHA-256 digests.
Usage
2-Rank Self-Contained Loopback Mode (Default)
CGO_ENABLED=0 go run ./examples/network/zero-config-tensor-cluster
Multi-Mac LAN / Thunderbolt Mode (-role=node)
Run the same command on two Macs on the same LAN or Thunderbolt bridge (no IP addresses or ports to configure):
# On Mac A and Mac B:
CGO_ENABLED=0 go run ./examples/network/zero-config-tensor-cluster \
-role=node -cluster=studio-mesh -psk=shared-cluster-secret
Both Macs bind an ephemeral QUIC UDP port on their preferred Thunderbolt/LAN interface, advertise via Bonjour, discover each other, deterministically elect Rank 0 (coordinator) and Rank 1 (worker) via meshdisc.BuildRendezvousConfig, mutually attest with x/enclave, exchange 16 MiB float32 tensors over multiplexed QUIC streams, and verify bit-identical Metal 4 GPU reduce_add outputs.
Flags
-role (default loopback): loopback (2-rank self-contained) or node (multi-Mac LAN)
-service (default _tensormesh._tcp): Bonjour service type (_tensormesh._tcp or _tensormesh._udp)
-cluster: cluster session name (auto-generated in loopback mode)
-psk: pre-shared key secret for headless TLS 1.3 QUIC
-name: node name in -role=node mode (default: hostname)
-streams (default 4): number of concurrent bidirectional QUIC streams
-mib (default 16): per-rank float32 tensor size in MiB
-world-size (default 2): number of peers in -role=node mode
-discover-timeout (default 10s): Bonjour peer discovery timeout
-timeout (default 25s): overall operation timeout
Verification
CGO_ENABLED=0 go vet ./examples/network/zero-config-tensor-cluster
CGO_ENABLED=0 go test -v -count=1 -timeout 30s ./examples/network/zero-config-tensor-cluster
CGO_ENABLED=0 go run ./examples/network/zero-config-tensor-cluster
Measured Output (Apple M4 Max, macOS, CGO_ENABLED=0)
From CGO_ENABLED=0 go run ./examples/network/zero-config-tensor-cluster (16 MiB / 4,194,304 float32s per rank, 32 MiB bidirectional across 4 QUIC streams):
Zero-Config Tensor Cluster Allreduce (_tensormesh._tcp, zctc-11280-953000)
GPU : Apple M4 Max (Metal 4 compute)
Enclave P-256 : hardware Secure Enclave active
Local links : bridge0(thunderbolt+tb,mtu=1500), lo0(loopback,mtu=16384), en3(ethernet,mtu=1500), en0(wifi,mtu=1500), utun6(other,mtu=1280), en31(ethernet,mtu=1500)
Discovery : Bonjour _tensormesh._tcp -> 127.0.0.1:62984 in 1.015553s (world_size=2 backend=jaccl tb_mesh=true)
Attestation : mutual P-256 ECDSA-SHA256 OK (rank0->rank1=eb6e70bedb06ca5f in 104.143ms, rank1->rank0=e0794a7e0f48e8e7 in 77.99ms)
Tensor : 16.00 MiB (4194304 float32s) per rank across 4 bidirectional QUIC streams (IDs=[8 12 16 20])
QUIC exchange : 32.00 MiB bidirectional in 704.899ms (45.40 MiB/s aggregate)
Datagrams : sync RTT=84.926ms, done-parity RTT=7.819ms (RFC 9221 OK)
Metal 4 GPU : rank0 fill=19.263ms reduce=8.58ms | rank1 fill=7.942ms reduce=4.21ms
Allreduce hash : c2a2e2233272c33a4ff4aea9237e3d8a4b76bc53cbb7031246db762ff364c2a7 (rank0 == rank1 bit-identical: true)
TransferReport : sentApp=16777248 recvApp=16777216 sentWire=67163010 recvWire=67311141 retrans=0 minRTT=0s smoothedRTT=3ms paths=1
Total elapsed : 2.205866s
From CGO_ENABLED=0 go test -v -count=1 -timeout 30s ./examples/network/zero-config-tensor-cluster:
=== RUN TestZeroConfigTensorClusterLoopback
main_test.go:53: 16 MiB/rank (32 MiB bidirectional) over 4 streams [8 12 16 20]: discovered 127.0.0.1:61606 in 1.119042s, exchange=811.758ms (39.42 MiB/s), gpu fill=9.265ms/6.149ms reduce=3.235ms/4.146ms, syncDG=81.645ms doneDG=48.725ms, sha256=c2a2e2233272c33a
--- PASS: TestZeroConfigTensorClusterLoopback (2.79s)
=== RUN TestEnclaveAttestationVerification
--- PASS: TestEnclaveAttestationVerification (0.04s)
PASS
ok github.com/tmc/apple/examples/network/zero-config-tensor-cluster 3.649s