Bolt
Bolt.h
1 // Copyright (C) 2019. Huawei Technologies Co., Ltd. All rights reserved.
2 
3 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 // to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 
7 // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 
9 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
10 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
11 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 
14 #ifndef DLLITE_BOLT_H
15 #define DLLITE_BOLT_H
16 
17 #include <vector>
18 #include <string>
19 
20 namespace bolt {
21 
23 using ModelHandle = void *;
24 
26 using ResultHandle = void *;
27 
29 enum class AffinityType {
31  CPU_LOW_POWER = 1,
32  GPU = 2
33 };
34 
36 enum class TensorType {
37  FP32 = 0,
38  FP16 = 1,
39  INT32 = 2,
40  UINT32 = 3
41 };
42 
44 enum class TensorLayout {
45  NCHW = 0,
46  NHWC = 1,
47  NCHWC8 = 2,
48  ROW_MAJOR = 3,
49  RNN_MTK = 4
50 };
51 
52 // IOTensor
53 struct IOTensor {
54  std::string name;
55  TensorType type;
56  TensorLayout layout;
57  std::vector<size_t> shape;
58  std::pair<void *, size_t> buffer; // <ptr_to_memory, size of bytes>
59 };
60 
61 // For model and algo config, either both use stream (default) or both use path
62 struct ModelConfig {
63  AffinityType affinity;
64  std::pair<void *, size_t> modelStream;
65  std::pair<void *, size_t> algoStream;
66  std::string modelPath;
67  std::string algoPath;
68 };
69 
70 // Return status
71 enum class ReturnStatus {
72  SUCCESS = 0,
73  FAIL = -1,
74  NULLPTR = -2
75 };
76 
77 ModelHandle CreateModel(const ModelConfig &modelConfig);
78 
79 ReturnStatus GetIOFormats(
80  ModelHandle modelHandle, std::vector<IOTensor> &inputs, std::vector<IOTensor> &outputs);
81 
82 ReturnStatus PrepareModel(ModelHandle modelHandle, const std::vector<IOTensor> &inputs);
83 
84 ReturnStatus GetInputTensors(ModelHandle modelHandle, std::vector<IOTensor> &inputs);
85 
86 ReturnStatus ResizeInput(ModelHandle modelHandle, const std::vector<IOTensor> &inputs);
87 
88 ResultHandle AllocResult(ModelHandle modelHandle, const std::vector<IOTensor> &outputs);
89 
90 ReturnStatus RunModel(
91  ModelHandle modelHandle, ResultHandle resultHandle, const std::vector<IOTensor> &inputs);
92 
93 ReturnStatus GetOutputTensors(ResultHandle resultHandle, std::vector<IOTensor> &outputs);
94 
95 ReturnStatus FreeResult(ResultHandle resultHandle);
96 
97 ReturnStatus DestroyModel(ModelHandle modelHandle);
98 
99 } // namespace bolt
100 
101 #endif // DLLITE_BOLT_H
batch->channel/8->high->width->channel four element data order
Definition: bolt.h:73
Definition: Bolt.h:20
void PrepareModel(ModelHandle ih, const int num_inputs, const char **name, const int *n, const int *c, const int *h, const int *w, const DATA_TYPE *dt, const DATA_FORMAT *df)
complete model inference engine prepare
power is high priority(use small core)
Definition: bolt.h:37
ModelHandle CreateModel(const char *modelPath, AFFINITY_TYPE affinity, const char *algorithmMapPath)
create model from file
void * ResultHandle
Definition: bolt.h:32
performance is high priority(use big core)
Definition: bolt.h:36
void DestroyModel(ModelHandle ih)
destroy model
optional string type
Definition: flow.proto:47
void * ModelHandle
Definition: bolt.h:29
batch->channel->high->width data order
Definition: bolt.h:71
use GPU
Definition: bolt.h:38
void RunModel(ModelHandle ih, ResultHandle ir, int num_inputs, const char **name, void **data)
inference result from input
batch->high->width->channel data order
Definition: bolt.h:72