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 int fd = -1; 48 }; 49 50 struct ExtensionConfig { 51 Buffer quantBuffer; 52 std::string modelName; 53 std::string isProfiling; 54 std::map<std::string, std::string> opLayout; 55 TuningStrategy tuningStrategy{TuningStrategy::OFF}; 56 // inputDims and dynamicDims are used in hiai adapter 57 std::vector<std::vector<int32_t>> inputDims; 58 std::vector<std::vector<int32_t>> dynamicDims; 59 bool isNpuFmShared = false; 60 bool isExceedRamLimit = false; 61 }; 62 63 struct ModelConfig { 64 bool enableFloat16; 65 OH_NN_PerformanceMode mode; 66 OH_NN_Priority priority; 67 std::string cachePath; 68 ExtensionConfig extensionConfig; 69 }; 70 71 struct QuantParam { 72 uint32_t numBits; 73 double scale; 74 int32_t zeroPoint; 75 }; 76 77 struct IOTensor { 78 std::string name; 79 OH_NN_DataType dataType; 80 OH_NN_Format format; 81 std::vector<int> dimensions; 82 void* data; 83 size_t length; 84 }; 85 } // NeuralNetworkRuntime 86 } // OHOS 87 88 #endif // NEURAL_NETWORK_RUNTIME_CPP_API_TYPE_H