---
title: "ClikaRT::graph::CompiledFunction"
sidebar_label: "CompiledFunction"
description: "The self-capturing callable ClikaRT::compile returns. Move-only."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/graph/compile.h`

The self-capturing callable `ClikaRT::compile` returns. Move-only.

In every state a call returns exactly what calling the wrapped function eagerly returns; a captured graph serves a call only when it ran cleanly on matching shapes; every other path serves the eager result.

## Types

### enum State {#State}

<div class="api-signature">

`enum class` **`State`** `:` `std::uint8_t`

</div>

Where the function is in its capture lifecycle. `Fallback` means the function serves eagerly and will not re-capture on its own; after a failed capture, a failed graph run, shape drift past the re-capture budget, or a [`take_graph()`](./CompiledFunction.md#take_graph); [`reset()`](./CompiledFunction.md#reset) re-arms it.

| Enumerator | Description |
| --- | --- |
| `Pending` | no capture yet; the next healthy call captures |
| `Compiled` | a captured graph serves shape-matching calls |
| `Fallback` | serving eagerly until an explicit [reset()](./CompiledFunction.md#reset) |

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 166

</div>

## Member functions

### CompiledFunction(CompiledFunction) {#CompiledFunction}

<div class="api-signature">

**`CompiledFunction`**(`CompiledFunction&&`) `noexcept`

</div>

Move-only: transfers the compiled function.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 176

</div>

### operator=(CompiledFunction) {#operator-assign}

<div class="api-signature">

[`CompiledFunction`](./CompiledFunction.md)`&` **`operator=`**([`CompiledFunction`](./CompiledFunction.md)`&&`) `noexcept`

</div>

Move-assign: transfers the compiled function.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 178

</div>

### CompiledFunction(CompiledFunction) {#CompiledFunction-2}

<div class="api-signature">

**`CompiledFunction`**(`const CompiledFunction&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 179

</div>

### operator=(CompiledFunction) {#operator-assign-2}

<div class="api-signature">

[`CompiledFunction`](./CompiledFunction.md)`&` **`operator=`**(`const` [`CompiledFunction`](./CompiledFunction.md)`&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 180

</div>

### \~CompiledFunction() {#CompiledFunction-3}

<div class="api-signature">

**`~CompiledFunction`**()

</div>

Releases the compiled function.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 182

</div>

### call\_impl() {#call_impl}

<div class="api-signature">

[`Result`](../Result.md)`<std::vector<`[`Tensor`](../Tensor.md)`>>` **`call_impl`**(`const std::vector<`[`Tensor`](../Tensor.md)`>&` `inputs`)

</div>

Call the function: positional inputs in, positional outputs out, the same contract as calling the wrapped function directly. Raises [`ClikaRT::Error`](../Error.md) exactly when the eager function would. A graph-served call returns exactly the function's own outputs; state outputs the capture surfaces ride the captured graph ([`take_graph`](./CompiledFunction.md#take_graph)), never the call.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 190

</div>

### operator()() {#operator-call}

<div class="api-signature">

`std::vector<`[`Tensor`](../Tensor.md)`>` **`operator()`**(`const std::vector<`[`Tensor`](../Tensor.md)`>&` `inputs`)

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 191

</div>

### state() {#state}

<div class="api-signature">

[`State`](./CompiledFunction.md#State) **`state`**() `const`

</div>

The current capture state.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 196

</div>

### recapture\_count() {#recapture_count}

<div class="api-signature">

`std::int64_t` **`recapture_count`**() `const`

</div>

How many times drifted input shapes forced a re-capture.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 199

</div>

### take\_graph() {#take_graph}

<div class="api-signature">

[`ModelGraph`](./ModelGraph.md) **`take_graph`**()

</div>

Take the captured [`ModelGraph`](./ModelGraph.md) out of the function, the road into a serving pipeline ([`runtime::from_graph`](../runtime/index.md#from_graph)), where a node needs the graph's I/O specs at creation. Consuming: afterwards the function serves eagerly (`Fallback`) until [`reset()`](./CompiledFunction.md#reset). Available in `Compiled` only; in `Pending` or `Fallback` it raises a readable `NOT_FOUND` error; drive one healthy call through the function first. A graph whose function writes state in place keeps advancing that state and runs one call at a time (see the serving contract above).

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 210

</div>

### reset() {#reset}

<div class="api-signature">

`void` **`reset`**()

</div>

Re-arm capture: back to `Pending`, dropping any captured graph and the re-capture count. The explicit companion of the no-staleness-detection contract; after changing state the function reads (a weight swap, a device move), [`reset()`](./CompiledFunction.md#reset) and the next call re-captures.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 216

</div>

## Static data members

### kMaxRecaptures {#kMaxRecaptures}

<div class="api-signature">

`static` `std::int64_t` **`kMaxRecaptures`** `= 4`

</div>

Re-captures a [`CompiledFunction`](./CompiledFunction.md) performs before latching `Fallback`.

<div class="api-declared">

Declared in `ClikaRT/graph/compile.h`, line 173

</div>
