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 "interfaces/kits/c/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 };
60 
61 struct ModelConfig {
62     bool enableFloat16;
63     OH_NN_PerformanceMode mode;
64     OH_NN_Priority priority;
65     std::string cachePath;
66     ExtensionConfig extensionConfig;
67 };
68 
69 struct QuantParam {
70     uint32_t numBits;
71     double scale;
72     int32_t zeroPoint;
73 };
74 
75 struct IOTensor {
76     std::string name;
77     OH_NN_DataType dataType;
78     OH_NN_Format format;
79     std::vector<int> dimensions;
80     void* data;
81     size_t length;
82 };
83 } // NeuralNetworkRuntime
84 } // OHOS
85 
86 #endif // NEURAL_NETWORK_RUNTIME_CPP_API_TYPE_H