已合并
fix: 修复OM2在线编译执行路径中的多个缺陷 #4122
wuzheng创建于 7月23日
fix: 修复OM2在线编译执行路径中的多个缺陷 #4122
已合并
wuzheng创建于 7月23日
12 个文件变更+239-259
@@ -15,6 +15,7 @@
15#include <cstdint>15#include <cstdint>
16#include <string>16#include <string>
17#include <fstream>17#include <fstream>
18+#include <utility>
18#include "framework/common/debug/log.h"19#include "framework/common/debug/log.h"
19 20 
20namespace ge {21namespace ge {
@@ -97,6 +98,14 @@ class JsonFile {
97 return data_;98 return data_;
98 }99 }
99 100 
101+ template <typename T, typename Fn>
102+ static void TryGetAndApply(const JsonFile &json_file, const std::string &key, Fn &&fn) {
103+ T value{};
104+ if (json_file.Get(key, value)) {
105+ std::forward<Fn>(fn)(value);
106+ }
107+ }
108+ 
100 private:109 private:
101 static constexpr int32_t kJsonPrettyIndent = 4;110 static constexpr int32_t kJsonPrettyIndent = 4;
102 json data_;111 json data_;
@@ -636,14 +636,6 @@ HostResourceCenterPtr GeRootModel::GetHostResourceCenterPtr() const {
636 return host_resource_center_;636 return host_resource_center_;
637}637}
638 638 
639-gert::Om2ModelData &GeRootModel::GetOm2ModelData() {
640- if (om2_model_data_ == nullptr) {
641- GELOGE(FAILED, "[GeRootModel] om2_model_data_ is null");
642- std::abort();
643- }
644- return *om2_model_data_;
645-}
646- 
647std::shared_ptr<GeRootModel> GeRootModel::Fork() {639std::shared_ptr<GeRootModel> GeRootModel::Fork() {
648 std::shared_ptr<GeRootModel> ge_root_model = MakeShared<ge::GeRootModel>();640 std::shared_ptr<GeRootModel> ge_root_model = MakeShared<ge::GeRootModel>();
649 GE_ASSERT_NOTNULL(ge_root_model);641 GE_ASSERT_NOTNULL(ge_root_model);
@@ -193,28 +193,27 @@ class GeRootModel : public std::enable_shared_from_this<GeRootModel> {
193 return custom_op_registry_;193 return custom_op_registry_;
194 }194 }
195 195 
196- bool HasOm2ModelData() const {
197- return om2_model_data_ != nullptr;
198- }
199 void SetOm2ModelData(std::shared_ptr<gert::Om2ModelData> data) {196 void SetOm2ModelData(std::shared_ptr<gert::Om2ModelData> data) {
200 om2_model_data_ = std::move(data);197 om2_model_data_ = std::move(data);
201 }198 }
202- gert::Om2ModelData &GetOm2ModelData();199+ const std::shared_ptr<gert::Om2ModelData> &GetOm2ModelData() const {
200+ return om2_model_data_;
201+ }
203 202 
204 std::shared_ptr<GeRootModel> Fork();203 std::shared_ptr<GeRootModel> Fork();
205 204 
206- inline void SetRootGraph(const ComputeGraphPtr &graph) {205+ void SetRootGraph(const ComputeGraphPtr &graph) {
207 root_graph_ = graph;206 root_graph_ = graph;
208 }207 }
209- inline const ComputeGraphPtr &GetRootGraph() const {208+ const ComputeGraphPtr &GetRootGraph() const {
210 return root_graph_;209 return root_graph_;
211 }210 }
212 211 
213- inline void SetModelName(const std::string &model_name) {212+ void SetModelName(const std::string &model_name) {
214 model_name_ = model_name;213 model_name_ = model_name;
215 }214 }
216 215 
217- inline const std::string &GetModelName() const {216+ const std::string &GetModelName() const {
218 return model_name_;217 return model_name_;
219 }218 }
220 219 
@@ -2873,9 +2873,10 @@ Status GraphManager::GetCompiledModel(uint32_t graph_id, ModelBufferData &model_
2873 GE_CHECK_NOTNULL(ge_root_model, "graph_id:%u", graph_id);2873 GE_CHECK_NOTNULL(ge_root_model, "graph_id:%u", graph_id);
2874 2874 
2875 // OM2 mode: serialize Om2ModelData to ModelBufferData2875 // OM2 mode: serialize Om2ModelData to ModelBufferData
2876- if (IsOm2OnlineMode() && ge_root_model->HasOm2ModelData()) {2876+ if (IsOm2OnlineMode()) {
2877 const auto &om2_model_data = ge_root_model->GetOm2ModelData();2877 const auto &om2_model_data = ge_root_model->GetOm2ModelData();
2878- return ge::Om2ZipSaver::Save(om2_model_data, model_buffer, false);2878+ GE_ASSERT_NOTNULL(om2_model_data, "[OM2] Missing Om2ModelData in OM2 online mode.");
2879+ return ge::Om2ZipSaver::Save(*om2_model_data, model_buffer, false);
2879 }2880 }
2880 2881 
2881 return SaveRootModel(ge_root_model, model_buffer);2882 return SaveRootModel(ge_root_model, model_buffer);
@@ -31,6 +31,7 @@ struct VISIBILITY_EXPORT Om2ModelLoadArg {
31 std::vector<ge::FileConstantMem> file_constant_mems;31 std::vector<ge::FileConstantMem> file_constant_mems;
32 bool need_clear_dfx_cache = false;32 bool need_clear_dfx_cache = false;
33 std::string om_path;33 std::string om_path;
34+ std::string weight_path;
34};35};
35 36 
36class VISIBILITY_EXPORT Om2ModelExecutor {37class VISIBILITY_EXPORT Om2ModelExecutor {
@@ -199,20 +199,20 @@ ge::Status BuildUserFileConstMemMap(const std::vector<ge::FileConstantMem> &file
199 return ge::SUCCESS;199 return ge::SUCCESS;
200}200}
201 201 
202-ge::Status ResolveFileConstWeightDir(const ge::ModelData &model_data, std::string &weight_dir) {202+ge::Status ResolveFileConstWeightDir(const std::string &weight_path, const std::string &om_path,
203+ std::string &weight_dir) {
203 weight_dir.clear();204 weight_dir.clear();
204- if (!model_data.weight_path.empty()) {205+ if (!weight_path.empty()) {
205- const auto real_weight_path = ge::om2::RealPath(model_data.weight_path.c_str());206+ const auto real_weight_path = ge::om2::RealPath(weight_path.c_str());
206- GE_ASSERT_TRUE(!real_weight_path.empty(), "[OM2][Check] Failed to resolve weight path: [%s].",207+ GE_ASSERT_TRUE(!real_weight_path.empty(), "[OM2][Check] Failed to resolve weight path: [%s].", weight_path.c_str());
207- model_data.weight_path.c_str());
208 weight_dir = real_weight_path + "/";208 weight_dir = real_weight_path + "/";
209 return ge::SUCCESS;209 return ge::SUCCESS;
210 }210 }
211- if (model_data.om_path.empty()) {211+ if (om_path.empty()) {
212 return ge::SUCCESS;212 return ge::SUCCESS;
213 }213 }
214- const auto real_om_path = ge::om2::RealPath(model_data.om_path.c_str());214+ const auto real_om_path = ge::om2::RealPath(om_path.c_str());
215- GE_ASSERT_TRUE(!real_om_path.empty(), "[OM2][Check] Failed to resolve om path: [%s].", model_data.om_path.c_str());215+ GE_ASSERT_TRUE(!real_om_path.empty(), "[OM2][Check] Failed to resolve om path: [%s].", om_path.c_str());
216 std::string om_dir;216 std::string om_dir;
217 std::string om_name;217 std::string om_name;
218 ge::om2::SplitFilePath(real_om_path, om_dir, om_name);218 ge::om2::SplitFilePath(real_om_path, om_dir, om_name);
@@ -36,7 +36,8 @@ struct FileConstContext {
36 36 
37ge::Status BuildUserFileConstMemMap(const std::vector<ge::FileConstantMem> &file_constant_mems,37ge::Status BuildUserFileConstMemMap(const std::vector<ge::FileConstantMem> &file_constant_mems,
38 std::map<std::string, ge::FileConstantMem> &file_name_to_mem);38 std::map<std::string, ge::FileConstantMem> &file_name_to_mem);
39-ge::Status ResolveFileConstWeightDir(const ge::ModelData &model_data, std::string &weight_dir);39+ge::Status ResolveFileConstWeightDir(const std::string &weight_path, const std::string &om_path,
40+ std::string &weight_dir);
40ge::Status ResolveFileConstFilePath(const std::string &weight_dir, const std::string &file_name,41ge::Status ResolveFileConstFilePath(const std::string &weight_dir, const std::string &file_name,
41 std::string &file_path);42 std::string &file_path);
42ge::Status PrepareCombinedConsts(const std::vector<Om2ConstItem> &const_items, const FileConstContext &ctx,43ge::Status PrepareCombinedConsts(const std::vector<Om2ConstItem> &const_items, const FileConstContext &ctx,
@@ -160,32 +160,25 @@ ge::Status ExtractEntryToBytes(const ge::RAIIZipArchive &archive, const std::str
160 return ge::SUCCESS;160 return ge::SUCCESS;
161}161}
162 162 
163-ge::Status ParseTensorDescFromJson(const ge::JsonFile::json &json, ge::Om2TensorDesc &desc) {163+ge::Status ParseTensorDescFromJson(const ge::JsonFile &json_file, ge::Om2TensorDesc &desc) {
164- if (json.contains("name")) {164+ ge::JsonFile::TryGetAndApply<std::string>(json_file, "name", [&](const std::string &v) { desc.SetName(v); });
165- desc.SetName(json["name"].get<std::string>());165+ ge::JsonFile::TryGetAndApply<std::vector<int64_t>>(json_file, "shape",
166- }166+ [&](const std::vector<int64_t> &v) { desc.SetShape(v); });
167- if (json.contains("shape")) {167+ ge::JsonFile::TryGetAndApply<std::string>(json_file, "data_type", [&](const std::string &v) {
168- desc.SetShape(json["shape"].get<std::vector<int64_t>>());168+ desc.SetDataType(ge::TypeUtilsInner::SerialStringToDataType(v));
169- }169+ });
170- if (json.contains("data_type")) {170+ ge::JsonFile::TryGetAndApply<std::string>(
171- desc.SetDataType(ge::TypeUtilsInner::SerialStringToDataType(json["data_type"].get<std::string>()));171+ json_file, "format", [&](const std::string &v) { desc.SetFormat(ge::TypeUtilsInner::SerialStringToFormat(v)); });
172- }172+ ge::JsonFile::TryGetAndApply<size_t>(json_file, "size", [&](const size_t &v) { desc.SetSize(v); });
173- if (json.contains("format")) {173+ ge::JsonFile::TryGetAndApply<std::vector<std::pair<int64_t, int64_t>>>(
174- desc.SetFormat(ge::TypeUtilsInner::SerialStringToFormat(json["format"].get<std::string>()));174+ json_file, "shape_range", [&](const std::vector<std::pair<int64_t, int64_t>> &v) { desc.SetShapeRange(v); });
175- }
176- if (json.contains("size")) {
177- desc.SetSize(json["size"].get<size_t>());
178- }
179- if (json.contains("shape_range")) {
180- desc.SetShapeRange(json["shape_range"].get<std::vector<std::pair<int64_t, int64_t>>>());
181- }
182 return ge::SUCCESS;175 return ge::SUCCESS;
183}176}
184 177 
185-ge::Status ParseOpAttrMapJson(const std::string &json_str,178+ge::Status ParseOpAttrMapJson(const uint8_t *data, size_t data_size,
186 std::map<std::string, std::map<std::string, std::string>> &op_attr_map) {179 std::map<std::string, std::map<std::string, std::string>> &op_attr_map) {
187 try {180 try {
188- const auto json_obj = ge::JsonFile::json::parse(json_str);181+ const auto json_obj = ge::JsonFile::json::parse(data, data + data_size);
189 if (!json_obj.is_object()) {182 if (!json_obj.is_object()) {
190 GELOGW("[OM2] op_attr.json root is not an object");183 GELOGW("[OM2] op_attr.json root is not an object");
191 return ge::FAILED;184 return ge::FAILED;
@@ -213,134 +206,88 @@ ge::Status ParseOpAttrMapJson(const std::string &json_str,
213 }206 }
214}207}
215 208 
216-ge::Status DeserializeCodegenArtifactsFromArchive(const ge::RAIIZipArchive &archive,209+ge::Status DeserializeCodegenEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
217- const std::vector<std::string> &entries,210+ gert::Om2ModelData &model_data) {
218- gert::Om2ModelData &model_data) {211+ ge::Om2CodegenArtifact artifact;
219- for (const auto &entry : entries) {212+ artifact.file_name = ExtractParentDirAndFileName(entry).second;
220- if (!IsFileNameEndsWith(entry, ".so")) {213+ std::string content;
221- continue;214+ GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, content));
222- }215+ artifact.data = std::move(content);
223- ge::Om2CodegenArtifact artifact;216+ model_data.program_body.so_artifact = std::move(artifact);
224- artifact.file_name = ExtractParentDirAndFileName(entry).second;
225- std::string content;
226- GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, content));
227- artifact.data = std::move(content);
228- model_data.program_body.so_artifact = std::move(artifact);
229- return ge::SUCCESS;
230- }
231 return ge::SUCCESS;217 return ge::SUCCESS;
232}218}
233 219 
234-ge::Status DeserializeWeightDataFromArchive(const ge::RAIIZipArchive &archive, const std::vector<std::string> &entries,220+ge::Status DeserializeWeightEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
ClarkXie
ClarkXieClarkXie7月24日

就一行,冗余的抽取吧

likedislike
wuzheng
7月25日 评论:
235- gert::Om2ModelData &model_data) {221+ gert::Om2ModelData &model_data) {
236- const std::string weight_prefix = "data/constants/constant_";222+ GE_ASSERT_SUCCESS(ExtractEntryToBytes(archive, entry, model_data.constants_data.weight_data));
237- for (const auto &entry : entries) {
238- if ((entry.find(weight_prefix) != std::string::npos) && !IsFileNameEndsWith(entry, ".json")) {
239- GE_ASSERT_SUCCESS(ExtractEntryToBytes(archive, entry, model_data.constants_data.weight_data));
240- return ge::SUCCESS;
241- }
242- }
243 return ge::SUCCESS;223 return ge::SUCCESS;
244}224}
245 225 
246-ge::Status DeserializeConstantsConfigFromArchive(const ge::RAIIZipArchive &archive,226+ge::Status DeserializeConstantsConfigEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
247- const std::vector<std::string> &entries,
248- gert::Om2ModelData &model_data) {
249- const std::string constants_dir = "data/constants/";
250- for (const auto &entry : entries) {
251- if ((entry.find(constants_dir) == std::string::npos) || !IsFileNameEndsWith(entry, "_constants_config.json")) {
252- continue;
253- }
254- std::string json_str;
255- GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, json_str));
256- const ge::JsonFile json_file(reinterpret_cast<const uint8_t *>(json_str.data()), json_str.size());
257- GE_ASSERT_TRUE(json_file.IsValid(), "[OM2] Invalid constants config JSON from entry %s", entry.c_str());
258- 
259- size_t internal_weight_size{0U};
260- (void)json_file.Get("internal_weight_size", internal_weight_size);
261- model_data.constants_data.internal_weight_size = internal_weight_size;
262- 
263- ge::JsonFile::json consts_json;
264- if (json_file.Get("consts", consts_json) && consts_json.is_object()) {
265- for (auto &[key, val] : consts_json.items()) {
266- (void)key;
267- ge::Om2ConstMeta meta;
268- if (val.contains("index")) {
269- meta.index = val["index"].get<size_t>();
270- }
271- if (val.contains("type")) {
272- meta.type = val["type"].get<std::string>();
273- }
274- if (val.contains("file_name")) {
275- meta.file_name = val["file_name"].get<std::string>();
276- }
277- if (val.contains("file_path")) {
278- meta.file_path = val["file_path"].get<std::string>();
279- }
280- if (val.contains("offset")) {
281- meta.offset = val["offset"].get<int64_t>();
282- }
283- if (val.contains("size")) {
284- meta.size = val["size"].get<int64_t>();
285- }
286- if (val.contains("op_name")) {
287- meta.op_name = val["op_name"].get<std::string>();
288- }
289- (void)model_data.constants_data.consts.emplace_back(std::move(meta));
290- }
291- }
292- break;
293- }
294- return ge::SUCCESS;
295-}
296- 
297-ge::Status DeserializeKernelBinariesFromArchive(const ge::RAIIZipArchive &archive,
298- const std::vector<std::string> &entries,
299- gert::Om2ModelData &model_data) {
300- for (const auto &entry : entries) {
301- if (!IsFileNameEndsWith(entry, ".o")) {
302- continue;
303- }
304- gert::Om2KernelBinary kernel_binary;
305- kernel_binary.name = ExtractParentDirAndFileName(entry).second;
306- GE_ASSERT_SUCCESS(ExtractEntryToBytes(archive, entry, kernel_binary.data));
307- (void)model_data.kernel_binaries.emplace_back(std::move(kernel_binary));
308- }
309- return ge::SUCCESS;
310-}
311- 
312-ge::Status DeserializeModelMetaFromArchive(const ge::RAIIZipArchive &archive, const std::vector<std::string> &entries,
313 gert::Om2ModelData &model_data) {227 gert::Om2ModelData &model_data) {
314- std::string json_str;228+ size_t buff_size = 0U;
315- bool found = false;229+ auto buff_data = archive.ExtractToMem(entry, buff_size);
316- for (const auto &entry : entries) {230+ GE_ASSERT_NOTNULL(buff_data, "[OM2] Failed to extract %s", entry.c_str());
317- if (IsFileNameEndsWith(entry, "data/model_0/model_meta.json")) {231+ GE_ASSERT_TRUE(buff_size > 0U);
318- GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, json_str));232+ const ge::JsonFile json_file(buff_data.get(), buff_size);
319- found = true;233+ GE_ASSERT_TRUE(json_file.IsValid(), "[OM2] Invalid constants config JSON from entry %s", entry.c_str());
320- break;234+ 
235+ size_t internal_weight_size{0U};
236+ (void)json_file.Get("internal_weight_size", internal_weight_size);
237+ model_data.constants_data.internal_weight_size = internal_weight_size;
238+ 
239+ ge::JsonFile::json consts_json;
240+ if (json_file.Get("consts", consts_json) && consts_json.is_object()) {
241+ for (auto &[key, val] : consts_json.items()) {
242+ (void)key;
243+ const ge::JsonFile val_file(val);
ClarkXie
ClarkXieClarkXie7月24日

这里为每个常量项执行 JsonFile val_file(val),但 JsonFile(json) 的参数按值传递,而 valitems() 返回的引用,因此会深拷贝整个 JSON 子树。常量项较多时会引入额外的内存分配和复制,相比原实现属于性能回退。建议提供基于 const json & 的只读访问方式,或直接通过不复制 val 的辅助接口读取字段。代码上下文:https://gitcode.com/cann/ge/blob/b4f7c71037d104824d0344254049ca814f81a3c6/runtime/om2/om2_model_executor.cc#L250-L263

likedislike
244+ ge::Om2ConstMeta meta;
245+ (void)val_file.Get("index", meta.index);
246+ (void)val_file.Get("type", meta.type);
247+ (void)val_file.Get("file_name", meta.file_name);
248+ (void)val_file.Get("file_path", meta.file_path);
249+ (void)val_file.Get("offset", meta.offset);
250+ (void)val_file.Get("size", meta.size);
251+ (void)val_file.Get("op_name", meta.op_name);
252+ (void)model_data.constants_data.consts.emplace_back(std::move(meta));
321 }253 }
322 }254 }
323- if (!found) {255+ return ge::SUCCESS;
324- GELOGW("[OM2] model_meta.json not found in ZIP archive");256+}
325- return ge::SUCCESS;
326- }
327 257 
328- const ge::JsonFile json_file(reinterpret_cast<const uint8_t *>(json_str.data()), json_str.size());258+ge::Status DeserializeKernelEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
259+ gert::Om2ModelData &model_data) {
260+ gert::Om2KernelBinary kernel_binary;
261+ kernel_binary.name = ExtractParentDirAndFileName(entry).second;
262+ GE_ASSERT_SUCCESS(ExtractEntryToBytes(archive, entry, kernel_binary.data));
263+ (void)model_data.kernel_binaries.emplace_back(std::move(kernel_binary));
264+ return ge::SUCCESS;
265+}
266+ 
267+ge::Status DeserializeModelMetaEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
268+ gert::Om2ModelData &model_data) {
269+ size_t buff_size = 0U;
270+ auto buff_data = archive.ExtractToMem(entry, buff_size);
271+ GE_ASSERT_NOTNULL(buff_data, "[OM2] Failed to extract %s", entry.c_str());
272+ GE_ASSERT_TRUE(buff_size > 0U);
273+ const ge::JsonFile json_file(buff_data.get(), buff_size);
329 GE_ASSERT_TRUE(json_file.IsValid(), "[OM2] Invalid model_meta.json");274 GE_ASSERT_TRUE(json_file.IsValid(), "[OM2] Invalid model_meta.json");
330 275 
331 ge::JsonFile::json inputs_json;276 ge::JsonFile::json inputs_json;
332 if (json_file.Get("inputs", inputs_json) && inputs_json.is_array()) {277 if (json_file.Get("inputs", inputs_json) && inputs_json.is_array()) {
333 for (const auto &input_json : inputs_json) {278 for (const auto &input_json : inputs_json) {
334- GE_ASSERT_TRUE(input_json.contains("shape_v2"), "[OM2] input shape_v2 not found in model_meta.json");279+ const ge::JsonFile input_file(input_json);
280+ std::vector<int64_t> shape_v2;
281+ GE_ASSERT_TRUE(input_file.Get("shape_v2", shape_v2), "[OM2] input shape_v2 not found in model_meta.json");
335 ge::Om2TensorDesc desc;282 ge::Om2TensorDesc desc;
336- GE_ASSERT_SUCCESS(ParseTensorDescFromJson(input_json, desc));283+ GE_ASSERT_SUCCESS(ParseTensorDescFromJson(input_file, desc));
337 model_data.model_meta.input_desc.emplace_back(desc);284 model_data.model_meta.input_desc.emplace_back(desc);
338 ge::Om2TensorDesc desc_v2 = desc;285 ge::Om2TensorDesc desc_v2 = desc;
339- desc_v2.SetShape(input_json["shape_v2"].get<std::vector<int64_t>>());286+ desc_v2.SetShape(shape_v2);
340 model_data.model_meta.input_desc_v2.emplace_back(desc_v2);287 model_data.model_meta.input_desc_v2.emplace_back(desc_v2);
341- if (input_json.contains("origin_input_dims")) {288+ std::vector<int64_t> origin_input_dims;
342- model_data.model_meta.origin_input_dims.emplace_back(289+ if (input_file.Get("origin_input_dims", origin_input_dims)) {
343- input_json["origin_input_dims"].get<std::vector<int64_t>>());290+ model_data.model_meta.origin_input_dims.emplace_back(std::move(origin_input_dims));
344 } else {291 } else {
345 (void)model_data.model_meta.origin_input_dims.emplace_back(desc.GetShape());292 (void)model_data.model_meta.origin_input_dims.emplace_back(desc.GetShape());
346 }293 }
@@ -350,8 +297,9 @@ ge::Status DeserializeModelMetaFromArchive(const ge::RAIIZipArchive &archive, co
350 ge::JsonFile::json outputs_json;297 ge::JsonFile::json outputs_json;
351 if (json_file.Get("outputs", outputs_json) && outputs_json.is_array()) {298 if (json_file.Get("outputs", outputs_json) && outputs_json.is_array()) {
352 for (const auto &output_json : outputs_json) {299 for (const auto &output_json : outputs_json) {
300+ const ge::JsonFile output_file(output_json);
353 ge::Om2TensorDesc desc;301 ge::Om2TensorDesc desc;
354- GE_ASSERT_SUCCESS(ParseTensorDescFromJson(output_json, desc));302+ GE_ASSERT_SUCCESS(ParseTensorDescFromJson(output_file, desc));
355 model_data.model_meta.output_desc.emplace_back(desc);303 model_data.model_meta.output_desc.emplace_back(desc);
356 model_data.model_meta.output_desc_v2.emplace_back(desc);304 model_data.model_meta.output_desc_v2.emplace_back(desc);
357 }305 }
@@ -368,67 +316,74 @@ ge::Status DeserializeModelMetaFromArchive(const ge::RAIIZipArchive &archive, co
368 return ge::SUCCESS;316 return ge::SUCCESS;
369}317}
370 318 
371-ge::Status DeserializeDebugInfoFromArchive(const ge::RAIIZipArchive &archive, const std::vector<std::string> &entries,319+ge::Status DeserializeOpAttrEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
372- gert::Om2ModelData &model_data) {320+ gert::Om2ModelData &model_data) {
373- for (const auto &entry : entries) {321+ size_t buff_size = 0U;
374- if (IsFileNameEndsWith(entry, "op_attr.json")) {322+ auto buff_data = archive.ExtractToMem(entry, buff_size);
375- std::string json_str;323+ GE_ASSERT_NOTNULL(buff_data, "[OM2] Failed to extract %s", entry.c_str());
376- GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, json_str));324+ GE_ASSERT_TRUE(buff_size > 0U);
377- if (ParseOpAttrMapJson(json_str, model_data.debug_info.op_attr_map) != ge::SUCCESS) {325+ if (ParseOpAttrMapJson(buff_data.get(), buff_size, model_data.debug_info.op_attr_map) != ge::SUCCESS) {
378- GELOGW("[OM2] Failed to parse op_attr.json, using empty map");326+ GELOGW("[OM2] Failed to parse op_attr.json, using empty map");
379- model_data.debug_info.op_attr_map.clear();327+ model_data.debug_info.op_attr_map.clear();
380- }
381- break;
382- }
383- }
384- 
385- for (const auto &entry : entries) {
386- const std::string debug_file = ExtractParentDirAndFileName(entry).second;
387- if ((debug_file.find("ge_visual_") != std::string::npos) && IsFileNameEndsWith(debug_file, ".json")) {
388- GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, model_data.debug_info.visual_json));
389- break;
390- }
391 }328 }
392 return ge::SUCCESS;329 return ge::SUCCESS;
393}330}
394 331 
395-ge::Status DeserializeManifestFromArchive(const ge::RAIIZipArchive &archive, const std::vector<std::string> &entries,332+ge::Status DeserializeVisualEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
396- gert::Om2ModelData &model_data) {333+ gert::Om2ModelData &model_data) {
397- for (const auto &entry : entries) {334+ GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, model_data.debug_info.visual_json));
398- if (IsFileNameEndsWith(entry, "manifest.json")) {335+ return ge::SUCCESS;
399- std::string json_str;336+}
400- GE_ASSERT_SUCCESS(ExtractEntryToString(archive, entry, json_str));337+ 
401- try {338+ge::Status HandleArchiveEntry(const ge::RAIIZipArchive &archive, const std::string &entry,
402- const auto manifest_json = nlohmann::json::parse(json_str);339+ gert::Om2ModelData &model_data) {
403- for (auto it = manifest_json.begin(); it != manifest_json.end(); ++it) {340+ if (entry.find("/runtime/") != std::string::npos && IsFileNameEndsWith(entry, ".so")) {
404- if (it.value().is_string()) {341+ GE_ASSERT_SUCCESS(DeserializeCodegenEntry(archive, entry, model_data));
405- model_data.manifest[it.key()] = it.value().get<std::string>();342+ return ge::SUCCESS;
406- } else {343+ }
407- model_data.manifest[it.key()] = it.value().dump();344+ if (entry.find("/debug/") != std::string::npos) {
408- }345+ if (IsFileNameEndsWith(entry, "op_attr.json")) {
409- }346+ GE_ASSERT_SUCCESS(DeserializeOpAttrEntry(archive, entry, model_data));
410- } catch (const std::exception &e) {347+ } else {
411- GELOGW("[OM2] Failed to parse manifest.json, msg: %s", e.what());348+ const std::string debug_file = ExtractParentDirAndFileName(entry).second;
412- }349+ if ((debug_file.find("ge_visual_") != std::string::npos) && IsFileNameEndsWith(debug_file, ".json")) {
413- return ge::SUCCESS;350+ GE_ASSERT_SUCCESS(DeserializeVisualEntry(archive, entry, model_data));
414- }351+ }
352+ }
353+ return ge::SUCCESS;
354+ }
355+ if (IsFileNameEndsWith(entry, "model_meta.json")) {
356+ GE_ASSERT_SUCCESS(DeserializeModelMetaEntry(archive, entry, model_data));
357+ return ge::SUCCESS;
358+ }
359+ if (entry.find("data/constants/") != std::string::npos) {
360+ if (IsFileNameEndsWith(entry, "_constants_config.json")) {
361+ GE_ASSERT_SUCCESS(DeserializeConstantsConfigEntry(archive, entry, model_data));
362+ } else if (entry.find("data/constants/constant_") != std::string::npos) {
363+ GE_ASSERT_SUCCESS(DeserializeWeightEntry(archive, entry, model_data));
364+ }
365+ return ge::SUCCESS;
366+ }
367+ if (entry.find("data/kernels_") != std::string::npos && IsFileNameEndsWith(entry, ".o")) {
368+ GE_ASSERT_SUCCESS(DeserializeKernelEntry(archive, entry, model_data));
415 }369 }
416- GELOGW("[OM2] manifest.json not found in ZIP archive");
417 return ge::SUCCESS;370 return ge::SUCCESS;
418}371}
419 372 
420ge::Status DeserializeOm2ModelDataFromArchive(ge::RAIIZipArchive &archive, gert::Om2ModelData &model_data) {373ge::Status DeserializeOm2ModelDataFromArchive(ge::RAIIZipArchive &archive, gert::Om2ModelData &model_data) {
421- GE_ASSERT_TRUE(archive.IsGood(), "[OM2] Failed to open OM2 ZIP archive for deserialization");374+ const auto &entries = archive.ListFiles();
422- const auto entries = archive.ListFiles();375+ if (entries.empty()) {
423- GE_ASSERT_TRUE(!entries.empty(), "[OM2] ZIP archive is empty");376+ GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[OM2] ZIP archive is empty");
377+ return ACL_ERROR_GE_PARAM_INVALID;
378+ }
424 379 
425- GE_ASSERT_SUCCESS(DeserializeCodegenArtifactsFromArchive(archive, entries, model_data));380+ for (const auto &entry : entries) {
426- GE_ASSERT_SUCCESS(DeserializeWeightDataFromArchive(archive, entries, model_data));381+ GE_ASSERT_SUCCESS(HandleArchiveEntry(archive, entry, model_data));
427- GE_ASSERT_SUCCESS(DeserializeConstantsConfigFromArchive(archive, entries, model_data));382+ }
428- GE_ASSERT_SUCCESS(DeserializeKernelBinariesFromArchive(archive, entries, model_data));383+ 
429- GE_ASSERT_SUCCESS(DeserializeModelMetaFromArchive(archive, entries, model_data));384+ GE_ASSERT_TRUE(!model_data.model_meta.model_name.empty(), "[OM2] model_meta.json not found in ZIP archive.");
430- GE_ASSERT_SUCCESS(DeserializeDebugInfoFromArchive(archive, entries, model_data));385+ GE_ASSERT_TRUE(!model_data.program_body.so_artifact.file_name.empty(),
431- GE_ASSERT_SUCCESS(DeserializeManifestFromArchive(archive, entries, model_data));386+ "[OM2] Compiled .so not found in ZIP archive.");
432 return ge::SUCCESS;387 return ge::SUCCESS;
433}388}
434 389 
@@ -738,12 +693,9 @@ class Om2ModelExecutor::Impl {
738 GE_ASSERT_SUCCESS(BuildUserFileConstMemMap(load_arg.file_constant_mems, user_file_const_mems));693 GE_ASSERT_SUCCESS(BuildUserFileConstMemMap(load_arg.file_constant_mems, user_file_const_mems));
739 GE_ASSERT_SUCCESS(694 GE_ASSERT_SUCCESS(
740 PrepareInternalConsts(weight_buf, load_arg, classified_items.internal_consts, internal_weight_size, constants));695 PrepareInternalConsts(weight_buf, load_arg, classified_items.internal_consts, internal_weight_size, constants));
741- // Build a ModelData with om_path from load_arg for file const resolution696+ GE_ASSERT_SUCCESS(PrepareCombinedConsts(load_arg.weight_path, load_arg.om_path, user_file_const_mems,
742- ge::ModelData model_data_for_consts;
743- model_data_for_consts.om_path = load_arg.om_path;
744- GE_ASSERT_SUCCESS(PrepareCombinedConsts(model_data_for_consts, user_file_const_mems,
745 classified_items.combined_consts, constants));697 classified_items.combined_consts, constants));
746- GE_ASSERT_SUCCESS(PrepareIndividualConsts(model_data_for_consts, user_file_const_mems,698+ GE_ASSERT_SUCCESS(PrepareIndividualConsts(load_arg.weight_path, load_arg.om_path, user_file_const_mems,
747 classified_items.individual_consts, constants));699 classified_items.individual_consts, constants));
748 return ge::SUCCESS;700 return ge::SUCCESS;
749 }701 }
@@ -1073,35 +1025,35 @@ class Om2ModelExecutor::Impl {
1073 return ge::SUCCESS;1025 return ge::SUCCESS;
1074 }1026 }
1075 1027 
1076- ge::Status PrepareCombinedConsts(const ge::ModelData &model_data,1028+ ge::Status PrepareCombinedConsts(const std::string &weight_path, const std::string &om_path,
1077 const std::map<std::string, ge::FileConstantMem> &user_file_const_mems,1029 const std::map<std::string, ge::FileConstantMem> &user_file_const_mems,
1078 const std::vector<Om2ConstItem> &const_items, std::vector<void *> &constants) {1030 const std::vector<Om2ConstItem> &const_items, std::vector<void *> &constants) {
1079 if (const_items.empty()) {1031 if (const_items.empty()) {
1080 return ge::SUCCESS;1032 return ge::SUCCESS;
1081 }1033 }
1082 FileConstContext file_const_ctx;1034 FileConstContext file_const_ctx;
1083- GE_ASSERT_SUCCESS(BuildFileConstContext(model_data, user_file_const_mems, file_const_ctx));1035+ GE_ASSERT_SUCCESS(BuildFileConstContext(weight_path, om_path, user_file_const_mems, file_const_ctx));
1084 GE_ASSERT_SUCCESS(gert::PrepareCombinedConsts(const_items, file_const_ctx, constants));1036 GE_ASSERT_SUCCESS(gert::PrepareCombinedConsts(const_items, file_const_ctx, constants));
1085 return ge::SUCCESS;1037 return ge::SUCCESS;
1086 }1038 }
1087 1039 
1088- ge::Status PrepareIndividualConsts(const ge::ModelData &model_data,1040+ ge::Status PrepareIndividualConsts(const std::string &weight_path, const std::string &om_path,
1089 const std::map<std::string, ge::FileConstantMem> &user_file_const_mems,1041 const std::map<std::string, ge::FileConstantMem> &user_file_const_mems,
1090 const std::vector<Om2ConstItem> &const_items, std::vector<void *> &constants) {1042 const std::vector<Om2ConstItem> &const_items, std::vector<void *> &constants) {
1091 if (const_items.empty()) {1043 if (const_items.empty()) {
1092 return ge::SUCCESS;1044 return ge::SUCCESS;
1093 }1045 }
1094 FileConstContext file_const_ctx;1046 FileConstContext file_const_ctx;
1095- GE_ASSERT_SUCCESS(BuildFileConstContext(model_data, user_file_const_mems, file_const_ctx));1047+ GE_ASSERT_SUCCESS(BuildFileConstContext(weight_path, om_path, user_file_const_mems, file_const_ctx));
1096 GE_ASSERT_SUCCESS(gert::PrepareIndividualConsts(const_items, file_const_ctx, device_id_, constants));1048 GE_ASSERT_SUCCESS(gert::PrepareIndividualConsts(const_items, file_const_ctx, device_id_, constants));
1097 return ge::SUCCESS;1049 return ge::SUCCESS;
1098 }1050 }
1099 1051 
1100- ge::Status BuildFileConstContext(const ge::ModelData &model_data,1052+ ge::Status BuildFileConstContext(const std::string &weight_path, const std::string &om_path,
1101 const std::map<std::string, ge::FileConstantMem> &user_file_const_mems,1053 const std::map<std::string, ge::FileConstantMem> &user_file_const_mems,
1102 FileConstContext &file_const_ctx) {1054 FileConstContext &file_const_ctx) {
1103 std::string weight_dir;1055 std::string weight_dir;
1104- GE_ASSERT_SUCCESS(ResolveFileConstWeightDir(model_data, weight_dir));1056+ GE_ASSERT_SUCCESS(ResolveFileConstWeightDir(weight_path, om_path, weight_dir));
1105 file_const_ctx.weight_dir = weight_dir;1057 file_const_ctx.weight_dir = weight_dir;
1106 file_const_ctx.user_file_const_mems = &user_file_const_mems;1058 file_const_ctx.user_file_const_mems = &user_file_const_mems;
1107 file_const_ctx.owned_buffers = &owned_buffers_;1059 file_const_ctx.owned_buffers = &owned_buffers_;
@@ -1144,12 +1096,14 @@ ge::Status Om2ModelExecutor::Load(ge::ModelData &model_data, const Om2ModelLoadA
1144 const uint64_t session_id) const {1096 const uint64_t session_id) const {
1145 gert::Om2ModelData om2_data;1097 gert::Om2ModelData om2_data;
1146 ge::RAIIZipArchive archive(static_cast<const uint8_t *>(model_data.model_data), model_data.model_len);1098 ge::RAIIZipArchive archive(static_cast<const uint8_t *>(model_data.model_data), model_data.model_len);
1147- GE_ASSERT_TRUE(archive.IsGood(), "[OM2] Failed to open OM2 ZIP archive for deserialization");1099+ if (!archive.IsGood()) {
1100+ GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[OM2] Failed to open OM2 ZIP archive for deserialization");
1101+ return ACL_ERROR_GE_PARAM_INVALID;
1102+ }
1148 GE_ASSERT_SUCCESS(DeserializeOm2ModelDataFromArchive(archive, om2_data));1103 GE_ASSERT_SUCCESS(DeserializeOm2ModelDataFromArchive(archive, om2_data));
1149 Om2ModelLoadArg load_arg_with_path = load_arg;1104 Om2ModelLoadArg load_arg_with_path = load_arg;
1150- if (load_arg_with_path.om_path.empty()) {1105+ load_arg_with_path.om_path = model_data.om_path;
1151- load_arg_with_path.om_path = model_data.om_path;1106+ load_arg_with_path.weight_path = model_data.weight_path;
1152- }
1153 return Load(om2_data, load_arg_with_path, session_id);1107 return Load(om2_data, load_arg_with_path, session_id);
1154}1108}
1155 1109 
@@ -357,6 +357,8 @@ Status ModelExecutor::RunGraphWithStream(const GraphNodePtr &graph_node, const G
357 GELOGE(ret, "[Execute][OM2][Graph] With Stream failed, graph_id = %u.", graph_id);357 GELOGE(ret, "[Execute][OM2][Graph] With Stream failed, graph_id = %u.", graph_id);
358 return ret;358 return ret;
359 }359 }
360+ outputs.clear();
361+ GE_ASSERT_SUCCESS(TensorTransUtils::GertTensors2GeTensors(gert_outputs, outputs));
360 return SUCCESS;362 return SUCCESS;
361 }363 }
362 const auto ret = graph_executor_.ExecuteGraphWithStream(stream, graph_node, ge_root_model, inputs, outputs);364 const auto ret = graph_executor_.ExecuteGraphWithStream(stream, graph_node, ge_root_model, inputs, outputs);
@@ -979,8 +981,8 @@ Status ModelExecutor::LoadOm2Graph(const GeRootModelPtr &ge_root_model, const Gr
979 // NOTE: Load 阶段不需要 stream。stream 在 Execute 阶段通过 RunOm2Graph 传递给 RunAsync。981 // NOTE: Load 阶段不需要 stream。stream 在 Execute 阶段通过 RunOm2Graph 传递给 RunAsync。
980 // OM1 路径中 ModelLoad 也不使用 stream 参数(仅 MallocFixedFeatureMemoryIfNeed 使用)。982 // OM1 路径中 ModelLoad 也不使用 stream 参数(仅 MallocFixedFeatureMemoryIfNeed 使用)。
981 (void)stream;983 (void)stream;
982- GE_ASSERT_TRUE(ge_root_model->HasOm2ModelData());
983 const auto &model_data = ge_root_model->GetOm2ModelData();984 const auto &model_data = ge_root_model->GetOm2ModelData();
985+ GE_ASSERT_NOTNULL(model_data, "[OM2][Check] Missing Om2ModelData.");
984 986 
985 const uint32_t graph_id = graph_node->GetGraphId();987 const uint32_t graph_id = graph_node->GetGraphId();
986 uint32_t model_id = ge_root_model->GetModelId();988 uint32_t model_id = ge_root_model->GetModelId();
@@ -1015,7 +1017,7 @@ Status ModelExecutor::LoadOm2Graph(const GeRootModelPtr &ge_root_model, const Gr
1015 feature_mem.first, feature_mem.second);1017 feature_mem.first, feature_mem.second);
1016 }1018 }
1017 1019 
1018- const ge::Status ret = Om2ModelManager::GetInstance().LoadModel(model_id, model_data, load_arg, session_id_);1020+ const ge::Status ret = Om2ModelManager::GetInstance().LoadModel(model_id, *model_data, load_arg, session_id_);
1019 if (ret == SUCCESS) {1021 if (ret == SUCCESS) {
1020 std::lock_guard<std::mutex> lock(om2_map_mutex_);1022 std::lock_guard<std::mutex> lock(om2_map_mutex_);
1021 om2_graph_to_model_map_[graph_id] = model_id;1023 om2_graph_to_model_map_[graph_id] = model_id;
@@ -1031,8 +1033,9 @@ Status ModelExecutor::GetOm2ModelTensorDesc(const GraphNodePtr &graph_node,
1031 GE_CHECK_NOTNULL(graph_node);1033 GE_CHECK_NOTNULL(graph_node);
1032 const auto ge_root_model = graph_node->GetGeRootModel();1034 const auto ge_root_model = graph_node->GetGeRootModel();
1033 GE_CHECK_NOTNULL(ge_root_model);1035 GE_CHECK_NOTNULL(ge_root_model);
1034- GE_ASSERT_TRUE(ge_root_model->HasOm2ModelData(), "[OM2][Check] Missing Om2ModelData.");1036+ const auto &model_data = ge_root_model->GetOm2ModelData();
1035- const auto &model_meta = ge_root_model->GetOm2ModelData().model_meta;1037+ GE_ASSERT_NOTNULL(model_data, "[OM2][Check] Missing Om2ModelData.");
1038+ const auto &model_meta = model_data->model_meta;
1036 input_desc = &model_meta.input_desc;1039 input_desc = &model_meta.input_desc;
1037 output_desc = &model_meta.output_desc;1040 output_desc = &model_meta.output_desc;
1038 return SUCCESS;1041 return SUCCESS;
@@ -28,6 +28,7 @@
28#include "framework/common/helper/om2_package_helper.h"28#include "framework/common/helper/om2_package_helper.h"
29#include "graph/execute/model_executor.h"29#include "graph/execute/model_executor.h"
30#include "graph/ge_local_context.h"30#include "graph/ge_local_context.h"
31+#include "graph/manager/graph_manager.h"
31#include "graph/manager/graph_manager_utils.h"32#include "graph/manager/graph_manager_utils.h"
32#include "graph/utils/graph_utils.h"33#include "graph/utils/graph_utils.h"
33#include "graph/graph.h"34#include "graph/graph.h"
@@ -36,6 +37,7 @@
36#include "init_ge.h"37#include "init_ge.h"
37#include "mmpa/mmpa_api.h"38#include "mmpa/mmpa_api.h"
38#include "common/model/ge_root_model.h"39#include "common/model/ge_root_model.h"
40+#include "ge/ge_api_v2.h"
39 41 
40#include "ge_runtime_stub/include/common/share_graph.h"42#include "ge_runtime_stub/include/common/share_graph.h"
41#include "ge_runtime_stub/include/faker/aicore_taskdef_faker.h"43#include "ge_runtime_stub/include/faker/aicore_taskdef_faker.h"
@@ -129,7 +131,7 @@ TEST_F(Om2OnlineSessionTest, GeRootModel_Om2DataLifecycle) {
129 ASSERT_NE(ge_root_model, nullptr);131 ASSERT_NE(ge_root_model, nullptr);
130 132 
131 // Initially no OM2 data133 // Initially no OM2 data
132- EXPECT_FALSE(ge_root_model->HasOm2ModelData());134+ EXPECT_EQ(ge_root_model->GetOm2ModelData(), nullptr);
133 135 
134 // Set OM2 data136 // Set OM2 data
135 auto om2_data = std::make_shared<gert::Om2ModelData>();137 auto om2_data = std::make_shared<gert::Om2ModelData>();
@@ -137,13 +139,13 @@ TEST_F(Om2OnlineSessionTest, GeRootModel_Om2DataLifecycle) {
137 om2_data->model_meta.work_size = 2048U;139 om2_data->model_meta.work_size = 2048U;
138 ge_root_model->SetOm2ModelData(om2_data);140 ge_root_model->SetOm2ModelData(om2_data);
139 141 
140- EXPECT_TRUE(ge_root_model->HasOm2ModelData());142+ EXPECT_NE(ge_root_model->GetOm2ModelData(), nullptr);
141- EXPECT_EQ(ge_root_model->GetOm2ModelData().model_meta.model_name, "test_model");143+ EXPECT_EQ(ge_root_model->GetOm2ModelData()->model_meta.model_name, "test_model");
142- EXPECT_EQ(ge_root_model->GetOm2ModelData().model_meta.work_size, 2048U);144+ EXPECT_EQ(ge_root_model->GetOm2ModelData()->model_meta.work_size, 2048U);
143 145 
144 // Clear OM2 data146 // Clear OM2 data
145 ge_root_model->SetOm2ModelData(nullptr);147 ge_root_model->SetOm2ModelData(nullptr);
146- EXPECT_FALSE(ge_root_model->HasOm2ModelData());148+ EXPECT_EQ(ge_root_model->GetOm2ModelData(), nullptr);
147}149}
148 150 
149// Test: Om2ModelData structure integrity151// Test: Om2ModelData structure integrity
@@ -190,15 +192,15 @@ TEST_F(Om2OnlineSessionTest, MultipleGeRootModels_IndependentOm2Data) {
190 model2->SetOm2ModelData(data2);192 model2->SetOm2ModelData(data2);
191 193 
192 // Each model has its own independent OM2 data194 // Each model has its own independent OM2 data
193- EXPECT_TRUE(model1->HasOm2ModelData());195+ EXPECT_NE(model1->GetOm2ModelData(), nullptr);
194- EXPECT_TRUE(model2->HasOm2ModelData());196+ EXPECT_NE(model2->GetOm2ModelData(), nullptr);
195- EXPECT_EQ(model1->GetOm2ModelData().model_meta.model_name, "model_1");197+ EXPECT_EQ(model1->GetOm2ModelData()->model_meta.model_name, "model_1");
196- EXPECT_EQ(model2->GetOm2ModelData().model_meta.model_name, "model_2");198+ EXPECT_EQ(model2->GetOm2ModelData()->model_meta.model_name, "model_2");
197 199 
198 // Clearing one doesn't affect the other200 // Clearing one doesn't affect the other
199 model1->SetOm2ModelData(nullptr);201 model1->SetOm2ModelData(nullptr);
200- EXPECT_FALSE(model1->HasOm2ModelData());202+ EXPECT_EQ(model1->GetOm2ModelData(), nullptr);
201- EXPECT_TRUE(model2->HasOm2ModelData());203+ EXPECT_NE(model2->GetOm2ModelData(), nullptr);
202}204}
203 205 
204// Test: Om2ModelData shared_ptr semantics (Fork scenario)206// Test: Om2ModelData shared_ptr semantics (Fork scenario)
@@ -214,12 +216,12 @@ TEST_F(Om2OnlineSessionTest, Om2ModelData_SharedPtrFork) {
214 // Simulate fork: shared_ptr copy216 // Simulate fork: shared_ptr copy
215 auto forked_data = om2_data; // shared_ptr copy, same underlying data217 auto forked_data = om2_data; // shared_ptr copy, same underlying data
216 218 
217- EXPECT_TRUE(ge_root_model->HasOm2ModelData());219+ EXPECT_NE(ge_root_model->GetOm2ModelData(), nullptr);
218 EXPECT_EQ(forked_data->model_meta.model_name, "shared_model");220 EXPECT_EQ(forked_data->model_meta.model_name, "shared_model");
219 EXPECT_EQ(forked_data->constants_data.weight_data.size(), 3U);221 EXPECT_EQ(forked_data->constants_data.weight_data.size(), 3U);
220 222 
221 // Both point to the same data223 // Both point to the same data
222- EXPECT_EQ(&ge_root_model->GetOm2ModelData(), forked_data.get());224+ EXPECT_EQ(ge_root_model->GetOm2ModelData().get(), forked_data.get());
223}225}
224 226 
225namespace {227namespace {
@@ -777,4 +779,30 @@ TEST_F(Om2OnlineModelExecutorTest, RunGraph_InputCountMismatch_ReturnsParamInval
777 EXPECT_EQ(model_executor.Finalize(), SUCCESS);779 EXPECT_EQ(model_executor.Finalize(), SUCCESS);
778}780}
779 781 
782+TEST_F(Om2OnlineModelExecutorTest, GetCompiledModel_Om2Mode_Success) {
783+ EnvValueGuard guard("ENABLE_RUNTIME_OM2");
784+ EnableOm2OnlineMode();
785+ 
786+ GraphManager graph_manager;
787+ const GraphId graph_id = 5012;
788+ const auto ge_root_model = CreateSimpleGeRootModel();
789+ ASSERT_NE(ge_root_model, nullptr);
790+ 
791+ auto graph_node = std::make_shared<GraphNode>(graph_id);
792+ graph_node->SetGeRootModel(ge_root_model);
793+ graph_node->SetBuildFlag(true);
794+ graph_manager.AddGraphNode(graph_id, graph_node);
795+ 
796+ const auto om2_model_data = std::make_shared<gert::Om2ModelData>();
797+ om2_model_data->model_meta.model_name = "om2_st_model";
798+ om2_model_data->model_meta.root_graph_name = "test_graph";
799+ om2_model_data->debug_info.visual_json = R"({"format":"ge_visual_json","format_version":1})";
800+ ge_root_model->SetOm2ModelData(om2_model_data);
801+ 
802+ ModelBufferData model_buffer;
803+ EXPECT_EQ(graph_manager.GetCompiledModel(graph_id, model_buffer), SUCCESS);
804+ ASSERT_NE(model_buffer.data, nullptr);
805+ EXPECT_GT(model_buffer.length, 0U);
806+}
807+ 
780} // namespace ge808} // namespace ge
@@ -239,7 +239,7 @@ TEST_F(UtestGeRootModel, Om2ModelData_InitiallyFalse) {
239 GeRootModel ge_root_model;239 GeRootModel ge_root_model;
240 auto root_graph = std::make_shared<ComputeGraph>("test_graph");240 auto root_graph = std::make_shared<ComputeGraph>("test_graph");
241 EXPECT_EQ(ge_root_model.Initialize(root_graph), SUCCESS);241 EXPECT_EQ(ge_root_model.Initialize(root_graph), SUCCESS);
242- EXPECT_FALSE(ge_root_model.HasOm2ModelData());242+ EXPECT_EQ(ge_root_model.GetOm2ModelData(), nullptr);
243}243}
244 244 
245TEST_F(UtestGeRootModel, Om2ModelData_SetAndGet) {245TEST_F(UtestGeRootModel, Om2ModelData_SetAndGet) {
@@ -252,17 +252,9 @@ TEST_F(UtestGeRootModel, Om2ModelData_SetAndGet) {
252 om2_data->model_meta.work_size = 1024U;252 om2_data->model_meta.work_size = 1024U;
253 ge_root_model.SetOm2ModelData(om2_data);253 ge_root_model.SetOm2ModelData(om2_data);
254 254 
255- EXPECT_TRUE(ge_root_model.HasOm2ModelData());255+ EXPECT_NE(ge_root_model.GetOm2ModelData(), nullptr);
256- EXPECT_EQ(ge_root_model.GetOm2ModelData().model_meta.model_name, "test_model");256+ EXPECT_EQ(ge_root_model.GetOm2ModelData()->model_meta.model_name, "test_model");
257- EXPECT_EQ(ge_root_model.GetOm2ModelData().model_meta.work_size, 1024U);257+ EXPECT_EQ(ge_root_model.GetOm2ModelData()->model_meta.work_size, 1024U);
258-}
259- 
260-TEST_F(UtestGeRootModel, Om2ModelData_GetMutableNull_Death) {
261- GeRootModel ge_root_model;
262- auto root_graph = std::make_shared<ComputeGraph>("test_graph");
263- EXPECT_EQ(ge_root_model.Initialize(root_graph), SUCCESS);
264- 
265- EXPECT_DEATH((void)ge_root_model.GetOm2ModelData(), "");
266}258}
267 259 
268TEST_F(UtestGeRootModel, Om2ModelData_SetNull_Overwrites) {260TEST_F(UtestGeRootModel, Om2ModelData_SetNull_Overwrites) {
@@ -273,10 +265,10 @@ TEST_F(UtestGeRootModel, Om2ModelData_SetNull_Overwrites) {
273 auto om2_data = std::make_shared<gert::Om2ModelData>();265 auto om2_data = std::make_shared<gert::Om2ModelData>();
274 om2_data->model_meta.model_name = "test_model";266 om2_data->model_meta.model_name = "test_model";
275 ge_root_model.SetOm2ModelData(om2_data);267 ge_root_model.SetOm2ModelData(om2_data);
276- EXPECT_TRUE(ge_root_model.HasOm2ModelData());268+ EXPECT_NE(ge_root_model.GetOm2ModelData(), nullptr);
277 269 
278 ge_root_model.SetOm2ModelData(nullptr);270 ge_root_model.SetOm2ModelData(nullptr);
279- EXPECT_FALSE(ge_root_model.HasOm2ModelData());271+ EXPECT_EQ(ge_root_model.GetOm2ModelData(), nullptr);
280}272}
281 273 
282TEST_F(UtestGeRootModel, Om2ModelData_MoveSemantics) {274TEST_F(UtestGeRootModel, Om2ModelData_MoveSemantics) {
@@ -300,8 +292,8 @@ TEST_F(UtestGeRootModel, ForkSharesOm2ModelData) {
300 292 
301 const auto forked = ge_root_model->Fork();293 const auto forked = ge_root_model->Fork();
302 ASSERT_NE(forked, nullptr);294 ASSERT_NE(forked, nullptr);
303- EXPECT_TRUE(forked->HasOm2ModelData());295+ EXPECT_NE(forked->GetOm2ModelData(), nullptr);
304- EXPECT_EQ(&forked->GetOm2ModelData(), &ge_root_model->GetOm2ModelData());296+ EXPECT_EQ(forked->GetOm2ModelData(), ge_root_model->GetOm2ModelData());
305}297}
306 298 
307} // namespace ge299} // namespace ge
@@ -187,7 +187,7 @@ TEST_F(FileConstLoaderUt, resolve_weight_dir_prefers_weight_path) {
187 model_data.weight_path = weight_dir;187 model_data.weight_path = weight_dir;
188 model_data.om_path = PathUtils::Join({test_dir_, "model.om2"});188 model_data.om_path = PathUtils::Join({test_dir_, "model.om2"});
189 std::string resolved_weight_dir;189 std::string resolved_weight_dir;
190- ASSERT_EQ(gert::ResolveFileConstWeightDir(model_data, resolved_weight_dir), SUCCESS);190+ ASSERT_EQ(gert::ResolveFileConstWeightDir(model_data.weight_path, model_data.om_path, resolved_weight_dir), SUCCESS);
191 EXPECT_EQ(resolved_weight_dir, ge::RealPath(weight_dir.c_str()) + "/");191 EXPECT_EQ(resolved_weight_dir, ge::RealPath(weight_dir.c_str()) + "/");
192}192}
193 193 
@@ -197,7 +197,7 @@ TEST_F(FileConstLoaderUt, resolve_weight_dir_from_om_path) {
197 ge::ModelData model_data;197 ge::ModelData model_data;
198 model_data.om_path = om_path;198 model_data.om_path = om_path;
199 std::string resolved_weight_dir;199 std::string resolved_weight_dir;
200- ASSERT_EQ(gert::ResolveFileConstWeightDir(model_data, resolved_weight_dir), SUCCESS);200+ ASSERT_EQ(gert::ResolveFileConstWeightDir(model_data.weight_path, model_data.om_path, resolved_weight_dir), SUCCESS);
201 EXPECT_EQ(resolved_weight_dir, test_dir_ + "/weight/");201 EXPECT_EQ(resolved_weight_dir, test_dir_ + "/weight/");
202}202}
203 203