Skip to content
fn

compile_metal_kernel

→MetalKernel
MetalKernel compile_metal_kernel(const int & source, const int & function_name)

Compile (or fetch from the global cache) a Metal compute pipeline.

Hashes (source, function_name) to form a cache key, then on miss compiles source via newLibraryWithSource:, looks up function_name inside the resulting library, and creates a MTLComputePipelineState + dedicated MTLCommandQueue.

See Also

run_metal_kernel — invokes the compiled pipeline.

Parameters

sourceconst std::string&
Complete MSL source text containing at least one kernel function named function_name.
function_nameconst std::string&
The MSL kernel function symbol to bind.

Returns

MetalKernel

A valid kernel handle on success. An invalid handle (is_valid() == false) is returned when Metal is unavailable (no GPU device on the host).

Raises

:runtime_error
On MSL compilation failure or pipeline-state creation error.

Notes

The pipeline cache is protected by an internal mutex, so concurrent callers safely share compiled kernels. Cached entries live for the lifetime of the process.