1be168c0dSopenharmony_ciFrom 40b0edbf17e4335b40b51887fabd53aea2f1ef2d Mon Sep 17 00:00:00 2001
2be168c0dSopenharmony_ciFrom: chengfeng27 <chengfeng27@huawei.com>
3be168c0dSopenharmony_ciDate: Wed, 12 Jun 2024 11:46:33 +0800
4be168c0dSopenharmony_ciSubject: [PATCH] adapter HiAI Foundation NPU
5be168c0dSopenharmony_ci
6be168c0dSopenharmony_ci---
7be168c0dSopenharmony_ci mindspore/lite/BUILD.gn                       |   7 +
8be168c0dSopenharmony_ci mindspore/lite/src/litert/c_api/context_c.cc  |  11 ++
9be168c0dSopenharmony_ci .../delegate/nnrt/extension_options_parser.cc |  90 ++++++++++++
10be168c0dSopenharmony_ci .../delegate/nnrt/extension_options_parser.h  |  46 ++++++
11be168c0dSopenharmony_ci .../delegate/nnrt/hiai_foundation_wrapper.cc  |  64 +++++++++
12be168c0dSopenharmony_ci .../delegate/nnrt/hiai_foundation_wrapper.h   |  47 +++++++
13be168c0dSopenharmony_ci .../src/litert/delegate/nnrt/nnrt_delegate.cc | 133 ++++++++++++++----
14be168c0dSopenharmony_ci .../src/litert/delegate/nnrt/nnrt_delegate.h  |  15 +-
15be168c0dSopenharmony_ci 8 files changed, 383 insertions(+), 30 deletions(-)
16be168c0dSopenharmony_ci create mode 100644 mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc
17be168c0dSopenharmony_ci create mode 100644 mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.h
18be168c0dSopenharmony_ci create mode 100644 mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.cc
19be168c0dSopenharmony_ci create mode 100644 mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.h
20be168c0dSopenharmony_ci
21be168c0dSopenharmony_cidiff --git a/mindspore/lite/BUILD.gn b/mindspore/lite/BUILD.gn
22be168c0dSopenharmony_ciindex 6f7f85e9..467cdb6a 100644
23be168c0dSopenharmony_ci--- a/mindspore/lite/BUILD.gn
24be168c0dSopenharmony_ci+++ b/mindspore/lite/BUILD.gn
25be168c0dSopenharmony_ci@@ -445,6 +445,8 @@ ohos_shared_library("mindspore_lib") {
26be168c0dSopenharmony_ci       "src/litert/delegate/nnrt/nnrt_delegate.cc",
27be168c0dSopenharmony_ci       "src/litert/delegate/nnrt/nnrt_model_kernel.cc",
28be168c0dSopenharmony_ci       "src/litert/delegate/nnrt/nnrt_allocator.cc",
29be168c0dSopenharmony_ci+      "src/litert/delegate/nnrt/hiai_foundation_wrapper.cc",
30be168c0dSopenharmony_ci+      "src/litert/delegate/nnrt/extension_options_parser.cc",
31be168c0dSopenharmony_ci     ]
32be168c0dSopenharmony_ci     include_dirs += [
33be168c0dSopenharmony_ci       "src/delegate/nnrt/include",
34be168c0dSopenharmony_ci@@ -510,6 +512,11 @@ ohos_shared_library("mindspore_ndk") {
35be168c0dSopenharmony_ci     "ENABLE_HI_APP_EVENT",
36be168c0dSopenharmony_ci   ]
37be168c0dSopenharmony_ci 
38be168c0dSopenharmony_ci+  if (mindspore_feature_nnrt_metagraph) {
39be168c0dSopenharmony_ci+    defines += [ "SUPPORT_NNRT_METAGRAPH" ]
40be168c0dSopenharmony_ci+    print("enabled feature: mindspore_feature_nnrt_metagraph")
41be168c0dSopenharmony_ci+  }
42be168c0dSopenharmony_ci+
43be168c0dSopenharmony_ci   configs = [
44be168c0dSopenharmony_ci     ":mindspore_api",
45be168c0dSopenharmony_ci     ":disable_android",
46be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/c_api/context_c.cc b/mindspore/lite/src/litert/c_api/context_c.cc
47be168c0dSopenharmony_ciindex bde0460c..6b6a50d5 100644
48be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/c_api/context_c.cc
49be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/c_api/context_c.cc
50be168c0dSopenharmony_ci@@ -18,6 +18,9 @@
51be168c0dSopenharmony_ci #include <string.h>
52be168c0dSopenharmony_ci #include "src/litert/c_api/type_c_private.h"
53be168c0dSopenharmony_ci #include "src/common/log_adapter.h"
54be168c0dSopenharmony_ci+#ifdef SUPPORT_NNRT_METAGRAPH
55be168c0dSopenharmony_ci+#include "src/litert/delegate/nnrt/hiai_foundation_wrapper.h"
56be168c0dSopenharmony_ci+#endif
57be168c0dSopenharmony_ci #ifdef SUPPORT_NNRT
58be168c0dSopenharmony_ci #include "interfaces/kits/c/neural_network_runtime/neural_network_runtime.h"
59be168c0dSopenharmony_ci #endif
60be168c0dSopenharmony_ci@@ -300,6 +303,14 @@ NNRTDeviceDesc *OH_AI_GetAllNNRTDeviceDescs(size_t *num) {
61be168c0dSopenharmony_ci     return nullptr;
62be168c0dSopenharmony_ci   }
63be168c0dSopenharmony_ci #ifdef SUPPORT_NNRT
64be168c0dSopenharmony_ci+#ifdef SUPPORT_NNRT_METAGRAPH
65be168c0dSopenharmony_ci+  void *hiai_handle_{nullptr};
66be168c0dSopenharmony_ci+  auto ret_load = mindspore::lite::LoadHiaiFLibraryFromPath(&hiai_handle_);
67be168c0dSopenharmony_ci+  if (!ret_load || hiai_handle_ == nullptr) {
68be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "Load HiAI_Foundation so failed.";
69be168c0dSopenharmony_ci+    return nullptr;
70be168c0dSopenharmony_ci+  }
71be168c0dSopenharmony_ci+#endif
72be168c0dSopenharmony_ci   *num = 0;
73be168c0dSopenharmony_ci 
74be168c0dSopenharmony_ci   const size_t *all_device_ids;
75be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc b/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc
76be168c0dSopenharmony_cinew file mode 100644
77be168c0dSopenharmony_ciindex 00000000..98343898
78be168c0dSopenharmony_ci--- /dev/null
79be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.cc
80be168c0dSopenharmony_ci@@ -0,0 +1,90 @@
81be168c0dSopenharmony_ci+/**
82be168c0dSopenharmony_ci+ * Copyright 2024 Huawei Technologies Co., Ltd
83be168c0dSopenharmony_ci+ *
84be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License");
85be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License.
86be168c0dSopenharmony_ci+ * You may obtain a copy of the License at
87be168c0dSopenharmony_ci+ *
88be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0
89be168c0dSopenharmony_ci+ *
90be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software
91be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS,
92be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and
94be168c0dSopenharmony_ci+ * limitations under the License.
95be168c0dSopenharmony_ci+ */
96be168c0dSopenharmony_ci+
97be168c0dSopenharmony_ci+#include "extension_options_parser.h"
98be168c0dSopenharmony_ci+#include "stdlib.h"
99be168c0dSopenharmony_ci+#include <map>
100be168c0dSopenharmony_ci+
101be168c0dSopenharmony_ci+namespace mindspore::lite::nnrt {
102be168c0dSopenharmony_ci+namespace {
103be168c0dSopenharmony_ci+const std::map<std::string, mindspore::lite::HiAI_BandMode> kBandModeMap = {
104be168c0dSopenharmony_ci+    {"HIAI_BANDMODE_UNSET", mindspore::lite::HIAI_BANDMODE_UNSET},
105be168c0dSopenharmony_ci+    {"HIAI_BANDMODE_LOW", mindspore::lite::HIAI_BANDMODE_LOW},
106be168c0dSopenharmony_ci+    {"HIAI_BANDMODE_NORMAL", mindspore::lite::HIAI_BANDMODE_NORMAL},
107be168c0dSopenharmony_ci+    {"HIAI_BANDMODE_HIGH", mindspore::lite::HIAI_BANDMODE_HIGH},
108be168c0dSopenharmony_ci+};
109be168c0dSopenharmony_ci+const std::string kCachePath = "CachePath";
110be168c0dSopenharmony_ci+const std::string kCacheVersion = "CacheVersion";
111be168c0dSopenharmony_ci+const std::string kBandMode = "BandMode";
112be168c0dSopenharmony_ci+const std::string kQuantConfigData = "QuantConfigData";
113be168c0dSopenharmony_ci+}  // namespace
114be168c0dSopenharmony_ci+
115be168c0dSopenharmony_ci+int ExtensionOptionsParser::Parse(const std::vector<Extension> &extensions, ExtensionOptions *param) {
116be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET(param != nullptr, RET_ERROR);
117be168c0dSopenharmony_ci+
118be168c0dSopenharmony_ci+  DoParseCachePath(extensions, &param->cache_path_);
119be168c0dSopenharmony_ci+  DoParseCacheVersion(extensions, &param->cache_version_);
120be168c0dSopenharmony_ci+  DoParseBondMode(extensions, &param->band_mode);
121be168c0dSopenharmony_ci+  DoParseQuantConfig(extensions, &param->quant_config, &param->quant_config_size);
122be168c0dSopenharmony_ci+  return RET_OK;
123be168c0dSopenharmony_ci+}
124be168c0dSopenharmony_ci+
125be168c0dSopenharmony_ci+void ExtensionOptionsParser::DoParseCachePath(const std::vector<Extension> &extensions, std::string *cache_path) {
126be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET_VOID(cache_path != nullptr);
127be168c0dSopenharmony_ci+  auto iter_config = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) {
128be168c0dSopenharmony_ci+    return extension.name == kCachePath;
129be168c0dSopenharmony_ci+  });
130be168c0dSopenharmony_ci+  if (iter_config != extensions.end()) {
131be168c0dSopenharmony_ci+    *cache_path = std::string(iter_config->value.begin(), iter_config->value.end());
132be168c0dSopenharmony_ci+  }
133be168c0dSopenharmony_ci+}
134be168c0dSopenharmony_ci+
135be168c0dSopenharmony_ci+void ExtensionOptionsParser::DoParseCacheVersion(const std::vector<Extension> &extensions, uint32_t *cache_version) {
136be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET_VOID(cache_version != nullptr);
137be168c0dSopenharmony_ci+  auto iter_config = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) {
138be168c0dSopenharmony_ci+    return extension.name == kCacheVersion;
139be168c0dSopenharmony_ci+  });
140be168c0dSopenharmony_ci+  if (iter_config != extensions.end()) {
141be168c0dSopenharmony_ci+    std::string version_str = std::string(iter_config->value.begin(), iter_config->value.end());
142be168c0dSopenharmony_ci+    *cache_version = static_cast<uint32_t>(std::atol(version_str.c_str()));
143be168c0dSopenharmony_ci+  }
144be168c0dSopenharmony_ci+}
145be168c0dSopenharmony_ci+
146be168c0dSopenharmony_ci+void ExtensionOptionsParser::DoParseBondMode(const std::vector<Extension> &extensions, mindspore::lite::HiAI_BandMode *band_mode) {
147be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET_VOID(band_mode != nullptr);
148be168c0dSopenharmony_ci+  auto iter_config = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) {
149be168c0dSopenharmony_ci+    return extension.name == kBandMode;
150be168c0dSopenharmony_ci+  });
151be168c0dSopenharmony_ci+  if (iter_config != extensions.end()) {
152be168c0dSopenharmony_ci+    auto iter = kBandModeMap.find(std::string(iter_config->value.begin(), iter_config->value.end()));
153be168c0dSopenharmony_ci+    if (iter != kBandModeMap.end()) {
154be168c0dSopenharmony_ci+      *band_mode = iter->second;
155be168c0dSopenharmony_ci+    }
156be168c0dSopenharmony_ci+  }
157be168c0dSopenharmony_ci+}
158be168c0dSopenharmony_ci+
159be168c0dSopenharmony_ci+void ExtensionOptionsParser::DoParseQuantConfig(const std::vector<Extension> &extensions, void **quant_config, size_t *num) {
160be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET_VOID(quant_config != nullptr);
161be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET_VOID(num != nullptr);
162be168c0dSopenharmony_ci+  auto iter_config = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) {
163be168c0dSopenharmony_ci+    return extension.name == kQuantConfigData;
164be168c0dSopenharmony_ci+  });
165be168c0dSopenharmony_ci+  if (iter_config != extensions.end()) {
166be168c0dSopenharmony_ci+    *quant_config = static_cast<void *>(const_cast<uint8_t *>(iter_config->value.data()));
167be168c0dSopenharmony_ci+    *num = iter_config->value.size();
168be168c0dSopenharmony_ci+  }
169be168c0dSopenharmony_ci+}
170be168c0dSopenharmony_ci+}  // mindspore::lite::nnrt
171be168c0dSopenharmony_ci\ No newline at end of file
172be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.h b/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.h
173be168c0dSopenharmony_cinew file mode 100644
174be168c0dSopenharmony_ciindex 00000000..792805a4
175be168c0dSopenharmony_ci--- /dev/null
176be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/delegate/nnrt/extension_options_parser.h
177be168c0dSopenharmony_ci@@ -0,0 +1,46 @@
178be168c0dSopenharmony_ci+/**
179be168c0dSopenharmony_ci+ * Copyright 2024 Huawei Technologies Co., Ltd
180be168c0dSopenharmony_ci+ *
181be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License");
182be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License.
183be168c0dSopenharmony_ci+ * You may obtain a copy of the License at
184be168c0dSopenharmony_ci+ *
185be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0
186be168c0dSopenharmony_ci+ *
187be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software
188be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS,
189be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and
191be168c0dSopenharmony_ci+ * limitations under the License.
192be168c0dSopenharmony_ci+ */
193be168c0dSopenharmony_ci+
194be168c0dSopenharmony_ci+#ifndef MINDSPORE_LITE_EXTENSION_OPTIONS_PARSER_H
195be168c0dSopenharmony_ci+#define MINDSPORE_LITE_EXTENSION_OPTIONS_PARSER_H
196be168c0dSopenharmony_ci+
197be168c0dSopenharmony_ci+#include <vector>
198be168c0dSopenharmony_ci+#include "src/litert/inner_context.h"
199be168c0dSopenharmony_ci+#include "hiai_foundation_wrapper.h"
200be168c0dSopenharmony_ci+
201be168c0dSopenharmony_ci+namespace mindspore::lite::nnrt {
202be168c0dSopenharmony_ci+struct ExtensionOptions {
203be168c0dSopenharmony_ci+  std::string cache_path_ = "";
204be168c0dSopenharmony_ci+  uint32_t cache_version_ = 0;
205be168c0dSopenharmony_ci+  mindspore::lite::HiAI_BandMode band_mode{HIAI_BANDMODE_UNSET};
206be168c0dSopenharmony_ci+  void *quant_config;
207be168c0dSopenharmony_ci+  size_t quant_config_size = 0;
208be168c0dSopenharmony_ci+};
209be168c0dSopenharmony_ci+
210be168c0dSopenharmony_ci+class ExtensionOptionsParser {
211be168c0dSopenharmony_ci+public:
212be168c0dSopenharmony_ci+  static int Parse(const std::vector<Extension> &extensions, ExtensionOptions *param);
213be168c0dSopenharmony_ci+
214be168c0dSopenharmony_ci+private:
215be168c0dSopenharmony_ci+  static void DoParseBondMode(const std::vector<Extension> &extensions, mindspore::lite::HiAI_BandMode *band_mode);
216be168c0dSopenharmony_ci+  static void DoParseQuantConfig(const std::vector<Extension> &extensions, void **quant_config, size_t *num);
217be168c0dSopenharmony_ci+  static void DoParseCachePath(const std::vector<Extension> &extensions, std::string *cache_path);
218be168c0dSopenharmony_ci+  static void DoParseCacheVersion(const std::vector<Extension> &extensions, uint32_t *cache_version);
219be168c0dSopenharmony_ci+};
220be168c0dSopenharmony_ci+
221be168c0dSopenharmony_ci+}  // namespace mindspore::lite::nnrt
222be168c0dSopenharmony_ci+
223be168c0dSopenharmony_ci+#endif  // MINDSPORE_LITE_EXTENSION_OPTIONS_PARSER_H
224be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.cc b/mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.cc
225be168c0dSopenharmony_cinew file mode 100644
226be168c0dSopenharmony_ciindex 00000000..e7a52827
227be168c0dSopenharmony_ci--- /dev/null
228be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.cc
229be168c0dSopenharmony_ci@@ -0,0 +1,64 @@
230be168c0dSopenharmony_ci+/**
231be168c0dSopenharmony_ci+ * Copyright 2024 Huawei Technologies Co., Ltd
232be168c0dSopenharmony_ci+ *
233be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License");
234be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License.
235be168c0dSopenharmony_ci+ * You may obtain a copy of the License at
236be168c0dSopenharmony_ci+ *
237be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0
238be168c0dSopenharmony_ci+ *
239be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software
240be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS,
241be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
242be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and
243be168c0dSopenharmony_ci+ * limitations under the License.
244be168c0dSopenharmony_ci+ */
245be168c0dSopenharmony_ci+
246be168c0dSopenharmony_ci+#include "hiai_foundation_wrapper.h"
247be168c0dSopenharmony_ci+#include "dlfcn.h"
248be168c0dSopenharmony_ci+#include "src/common/log.h"
249be168c0dSopenharmony_ci+
250be168c0dSopenharmony_ci+namespace mindspore::lite {
251be168c0dSopenharmony_ci+static const char *HIAI_F_LIB = "libhiai_foundation.so";
252be168c0dSopenharmony_ci+
253be168c0dSopenharmony_ci+bool UnLoadHiaiFLibrary(void *handle) {
254be168c0dSopenharmony_ci+  if (handle != nullptr) {
255be168c0dSopenharmony_ci+    if (dlclose(handle) != 0) {
256be168c0dSopenharmony_ci+      MS_LOG(WARNING) << "dlclose failed, error: " << dlerror();
257be168c0dSopenharmony_ci+      return false;
258be168c0dSopenharmony_ci+    }
259be168c0dSopenharmony_ci+    return true;
260be168c0dSopenharmony_ci+  }
261be168c0dSopenharmony_ci+  return true;
262be168c0dSopenharmony_ci+}
263be168c0dSopenharmony_ci+
264be168c0dSopenharmony_ci+bool LoadHiaiFLibraryFromPath(void **handle_ptr) {
265be168c0dSopenharmony_ci+  if (handle_ptr == nullptr) {
266be168c0dSopenharmony_ci+    return false;
267be168c0dSopenharmony_ci+  }
268be168c0dSopenharmony_ci+
269be168c0dSopenharmony_ci+  *handle_ptr = dlopen(HIAI_F_LIB, RTLD_NOW | RTLD_LOCAL);
270be168c0dSopenharmony_ci+  if (*handle_ptr == nullptr) {
271be168c0dSopenharmony_ci+    return false;
272be168c0dSopenharmony_ci+  }
273be168c0dSopenharmony_ci+
274be168c0dSopenharmony_ci+// load function ptr use dlopen and dlsym.
275be168c0dSopenharmony_ci+#define LOAD_HIAIF_FUNCTION_PTR(func_name)                                                    \
276be168c0dSopenharmony_ci+  func_name = reinterpret_cast<func_name##Func>(dlsym(*handle_ptr, #func_name));               \
277be168c0dSopenharmony_ci+  if (func_name == nullptr) {                                                                  \
278be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "load func (" << #func_name << ") from (" << HIAI_F_LIB << ") failed!"; \
279be168c0dSopenharmony_ci+    UnLoadHiaiFLibrary(*handle_ptr);                                                          \
280be168c0dSopenharmony_ci+    return false;                                                                              \
281be168c0dSopenharmony_ci+  }
282be168c0dSopenharmony_ci+
283be168c0dSopenharmony_ci+  LOAD_HIAIF_FUNCTION_PTR(HMS_HiAIOptions_SetQuantConfig);
284be168c0dSopenharmony_ci+  LOAD_HIAIF_FUNCTION_PTR(HMS_HiAIOptions_SetBandMode);
285be168c0dSopenharmony_ci+  return true;
286be168c0dSopenharmony_ci+}
287be168c0dSopenharmony_ci+
288be168c0dSopenharmony_ci+#define HIAIF_DEFINE_FUNC_PTR(func) func##Func func = nullptr
289be168c0dSopenharmony_ci+HIAIF_DEFINE_FUNC_PTR(HMS_HiAIOptions_SetQuantConfig);
290be168c0dSopenharmony_ci+HIAIF_DEFINE_FUNC_PTR(HMS_HiAIOptions_SetBandMode);
291be168c0dSopenharmony_ci+
292be168c0dSopenharmony_ci+#undef LOAD_HIAIF_FUNCTION_PTR
293be168c0dSopenharmony_ci+}  // mindspore::lite
294be168c0dSopenharmony_ci\ No newline at end of file
295be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.h b/mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.h
296be168c0dSopenharmony_cinew file mode 100644
297be168c0dSopenharmony_ciindex 00000000..9231940d
298be168c0dSopenharmony_ci--- /dev/null
299be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/delegate/nnrt/hiai_foundation_wrapper.h
300be168c0dSopenharmony_ci@@ -0,0 +1,47 @@
301be168c0dSopenharmony_ci+/**
302be168c0dSopenharmony_ci+ * Copyright 2024 Huawei Technologies Co., Ltd
303be168c0dSopenharmony_ci+ *
304be168c0dSopenharmony_ci+ * Licensed under the Apache License, Version 2.0 (the "License");
305be168c0dSopenharmony_ci+ * you may not use this file except in compliance with the License.
306be168c0dSopenharmony_ci+ * You may obtain a copy of the License at
307be168c0dSopenharmony_ci+ *
308be168c0dSopenharmony_ci+ * http://www.apache.org/licenses/LICENSE-2.0
309be168c0dSopenharmony_ci+ *
310be168c0dSopenharmony_ci+ * Unless required by applicable law or agreed to in writing, software
311be168c0dSopenharmony_ci+ * distributed under the License is distributed on an "AS IS" BASIS,
312be168c0dSopenharmony_ci+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313be168c0dSopenharmony_ci+ * See the License for the specific language governing permissions and
314be168c0dSopenharmony_ci+ * limitations under the License.
315be168c0dSopenharmony_ci+ */
316be168c0dSopenharmony_ci+
317be168c0dSopenharmony_ci+#ifndef LITE_HIAI_FOUNDATION_WRAPPER_H
318be168c0dSopenharmony_ci+#define LITE_HIAI_FOUNDATION_WRAPPER_H
319be168c0dSopenharmony_ci+
320be168c0dSopenharmony_ci+#include <string>
321be168c0dSopenharmony_ci+#include "interfaces/kits/c/neural_network_runtime/neural_network_runtime.h"
322be168c0dSopenharmony_ci+
323be168c0dSopenharmony_ci+namespace mindspore::lite {
324be168c0dSopenharmony_ci+bool LoadHiaiFLibraryFromPath(void **handle_ptr);
325be168c0dSopenharmony_ci+bool UnLoadHiaiFLibrary(void *handle);
326be168c0dSopenharmony_ci+
327be168c0dSopenharmony_ci+typedef enum {
328be168c0dSopenharmony_ci+  /** Automatically adjusted by the system. */
329be168c0dSopenharmony_ci+  HIAI_BANDMODE_UNSET = 0,
330be168c0dSopenharmony_ci+  /** Low bandwidth mode. */
331be168c0dSopenharmony_ci+  HIAI_BANDMODE_LOW = 1,
332be168c0dSopenharmony_ci+  /** Medium bandwidth mode. */
333be168c0dSopenharmony_ci+  HIAI_BANDMODE_NORMAL = 2,
334be168c0dSopenharmony_ci+  /** High bandwidth mode. */
335be168c0dSopenharmony_ci+  HIAI_BANDMODE_HIGH = 3,
336be168c0dSopenharmony_ci+} HiAI_BandMode;
337be168c0dSopenharmony_ci+
338be168c0dSopenharmony_ci+using HMS_HiAIOptions_SetQuantConfigFunc = OH_NN_ReturnCode (*)(OH_NNCompilation*, void*, size_t);
339be168c0dSopenharmony_ci+using HMS_HiAIOptions_SetBandModeFunc = OH_NN_ReturnCode (*)(OH_NNCompilation*, HiAI_BandMode);
340be168c0dSopenharmony_ci+
341be168c0dSopenharmony_ci+#define HIAIF_DECLARE_FUNC_PTR(func) extern func##Func func
342be168c0dSopenharmony_ci+HIAIF_DECLARE_FUNC_PTR(HMS_HiAIOptions_SetQuantConfig);
343be168c0dSopenharmony_ci+HIAIF_DECLARE_FUNC_PTR(HMS_HiAIOptions_SetBandMode);
344be168c0dSopenharmony_ci+#undef HIAIF_DECLARE_FUNC_PTR
345be168c0dSopenharmony_ci+}  // mindspore::lite
346be168c0dSopenharmony_ci+
347be168c0dSopenharmony_ci+#endif  // LITE_HIAI_FOUNDATION_WRAPPER_H
348be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.cc b/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.cc
349be168c0dSopenharmony_ciindex a949c910..17abd0ed 100644
350be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.cc
351be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.cc
352be168c0dSopenharmony_ci@@ -29,26 +29,20 @@
353be168c0dSopenharmony_ci 
354be168c0dSopenharmony_ci namespace mindspore {
355be168c0dSopenharmony_ci namespace lite {
356be168c0dSopenharmony_ci-void NNRTDelegate::InitCachePath() {
357be168c0dSopenharmony_ci-  static const std::string kCachePathName = "CachePath";
358be168c0dSopenharmony_ci-  static const std::string kCacheVersion = "CacheVersion";
359be168c0dSopenharmony_ci-
360be168c0dSopenharmony_ci-  const auto &extensions = nnrt_device_info_.extensions_;
361be168c0dSopenharmony_ci-
362be168c0dSopenharmony_ci-  auto iter_path = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) {
363be168c0dSopenharmony_ci-    return extension.name == kCachePathName;
364be168c0dSopenharmony_ci-  });
365be168c0dSopenharmony_ci-  if (iter_path != extensions.end()) {
366be168c0dSopenharmony_ci-    cache_path_ = std::string(iter_path->value.begin(), iter_path->value.end());
367be168c0dSopenharmony_ci+Status NNRTDelegate::Init() {
368be168c0dSopenharmony_ci+#ifdef SUPPORT_NNRT_METAGRAPH
369be168c0dSopenharmony_ci+  auto ret = mindspore::lite::LoadHiaiFLibraryFromPath(&hiai_handle_);
370be168c0dSopenharmony_ci+  if (!ret || hiai_handle_ == nullptr) {
371be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "Load HiAI_Foundation so failed.";
372be168c0dSopenharmony_ci+    return kLiteError;
373be168c0dSopenharmony_ci   }
374be168c0dSopenharmony_ci+#endif
375be168c0dSopenharmony_ci+  return kSuccess;
376be168c0dSopenharmony_ci+}
377be168c0dSopenharmony_ci 
378be168c0dSopenharmony_ci-  auto iter_version = std::find_if(extensions.begin(), extensions.end(), [](const Extension &extension) {
379be168c0dSopenharmony_ci-    return extension.name == kCacheVersion;
380be168c0dSopenharmony_ci-  });
381be168c0dSopenharmony_ci-  if (iter_version != extensions.end()) {
382be168c0dSopenharmony_ci-    std::string version_str = std::string(iter_version->value.begin(), iter_version->value.end());
383be168c0dSopenharmony_ci-    cache_version_ = static_cast<uint32_t>(std::atol(version_str.c_str()));
384be168c0dSopenharmony_ci-  }
385be168c0dSopenharmony_ci+void NNRTDelegate::InitExtensionOptions() {
386be168c0dSopenharmony_ci+  const auto &extensions = nnrt_device_info_.extensions_;
387be168c0dSopenharmony_ci+  mindspore::lite::nnrt::ExtensionOptionsParser::Parse(extensions, &extension_options_);
388be168c0dSopenharmony_ci }
389be168c0dSopenharmony_ci 
390be168c0dSopenharmony_ci Status NNRTDelegate::Build(DelegateModel<schema::Primitive> *model) {
391be168c0dSopenharmony_ci@@ -59,11 +53,15 @@ Status NNRTDelegate::Build(DelegateModel<schema::Primitive> *model) {
392be168c0dSopenharmony_ci     return kLiteError;
393be168c0dSopenharmony_ci   }
394be168c0dSopenharmony_ci #ifdef SUPPORT_NNRT_METAGRAPH
395be168c0dSopenharmony_ci-  if (IsKirinNPU()) {
396be168c0dSopenharmony_ci-    MS_LOG(DEBUG) << "Choose to build nnrt model with Metagraph";
397be168c0dSopenharmony_ci-    InitCachePath();
398be168c0dSopenharmony_ci+  InitExtensionOptions();
399be168c0dSopenharmony_ci+  if (IsKirinNPUWithOnlineInference()) {
400be168c0dSopenharmony_ci+    MS_LOG(DEBUG) << "Choose to build online inference model";
401be168c0dSopenharmony_ci     return BuildKirinNPUModel(model);
402be168c0dSopenharmony_ci   }
403be168c0dSopenharmony_ci+  if (IsKirinNPUWithOfflineInference()) {
404be168c0dSopenharmony_ci+    MS_LOG(DEBUG) << "Choose to build offline inference model";
405be168c0dSopenharmony_ci+    return BuildOfflineModel(model);
406be168c0dSopenharmony_ci+  }
407be168c0dSopenharmony_ci #endif
408be168c0dSopenharmony_ci 
409be168c0dSopenharmony_ci   return BuildNormalModel(model);
410be168c0dSopenharmony_ci@@ -88,8 +86,8 @@ bool NNRTDelegate::IsCustomModel() const {
411be168c0dSopenharmony_ci }
412be168c0dSopenharmony_ci 
413be168c0dSopenharmony_ci #ifdef SUPPORT_NNRT_METAGRAPH
414be168c0dSopenharmony_ci-bool NNRTDelegate::IsKirinNPU() const {
415be168c0dSopenharmony_ci-  const std::string kirin_npu_name_prefix = "NPU_";
416be168c0dSopenharmony_ci+bool NNRTDelegate::CheckNPUPrefix(const std::string prefix_name) const {
417be168c0dSopenharmony_ci+  const std::string kirin_npu_name_prefix = prefix_name;
418be168c0dSopenharmony_ci   auto device_id = nnrt_device_info_.device_id_;
419be168c0dSopenharmony_ci   const char *device_name;
420be168c0dSopenharmony_ci   auto ret = OH_NNDevice_GetName(device_id, &device_name);
421be168c0dSopenharmony_ci@@ -105,6 +103,14 @@ bool NNRTDelegate::IsKirinNPU() const {
422be168c0dSopenharmony_ci   return true;
423be168c0dSopenharmony_ci }
424be168c0dSopenharmony_ci 
425be168c0dSopenharmony_ci+bool NNRTDelegate::IsKirinNPUWithOnlineInference() const {
426be168c0dSopenharmony_ci+  return CheckNPUPrefix("NPU_");
427be168c0dSopenharmony_ci+}
428be168c0dSopenharmony_ci+
429be168c0dSopenharmony_ci+bool NNRTDelegate::IsKirinNPUWithOfflineInference() const {
430be168c0dSopenharmony_ci+  return CheckNPUPrefix("HIAI_F");
431be168c0dSopenharmony_ci+}
432be168c0dSopenharmony_ci+
433be168c0dSopenharmony_ci Status NNRTDelegate::BuildKirinNPUModel(DelegateModel<schema::Primitive> *model) {
434be168c0dSopenharmony_ci   OH_NNModel *nn_model = OH_NNModel_Construct();
435be168c0dSopenharmony_ci   if (nn_model == nullptr) {
436be168c0dSopenharmony_ci@@ -142,6 +148,64 @@ Status NNRTDelegate::BuildKirinNPUModel(DelegateModel<schema::Primitive> *model)
437be168c0dSopenharmony_ci   return kSuccess;
438be168c0dSopenharmony_ci }
439be168c0dSopenharmony_ci 
440be168c0dSopenharmony_ci+namespace {
441be168c0dSopenharmony_ci+constexpr int32_t kNum2 = 2;
442be168c0dSopenharmony_ci+}
443be168c0dSopenharmony_ci+
444be168c0dSopenharmony_ci+Status NNRTDelegate::BuildOfflineModel(DelegateModel<schema::Primitive> *model) {
445be168c0dSopenharmony_ci+  if (!IsCustomModel()) {
446be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "not third party model";
447be168c0dSopenharmony_ci+    return kLiteNullptr;
448be168c0dSopenharmony_ci+  }
449be168c0dSopenharmony_ci+
450be168c0dSopenharmony_ci+  auto node = lite_graph_->all_nodes_[0];
451be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET(node != nullptr, kLiteError);
452be168c0dSopenharmony_ci+  auto input_num = node->input_indices_.size();
453be168c0dSopenharmony_ci+  // at least one input and one OM model buffer(as the last constant input)
454be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET(input_num >= kNum2, kLiteError);
455be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET(lite_graph_->all_tensors_.size() >= kNum2, kLiteError);
456be168c0dSopenharmony_ci+  auto tensor = lite_graph_->all_tensors_[node->input_indices_[input_num - 1]];
457be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET(tensor != nullptr, kLiteError);
458be168c0dSopenharmony_ci+  MS_CHECK_TRUE_RET(tensor->data() != nullptr, kLiteError);
459be168c0dSopenharmony_ci+  const uint8_t *model_buf = static_cast<const uint8_t *>(tensor->data()->data());
460be168c0dSopenharmony_ci+  size_t model_size = tensor->data()->size();
461be168c0dSopenharmony_ci+
462be168c0dSopenharmony_ci+  OH_NNCompilation *nn_compilation = OH_NNCompilation_ConstructWithOfflineModelBuffer(model_buf, model_size);
463be168c0dSopenharmony_ci+  if (nn_compilation == nullptr) {
464be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "Construct Offline NNCompilation failed";
465be168c0dSopenharmony_ci+    return kLiteError;
466be168c0dSopenharmony_ci+  }
467be168c0dSopenharmony_ci+  MS_LOG(DEBUG) << "NNRTDelegate creates NNCompilation success.";
468be168c0dSopenharmony_ci+
469be168c0dSopenharmony_ci+  auto ret_code = InitNNCompilation(nn_compilation);
470be168c0dSopenharmony_ci+  if (ret_code != kSuccess) {
471be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "Init NNCompilation failed";
472be168c0dSopenharmony_ci+    OH_NNCompilation_Destroy(&nn_compilation);
473be168c0dSopenharmony_ci+    return kLiteError;
474be168c0dSopenharmony_ci+  }
475be168c0dSopenharmony_ci+  MS_LOG(DEBUG) << "HiAI F InitNNCompilation success";
476be168c0dSopenharmony_ci+
477be168c0dSopenharmony_ci+  OH_NNExecutor *nn_executor = nullptr;
478be168c0dSopenharmony_ci+  nn_executor = OH_NNExecutor_Construct(nn_compilation);
479be168c0dSopenharmony_ci+  if (nn_executor == nullptr) {
480be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "Construct NNExecutor failed, ret: " << ret_code;
481be168c0dSopenharmony_ci+    OH_NNCompilation_Destroy(&nn_compilation);
482be168c0dSopenharmony_ci+    return kLiteError;
483be168c0dSopenharmony_ci+  }
484be168c0dSopenharmony_ci+  OH_NNCompilation_Destroy(&nn_compilation);
485be168c0dSopenharmony_ci+
486be168c0dSopenharmony_ci+  auto nnrt_model_kernel = new (std::nothrow) NNRTModelKernel(nn_executor, nnrt_device_info_.device_id_, model->inputs(), model->outputs());
487be168c0dSopenharmony_ci+  if (nnrt_model_kernel == nullptr) {
488be168c0dSopenharmony_ci+    OH_NNExecutor_Destroy(&nn_executor);
489be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "new NNRTModelKernel failed";
490be168c0dSopenharmony_ci+    return kLiteError;
491be168c0dSopenharmony_ci+  }
492be168c0dSopenharmony_ci+  nn_executor_list_.push_back(nn_executor);
493be168c0dSopenharmony_ci+
494be168c0dSopenharmony_ci+  (void)model->Replace(model->BeginKernelIterator(), model->EndKernelIterator(), nnrt_model_kernel);
495be168c0dSopenharmony_ci+  return kSuccess;
496be168c0dSopenharmony_ci+}
497be168c0dSopenharmony_ci+
498be168c0dSopenharmony_ci Status NNRTDelegate::CreateFullModelKernel(DelegateModel<schema::Primitive> *model, OH_NNModel *nn_model) {
499be168c0dSopenharmony_ci   OH_NNCompilation *nn_compilation = OH_NNCompilation_Construct(nn_model);
500be168c0dSopenharmony_ci   if (nn_compilation == nullptr) {
501be168c0dSopenharmony_ci@@ -473,14 +537,33 @@ Status NNRTDelegate::InitNNCompilation(OH_NNCompilation *nn_compilation) const {
502be168c0dSopenharmony_ci     return kLiteError;
503be168c0dSopenharmony_ci   }
504be168c0dSopenharmony_ci 
505be168c0dSopenharmony_ci-  if (!cache_path_.empty()) { // Set cache path if user indeed set it.
506be168c0dSopenharmony_ci-    ret_code = OH_NNCompilation_SetCache(nn_compilation, cache_path_.c_str(), cache_version_);
507be168c0dSopenharmony_ci+  if (!extension_options_.cache_path_.empty()) {  // Set cache path if user indeed set it.
508be168c0dSopenharmony_ci+    ret_code = OH_NNCompilation_SetCache(nn_compilation, extension_options_.cache_path_.c_str(),
509be168c0dSopenharmony_ci+                                         extension_options_.cache_version_);
510be168c0dSopenharmony_ci     if ((ret_code != OH_NN_SUCCESS) && (ret_code != OH_NN_OPERATION_FORBIDDEN)) {
511be168c0dSopenharmony_ci       MS_LOG(ERROR) << "NNCompilation set cache failed, ret: " << ret_code;
512be168c0dSopenharmony_ci       return kLiteError;
513be168c0dSopenharmony_ci     }
514be168c0dSopenharmony_ci   }
515be168c0dSopenharmony_ci 
516be168c0dSopenharmony_ci+#ifdef SUPPORT_NNRT_METAGRAPH
517be168c0dSopenharmony_ci+  ret_code = mindspore::lite::HMS_HiAIOptions_SetBandMode(nn_compilation, extension_options_.band_mode);
518be168c0dSopenharmony_ci+  if ((ret_code != OH_NN_SUCCESS) && (ret_code != OH_NN_OPERATION_FORBIDDEN)) {
519be168c0dSopenharmony_ci+    MS_LOG(ERROR) << "NNCompilation set BandMode failed, ret: " << ret_code;
520be168c0dSopenharmony_ci+    return kLiteError;
521be168c0dSopenharmony_ci+  }
522be168c0dSopenharmony_ci+
523be168c0dSopenharmony_ci+  if (extension_options_.quant_config != nullptr && extension_options_.quant_config_size != 0) {
524be168c0dSopenharmony_ci+    ret_code = mindspore::lite::HMS_HiAIOptions_SetQuantConfig(nn_compilation,
525be168c0dSopenharmony_ci+                                                                      extension_options_.quant_config,
526be168c0dSopenharmony_ci+                                                                      extension_options_.quant_config_size);
527be168c0dSopenharmony_ci+    if ((ret_code != OH_NN_SUCCESS) && (ret_code != OH_NN_OPERATION_FORBIDDEN)) {
528be168c0dSopenharmony_ci+      MS_LOG(ERROR) << "NNCompilation set QuantConfig failed, ret: " << ret_code;
529be168c0dSopenharmony_ci+      return kLiteError;
530be168c0dSopenharmony_ci+    }
531be168c0dSopenharmony_ci+  }
532be168c0dSopenharmony_ci+#endif
533be168c0dSopenharmony_ci+
534be168c0dSopenharmony_ci   ret_code = OH_NNCompilation_Build(nn_compilation);
535be168c0dSopenharmony_ci   if (ret_code != OH_NN_SUCCESS) {
536be168c0dSopenharmony_ci     MS_LOG(ERROR) << "Build NNCompilation failed, ret: " << ret_code;
537be168c0dSopenharmony_cidiff --git a/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.h b/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.h
538be168c0dSopenharmony_ciindex db2f0ee7..c1adc9f0 100644
539be168c0dSopenharmony_ci--- a/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.h
540be168c0dSopenharmony_ci+++ b/mindspore/lite/src/litert/delegate/nnrt/nnrt_delegate.h
541be168c0dSopenharmony_ci@@ -22,6 +22,8 @@
542be168c0dSopenharmony_ci #include "include/model.h"
543be168c0dSopenharmony_ci #include "src/litert/inner_context.h"
544be168c0dSopenharmony_ci #include "nnrt_model_kernel.h"
545be168c0dSopenharmony_ci+#include "hiai_foundation_wrapper.h"
546be168c0dSopenharmony_ci+#include "extension_options_parser.h"
547be168c0dSopenharmony_ci #include "schema/model_generated.h"
548be168c0dSopenharmony_ci #include "interfaces/kits/c/neural_network_runtime/neural_network_runtime_type.h"
549be168c0dSopenharmony_ci #include "interfaces/kits/c/neural_network_runtime/neural_network_runtime.h"
550be168c0dSopenharmony_ci@@ -43,7 +45,7 @@ class NNRTDelegate : public Delegate {
551be168c0dSopenharmony_ci   NNRTDelegate() = default;
552be168c0dSopenharmony_ci   NNRTDelegate(const NNRtDeviceInfo &nnrt_device_info) : nnrt_device_info_(nnrt_device_info) {}
553be168c0dSopenharmony_ci   ~NNRTDelegate() override;
554be168c0dSopenharmony_ci-  Status Init() override { return kSuccess; }
555be168c0dSopenharmony_ci+  Status Init() override;
556be168c0dSopenharmony_ci   Status Build(DelegateModel<schema::Primitive> *model) override;
557be168c0dSopenharmony_ci   void ShallowCopyLiteGraph(const lite::LiteGraph &liteGraph);
558be168c0dSopenharmony_ci   void FreeLiteGraph(lite::LiteGraph **liteGraph);
559be168c0dSopenharmony_ci@@ -57,7 +59,7 @@ class NNRTDelegate : public Delegate {
560be168c0dSopenharmony_ci                                                         const std::vector<bool> &op_supports);
561be168c0dSopenharmony_ci 
562be168c0dSopenharmony_ci  private:
563be168c0dSopenharmony_ci-  void InitCachePath();
564be168c0dSopenharmony_ci+  void InitExtensionOptions();
565be168c0dSopenharmony_ci   Status BuildNormalModel(DelegateModel<schema::Primitive> *model);
566be168c0dSopenharmony_ci   OH_NNModel *CreateFullNNModel();
567be168c0dSopenharmony_ci   std::vector<bool> QueryOpSupports(OH_NNModel *nn_model);
568be168c0dSopenharmony_ci@@ -82,21 +84,24 @@ class NNRTDelegate : public Delegate {
569be168c0dSopenharmony_ci   schema::Tensor *TensorToSchemaTensor(Tensor *lite_tensor, schema::Tensor *schema_tensor);
570be168c0dSopenharmony_ci 
571be168c0dSopenharmony_ci #ifdef SUPPORT_NNRT_METAGRAPH
572be168c0dSopenharmony_ci-  bool IsKirinNPU() const;
573be168c0dSopenharmony_ci+  bool CheckNPUPrefix(const std::string prefix_name) const;
574be168c0dSopenharmony_ci+  bool IsKirinNPUWithOnlineInference() const;
575be168c0dSopenharmony_ci+  bool IsKirinNPUWithOfflineInference() const;
576be168c0dSopenharmony_ci   Status BuildKirinNPUModel(DelegateModel<schema::Primitive> *model);
577be168c0dSopenharmony_ci+  Status BuildOfflineModel(DelegateModel<schema::Primitive> *model);
578be168c0dSopenharmony_ci   Status CreateFullModelKernel(DelegateModel<schema::Primitive> *model, OH_NNModel *nn_model);
579be168c0dSopenharmony_ci #endif
580be168c0dSopenharmony_ci 
581be168c0dSopenharmony_ci   NNRtDeviceInfo nnrt_device_info_;
582be168c0dSopenharmony_ci   LiteGraph *lite_graph_ = nullptr;
583be168c0dSopenharmony_ci   const void *meta_graph_ = nullptr;
584be168c0dSopenharmony_ci-  std::string cache_path_ = "";
585be168c0dSopenharmony_ci-  uint32_t cache_version_ = 0;
586be168c0dSopenharmony_ci+  nnrt::ExtensionOptions extension_options_;
587be168c0dSopenharmony_ci   std::vector<OH_NNExecutor *> nn_executor_list_;
588be168c0dSopenharmony_ci   std::vector<Tensor *> *dequant_src_tensors_;
589be168c0dSopenharmony_ci   std::map<uint32_t, schema::Tensor *> dequant_schema_tensors_;
590be168c0dSopenharmony_ci   std::map<schema::Tensor *, void *> dequant_schema_tensors_buffer_map_;
591be168c0dSopenharmony_ci   std::vector<schema::Tensor *> replaced_schema_tensors_;
592be168c0dSopenharmony_ci+  void *hiai_handle_{nullptr};
593be168c0dSopenharmony_ci };
594be168c0dSopenharmony_ci }  // namespace lite
595be168c0dSopenharmony_ci }  // namespace mindspore
596be168c0dSopenharmony_ci-- 
597be168c0dSopenharmony_ci2.17.1
598be168c0dSopenharmony_ci
599