Module Tolk_metal
Metal GPU device backend.
Tolk_metal provides a Tolk.Device.t that executes compiled kernels on Apple Metal GPUs. Construct a device with create and interact with it through the Tolk.Device interface.
For batched multi-kernel execution, Icb encodes a sequence of compute dispatches into a Metal indirect command buffer that can be replayed with a single GPU submission.
Kernel compilation
Kernels are compiled in two stages. The compiler first attempts offline compilation via Apple's private MTLCompiler framework (source to MTLB binary). When that framework is unavailable, it falls back to runtime source compilation through the Metal API.
Environment variables
METAL_FAST_MATH— when set to a non-zero integer, enables fast-math mode for runtime source compilation (the fallback path). Defaults to0(disabled).
Device
val create : string -> Tolk.Device.tcreate name is a Metal device identified by name.
The device uses the system default Metal GPU, an LRU-cached shared-memory allocator with blit-based buffer transfers, and a Metal renderer built from the device's Metal GPU family. An Stdlib.at_exit handler synchronizes in-flight work and releases the underlying Metal device, command queue, and shared event.
Raises Failure if no Metal GPU is available (e.g. running in a VM or on unsupported hardware).
Device state
module State : sig ... endIndirect command buffers
An indirect command buffer (ICB) pre-encodes a fixed sequence of compute dispatches that can be replayed with a single GPU submission. Buffers and dispatch dimensions can be updated between replays without re-encoding the full command sequence.
Typical usage:
Icb.createto allocate the ICB.Icb.encodefor each kernel in the batch.Icb.executeto submit.Icb.update_buffer/Icb.update_dispatchthenIcb.executefor subsequent iterations.Icb.releasewhen done.
module Icb : sig ... end