tensor-broker

command
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tensor-broker

tensor-broker demonstrates zero-copy cross-process sharing of a 64 MiB FP16 tensor ([4096, 8192], 67,108,864 bytes) on macOS using x/xpctensor (IOSurfaceCreateXPCObject / IOSurfaceLookupFromXPCObject + x/zerocopy SurfacePool / MTLBuffer) and a self-contained parent/child subprocess benchmark (os.Args[0] -role=client).

What it proves

  1. 64 MiB FP16 handoff latency vs. Unix-domain socket copy control: Measures xpctensor.Client.Fetch (XPC Mach send right + MTLBuffer wrap) and cross-process IOSurfaceLookup + NewBufferWithBytesNoCopy against a 64 MiB payload copy over a Unix-domain socket.
  2. Physical memory aliasing across processes:
    • Parent flips sentinel bytes at offsets 0, n/3, n/2, and n-1 in its MTLBuffer and confirms the child observes both the write and the restore through its own MTLBuffer.Contents() without transferring tensor bytes.
    • Child writes 0xCAFEBABEDEADBEEF at offset 64 of its MTLBuffer; parent reads it directly from its own MTLBuffer.
  3. Crash cleanup on SIGKILL:
    • Abrupt XPC client disconnect triggers BrokerOptions.OnPeerDisconnect and decrements IOSurfaceGetUseCount back to 0.
    • Sending SIGKILL to the child subprocess holding the IOSurface lease causes the kernel to tear down the child's descriptors immediately, reclaiming the lease (useCount 1 -> 0, IOSurfaceIsInUse == false).

Usage

CGO_ENABLED=0 go run ./examples/xpc/tensor-broker
CGO_ENABLED=0 go test -v -count=1 ./examples/xpc/tensor-broker

Flags:

  • -size-mib (default 64): tensor size in MiB (FP16).
  • -iters (default 5): benchmark iterations.
  • -role (demo or client): internal re-exec switch for the child process.

Measured results

Measured on Apple M4 Max (128 GiB), macOS 26.6.2 (25G83), CGO_ENABLED=0:

xpctensor / tensor-broker benchmark (64 MiB FP16 tensor, 67108864 bytes)
=======================================================================
[1] x/xpctensor XPC Broker (IOSurfaceCreateXPCObject -> MTLBuffer)
    Fetch latency (median / min): 289 µs / 151 µs
    Zero-copy aliasing verified:  true
    Disconnect lease cleanup:     true

[2] Cross-Process Parent <-> Child Subprocess
    Zero-copy attach (median):    233 µs (IOSurfaceLookup: 19 µs, MTLBuffer wrap: 27 µs)
    UDS 64 MiB copy (median):    1392.91 ms (45.9 MiB/s)
    Speedup (zero-copy vs UDS):   5957.9x
    Parent->Child alias check:    true
    Child->Parent sentinel seen:  true
    SIGKILL cleanup:              useCount 1 -> 0, inUse=false (reclaimed in 3345 µs)

Documentation

Rendered for darwin/amd64

Overview

Command tensor-broker demonstrates zero-copy 64 MiB FP16 tensor sharing using x/xpctensor (XPC + IOSurface + Metal) and a self-contained parent/child subprocess proof of:

  1. 64 MiB FP16 tensor handoff latency (µs) vs. Unix-domain socket copy control
  2. Physical memory aliasing across processes (verified via Metal/CPU sentinels)
  3. Kernel-guaranteed ref/lease reclamation after child SIGKILL

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL