SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_types.h
Go to the documentation of this file.
1 #ifndef _MA_TYPES_H_
2 #define _MA_TYPES_H_
3 
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <string.h>
8 
9 #include "ma_compiler.h"
10 #include "ma_config_internal.h"
11 
12 #ifdef __cplusplus
13 
14 #include <cstddef>
15 #include <cstdint>
16 #include <vector>
17 
18 extern "C" {
19 #endif
20 
21 typedef enum {
22  MA_FAILED = -1, // UNKOWN ERROR
23  MA_OK = 0, // No error
24  MA_AGAIN = 1, // Not ready yet
25  MA_ELOG = 2, // Logic error
26  MA_ETIMEOUT = 3, // Timeout
27  MA_EIO = 4, // IO error
28  MA_EINVAL = 5, // Invalid argument
29  MA_ENOMEM = 6, // Not enough memory
30  MA_EBUSY = 7, // Busy
31  MA_ENOTSUP = 8, // Not supported yet
32  MA_EPERM = 9, // Operation not permitted
33  MA_ENOENT = 10, // No such entity
34  MA_EEXIST = 11, // Entity already exists
35  MA_OVERFLOW = 12, // Overflow
36 } ma_err_t;
37 
38 typedef struct {
39  void* pool;
40  size_t size;
41  bool own;
43 
44 typedef struct {
45  float scale;
46  int32_t zero_point;
48 
49 typedef struct {
50  uint32_t size;
51  int32_t dims[MA_ENGINE_SHAPE_MAX_DIM];
52 } ma_shape_t;
53 
54 typedef enum {
73 
74 typedef struct {
78  size_t size;
79 #if MA_USE_ENGINE_TENSOR_INDEX
80  size_t index;
81 #endif
82 #if MA_USE_ENGINE_TENSOR_NAME
83  const char* name;
84 #endif
85  union {
86  void* data;
87  uint8_t* u8;
88  int8_t* s8;
89  uint16_t* u16;
90  int16_t* s16;
91  uint32_t* u32;
92  int32_t* s32;
93  uint64_t* u64;
94  int64_t* s64;
95  float* f32;
96  double* f64;
97  } data;
98  bool is_physical; // For physical tensor
99  bool is_variable; // For constant tensor
100  void* external_handler = nullptr;
101 } ma_tensor_t;
102 
103 typedef enum {
115 
116 typedef enum {
123 
124 typedef struct {
125  uint32_t size;
126  uint16_t width;
127  uint16_t height;
130  uint32_t timestamp;
131  bool key;
132  uint8_t index;
133  uint8_t count;
134  bool physical; // For physical frame
135  uint8_t* data;
136 } ma_img_t;
137 
138 typedef struct {
139  int64_t preprocess;
140  int64_t inference;
141  int64_t postprocess;
142 } ma_perf_t;
143 
144 typedef struct {
145  float x;
146  float y;
147 } ma_pt2f_t;
148 
149 typedef struct {
150  float x;
151  float y;
152  float z;
153 } ma_pt3f_t;
154 
155 typedef struct {
156  float x;
157  float y;
158  float z;
159  float t;
160 } ma_pt4f_t;
161 
162 typedef struct {
163  size_t stride;
164  size_t split;
165  size_t size;
166  size_t start;
168 
169 typedef struct {
170  float x;
171  float y;
172  float score;
173  int target;
174 } ma_point_t;
175 
176 typedef struct {
177  float score;
178  int target;
179 } ma_class_t;
180 
181 struct ma_bbox_t {
182  float x;
183  float y;
184  float w;
185  float h;
186  float score;
187  int target;
188 };
189 
190 #ifdef __cplusplus
191 struct ma_bbox_ext_t : public ma_bbox_t {
192  size_t level;
193  size_t index;
194 };
195 #endif
196 
197 struct ma_types {
198  /* data */
199 };
200 
201 #ifdef __cplusplus
202 struct ma_keypoint2f_t {
203  ma_bbox_t box;
204  std::vector<ma_pt2f_t> pts;
205 };
206 
207 struct ma_keypoint3f_t {
208  ma_bbox_t box;
209  std::vector<ma_pt3f_t> pts;
210 };
211 
212 struct ma_keypoint4f_t {
213  ma_bbox_t box;
214  std::vector<ma_pt4f_t> pts;
215 };
216 
217 struct ma_segm2f_t {
218  ma_bbox_t box;
219  struct {
220  uint16_t width;
221  uint16_t height;
222  std::vector<uint8_t> data;
223  } mask;
224 };
225 
226 
227 #endif
228 
229 typedef enum {
234 
235 typedef enum {
246 
247 typedef enum {
251 
253 
254 #define MA_INPUT_TYPE_MASK 0xF000
255 #define MA_OUTPUT_TYPE_MASK 0x0F00
256 #define MA_MODEL_TYPE_MASK 0x00FF
257 
258 typedef enum {
263 
264 typedef enum {
272 
273 
274 typedef enum {
288 
289 typedef struct {
290  uint8_t id;
291  uint32_t size;
292  // don't think it a good idea to use self allocated memory in struct
293  const void* name;
294  const void* addr;
296 } ma_model_t;
297 
298 typedef enum { SEC_AUTO = 0, SEC_NONE = 1, SEC_WEP = 2, SEC_WPA1_WPA2 = 3, SEC_WPA2_WPA3 = 4, SEC_WPA3 = 5 } ma_wifi_security_t;
299 
300 typedef struct {
304  int8_t security;
306 
307 typedef struct {
310  char* client_cert;
311  char* client_key;
313 
314 typedef struct {
316  int16_t port;
320  int8_t use_ssl;
322 
323 typedef struct {
324  char pub_topic[MA_MQTT_MAX_TOPIC_LENGTH];
325  char sub_topic[MA_MQTT_MAX_TOPIC_LENGTH];
326  int8_t pub_qos;
327  int8_t sub_qos;
329 
330 typedef enum MA_ATTR_PACKED {
331  CAM_EVT_OPEN = 0b00000001,
332  CAM_EVT_CLOSE = 0b00000010,
333  CAM_EVT_START = 0b00000100,
334  CAM_EVT_STOP = 0b00001000,
335  CAM_EVT_CAPTURE = 0b00010000,
336  CAM_EVT_FRAME = 0b00100000,
337  CAM_EVT_CLEANUP = 0b01000000,
339 
340 #ifdef __cplusplus
341 }
342 
343 #include <string>
344 
345 struct ipv4_addr_t {
346  ipv4_addr_t() : addr{0} {}
347 
348  ~ipv4_addr_t() = default;
349 
350  uint8_t addr[4];
351 
352  // we're not going to validate the input string
353  static decltype(auto) from_str(std::string s) {
354  ipv4_addr_t r;
355  uint8_t l{0};
356 
357  for (std::size_t i = 0; i < s.length(); ++i) {
358  if (!std::isdigit(s[i]))
359  continue;
360 
361  uint8_t n{0};
362  for (; (++i < s.length()) & (++n < 3);)
363  if (!std::isdigit(s[i]))
364  break;
365  if (n) {
366  auto num{s.substr(i - n, n)};
367  r.addr[l++] = static_cast<uint8_t>(std::atoi(num.c_str()));
368  if (l > 3)
369  return r;
370  }
371  }
372 
373  return r;
374  }
375 
376  decltype(auto) to_str() const {
377  std::string r{};
378  r.reserve(sizeof "255.255.255.255.");
379  for (std::size_t i = 0; i < 4; ++i) {
380  r += std::to_string(addr[i]);
381  r += '.';
382  }
383  return r.substr(0, r.length() - 1);
384  }
385 };
386 
387 struct ipv6_addr_t {
388  ipv6_addr_t() : addr{0} {}
389  ~ipv6_addr_t() = default;
390 
391  uint16_t addr[8];
392 
393  static decltype(auto) from_str(std::string s) {
394  ipv6_addr_t r;
395  uint8_t l{0};
396 
397  for (std::size_t i = 0; i < s.length(); ++i) {
398  if (!std::isxdigit(s[i]))
399  continue;
400 
401  uint16_t n{0};
402  for (; (++i < s.length()) & (++n < 4);)
403  if (!std::isxdigit(s[i]))
404  break;
405  if (n) {
406  auto num{s.substr(i - n, n)};
407  r.addr[l++] = static_cast<uint16_t>(std::strtol(num.c_str(), nullptr, 16));
408  if (l > 7)
409  return r;
410  }
411  }
412 
413  return r;
414  }
415 
416  decltype(auto) to_str() const {
417  static const char* digits = "0123456789abcdef";
418  std::string r;
419  r.reserve(sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:");
420  for (std::size_t i = 0; i < 8; ++i) {
421  if (addr[i]) {
422  std::string t;
423  t.reserve(4);
424  for (uint16_t n = addr[i]; n; n >>= 4)
425  t += digits[n & 0x0f];
426  r.append(t.rbegin(), t.rend());
427  } else
428  r += '0';
429  r += ':';
430  }
431  return r.substr(0, r.length() - 1);
432  }
433 };
434 
435 typedef struct in4_info_t {
436  ipv4_addr_t ip;
437  ipv4_addr_t netmask;
438  ipv4_addr_t gateway;
439 } in4_info_t;
440 
441 typedef struct in6_info_t {
442  ipv6_addr_t ip;
443 } in6_info_t;
444 
445 #endif
446 
447 #endif // _MA_TYPES_H_
#define MA_MQTT_MAX_PASSWORD_LENGTH
Definition: ma_config_internal.h:68
#define MA_MQTT_MAX_BROKER_LENGTH
Definition: ma_config_internal.h:52
#define MA_MQTT_MAX_CLIENT_ID_LENGTH
Definition: ma_config_internal.h:56
#define MA_MAX_WIFI_SSID_LENGTH
Definition: ma_config_internal.h:40
#define MA_MQTT_MAX_USERNAME_LENGTH
Definition: ma_config_internal.h:64
#define MA_MAX_WIFI_PASSWORD_LENGTH
Definition: ma_config_internal.h:48
#define MA_ENGINE_SHAPE_MAX_DIM
Definition: ma_config_internal.h:36
#define MA_MQTT_MAX_TOPIC_LENGTH
Definition: ma_config_internal.h:60
#define MA_MAX_WIFI_BSSID_LENGTH
Definition: ma_config_internal.h:44
ma_model_type_t
Definition: ma_types.h:274
@ MA_MODEL_TYPE_YOLOV5
Definition: ma_types.h:278
@ MA_MODEL_TYPE_PFLD
Definition: ma_types.h:277
@ MA_MODEL_TYPE_YOLOV8_POSE
Definition: ma_types.h:280
@ MA_MODEL_TYPE_IMCLS
Definition: ma_types.h:279
@ MA_MODEL_TYPE_FOMO
Definition: ma_types.h:276
@ MA_MODEL_TYPE_NVIDIA_DET
Definition: ma_types.h:282
@ MA_MODEL_TYPE_YOLO11_POSE
Definition: ma_types.h:285
@ MA_MODEL_TYPE_YOLO_WORLD
Definition: ma_types.h:283
@ MA_MODEL_TYPE_UNDEFINED
Definition: ma_types.h:275
@ MA_MODEL_TYPE_YOLO11
Definition: ma_types.h:284
@ MA_MODEL_TYPE_YOLO11_SEG
Definition: ma_types.h:286
@ MA_MODEL_TYPE_YOLOV8
Definition: ma_types.h:281
ma_wifi_security_t
Definition: ma_types.h:298
@ SEC_WPA1_WPA2
Definition: ma_types.h:298
@ SEC_NONE
Definition: ma_types.h:298
@ SEC_WPA2_WPA3
Definition: ma_types.h:298
@ SEC_WEP
Definition: ma_types.h:298
@ SEC_WPA3
Definition: ma_types.h:298
@ SEC_AUTO
Definition: ma_types.h:298
ma_msg_type_t
Definition: ma_types.h:252
@ MA_MSG_TYPE_LOG
Definition: ma_types.h:252
@ MA_MSG_TYPE_REQ
Definition: ma_types.h:252
@ MA_MSG_TYPE_HB
Definition: ma_types.h:252
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
@ MA_MSG_TYPE_EVT
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
@ MA_ELOG
Definition: ma_types.h:25
@ MA_EIO
Definition: ma_types.h:27
@ MA_ETIMEOUT
Definition: ma_types.h:26
@ MA_EPERM
Definition: ma_types.h:32
@ MA_ENOENT
Definition: ma_types.h:33
@ MA_ENOMEM
Definition: ma_types.h:29
@ MA_FAILED
Definition: ma_types.h:22
@ MA_EBUSY
Definition: ma_types.h:30
@ MA_ENOTSUP
Definition: ma_types.h:31
@ MA_OK
Definition: ma_types.h:23
@ MA_EEXIST
Definition: ma_types.h:34
@ MA_AGAIN
Definition: ma_types.h:24
@ MA_EINVAL
Definition: ma_types.h:28
@ MA_OVERFLOW
Definition: ma_types.h:35
enum MA_ATTR_PACKED ma_camera_event_t
ma_model_cfg_opt_t
Definition: ma_types.h:229
@ MA_MODEL_CFG_OPT_NMS
Definition: ma_types.h:231
@ MA_MODEL_CFG_OPT_TOPK
Definition: ma_types.h:232
@ MA_MODEL_CFG_OPT_THRESHOLD
Definition: ma_types.h:230
ma_output_type_t
Definition: ma_types.h:264
@ MA_OUTPUT_TYPE_KEYPOINT
Definition: ma_types.h:269
@ MA_OUTPUT_TYPE_SEGMENTATION
Definition: ma_types.h:270
@ MA_OUTPUT_TYPE_TENSOR
Definition: ma_types.h:265
@ MA_OUTPUT_TYPE_CLASS
Definition: ma_types.h:266
@ MA_OUTPUT_TYPE_BBOX
Definition: ma_types.h:268
@ MA_OUTPUT_TYPE_POINT
Definition: ma_types.h:267
MA_ATTR_PACKED
Definition: ma_types.h:330
@ CAM_EVT_CLOSE
Definition: ma_types.h:332
@ CAM_EVT_STOP
Definition: ma_types.h:334
@ CAM_EVT_START
Definition: ma_types.h:333
@ CAM_EVT_CAPTURE
Definition: ma_types.h:335
@ CAM_EVT_OPEN
Definition: ma_types.h:331
@ CAM_EVT_CLEANUP
Definition: ma_types.h:337
@ CAM_EVT_FRAME
Definition: ma_types.h:336
ma_pixel_format_t
Definition: ma_types.h:103
@ MA_PIXEL_FORMAT_RGB565
Definition: ma_types.h:106
@ MA_PIXEL_FORMAT_GRAYSCALE
Definition: ma_types.h:108
@ MA_PIXEL_FORMAT_RGB888
Definition: ma_types.h:105
@ MA_PIXEL_FORMAT_H265
Definition: ma_types.h:111
@ MA_PIXEL_FORMAT_UNKNOWN
Definition: ma_types.h:113
@ MA_PIXEL_FORMAT_H264
Definition: ma_types.h:110
@ MA_PIXEL_FORMAT_RGB888_PLANAR
Definition: ma_types.h:112
@ MA_PIXEL_FORMAT_JPEG
Definition: ma_types.h:109
@ MA_PIXEL_FORMAT_AUTO
Definition: ma_types.h:104
@ MA_PIXEL_FORMAT_YUV422
Definition: ma_types.h:107
ma_pixel_rotate_t
Definition: ma_types.h:116
@ MA_PIXEL_ROTATE_90
Definition: ma_types.h:118
@ MA_PIXEL_ROTATE_UNKNOWN
Definition: ma_types.h:121
@ MA_PIXEL_ROTATE_270
Definition: ma_types.h:120
@ MA_PIXEL_ROTATE_180
Definition: ma_types.h:119
@ MA_PIXEL_ROTATE_0
Definition: ma_types.h:117
ma_tensor_type_t
Definition: ma_types.h:54
@ MA_TENSOR_TYPE_NMS_BBOX_U16
Definition: ma_types.h:70
@ MA_TENSOR_TYPE_U8
Definition: ma_types.h:56
@ MA_TENSOR_TYPE_S32
Definition: ma_types.h:61
@ MA_TENSOR_TYPE_BF16
Definition: ma_types.h:69
@ MA_TENSOR_TYPE_U64
Definition: ma_types.h:62
@ MA_TENSOR_TYPE_S8
Definition: ma_types.h:57
@ MA_TENSOR_TYPE_F64
Definition: ma_types.h:66
@ MA_TENSOR_TYPE_STR
Definition: ma_types.h:67
@ MA_TENSOR_TYPE_F16
Definition: ma_types.h:64
@ MA_TENSOR_TYPE_S64
Definition: ma_types.h:63
@ MA_TENSOR_TYPE_NONE
Definition: ma_types.h:55
@ MA_TENSOR_TYPE_F32
Definition: ma_types.h:65
@ MA_TENSOR_TYPE_S16
Definition: ma_types.h:59
@ MA_TENSOR_TYPE_U32
Definition: ma_types.h:60
@ MA_TENSOR_TYPE_U16
Definition: ma_types.h:58
@ MA_TENSOR_TYPE_NMS_BBOX_F32
Definition: ma_types.h:71
@ MA_TENSOR_TYPE_BOOL
Definition: ma_types.h:68
ma_input_type_t
Definition: ma_types.h:258
@ MA_INPUT_TYPE_AUDIO
Definition: ma_types.h:261
@ MA_INPUT_TYPE_IMAGE
Definition: ma_types.h:260
@ MA_INPUT_TYPE_TENSOR
Definition: ma_types.h:259
ma_transport_type_t
Definition: ma_types.h:235
@ MA_TRANSPORT_SERIAL
Definition: ma_types.h:238
@ MA_TRANSPORT_UDP
Definition: ma_types.h:243
@ MA_TRANSPORT_I2C
Definition: ma_types.h:240
@ MA_TRANSPORT_SPI
Definition: ma_types.h:239
@ MA_TRANSPORT_RTSP
Definition: ma_types.h:244
@ MA_TRANSPORT_CONSOLE
Definition: ma_types.h:237
@ MA_TRANSPORT_UNKOWN
Definition: ma_types.h:236
@ MA_TRANSPORT_MQTT
Definition: ma_types.h:241
@ MA_TRANSPORT_TCP
Definition: ma_types.h:242
ma_transport_cfg_opt_t
Definition: ma_types.h:247
@ MA_TRANSPORT_CFG_OPT_TIMEOUT
Definition: ma_types.h:249
@ MA_TRANSPORT_CFG_OPT_NONE
Definition: ma_types.h:248
Definition: ma_types.h:162
size_t stride
Definition: ma_types.h:163
size_t size
Definition: ma_types.h:165
size_t start
Definition: ma_types.h:166
size_t split
Definition: ma_types.h:164
Definition: ma_types.h:181
float h
Definition: ma_types.h:185
float y
Definition: ma_types.h:183
int target
Definition: ma_types.h:187
float score
Definition: ma_types.h:186
float w
Definition: ma_types.h:184
float x
Definition: ma_types.h:182
Definition: ma_types.h:176
float score
Definition: ma_types.h:177
int target
Definition: ma_types.h:178
Definition: ma_types.h:124
uint8_t * data
Definition: ma_types.h:135
uint32_t size
Definition: ma_types.h:125
bool physical
Definition: ma_types.h:134
uint8_t count
Definition: ma_types.h:133
uint32_t timestamp
Definition: ma_types.h:130
uint16_t width
Definition: ma_types.h:126
uint16_t height
Definition: ma_types.h:127
bool key
Definition: ma_types.h:131
ma_pixel_rotate_t rotate
Definition: ma_types.h:129
ma_pixel_format_t format
Definition: ma_types.h:128
uint8_t index
Definition: ma_types.h:132
Definition: ma_types.h:38
size_t size
Definition: ma_types.h:40
bool own
Definition: ma_types.h:41
void * pool
Definition: ma_types.h:39
Definition: ma_types.h:289
uint8_t id
Definition: ma_types.h:290
uint32_t size
Definition: ma_types.h:291
const void * name
Definition: ma_types.h:293
ma_model_type_t type
Definition: ma_types.h:295
const void * addr
Definition: ma_types.h:294
Definition: ma_types.h:314
int16_t port
Definition: ma_types.h:316
int8_t use_ssl
Definition: ma_types.h:320
Definition: ma_types.h:307
char * client_cert
Definition: ma_types.h:310
char * client_key
Definition: ma_types.h:311
char * certification_authority
Definition: ma_types.h:309
Definition: ma_types.h:323
int8_t sub_qos
Definition: ma_types.h:327
int8_t pub_qos
Definition: ma_types.h:326
Definition: ma_types.h:138
int64_t preprocess
Definition: ma_types.h:139
int64_t inference
Definition: ma_types.h:140
int64_t postprocess
Definition: ma_types.h:141
Definition: ma_types.h:169
float x
Definition: ma_types.h:170
float score
Definition: ma_types.h:172
int target
Definition: ma_types.h:173
float y
Definition: ma_types.h:171
Definition: ma_types.h:144
float x
Definition: ma_types.h:145
float y
Definition: ma_types.h:146
Definition: ma_types.h:149
float z
Definition: ma_types.h:152
float x
Definition: ma_types.h:150
float y
Definition: ma_types.h:151
Definition: ma_types.h:155
float z
Definition: ma_types.h:158
float x
Definition: ma_types.h:156
float t
Definition: ma_types.h:159
float y
Definition: ma_types.h:157
Definition: ma_types.h:44
int32_t zero_point
Definition: ma_types.h:46
float scale
Definition: ma_types.h:45
Definition: ma_types.h:49
uint32_t size
Definition: ma_types.h:50
Definition: ma_types.h:74
ma_shape_t shape
Definition: ma_types.h:75
ma_quant_param_t quant_param
Definition: ma_types.h:76
bool is_physical
Definition: ma_types.h:98
uint16_t * u16
Definition: ma_types.h:89
size_t size
Definition: ma_types.h:78
uint8_t * u8
Definition: ma_types.h:87
void * data
Definition: ma_types.h:86
int16_t * s16
Definition: ma_types.h:90
int32_t * s32
Definition: ma_types.h:92
int8_t * s8
Definition: ma_types.h:88
int64_t * s64
Definition: ma_types.h:94
uint64_t * u64
Definition: ma_types.h:93
double * f64
Definition: ma_types.h:96
float * f32
Definition: ma_types.h:95
bool is_variable
Definition: ma_types.h:99
uint32_t * u32
Definition: ma_types.h:91
ma_tensor_type_t type
Definition: ma_types.h:77
Definition: ma_types.h:197
Definition: ma_types.h:300
int8_t security
Definition: ma_types.h:304