fhelium.compile._callable
Own callable specialization and reuse of linked execution programs.
CompiledCallable
class View source
CompiledCallable(source: Program | Compilation | Callable[_P, _R], *, backend: OperationBackend | None=None, pipeline: Pipeline | Callable[[CallSignature], Pipeline] | None=None, on_miss: Literal['compile', 'error']='compile', workspace: CompileWorkspace | None=None, inputs: Mapping[str, InputSpec] | None=None, material_names: Mapping[str, object] | None=None)Bases: Generic[_P, _R]
Prepare and repeatedly execute a Python function or Compile Program.
Construction does not capture, compile, allocate execution buffers, or run the computation. A first call prepares its input variant unless on_miss='error' requires prior prepare. Later calls reuse a linked executable when recorded input conditions match. No global capture context is installed, and compilation failures never silently execute Python.
pipeline is a complete caller-supplied pass sequence, or a function selecting one from a CallSignature. Omitting it selects dead-value removal, legal rotation hoisting, internal-transform reuse, and supported CUDA fusion while retaining native whole-operation routes. It does not insert rescaling or relinearization. Explicit pipelines replace that sequence rather than extending an implicit default.
backend=None uses the standard operation registry. Captured numerical data belongs to each Compilation's material_bindings. Capture may use several Engines as data providers; it does not establish an Engine owner or generate missing evaluation keys. Each specialization exposes the actual Backend selected for its transformed Program.
Inputs are flat Tensor/CKKS values and immutable scalar parameters. Capture supports pure Python functions, not async functions, methods, or arbitrary callable objects. A compiled helper is source-inlined during Eager capture; the outer pipeline and Backend govern its operations.
The top-level workspace and material binding dictionary are copied. Their materials and other custom mutable entries remain caller-owned and shared. Clear a callable after changing captured Python constants, and create a new one after changing a source Program or pass policy. Ordinary input Tensor contents may change without recompilation.
specializations
property
specializations: tuple[Specialization, ...]Return successfully linked variants in preparation order.
prepare
method
def prepare(*args: _P.args, **kwargs: _P.kwargs) -> Specialization: ...Capture, transform, and link this invocation without executing it.
Preparation is allowed with on_miss='error'. That option governs the callable's prepared-program cache, not a Backend compiler's kernel cache. Lazy Triton kernels may compile GPU binaries on the first actual call; execute representative warmup calls before timing or CUDA Graph capture. Material bindings and existing execution resources are supplied during linking; preparation neither generates evaluation keys nor executes the captured numerical computation.
with_backend
method
def with_backend(backend: OperationBackend) -> CompiledCallable[_P, _R]: ...Relink a snapshot of compiled variants against another Backend.
The returned callable starts without linked executables: call prepare first when on_miss='error'. Existing compilations retain their selected implementations and target/ABI assumptions. A changed Backend is not an instruction to silently reselect implementations or migrate machine code. New input signatures are prepared independently by each callable.
clear
method
def clear() -> None: ...Release this callable's variants without destroying caller resources.
Peers made with with_backend retain their previously shared compiled results. No allocator flush or resource mutation is performed.