Documentation
¶
Overview ¶
Package metal owns a Metal device and its default command queue and provides buffer and pipeline construction helpers.
Raw, Queue, and objects constructed from a Device are borrowed from or derived from that Device. Callers must finish command buffers and release derived objects before closing the Device. Device methods may be called concurrently, but borrowed objects must not be used concurrently with Close.
Index ¶
- Variables
- func SetScalar[T Scalar](enc metal.MTLComputeCommandEncoder, v T, index int)
- func Threadgroups(n, group int) metal.MTLSize
- func Threads(n int) metal.MTLSize
- type Device
- func (d *Device) AllocBuffer(bytes int) (metal.MTLBuffer, error)
- func (d *Device) AllocBufferBytes(data []byte) (metal.MTLBuffer, error)
- func (d *Device) Close() error
- func (d *Device) CompileLibrary(source string) (metal.MTLLibrary, error)
- func (d *Device) Name() string
- func (d *Device) NewComputePipeline(lib metal.MTLLibrary, name string) (metal.MTLComputePipelineState, error)
- func (d *Device) Queue() metal.MTLCommandQueue
- func (d *Device) Raw() metal.MTLDevice
- type Scalar
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("metal: device is closed")
ErrClosed is returned by operations on a closed Device.
Functions ¶
func SetScalar ¶
func SetScalar[T Scalar](enc metal.MTLComputeCommandEncoder, v T, index int)
SetScalar binds v into enc's argument table at index. Kernel scalars are small and change on every dispatch, so copying them inline is cheaper than allocating a buffer per argument per dispatch.
func Threadgroups ¶
Threadgroups returns the one-dimensional size covering n threads in groups of group threads each, rounding up so a partial final group still runs. A group below one is treated as one.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents an Apple Metal GPU device.
func (*Device) AllocBuffer ¶
AllocBuffer allocates a shared Metal buffer owned by the caller.
Example ¶
package main
import (
"fmt"
"github.com/tmc/apple/objectivec"
"github.com/tmc/lib/apple/x/metal"
)
func main() {
dev, err := metal.NewDevice()
if err != nil {
fmt.Println(err)
return
}
defer dev.Close()
buf, err := dev.AllocBuffer(16)
if err != nil {
fmt.Println(err)
return
}
defer objectivec.ObjectFromID(buf.GetID()).Release()
fmt.Println(buf.Length())
}
Output: 16
func (*Device) AllocBufferBytes ¶
AllocBufferBytes copies host data into a shared buffer owned by the caller.
func (*Device) Close ¶
Close releases the command queue and Metal device. It is idempotent. The caller must complete all command buffers and release device-derived objects before calling Close. Close waits for Device methods already in progress; borrowed values returned by Raw and Queue must not be used concurrently with Close.
func (*Device) CompileLibrary ¶
func (d *Device) CompileLibrary(source string) (metal.MTLLibrary, error)
CompileLibrary compiles MSL source into a library owned by the caller. The caller must release the library after creating its functions and pipelines.
func (*Device) NewComputePipeline ¶
func (d *Device) NewComputePipeline(lib metal.MTLLibrary, name string) (metal.MTLComputePipelineState, error)
NewComputePipeline creates a pipeline owned by the caller. The temporary function used to create the pipeline is released before the method returns.
type Scalar ¶
type Scalar interface {
~int8 | ~int16 | ~int32 | ~int64 |
~uint8 | ~uint16 | ~uint32 | ~uint64 |
~float32 | ~float64
}
Scalar is the set of types a Metal kernel scalar argument may have.
Go's int and uint are deliberately absent. They are 64 bits wide on Apple silicon, while MSL's int and uint are 32, so binding one writes twice the bytes the kernel reads and leaves the kernel with a value it never agreed to. Convert to a fixed-width type at the call site instead.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package egraph provides equality saturation, expression extraction, and execution-plan telemetry.
|
Package egraph provides equality saturation, expression extraction, and execution-plan telemetry. |
|
Package mempool provides typed memory allocations and pooling for Apple Silicon Unified Memory.
|
Package mempool provides typed memory allocations and pooling for Apple Silicon Unified Memory. |
|
Package metalattn provides SIMD-group causal FlashAttention kernels and configurations for Apple Metal.
|
Package metalattn provides SIMD-group causal FlashAttention kernels and configurations for Apple Metal. |
|
Package metalbench provides experimental wall-clock timing and empirical autotuning harnesses for Apple Silicon Metal.
|
Package metalbench provides experimental wall-clock timing and empirical autotuning harnesses for Apple Silicon Metal. |
|
Package metalcapture provides pure Go portable recording, serialization, and inspection of Metal profiling captures.
|
Package metalcapture provides pure Go portable recording, serialization, and inspection of Metal profiling captures. |
|
Package metalgrammar provides zero-overhead FSM grammar and bitmask logit filtering for Metal.
|
Package metalgrammar provides zero-overhead FSM grammar and bitmask logit filtering for Metal. |
|
Package metalgraphexec provides Metal Indirect Command Buffer (ICB) and compute graph execution caching for single-launch multi-layer transformer dispatch on Apple Silicon GPUs.
|
Package metalgraphexec provides Metal Indirect Command Buffer (ICB) and compute graph execution caching for single-launch multi-layer transformer dispatch on Apple Silicon GPUs. |
|
Package metalicb provides Indirect Command Buffer (ICB) execution abstractions for GPU-driven hardware graph replays on Apple Silicon.
|
Package metalicb provides Indirect Command Buffer (ICB) execution abstractions for GPU-driven hardware graph replays on Apple Silicon. |
|
Package metalio provides high-performance asynchronous storage ingestion and streaming into Apple Unified Memory buffers.
|
Package metalio provides high-performance asynchronous storage ingestion and streaming into Apple Unified Memory buffers. |
|
Package metalir provides a symbolic computation graph and memory arena planner for Apple Metal.
|
Package metalir provides a symbolic computation graph and memory arena planner for Apple Metal. |
|
Package metalkv provides static KV-cache management in Apple Silicon Unified Memory.
|
Package metalkv provides static KV-cache management in Apple Silicon Unified Memory. |
|
Package metalmegakernel provides experimental Metal kernels used by the llama inference example.
|
Package metalmegakernel provides experimental Metal kernels used by the llama inference example. |
|
Package metalmem provides typed memory management, zero-copy unified memory allocations, and host-device copy primitives for Apple Silicon Metal GPUs.
|
Package metalmem provides typed memory management, zero-copy unified memory allocations, and host-device copy primitives for Apple Silicon Metal GPUs. |
|
Package metalmlx is an experimental, minimal Go conversion of the host-side runtime of MLX's Metal backend (mlx/backend/metal), built on the pure-Go Metal bindings.
|
Package metalmlx is an experimental, minimal Go conversion of the host-side runtime of MLX's Metal backend (mlx/backend/metal), built on the pure-Go Metal bindings. |
|
Package metalmoe provides Mixture of Experts routing and expert cache offloading for Apple Silicon Metal.
|
Package metalmoe provides Mixture of Experts routing and expert cache offloading for Apple Silicon Metal. |
|
Package metalmtp implements Multi-Token Prediction (MTP) and speculative tree decoding optimized via equality saturation (E-Graph) megakernels on Apple Metal.
|
Package metalmtp implements Multi-Token Prediction (MTP) and speculative tree decoding optimized via equality saturation (E-Graph) megakernels on Apple Metal. |
|
Package metalmxfp4 provides Apple Silicon Metal compute kernels for OCP Microscaling FP4 (E2M1) dequantization and high-throughput fused GEMV matrix-vector multiplication.
|
Package metalmxfp4 provides Apple Silicon Metal compute kernels for OCP Microscaling FP4 (E2M1) dequantization and high-throughput fused GEMV matrix-vector multiplication. |
|
Package metalprof provides Apple Metal capture helpers, hardware timestamp sampling, caller-supplied event recording, and pprof integration.
|
Package metalprof provides Apple Metal capture helpers, hardware timestamp sampling, caller-supplied event recording, and pprof integration. |
|
Package metalquant encodes and decodes Q4_0 and Q8_0 blocks used by Metal kernels.
|
Package metalquant encodes and decodes Q4_0 and Q8_0 blocks used by Metal kernels. |
|
Package metalref provides host CPU reference oracle implementations for parity testing.
|
Package metalref provides host CPU reference oracle implementations for parity testing. |
|
Package metalsafetensors reads safetensors files and copies selected tensors into shared Metal buffers.
|
Package metalsafetensors reads safetensors files and copies selected tensors into shared Metal buffers. |
|
Package metalsample provides greedy argmax selection for Apple Metal.
|
Package metalsample provides greedy argmax selection for Apple Metal. |
|
Package metalspec provides speculative decoding drafters, tree verifiers, and candidate token verification for Metal.
|
Package metalspec provides speculative decoding drafters, tree verifiers, and candidate token verification for Metal. |
|
Package metaltensor provides high-level symbolic and device-backed tensor operations for Apple Silicon Metal.
|
Package metaltensor provides high-level symbolic and device-backed tensor operations for Apple Silicon Metal. |
|
Package metalx compiles Metal Shading Language libraries and owns device-scoped compute pipeline caches.
|
Package metalx compiles Metal Shading Language libraries and owns device-scoped compute pipeline caches. |