diff --git a/frameworks/native/neural_network_core/cpp_type.h b/frameworks/native/neural_network_core/cpp_type.h index faf90394b9ff8aaa1e0585c2478ef74567ea4418..7007244d397071c6d08488f3ea2cbecb24309c61 100644 --- a/frameworks/native/neural_network_core/cpp_type.h +++ b/frameworks/native/neural_network_core/cpp_type.h @@ -34,6 +34,13 @@ enum DeviceStatus: int { OFFLINE }; +enum class TuningStrategy { + OFF = 0, + ON_DEVICE_TUNING, + ON_DEVICE_PREPROCESS_TUNING, + ON_CLOUD_TUNING +}; + struct ModelConfig { bool enableFloat16; OH_NN_PerformanceMode mode; @@ -41,6 +48,7 @@ struct ModelConfig { std::string isProfiling; std::string cachePath; std::map opLayout; + TuningStrategy tuningStrategy{TuningStrategy::OFF}; }; struct Buffer { diff --git a/frameworks/native/neural_network_runtime/inner_model.cpp b/frameworks/native/neural_network_runtime/inner_model.cpp index b9dfea9c1208489ad596d6a82fc5c30ee4fc84e7..15f51e234ea35a83db63e8e0f3f9424f6b3a2378 100644 --- a/frameworks/native/neural_network_runtime/inner_model.cpp +++ b/frameworks/native/neural_network_runtime/inner_model.cpp @@ -780,5 +780,15 @@ std::map InnerModel::GetOpLayouts() const { return m_opLayouts; } + +TuningStrategy InnerModel::GetTuningStrategy() const +{ + return m_tuningStrategy; +} + +void InnerModel::SetTuningStrategy(const TuningStrategy tuningStrategy) +{ + m_tuningStrategy = tuningStrategy; +} } // namespace NeuralNetworkRuntime } // namespace OHOS diff --git a/frameworks/native/neural_network_runtime/inner_model.h b/frameworks/native/neural_network_runtime/inner_model.h index e5cc36f9c10b26c4e957e856982167c28dc0f6b7..a5c3fb068b18ce5baa95a0758b0b8c80e90c487e 100644 --- a/frameworks/native/neural_network_runtime/inner_model.h +++ b/frameworks/native/neural_network_runtime/inner_model.h @@ -63,6 +63,8 @@ public: std::string GetModelName() const; std::string GetProfiling() const; std::map GetOpLayouts() const; + TuningStrategy GetTuningStrategy() const; + void SetTuningStrategy(const TuningStrategy tuningStrategy); private: void AddTensorsToLiteGraph(std::unordered_map& modelIDToGraphID); @@ -86,6 +88,7 @@ private: std::string m_modelName; std::string m_isProfiling; std::map m_opLayouts; + TuningStrategy m_tuningStrategy{TuningStrategy::OFF}; }; } // namespace NeuralNetworkRuntime } // namespace OHOS diff --git a/frameworks/native/neural_network_runtime/neural_network_runtime.cpp b/frameworks/native/neural_network_runtime/neural_network_runtime.cpp index 020ab6a95a496cc3921fc1190f0196f2d47707b1..f6402f61165e2dfe016e824f14e1d7fb6d538db9 100644 --- a/frameworks/native/neural_network_runtime/neural_network_runtime.cpp +++ b/frameworks/native/neural_network_runtime/neural_network_runtime.cpp @@ -331,6 +331,7 @@ NNRT_API OH_NN_ReturnCode OH_NNModel_BuildFromLiteGraph(OH_NNModel *model, const auto *pLiteGraph = static_cast(liteGraph); InnerModel *innerModel = reinterpret_cast(model); + innerModel->SetTuningStrategy(TuningStrategy::ON_DEVICE_PREPROCESS_TUNING); // Once the innerModel built from the liteGraph successfully, the innerModel // owns the liteGraph, in which case, the invoker should not delete diff --git a/frameworks/native/neural_network_runtime/nncompiler.cpp b/frameworks/native/neural_network_runtime/nncompiler.cpp index 56ab88632363f1d65b9d2a3514243a5a4cd9f8a4..ad383f46d0e147cf486bd3f3d0b6156701945db3 100644 --- a/frameworks/native/neural_network_runtime/nncompiler.cpp +++ b/frameworks/native/neural_network_runtime/nncompiler.cpp @@ -130,6 +130,7 @@ NNCompiler::NNCompiler(const void* model, std::shared_ptr device, size_t m_modelName = m_innerModel->GetModelName(); m_isProfiling = m_innerModel->GetProfiling(); m_opLayouts = m_innerModel->GetOpLayouts(); + m_tuningStrategy = m_innerModel->GetTuningStrategy(); } NNCompiler::~NNCompiler() @@ -375,7 +376,7 @@ OH_NN_ReturnCode NNCompiler::NormalBuild() } ModelConfig config {m_enableFp16, static_cast(m_performance), - static_cast(m_priority), m_isProfiling, m_cachePath, m_opLayouts}; + static_cast(m_priority), m_isProfiling, m_cachePath, m_opLayouts, m_tuningStrategy}; if (m_liteGraph != nullptr) { ret = m_device->PrepareModel(m_liteGraph, m_quantBuffer, config, m_preparedModel); } diff --git a/frameworks/native/neural_network_runtime/nncompiler.h b/frameworks/native/neural_network_runtime/nncompiler.h index b5655a72f99ceb3b797f69d35ced10ae805b1b50..62b88ee672c80d449171b809306e6ebc6ea0db98 100644 --- a/frameworks/native/neural_network_runtime/nncompiler.h +++ b/frameworks/native/neural_network_runtime/nncompiler.h @@ -89,6 +89,7 @@ private: std::shared_ptr m_liteGraph {nullptr}; std::vector, OH_NN_TensorType>> m_inputTensorDescs; std::vector, OH_NN_TensorType>> m_outputTensorDescs; + TuningStrategy m_tuningStrategy{TuningStrategy::OFF}; }; } // NeuralNetworkRuntime } // OHOS