• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef NEURAL_NETWORK_RUNTIME_CPP_API_TYPE_H
17 #define NEURAL_NETWORK_RUNTIME_CPP_API_TYPE_H
18 
19 #include <vector>
20 #include <string>
21 #include <memory>
22 #include <map>
23 
24 #include "neural_network_runtime/neural_network_runtime_type.h"
25 
26 namespace OHOS {
27 namespace NeuralNetworkRuntime {
28 // ALLOCATE_BUFFER_LIMIT is 1 Gb
29 const size_t ALLOCATE_BUFFER_LIMIT = 1024 * 1024 * 1024;
30 enum DeviceStatus: int {
31     UNKNOWN,
32     AVAILABLE,
33     BUSY,
34     OFFLINE
35 };
36 
37 enum class TuningStrategy {
38     OFF = 0,
39     ON_DEVICE_TUNING,
40     ON_DEVICE_PREPROCESS_TUNING,
41     ON_CLOUD_TUNING
42 };
43 
44 struct Buffer {
45     void* data = nullptr;
46     size_t length = 0;
47 };
48 
49 struct ExtensionConfig {
50     Buffer quantBuffer;
51     std::string modelName;
52     std::string isProfiling;
53     std::map<std::string, std::string> opLayout;
54     TuningStrategy tuningStrategy{TuningStrategy::OFF};
55     // inputDims and dynamicDims are used in hiai adapter
56     std::vector<std::vector<int32_t>> inputDims;
57     std::vector<std::vector<int32_t>> dynamicDims;
58     bool isNpuFmShared = false;
59     bool isExceedRamLimit = false;
60 };
61 
62 struct ModelConfig {
63     bool enableFloat16;
64     OH_NN_PerformanceMode mode;
65     OH_NN_Priority priority;
66     std::string cachePath;
67     ExtensionConfig extensionConfig;
68 };
69 
70 struct QuantParam {
71     uint32_t numBits;
72     double scale;
73     int32_t zeroPoint;
74 };
75 
76 struct IOTensor {
77     std::string name;
78     OH_NN_DataType dataType;
79     OH_NN_Format format;
80     std::vector<int> dimensions;
81     void* data;
82     size_t length;
83 };
84 } // NeuralNetworkRuntime
85 } // OHOS
86 
87 #endif // NEURAL_NETWORK_RUNTIME_CPP_API_TYPE_H