# litert::Options


`#include <litert_options.h>`

Manages the configuration options for compiling a LiteRT model.

## Summary

This class provides methods to set hardware accelerators, add custom operations, bind external tensors, and configure various backend-specific options (e.g., GPU, CPU, Qualcomm, MediaTek, etc.).

### Inheritance

Inherits from: internal::BaseHandle\< LiteRtOptions \>

| ### Constructors and Destructors ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a8cc9b018d820db9c3d60ae6e536f1a28()` ||
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1adbff5a84bd5ab6d325d0b8b49be296fc(LiteRtOptions compilation_options, OwnHandle owned)` Constructs an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options` object from a C handle. ||

| ### Public types ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a88c5cb5864e4548953d9bd60b76287dd` | using `absl::flat_hash_map< std::string, ScopedWeightSection >` A map from a group name to a weight section. |

| ### Friend classes ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a6ae84462afe657ef106b4947e01f36a9` | `friend class` |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a1994de2fb6841f41f629523ab7c4c384` | `friend class` |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1af3cb228a1f0fd1f60df8d3077a8d02c3` | `friend LiteRtStatus` |

| ### Public functions ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a125b1d8ae8af47c46d04ef8fe2ec2300(const std::string & custom_op_name, int custom_op_version, const LiteRtCustomOpKernel & custom_op_kernel, void *custom_op_kernel_user_data)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Adds a custom operator kernel. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1aab745ee9f35e297bf4f11bb43587c677(https://developers.google.com/edge/api/litert/c/classlitert/1-1-custom-op-kernel#classlitert_1_1_custom_op_kernel & custom_op_kernel)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Adds a custom operator kernel. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1ac8dc245feb648924ba7c878cdc0725aa(const std::string & signature_name, const std::string & tensor_name, void *data, size_t size_bytes)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Binds an external memory buffer to a specific tensor in the model. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a2744d62ee65207e2fde666086c14aee7(https://developers.google.com/edge/api/litert/c/classlitert/1-1-opaque-options#classlitert_1_1_opaque_options && options)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` **[Deprecated.](https://developers.google.com/edge/api/litert/c/deprecated/deprecated)** Use the `GetXXXOptions()` methods instead. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1ac695f1e0b4565378fe85f2dfa48f606e()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< CompilerOptions & >` Returns a reference to the compiler options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a76a07e61f8e5b2891b309a0f31322407()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< CpuOptions & >` Returns a reference to the CPU options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a47a22789781252c955e89deb0f7ce805()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< google_tensor::GoogleTensorOptions & >` Returns a reference to the Google Tensor options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a4237d549f3aa05591c1b3b50a6f4fae3()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< GpuOptions & >` Returns a reference to the GPU options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a1d44dac4f72f490a37e1b22ae0826367()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< LiteRtHwAcceleratorSet >` Retrieves the currently set hardware accelerators. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a72f6edcf1f797fabc4e7e357e0279a9c()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< intel_openvino::IntelOpenVinoOptions & >` Returns a reference to the Intel OpenVINO options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a3d7d870f3c5f66360b2b5f3ad4278ec3()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< mediatek::MediatekOptions & >` Returns a reference to the MediaTek options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a2084415f1cd6d4995e3792ec63e80f48()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< https://developers.google.com/edge/api/litert/c/classlitert/1-1-opaque-options#classlitert_1_1_opaque_options >` Retrieves the opaque options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a7ea59e986bb805a952276aba6ba327ff()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< qualcomm::QualcommOptions & >` Returns a reference to the Qualcomm options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a3ac7659533fcd40aa6630042b5c4ca54()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< RuntimeOptions & >` Returns a reference to the runtime options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a744a85a0945dcd3675025175d14d1b1d()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< samsung::SamsungOptions & >` Returns a reference to the Samsung options. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a2b39f8401cc4455361c15370090ff753(ScopedFile & scoped_file, https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a88c5cb5864e4548953d9bd60b76287dd sections)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Registers a `ScopedFile` that contains all external buffer groups. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1aec2a0e9d5b27a231f1aae7942793df8e(HwAccelerators accelerators)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Sets the hardware accelerators to be used for the model. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1a8b83aa2a4020173009ea2d734faee0be(HwAcceleratorSet accelerators)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Sets the hardware accelerators to be used for the model. |

| ### Public static functions ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options_1ab4411d3926130e416c5ea5cdb656f4bf()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options >` Creates a new `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options` object. |

## Public types

### ScopedWeightSectionMap

```
absl::flat_hash_map< std::string, ScopedWeightSection > ScopedWeightSectionMap
```
A map from a group name to a weight section.

A weight section contains the offset and length of a contiguous region inside a `ScopedFile` that backs a single external buffer group. This map provides the mapping between the group name and its section.

## Friend classes

### CompiledModel

```
friend class CompiledModel
```

### CompiledModelNext

```
friend class CompiledModelNext
```

### tools::ApplyPlugin

```
friend LiteRtStatus tools::ApplyPlugin(std::unique_ptr< tools::ApplyPluginRun > run)
```

## Public functions

### AddCustomOpKernel

```
Expected< void > AddCustomOpKernel(
  const std::string & custom_op_name,
  int custom_op_version,
  const LiteRtCustomOpKernel & custom_op_kernel,
  void *custom_op_kernel_user_data
)
```
Adds a custom operator kernel.

<br />

Details Parameters `custom_op_name` The name of the custom operator. `custom_op_version` The version of the custom operator. `custom_op_kernel` The custom operator kernel implementation. `custom_op_kernel_user_data` User data to be passed to the kernel. **Returns** An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object that is empty on success, or contains an error.

### AddCustomOpKernel

```
Expected< void > AddCustomOpKernel(
  CustomOpKernel & custom_op_kernel
)
```
Adds a custom operator kernel.

<br />

Details Parameters `custom_op_kernel` The custom operator kernel to add. **Returns** An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object that is empty on success, or contains an error.

### AddExternalTensorBinding

```
Expected< void > AddExternalTensorBinding(
  const std::string & signature_name,
  const std::string & tensor_name,
  void *data,
  size_t size_bytes
)
```
Binds an external memory buffer to a specific tensor in the model.

This function sets the tensor's allocation type to `kTfLiteCustom`, making it appear as a constant tensor with a pre-allocated buffer.


> [!NOTE]
> **Note:** `data` is owned by the caller and must outlive the lifetime of the `https://developers.google.com/edge/api/litert/c/classlitert/1-1-compiled-model#classlitert_1_1_compiled_model`. `size_bytes` must match the tensor's expected size.

<br />

Details Parameters `signature_name` The name of the signature containing the tensor. `tensor_name` The name of the tensor to bind. `data` A pointer to the external memory buffer. `size_bytes` The size of the external memory buffer in bytes. **Returns** An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object that is empty on success, or contains an error.

### AddOpaqueOptions

```
Expected< void > AddOpaqueOptions(
  OpaqueOptions && options
)
```
**[Deprecated.](https://developers.google.com/edge/api/litert/c/deprecated/deprecated)** Use the `GetXXXOptions()` methods instead.

### GetCompilerOptions

```
Expected< CompilerOptions & > GetCompilerOptions()
```
Returns a reference to the compiler options.

### GetCpuOptions

```
Expected< CpuOptions & > GetCpuOptions()
```
Returns a reference to the CPU options.

Use this to configure CPU-specific settings.

### GetGoogleTensorOptions

```
Expected< google_tensor::GoogleTensorOptions & > GetGoogleTensorOptions()
```
Returns a reference to the Google Tensor options.

Use this to configure Google Tensor-specific settings.

### GetGpuOptions

```
Expected< GpuOptions & > GetGpuOptions()
```
Returns a reference to the GPU options.

Use this to configure GPU-specific settings.

### GetHardwareAccelerators

```
Expected< LiteRtHwAcceleratorSet > GetHardwareAccelerators()
```
Retrieves the currently set hardware accelerators.

<br />

| Details ||
|---|---|
| **Returns** | An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object containing the set of hardware accelerators, or an error. |

### GetIntelOpenVinoOptions

```
Expected< intel_openvino::IntelOpenVinoOptions & > GetIntelOpenVinoOptions()
```
Returns a reference to the Intel OpenVINO options.

Use this to configure Intel OpenVINO-specific settings.

### GetMediatekOptions

```
Expected< mediatek::MediatekOptions & > GetMediatekOptions()
```
Returns a reference to the MediaTek options.

Use this to configure MediaTek-specific settings.

### GetOpaqueOptions

```
Expected< OpaqueOptions > GetOpaqueOptions()
```
Retrieves the opaque options.

<br />

| Details ||
|---|---|
| **Returns** | An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object containing the opaque options, or an error. |

### GetQualcommOptions

```
Expected< qualcomm::QualcommOptions & > GetQualcommOptions()
```
Returns a reference to the Qualcomm options.

Use this to configure Qualcomm-specific settings.

### GetRuntimeOptions

```
Expected< RuntimeOptions & > GetRuntimeOptions()
```
Returns a reference to the runtime options.

### GetSamsungOptions

```
Expected< samsung::SamsungOptions & > GetSamsungOptions()
```
Returns a reference to the Samsung options.

Use this to configure Samsung-specific settings.

### Options

```
 Options()=default
```

### Options

```
 Options(
  LiteRtOptions compilation_options,
  OwnHandle owned
)
```
Constructs an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options` object from a C handle.

<br />

Details Parameters `compilation_options` The C handle to the LiteRT options. `owned` Indicates whether this object should take ownership of the provided handle.

### SetExternalWeightScopedFile

```
Expected< void > SetExternalWeightScopedFile(
  ScopedFile & scoped_file,
  ScopedWeightSectionMap sections
)
```
Registers a `ScopedFile` that contains all external buffer groups.

<br />

Details Parameters `scoped_file` The file containing the external weights. `sections` A map from group names to their respective sections in the file. **Returns** An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object that is empty on success, or contains an error.

### SetHardwareAccelerators

```
Expected< void > SetHardwareAccelerators(
  HwAccelerators accelerators
)
```
Sets the hardware accelerators to be used for the model.

<br />

Details Parameters `accelerators` A bitmask of hardware accelerators. **Returns** An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object that is empty on success, or contains an error.

### SetHardwareAccelerators

```
Expected< void > SetHardwareAccelerators(
  HwAcceleratorSet accelerators
)
```
Sets the hardware accelerators to be used for the model.

<br />

Details Parameters `accelerators` A set of hardware accelerators. **Returns** An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object that is empty on success, or contains an error.

## Public static functions

### Create

```
Expected< Options > Create()
```
Creates a new `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options` object.

<br />

| Details ||
|---|---|
| **Returns** | An `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected` object containing the new `https://developers.google.com/edge/api/litert/c/classlitert/1-1-options#classlitert_1_1_options` instance, or an error if creation fails. |