Send feedback
Stay organized with collections
Save and categorize content based on your preferences.
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
Options
(LiteRtOptions compilation_options, OwnHandle owned)
Constructs an Options
object from a C handle.
using absl::flat_hash_map< std::string, ScopedWeightSection >
A map from a group name to a weight section.
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.
Adds a custom operator kernel.
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.
Returns a reference to the compiler options.
Returns a reference to the CPU options.
Expected
< google_tensor::GoogleTensorOptions & >
Returns a reference to the Google Tensor options.
Returns a reference to the GPU options.
Retrieves the currently set hardware accelerators.
Expected
< intel_openvino::IntelOpenVinoOptions & >
Returns a reference to the Intel OpenVINO options.
Expected
< mediatek::MediatekOptions & >
Returns a reference to the MediaTek options.
Retrieves the opaque options.
Expected
< qualcomm::QualcommOptions & >
Returns a reference to the Qualcomm options.
Returns a reference to the runtime options.
Returns a reference to the Samsung options.
Registers a ScopedFile
that contains all external buffer groups.
Sets the hardware accelerators to be used for the model.
Sets the hardware accelerators to be used for the model.
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
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.
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 Expected
object that is empty on success, or contains an error.
AddCustomOpKernel
Expected
< void > AddCustomOpKernel( CustomOpKernel
& custom_op_kernel
)
Adds a custom operator kernel.
Parameters
custom_op_kernel
The custom operator kernel to add.
Returns
An 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: data
is owned by the caller and must outlive the lifetime of the CompiledModel
. size_bytes
must match the tensor's expected size.
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 Expected
object that is empty on success, or contains an error.
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.
GetIntelOpenVinoOptions
Expected
< intel_openvino::IntelOpenVinoOptions & > GetIntelOpenVinoOptions()
Returns a reference to the Intel OpenVINO options.
Use this to configure Intel OpenVINO-specific settings.
Expected
< mediatek::MediatekOptions & > GetMediatekOptions()
Returns a reference to the MediaTek options.
Use this to configure MediaTek-specific settings.
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 Options
object from a C handle.
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.
Parameters
scoped_file
The file containing the external weights.
sections
A map from group names to their respective sections in the file.
Returns
An 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.
Parameters
accelerators
A bitmask of hardware accelerators.
Returns
An 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.
Parameters
accelerators
A set of hardware accelerators.
Returns
An Expected
object that is empty on success, or contains an error.
Public static functions
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-05-28 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-05-28 UTC."],[],[]]