nndeploy C++ API  0.2.0
nndeploy C++ API
common.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_BASE_COMMON_H_
3 #define _NNDEPLOY_BASE_COMMON_H_
4 
6 #include "nndeploy/base/half.h"
7 #include "nndeploy/base/half.hpp"
8 #include "nndeploy/base/macro.h"
9 
10 namespace nndeploy {
11 namespace base {
12 
13 enum DataTypeCode : uint8_t {
18  // opaque handle
20  // not support
22 };
23 
26  DataType(DataTypeCode code, uint8_t bits, uint16_t lanes = (uint16_t)1);
27  DataType(uint8_t code, uint8_t bits, uint16_t lanes = (uint16_t)1);
28 
30 
31  DataType(const DataType &other);
32  DataType &operator=(const DataType &other);
33 
34  DataType(DataType &&other);
36 
37  bool operator==(const DataType &other) const;
38  bool operator==(const DataTypeCode &other) const;
39 
40  bool operator!=(const DataType &other) const;
41  bool operator!=(const DataTypeCode &other) const;
42 
43  bool operator<(const DataType &other) const; // used for std::map
44 
45  size_t size() const;
46 
47  uint8_t code_;
48  uint8_t bits_;
49  uint16_t lanes_;
50 };
51 
52 template <typename T>
54  return DataType(kDataTypeCodeOpaqueHandle, sizeof(T) << 3);
55 }
56 template <>
58 template <>
60 template <>
62 template <>
63 NNDEPLOY_CC_API DataType dataTypeOf<half_float::half>();
64 template <>
66 template <>
68 template <>
70 template <>
72 template <>
74 template <>
76 template <>
78 template <>
80 
81 enum DeviceTypeCode : int {
86 
94 
97 
104 
105  // not support
107 };
108 
111  DeviceType(DeviceTypeCode code, int device_id = 0);
112 
113  DeviceType(const DeviceType &other);
116 
119 
120  bool operator==(const DeviceType &other) const;
121  bool operator==(const DeviceTypeCode &other) const;
122 
123  bool operator!=(const DeviceType &other) const;
124  bool operator!=(const DeviceTypeCode &other) const;
125 
128 };
129 
130 enum DataFormat : int {
131  // 1D,scale
132  kDataFormatN = 0x0000,
133 
134  // 2D
136 
137  // 3D
138  // kDataFormatNHW,
139  // kDataFormatNWC,
140  // kDataFormatNCW,
142 
143  kDataFormatS1D, // [seq_len, 1, dim]
144 
145  // 4D
146  kDataFormatNCHW, // 为主
148  // # 4D 延伸 - NCHW的权重
150  // # 4D 变种
153 
154  // 5D
157  // TODO:NEW
159 
160  // auto
162 
163  // not support
165 };
166 
167 enum PrecisionType : int {
172 
173  // not support
175 };
176 
177 enum PowerType : int {
178  kPowerTypeHigh = 0x0000,
181 
182  // not support
184 };
185 
186 enum ShareMemoryType : int {
189 
190  // not support
192 };
193 
194 enum MemoryType : int {
195  kMemoryTypeNone = 0x0000,
199 };
200 
205 };
206 
207 enum MemoryPoolType : int {
211 };
212 
213 enum TensorType : int {
216 };
217 
218 enum ForwardOpType : int {
220 
226 
227  // not support
229 };
230 
231 enum InferenceOptLevel : int {
234 
235  // auto
237 };
238 
239 enum ModelType : int {
241 
248 
254 
257 
260 
262 
263  // torch - 结构和权重
265  // torch - 权重
267 
268  // tensorflow - hdf5
270 
271  // safetensors
273 
274  // mtk: neuro-pilot
276 
277  // gguf
279 
280  // not support
282 };
283 
284 enum InferenceType : int {
286 
288 
295 
301 
304 
307 
309 
311 
313 
314  // mtk: neuro-pilot
316 
322 
327 
328  // not support
330 };
331 
332 enum EncryptType : int {
335 };
336 
337 enum CodecType : int {
338  kCodecTypeNone = 0x0000,
342 };
343 
344 enum CodecFlag : int {
345  kCodecFlagImage = 0x0000,
349 
351 };
352 
353 enum ParallelType : int {
355  kParallelTypeSequential = 0x0001 << 1,
356  kParallelTypeTask = 0x0001 << 2,
357  kParallelTypePipeline = 0x0001 << 3,
358 };
359 
360 enum EdgeType : int {
361  kEdgeTypeFixed = 0x0001,
362  kEdgeTypePipeline = 0x0001 << 1,
363 };
364 
365 enum EdgeUpdateFlag : int {
368  kEdgeUpdateFlagError = 0x0001 << 2,
369 };
370 
371 enum NodeColorType : int {
372  kNodeColorWhite = 0x0000,
375 };
376 
378 
379 using IntVector = std::vector<int>;
380 using SizeVector = std::vector<size_t>;
381 using ShapeMap = std::map<std::string, std::vector<int>>;
382 
385 stringToDataTypeCode(const std::string &src);
386 extern NNDEPLOY_CC_API std::string dataTypeToString(DataType data_type);
387 extern NNDEPLOY_CC_API DataType stringToDataType(const std::string &str);
388 
389 extern NNDEPLOY_CC_API std::string dataFormatToString(DataFormat data_format);
390 extern NNDEPLOY_CC_API DataFormat stringToDataFormat(const std::string &str);
391 
393 stringToDeviceTypeCode(const std::string &src);
395 extern NNDEPLOY_CC_API DeviceType stringToDeviceType(const std::string &src);
397 
398 extern NNDEPLOY_CC_API ModelType stringToModelType(const std::string &src);
400 
402 stringToInferenceType(const std::string &src);
404 
405 extern NNDEPLOY_CC_API EncryptType stringToEncryptType(const std::string &src);
407 
409 stringToShareMemoryType(const std::string &src);
411 
412 extern NNDEPLOY_CC_API MemoryType stringToMemoryType(const std::string &src);
414 
416 stringToMemoryPoolType(const std::string &src);
418 
419 extern NNDEPLOY_CC_API TensorType stringToTensorType(const std::string &src);
421 
423 stringToForwardOpType(const std::string &src);
425 
427 stringToInferenceOptLevel(const std::string &src);
429  InferenceOptLevel src);
430 
432 stringToPrecisionType(const std::string &src);
434 
435 extern NNDEPLOY_CC_API PowerType stringToPowerType(const std::string &src);
437 
438 extern NNDEPLOY_CC_API CodecType stringToCodecType(const std::string &src);
440 
441 extern NNDEPLOY_CC_API CodecFlag stringToCodecFlag(const std::string &src);
443 
446 stringToParallelType(const std::string &src);
447 
449  QueueOverflowPolicy src);
451 stringToOverflowPolicy(const std::string &src);
452 
453 extern NNDEPLOY_CC_API EdgeType stringToEdgeType(const std::string &src);
454 extern NNDEPLOY_CC_API std::string edgeTypeToString(EdgeType src);
455 
457 stringToEdgeUpdateFlag(const std::string &src);
459 
461 stringToNodeColorType(const std::string &src);
463 
465 stringToTopoSortType(const std::string &src);
467 
469 
470 } // namespace base
471 } // namespace nndeploy
472 
473 #endif
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
std::string dataFormatToString(DataFormat data_format)
std::string codecTypeToString(CodecType src)
ForwardOpType stringToForwardOpType(const std::string &src)
@ kEdgeTypeFixed
Definition: common.h:361
@ kEdgeTypePipeline
Definition: common.h:362
std::string nodeColorTypeToString(NodeColorType src)
std::string inferenceOptLevelToString(InferenceOptLevel src)
@ kInferenceTypeOneDiff
Definition: common.h:324
@ kInferenceTypeNcnn
Definition: common.h:296
@ kInferenceTypeOpenVino
Definition: common.h:289
@ kInferenceTypeAITemplate
Definition: common.h:303
@ kInferenceTypeTvm
Definition: common.h:302
@ kInferenceTypeDiffusers
Definition: common.h:325
@ kInferenceTypeSnpe
Definition: common.h:305
@ kInferenceTypeAscendCL
Definition: common.h:294
@ kInferenceTypeTorch
Definition: common.h:310
@ kInferenceTypeQnn
Definition: common.h:306
@ kInferenceTypeOnnxRuntime
Definition: common.h:293
@ kInferenceTypeTfLite
Definition: common.h:292
@ kInferenceTypeSophon
Definition: common.h:308
@ kInferenceTypeRknn
Definition: common.h:300
@ kInferenceTypeSGLang
Definition: common.h:318
@ kInferenceTypeTensorFlow
Definition: common.h:312
@ kInferenceTypeNotSupport
Definition: common.h:329
@ kInferenceTypeLlamaCpp
Definition: common.h:320
@ kInferenceTypeNone
Definition: common.h:285
@ kInferenceTypeMnn
Definition: common.h:298
@ kInferenceTypeNeuroPilot
Definition: common.h:315
@ kInferenceTypeCoreML
Definition: common.h:291
@ kInferenceTypeXDit
Definition: common.h:323
@ kInferenceTypeTensorRt
Definition: common.h:290
@ kInferenceTypeDiff
Definition: common.h:326
@ kInferenceTypeLLM
Definition: common.h:321
@ kInferenceTypeTnn
Definition: common.h:297
@ kInferenceTypeLmdeploy
Definition: common.h:319
@ kInferenceTypePaddleLite
Definition: common.h:299
@ kInferenceTypeDefault
Definition: common.h:287
@ kInferenceTypeVllm
Definition: common.h:317
std::string memoryTypeToString(MemoryType src)
DataType dataTypeOf< int8_t >()
CodecType stringToCodecType(const std::string &src)
QueueOverflowPolicy stringToOverflowPolicy(const std::string &src)
DataType dataTypeOf< uint64_t >()
@ kPrecisionTypeBFp16
Definition: common.h:168
@ kPrecisionTypeFp16
Definition: common.h:169
@ kPrecisionTypeFp32
Definition: common.h:170
@ kPrecisionTypeFp64
Definition: common.h:171
@ kPrecisionTypeNotSupport
Definition: common.h:174
std::string topoSortTypeToString(TopoSortType src)
DataType stringToDataType(const std::string &str)
std::vector< int > IntVector
Definition: common.h:379
EdgeType stringToEdgeType(const std::string &src)
std::map< std::string, std::vector< int > > ShapeMap
Definition: common.h:381
@ kTopoSortTypeDFS
Definition: common.h:377
@ kTopoSortTypeBFS
Definition: common.h:377
MemoryPoolType stringToMemoryPoolType(const std::string &src)
DataType dataTypeOf()
Definition: common.h:53
MemoryType stringToMemoryType(const std::string &src)
std::string codecFlagToString(CodecFlag src)
DataType dataTypeOf< uint8_t >()
std::string powerTypeToString(PowerType src)
@ kModelTypeTensorRt
Definition: common.h:243
@ kModelTypeAscendCL
Definition: common.h:247
@ kModelTypeTorchScript
Definition: common.h:264
@ kModelTypeNotSupport
Definition: common.h:281
@ kModelTypeSnpe
Definition: common.h:258
@ kModelTypePaddleLite
Definition: common.h:252
@ kModelTypeNcnn
Definition: common.h:249
@ kModelTypeOpenVino
Definition: common.h:242
@ kModelTypeNeuroPilot
Definition: common.h:275
@ kModelTypeRknn
Definition: common.h:253
@ kModelTypeGGUF
Definition: common.h:278
@ kModelTypeTorchPth
Definition: common.h:266
@ kModelTypeSafetensors
Definition: common.h:272
@ kModelTypeAITemplate
Definition: common.h:256
@ kModelTypeOnnx
Definition: common.h:246
@ kModelTypeHdf5
Definition: common.h:269
@ kModelTypeDefault
Definition: common.h:240
@ kModelTypeCoreML
Definition: common.h:244
@ kModelTypeTfLite
Definition: common.h:245
@ kModelTypeSophon
Definition: common.h:261
PowerType stringToPowerType(const std::string &src)
InferenceOptLevel stringToInferenceOptLevel(const std::string &src)
std::string edgeUpdateFlagToString(EdgeUpdateFlag src)
DeviceTypeCode stringToDeviceTypeCode(const std::string &src)
PrecisionType stringToPrecisionType(const std::string &src)
DataFormat stringToDataFormat(const std::string &str)
TensorType stringToTensorType(const std::string &src)
@ kQueueOverflowPolicyDropOldest
Definition: common.h:204
@ kQueueOverflowPolicyNodeBackpressure
Definition: common.h:202
@ kQueueOverflowPolicyAllBackpressure
Definition: common.h:203
@ kPowerTypeNotSupport
Definition: common.h:183
@ kPowerTypeNormal
Definition: common.h:179
@ kPowerTypeHigh
Definition: common.h:178
std::string tensorTypeToString(TensorType src)
PrecisionType getPrecisionType(DataType data_type)
std::string forwardOpTypeToString(ForwardOpType src)
EncryptType stringToEncryptType(const std::string &src)
@ kDataTypeCodeNotSupport
Definition: common.h:21
@ kDataTypeCodeOpaqueHandle
Definition: common.h:19
@ kDataTypeCodeUint
Definition: common.h:14
@ kDataTypeCodeInt
Definition: common.h:15
@ kDataTypeCodeFp
Definition: common.h:16
@ kDataTypeCodeBFp
Definition: common.h:17
DataType dataTypeOf< uint32_t >()
std::string dataTypeToString(DataType data_type)
std::vector< size_t > SizeVector
Definition: common.h:380
std::string dataTypeCodeToString(DataTypeCode src)
DataType dataTypeOf< bfp16_t >()
InferenceType stringToInferenceType(const std::string &src)
std::string shareMemoryTypeToString(ShareMemoryType src)
@ kParallelTypeSequential
Definition: common.h:355
@ kParallelTypeNone
Definition: common.h:354
@ kParallelTypeTask
Definition: common.h:356
@ kParallelTypePipeline
Definition: common.h:357
@ kCodecTypeNone
Definition: common.h:338
@ kCodecTypeOpenCV
Definition: common.h:339
@ kCodecTypeFFmpeg
Definition: common.h:340
std::string overflowPolicyToString(QueueOverflowPolicy src)
@ kCodecFlagImage
Definition: common.h:345
@ kCodecFlagImages
Definition: common.h:346
@ kCodecFlagOther
Definition: common.h:350
@ kCodecFlagVideo
Definition: common.h:347
@ kCodecFlagCamera
Definition: common.h:348
DataType dataTypeOf< double >()
@ kMemoryPoolTypeEmbed
Definition: common.h:208
@ kMemoryPoolTypeChunkIndepend
Definition: common.h:210
@ kMemoryPoolTypeUnity
Definition: common.h:209
std::string precisionTypeToString(PrecisionType src)
ModelType stringToModelType(const std::string &src)
@ kTensorTypeDefault
Definition: common.h:214
@ kTensorTypePipeline
Definition: common.h:215
DataTypeCode stringToDataTypeCode(const std::string &src)
DataType dataTypeOf< float >()
@ kDeviceTypeCodeSyCL
Definition: common.h:89
@ kDeviceTypeCodeHexagon
Definition: common.h:95
@ kDeviceTypeCodeOpenCL
Definition: common.h:90
@ kDeviceTypeCodeSophonNpu
Definition: common.h:103
@ kDeviceTypeCodeAscendCL
Definition: common.h:98
@ kDeviceTypeCodeArm
Definition: common.h:83
@ kDeviceTypeCodeCpu
Definition: common.h:82
@ kDeviceTypeCodeRiscV
Definition: common.h:85
@ kDeviceTypeCodeMtkVpu
Definition: common.h:96
@ kDeviceTypeCodeQualcommNpu
Definition: common.h:101
@ kDeviceTypeCodeNotSupport
Definition: common.h:106
@ kDeviceTypeCodeVulkan
Definition: common.h:93
@ kDeviceTypeCodeAppleNpu
Definition: common.h:99
@ kDeviceTypeCodeX86
Definition: common.h:84
@ kDeviceTypeCodeMetal
Definition: common.h:92
@ kDeviceTypeCodeMtkNpu
Definition: common.h:102
@ kDeviceTypeCodeCuda
Definition: common.h:87
@ kDeviceTypeCodeOpenGL
Definition: common.h:91
@ kDeviceTypeCodeRkNpu
Definition: common.h:100
@ kDeviceTypeCodeRocm
Definition: common.h:88
@ kMemoryTypeNone
Definition: common.h:195
@ kMemoryTypeExternal
Definition: common.h:197
@ kMemoryTypeAllocate
Definition: common.h:196
@ kMemoryTypeMapped
Definition: common.h:198
DeviceType stringToDeviceType(const std::string &src)
std::string deviceTypeToString(DeviceType src)
ParallelType stringToParallelType(const std::string &src)
@ kEncryptTypeBase64
Definition: common.h:334
@ kEncryptTypeNone
Definition: common.h:333
std::string inferenceTypeToString(InferenceType src)
DataType dataTypeOf< uint16_t >()
@ kNodeColorWhite
Definition: common.h:372
@ kNodeColorBlack
Definition: common.h:374
@ kNodeColorGray
Definition: common.h:373
DataType dataTypeOf< int16_t >()
DataType dataTypeOf< int64_t >()
CodecFlag stringToCodecFlag(const std::string &src)
@ kShareMemoryTypeShareFromExternal
Definition: common.h:188
@ kShareMemoryTypeNoShare
Definition: common.h:187
@ kShareMemoryTypeNotSupport
Definition: common.h:191
@ kInferenceOptLevel0
Definition: common.h:232
@ kInferenceOptLevel1
Definition: common.h:233
@ kInferenceOptLevelAuto
Definition: common.h:236
@ kEdgeUpdateFlagComplete
Definition: common.h:366
@ kEdgeUpdateFlagTerminate
Definition: common.h:367
@ kEdgeUpdateFlagError
Definition: common.h:368
std::string parallelTypeToString(ParallelType src)
std::string deviceTypeCodeToString(DeviceTypeCode src)
EdgeUpdateFlag stringToEdgeUpdateFlag(const std::string &src)
std::string modelTypeToString(ModelType src)
std::string encryptTypeToString(EncryptType src)
ShareMemoryType stringToShareMemoryType(const std::string &src)
TopoSortType stringToTopoSortType(const std::string &src)
@ kDataFormatNHWC
Definition: common.h:147
@ kDataFormatNCHW
Definition: common.h:146
@ kDataFormatNCL
Definition: common.h:141
@ kDataFormatNCDHW
Definition: common.h:155
@ kDataFormatNotSupport
Definition: common.h:164
@ kDataFormatNDHWC
Definition: common.h:156
@ kDataFormatNC4HW
Definition: common.h:151
@ kDataFormatNC8HW
Definition: common.h:152
@ kDataFormatAuto
Definition: common.h:161
@ kDataFormatS1D
Definition: common.h:143
@ kDataFormatOIHW
Definition: common.h:149
@ kDataFormatNDCHW
Definition: common.h:158
NodeColorType stringToNodeColorType(const std::string &src)
@ kForwardOpTypeAclOp
Definition: common.h:225
@ kForwardOpTypeCudnn
Definition: common.h:224
@ kForwardOpTypeXnnPack
Definition: common.h:222
@ kForwardOpTypeNotSupport
Definition: common.h:228
@ kForwardOpTypeOneDnn
Definition: common.h:221
@ kForwardOpTypeQnnPack
Definition: common.h:223
@ kForwardOpTypeDefault
Definition: common.h:219
std::string edgeTypeToString(EdgeType src)
std::string memoryPoolTypeToString(MemoryPoolType src)
DataType dataTypeOf< int32_t >()
DataType(DataType &&other)
DataType(uint8_t code, uint8_t bits, uint16_t lanes=(uint16_t) 1)
DataType & operator=(DataType &&other)
bool operator!=(const DataTypeCode &other) const
DataType & operator=(const DataType &other)
bool operator!=(const DataType &other) const
bool operator==(const DataType &other) const
DataType(DataTypeCode code, uint8_t bits, uint16_t lanes=(uint16_t) 1)
bool operator<(const DataType &other) const
DataType(const DataType &other)
bool operator==(const DataTypeCode &other) const
DeviceType & operator=(const DeviceTypeCode &other)
DeviceType(DeviceTypeCode code, int device_id=0)
bool operator!=(const DeviceType &other) const
bool operator==(const DeviceTypeCode &other) const
bool operator!=(const DeviceTypeCode &other) const
DeviceType & operator=(DeviceType &&other)
bool operator==(const DeviceType &other) const
DeviceTypeCode code_
Definition: common.h:126
DeviceType(DeviceType &&other)
DeviceType(const DeviceType &other)
DeviceType & operator=(const DeviceType &other)