18#include <ove/storage.h>
21#ifdef CONFIG_OVE_INFER
37template <
size_t ArenaSize = 0>
class Model
46 explicit Model(
const struct ove_model_config &cfg)
48#ifdef CONFIG_OVE_ZERO_HEAP
49 int err = ove_model_init(&handle_, &storage_, arena_, &cfg);
51 int err = ove_model_create(&handle_, &cfg);
53 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
60#ifdef CONFIG_OVE_ZERO_HEAP
61 ove_model_deinit(handle_);
63 ove_model_destroy(handle_);
67 Model(
const Model &) =
delete;
68 Model &operator=(
const Model &) =
delete;
70#ifdef CONFIG_OVE_ZERO_HEAP
71 Model(Model &&) =
delete;
72 Model &operator=(Model &&) =
delete;
77 other.handle_ =
nullptr;
84 ove_model_destroy(handle_);
85 handle_ = other.handle_;
86 other.handle_ =
nullptr;
98 return from_rc(ove_model_invoke(handle_));
104 struct ove_tensor_info info;
105 if (ove_model_input(handle_, index, &info) != OVE_OK)
107 return static_cast<T *
>(info.data);
111 template <
typename T>
const T *
output_data(
unsigned int index = 0)
const
113 struct ove_tensor_info info;
114 if (ove_model_output(handle_, index, &info) != OVE_OK)
116 return static_cast<const T *
>(info.data);
125 struct ove_tensor_info info {
127 const int rc = ove_model_input(handle_, index, &info);
134 struct ove_tensor_info info {
136 const int rc = ove_model_output(handle_, index, &info);
143 return ove_model_last_inference_us(handle_);
153 ove_model_t handle_ =
nullptr;
154#ifdef CONFIG_OVE_ZERO_HEAP
155 ove_model_storage_t storage_ = {};
156 alignas(16) uint8_t arena_[ArenaSize] = {};
RAII wrapper for an ML inference model session.
Definition infer.hpp:38
T * input_data(unsigned int index=0)
Get a typed pointer to input tensor data; nullptr on failure.
Definition infer.hpp:102
Result< struct ove_tensor_info > output(unsigned int index) const noexcept
Get full tensor descriptor for an output.
Definition infer.hpp:132
Result< struct ove_tensor_info > input(unsigned int index) const noexcept
Get full tensor descriptor for an input.
Definition infer.hpp:123
Model(const struct ove_model_config &cfg)
Construct a model from the given configuration.
Definition infer.hpp:46
Result< void > invoke() noexcept
Run the model forward pass.
Definition infer.hpp:96
uint64_t last_inference_us() const
Return last inference duration in microseconds.
Definition infer.hpp:141
const T * output_data(unsigned int index=0) const
Get a typed pointer to output tensor data (const); nullptr on failure.
Definition infer.hpp:111
Model & operator=(Model &&other) noexcept
Move-assignment — destroys current model, then takes other's handle.
Definition infer.hpp:80
ove_model_t handle() const
Access the underlying C handle.
Definition infer.hpp:147
Model(Model &&other) noexcept
Move constructor — transfers handle ownership; source becomes empty.
Definition infer.hpp:75
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:20
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139