oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
infer.h
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
30#ifndef OVE_INFER_H
31#define OVE_INFER_H
32
33#include "ove/types.h"
34#include "ove_config.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#include "ove/storage.h"
41
49 OVE_TENSOR_FLOAT32 = 0,
50 OVE_TENSOR_INT8 = 1,
51 OVE_TENSOR_UINT8 = 2,
52 OVE_TENSOR_INT16 = 3,
53 OVE_TENSOR_INT32 = 4,
54};
55
64 void *data;
65 size_t size;
67 unsigned int ndims;
68 int dims[5];
69};
70
80 const void *model_data;
81 size_t model_size;
82 size_t arena_size;
83};
84
85#ifdef CONFIG_OVE_INFER
86
103int ove_model_init(ove_model_t *model, ove_model_storage_t *storage,
104 void *arena, const struct ove_model_config *cfg);
105
115void ove_model_deinit(ove_model_t model);
116
117/* _create / _destroy — heap-gated */
118#ifdef OVE_HEAP_INFER
119
133int ove_model_create(ove_model_t *model,
134 const struct ove_model_config *cfg);
135
143void ove_model_destroy(ove_model_t model);
144
145#elif !defined(__ZIG_CIMPORT__) /* !OVE_HEAP_INFER — zero-heap mode */
146
147/* Unified macro — arena_size must be a compile-time constant. */
148#define ove_model_create(pm, cfg) \
149 ({ static ove_model_storage_t _ove_stor_; \
150 static uint8_t __attribute__((aligned(16))) \
151 _ove_arena_[(cfg)->arena_size]; \
152 ove_model_init((pm), &_ove_stor_, _ove_arena_, (cfg)); })
153#define ove_model_destroy(m) ove_model_deinit(m)
154
155#endif /* OVE_HEAP_INFER */
156
168int ove_model_invoke(ove_model_t model);
169
184int ove_model_input(ove_model_t model, unsigned int index,
185 struct ove_tensor_info *info);
186
201int ove_model_output(ove_model_t model, unsigned int index,
202 struct ove_tensor_info *info);
203
213uint64_t ove_model_last_inference_us(ove_model_t model);
214
215#else /* !CONFIG_OVE_INFER */
216
218static inline int ove_model_create(ove_model_t *m, const struct ove_model_config *c) { (void)m; (void)c; return OVE_ERR_NOT_SUPPORTED; }
219static inline void ove_model_destroy(ove_model_t m) { (void)m; }
220static inline int ove_model_invoke(ove_model_t m) { (void)m; return OVE_ERR_NOT_SUPPORTED; }
221static inline int ove_model_input(ove_model_t m, unsigned int i, struct ove_tensor_info *t) { (void)m; (void)i; (void)t; return OVE_ERR_NOT_SUPPORTED; }
222static inline int ove_model_output(ove_model_t m, unsigned int i, struct ove_tensor_info *t) { (void)m; (void)i; (void)t; return OVE_ERR_NOT_SUPPORTED; }
223static inline uint64_t ove_model_last_inference_us(ove_model_t m) { (void)m; return 0; }
226#endif /* CONFIG_OVE_INFER */
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif /* OVE_INFER_H */
233
ove_tensor_type
Tensor element types.
Definition infer.h:48
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_model * ove_model_t
Opaque handle for an ML inference model session.
Definition types.h:118
Configuration for an ML inference session.
Definition infer.h:79
size_t model_size
Definition infer.h:81
const void * model_data
Definition infer.h:80
size_t arena_size
Definition infer.h:82
Tensor descriptor returned by ove_model_input() / ove_model_output().
Definition infer.h:63
unsigned int ndims
Definition infer.h:67
void * data
Definition infer.h:64
int dims[5]
Definition infer.h:68
size_t size
Definition infer.h:65
enum ove_tensor_type type
Definition infer.h:66