RAII handle for a compiled Metal compute pipeline.
Wraps a MTLComputePipelineState plus its dedicated
MTLCommandQueue (both CFRetain-ed) so that one pipeline can
be invoked many times without re-compiling MSL source. The Obj-C
types are erased to void* here to keep this header includable
from plain C++. Non-copyable, move-only.
See Also
compile_metal_kernel — factory that produces these.
run_metal_kernel — invokes the compiled pipeline.
Attributes
pipeline_ statevoid*id<MTLComputePipelineState>. nullptr if compilation failed.command_ queuevoid*id<MTLCommandQueue>. Owned independently from any other queue so kernel launches do not contend with MLX's own queue.namestd::stringpipeline_state. Useful for debug logs.Notes
Released in release_. Move constructors null out the
source so the destructor only releases once.
Constructors
1MetalKernel
void MetalKernel()Default-construct an invalid kernel handle.
Equivalent to a moved-from state — is_valid returns
false until populated by compile_metal_kernel.
Destructor
1~MetalKernel
void ~MetalKernel()Release the pipeline + queue on destruction.
Operators
1Methods
2Return true iff compilation produced a usable pipeline.
A false return means either Metal is unavailable on this
system or compile_metal_kernel failed silently (e.g.
device offline). Hard MSL syntax errors throw rather than
returning here.
Returns
booltrue iff pipeline_state != nullptr.
Release the retained Metal objects and clear the handle fields.
Notes
Idempotent — safe to call on an already-released kernel.