Skip to main content
Every profiling API is a no-op when no profiler is active, and profiling never changes generated MSL. See the Profiling guide for concepts and worked examples.

enigma.profile()

Create a Profiler context manager. Installs the profiler in a contextvar so runtime dispatch routes through the timed GPU path; outside the context, dispatch takes the untimed fast path.

Parameters

Returns

A Profiler context manager. With capture set, entering the context starts GPU capture and requires MTL_CAPTURE_ENABLED=1 plus an existing MetalRuntime — it raises RuntimeError otherwise (never fails silently), and ValueError if the path does not end in .gputrace.

enigma.scope()

Context manager that profiles a named region and stamps the call path onto every event recorded inside it. Scopes nest; the stack of active scopes is the call path. No-op when no profiler is active.

Parameters

The flops and bytes metric keys drive derived GFLOP/s and GB/s; any other keys pass through to exports untouched. The scope stack is restored even if the body raises.

enigma.record_function()

Alias of scope with category="python", for marking Python-side regions.

enigma.get_active_profiler()

Return the Profiler active in the current context, or None.

enigma.register_kernel_hook()

Attach a metrics hook to every profiled dispatch of kernel_name. The hook fires only when the event has no metrics already, and is called as hook(kernel_name=..., grid=..., threads=...); it should return a metrics dict such as {"flops": ..., "bytes": ...}.

Parameters


enigma.unregister_kernel_hook()

Remove a previously registered hook. Safe to call when no hook is registered.

enigma.benchmark_kernel()

Benchmark a PreparedKernel using Metal GPU timestamps only — no profiler events and no Python timing inside the measured region. Warmup dispatches run on the untimed fast path to absorb pipeline creation, driver work, and unified-memory page residency.

Parameters

Returns

A KernelBenchmark. Raises ValueError if repeat < 1 or warmup < 0.

enigma.profile_kernel()

Profile repeated dispatches of a prepared kernel and return aggregated rows. Use this to understand where time goes; use benchmark_kernel to compare kernels.

Parameters

Returns

A ProfilerResult. Raises ValueError if repeat < 1 or warmup < 0.

Profiler

The object returned by enigma.profile(). Load a Hatchet export with hatchet.GraphFrame.from_literal(json.load(f)) to query hotspots or diff two profiles.

ProfilerResult

Aggregated view over events, returned by key_averages().

ProfilerRow


ProfilerEvent

A single timed event. Frozen dataclass.

KernelBenchmark

Returned by benchmark_kernel. Frozen dataclass; times come from GPU timestamps only.