已合并
feat(om2): 支持host tensor H2D/D2H并优化model_executor体积 #4389
wuzheng创建于 20 天前
feat(om2): 支持host tensor H2D/D2H并优化model_executor体积 #4389
已合并
共 13 个文件变更+89-407
| @@ -57,11 +57,6 @@ ge::Status Om2ModelManager::RunModel(uint32_t model_id, void *stream, std::vecto | |||
| 57 | executor = iter->second; | 57 | executor = iter->second; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | - if (executor == nullptr) { | ||
| 61 | - GELOGE(GE_GRAPH_PARAM_NULLPTR, "[OM2] Executor is null for model %u", model_id); | ||
| 62 | - return GE_GRAPH_PARAM_NULLPTR; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | if (stream == nullptr) { | 60 | if (stream == nullptr) { |
| 66 | return executor->Run(inputs, outputs); | 61 | return executor->Run(inputs, outputs); |
| 67 | } | 62 | } |
| @@ -10,11 +10,6 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | 13 | ||
| 19 | 14 | ||
| 20 | ge::Status ProfGetDeviceFormGraphId(const uint32_t graph_id, uint32_t &device_id) { | 15 | ge::Status ProfGetDeviceFormGraphId(const uint32_t graph_id, uint32_t &device_id) { |
| @@ -11,24 +11,12 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | - | ||
| 15 | - | ||
| 16 | 14 | ||
| 17 | - | ||
| 18 | 15 | ||
| 19 | 16 | ||
| 20 | 17 | ||
| 21 | - | ||
| 22 | 18 | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | 19 | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | 20 | ||
| 33 | 21 | ||
| 34 | 22 | ||
| @@ -24,7 +24,6 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | - | ||
| 28 | 27 | ||
| 29 | 28 | ||
| 30 | 29 | ||
| @@ -162,18 +161,9 @@ Status ModelExecutor::UnloadGraph(const GeRootModelPtr &ge_root_model, const uin | |||
| 162 | GE_CHECK_NOTNULL(ge_root_model); | 161 | GE_CHECK_NOTNULL(ge_root_model); |
| 163 | GE_CHK_ACL_RET(aclrtSetDevice(static_cast<int32_t>(GetContext().DeviceId()))); | 162 | GE_CHK_ACL_RET(aclrtSetDevice(static_cast<int32_t>(GetContext().DeviceId()))); |
| 164 | 163 | ||
| 165 | - GraphNodePtr graph_node; | ||
| 166 | - { | ||
| 167 | - const std::lock_guard<std::mutex> lk(mutex_); | ||
| 168 | - auto it = graph_nodes_.find(graph_id); | ||
| 169 | - if (it != graph_nodes_.end()) { | ||
| 170 | - graph_node = it->second; | ||
| 171 | - } | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | Status unload_ret; | 164 | Status unload_ret; |
| 175 | - if (graph_node != nullptr && IsOm2OnlineMode()) { | 165 | + if (IsOm2OnlineMode()) { |
| 176 | - unload_ret = UnloadOm2Graph(graph_id); | 166 | + unload_ret = UnloadOm2Graph(ge_root_model, graph_id); |
| 177 | } else { | 167 | } else { |
| 178 | unload_ret = UnloadModel(ge_root_model, graph_id); | 168 | unload_ret = UnloadModel(ge_root_model, graph_id); |
| 179 | } | 169 | } |
| @@ -261,14 +251,6 @@ void ModelExecutor::RunThread() { | |||
| 261 | error_message::SetErrMgrContext(args->error_context); | 251 | error_message::SetErrMgrContext(args->error_context); |
| 262 | GetContext().SetSessionId(args->session_id); | 252 | GetContext().SetSessionId(args->session_id); |
| 263 | GetThreadLocalContext() = args->context; | 253 | GetThreadLocalContext() = args->context; |
| 264 | - bool is_continue = false; | ||
| 265 | - if (is_continue) { | ||
| 266 | - GELOGI("graph [%u] is suspended, return success", args->graph_id); | ||
| 267 | - std::vector<gert::Tensor> outputs; | ||
| 268 | - args->callback(SUCCESS, outputs); | ||
| 269 | - args->graph_node->SetRunFlag(false); | ||
| 270 | - continue; | ||
| 271 | - } | ||
| 272 | 254 | ||
| 273 | auto ge_root_model = args->graph_node->GetGeRootModel(); | 255 | auto ge_root_model = args->graph_node->GetGeRootModel(); |
| 274 | if (ge_root_model == nullptr) { | 256 | if (ge_root_model == nullptr) { |
| @@ -860,7 +842,7 @@ Status ModelExecutor::CheckAndReleaseMemory(const GeRootModelPtr &ge_root_model, | |||
| 860 | continue; | 842 | continue; |
| 861 | } | 843 | } |
| 862 | GeRootModelPtr tmp_ge_root_model = it.second->GetGeRootModel(); | 844 | GeRootModelPtr tmp_ge_root_model = it.second->GetGeRootModel(); |
| 863 | - if (!DoReleaseModel(tmp_ge_root_model, it.second)) { | 845 | + if (!ReleaseMemory(tmp_ge_root_model, it.second)) { |
| 864 | continue; | 846 | continue; |
| 865 | } | 847 | } |
| 866 | it.second->SetLoadFlag(false); | 848 | it.second->SetLoadFlag(false); |
| @@ -883,10 +865,6 @@ Status ModelExecutor::CheckAndReleaseMemory(const GeRootModelPtr &ge_root_model, | |||
| 883 | return SUCCESS; | 865 | return SUCCESS; |
| 884 | } | 866 | } |
| 885 | 867 | ||
| 886 | -bool ModelExecutor::DoReleaseModel(const GeRootModelPtr &ge_root_model, const GraphNodePtr &loaded_graph_node) const { | ||
| 887 | - return ReleaseMemory(ge_root_model, loaded_graph_node); | ||
| 888 | -} | ||
| 889 | - | ||
| 890 | Status ModelExecutor::GetStreamNum(const GeRootModelPtr &ge_root_model, uint32_t &stream_num, | 868 | Status ModelExecutor::GetStreamNum(const GeRootModelPtr &ge_root_model, uint32_t &stream_num, |
| 891 | uint64_t &hccl_follow_stream) const { | 869 | uint64_t &hccl_follow_stream) const { |
| 892 | const auto ge_model = GetGeModel(ge_root_model); | 870 | const auto ge_model = GetGeModel(ge_root_model); |
| @@ -1061,6 +1039,8 @@ Status ModelExecutor::LoadOm2Graph(const GeRootModelPtr &ge_root_model, const Gr | |||
| 1061 | // NOTE: Load 阶段不需要 stream。stream 在 Execute 阶段通过 RunOm2Graph 传递给 RunAsync。 | 1039 | // NOTE: Load 阶段不需要 stream。stream 在 Execute 阶段通过 RunOm2Graph 传递给 RunAsync。 |
| 1062 | // OM1 路径中 ModelLoad 也不使用 stream 参数(仅 MallocFixedFeatureMemoryIfNeed 使用)。 | 1040 | // OM1 路径中 ModelLoad 也不使用 stream 参数(仅 MallocFixedFeatureMemoryIfNeed 使用)。 |
| 1063 | (void)stream; | 1041 | (void)stream; |
C | |||
| 1042 | + uint32_t device_id = GetContext().DeviceId(); | ||
C 这里的 device_id 初始化后不会再修改,建议声明为 const,保持 GE/C++ 默认不可变风格:const uint32_t device_id = GetContext().DeviceId();。上下文:https://gitcode.com/cann/ge/blob/13c25bbb2a1214da4b11d20785d795851a07981b2/runtime/v1/graph/execute/model_executor.cc#L1039-L1045 ![]() ![]() | |||
| 1043 | + GE_CHK_STATUS_RET(ModelUtils::SetDevice(device_id), "[Call][SetDevice] failed, device_id:%u", device_id); | ||
| 1064 | const auto &model_data = ge_root_model->GetOm2ModelData(); | 1044 | const auto &model_data = ge_root_model->GetOm2ModelData(); |
| 1065 | GE_ASSERT_NOTNULL(model_data, "[OM2][Check] Missing Om2ModelData."); | 1045 | GE_ASSERT_NOTNULL(model_data, "[OM2][Check] Missing Om2ModelData."); |
| 1066 | 1046 | ||
| @@ -1069,7 +1049,6 @@ Status ModelExecutor::LoadOm2Graph(const GeRootModelPtr &ge_root_model, const Gr | |||
| 1069 | if (model_id == INVALID_MODEL_ID) { | 1049 | if (model_id == INVALID_MODEL_ID) { |
| 1070 | model_id = Om2ModelManager::GetInstance().GenModelId(); | 1050 | model_id = Om2ModelManager::GetInstance().GenModelId(); |
| 1071 | ge_root_model->SetModelId(model_id); | 1051 | ge_root_model->SetModelId(model_id); |
| 1072 | - GELOGI("[OM2] Generated model_id %u for graph %u", model_id, graph_id); | ||
| 1073 | } | 1052 | } |
| 1074 | 1053 | ||
| 1075 | // NOTE: OM2 路径不需要调用 MallocFixedFeatureMemoryIfNeed。 | 1054 | // NOTE: OM2 路径不需要调用 MallocFixedFeatureMemoryIfNeed。 |
| @@ -1100,8 +1079,6 @@ Status ModelExecutor::LoadOm2Graph(const GeRootModelPtr &ge_root_model, const Gr | |||
| 1100 | 1079 | ||
| 1101 | const ge::Status ret = Om2ModelManager::GetInstance().LoadModel(model_id, *model_data, load_arg, session_id_); | 1080 | const ge::Status ret = Om2ModelManager::GetInstance().LoadModel(model_id, *model_data, load_arg, session_id_); |
| 1102 | if (ret == SUCCESS) { | 1081 | if (ret == SUCCESS) { |
| 1103 | - std::lock_guard<std::mutex> lock(om2_map_mutex_); | ||
| 1104 | - om2_graph_to_model_map_[graph_id] = model_id; | ||
| 1105 | graph_node->SetLoaded(); | 1082 | graph_node->SetLoaded(); |
| 1106 | AddGraphNode(graph_id, graph_node); | 1083 | AddGraphNode(graph_id, graph_node); |
| 1107 | } | 1084 | } |
| @@ -1122,29 +1099,6 @@ Status ModelExecutor::GetOm2ModelTensorDesc(const GraphNodePtr &graph_node, | |||
| 1122 | return SUCCESS; | 1099 | return SUCCESS; |
| 1123 | } | 1100 | } |
| 1124 | 1101 | ||
| 1125 | -Status ModelExecutor::ValidateOm2Tensors(const std::vector<ge::Om2TensorDesc> &descs, | ||
C [P1] 这里删除 ValidateOm2Tensors 后,输入/输出数量、地址和 size 校验完全缺失。现有 UT 仍要求数量不匹配、size 不足和空地址返回 PARAM_INVALID(https://gitcode.com/cann/ge/blob/13c25bbb2a1214da4b11d20785d795851a07981b2/runtime/v1/graph/execute/model_executor.cc#L1099-L1138)。测试中的 fake Om2ModelRun 对任意参数都返回 0,因此非法 Tensor 会被当作成功执行,空地址还可能直接进入 aclrtMemcpy。请在 host staging 前恢复等价校验,或下沉到 Om2ModelExecutor/Om2ModelManager,并保持 PARAM_INVALID 契约。 ![]() ![]() | |||
| 1126 | - const std::vector<gert::Tensor> &tensors, const char *kind, | ||
| 1127 | - uint32_t graph_id) const { | ||
| 1128 | - if (descs.size() != tensors.size()) { | ||
| 1129 | - GELOGE(PARAM_INVALID, "[OM2][Check] Invalid %s tensor count, expected=%zu, actual=%zu, graph_id=%u.", kind, | ||
| 1130 | - descs.size(), tensors.size(), graph_id); | ||
| 1131 | - return PARAM_INVALID; | ||
| 1132 | - } | ||
| 1133 | - for (size_t i = 0U; i < descs.size(); ++i) { | ||
| 1134 | - const size_t required_size = descs[i].GetByteSize(); | ||
| 1135 | - if ((required_size > 0U) && (tensors[i].GetAddr() == nullptr)) { | ||
| 1136 | - GELOGE(PARAM_INVALID, "[OM2][Check] %s tensor[%zu] addr is null, graph_id=%u.", kind, i, graph_id); | ||
| 1137 | - return PARAM_INVALID; | ||
| 1138 | - } | ||
| 1139 | - if (tensors[i].GetSize() < required_size) { | ||
| 1140 | - GELOGE(PARAM_INVALID, "[OM2][Check] %s tensor[%zu] size is insufficient, expected=%zu, actual=%zu, graph_id=%u.", | ||
| 1141 | - kind, i, required_size, tensors[i].GetSize(), graph_id); | ||
| 1142 | - return PARAM_INVALID; | ||
| 1143 | - } | ||
| 1144 | - } | ||
| 1145 | - return SUCCESS; | ||
| 1146 | -} | ||
| 1147 | - | ||
| 1148 | Status ModelExecutor::PrepareOm2Outputs(const GraphNodePtr &graph_node, std::vector<gert::Tensor> &outputs) const { | 1102 | Status ModelExecutor::PrepareOm2Outputs(const GraphNodePtr &graph_node, std::vector<gert::Tensor> &outputs) const { |
| 1149 | const std::vector<ge::Om2TensorDesc> *input_desc = nullptr; | 1103 | const std::vector<ge::Om2TensorDesc> *input_desc = nullptr; |
| 1150 | const std::vector<ge::Om2TensorDesc> *output_desc = nullptr; | 1104 | const std::vector<ge::Om2TensorDesc> *output_desc = nullptr; |
| @@ -1173,62 +1127,92 @@ Status ModelExecutor::PrepareOm2Outputs(const GraphNodePtr &graph_node, std::vec | |||
| 1173 | 1127 | ||
| 1174 | Status ModelExecutor::RunOm2Graph(const GraphNodePtr &graph_node, uint32_t graph_id, const aclrtStream stream, | 1128 | Status ModelExecutor::RunOm2Graph(const GraphNodePtr &graph_node, uint32_t graph_id, const aclrtStream stream, |
| 1175 | const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs) { | 1129 | const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs) { |
| 1176 | - uint32_t model_id; | 1130 | + const auto ge_root_model = graph_node->GetGeRootModel(); |
| 1177 | - { | 1131 | + GE_CHECK_NOTNULL(ge_root_model); |
| 1178 | - std::lock_guard<std::mutex> lock(om2_map_mutex_); | 1132 | + const uint32_t model_id = ge_root_model->GetModelId(); |
| 1179 | - auto it = om2_graph_to_model_map_.find(graph_id); | 1133 | + if (model_id == INVALID_MODEL_ID) { |
| 1180 | - if (it == om2_graph_to_model_map_.end()) { | 1134 | + GELOGE(GE_GRAPH_GRAPH_NOT_EXIST, "OM2 graph %u not loaded", graph_id); |
| 1181 | - GELOGE(GE_GRAPH_GRAPH_NOT_EXIST, "OM2 graph %u not loaded", graph_id); | 1135 | + return GE_GRAPH_GRAPH_NOT_EXIST; |
| 1182 | - return GE_GRAPH_GRAPH_NOT_EXIST; | ||
| 1183 | - } | ||
| 1184 | - model_id = it->second; | ||
| 1185 | } | 1136 | } |
| 1186 | 1137 | ||
| 1187 | - const std::vector<ge::Om2TensorDesc> *input_desc = nullptr; | 1138 | + std::vector<void *> temp_device_buffers; |
| 1188 | - const std::vector<ge::Om2TensorDesc> *output_desc = nullptr; | 1139 | + GE_MAKE_GUARD(cleanup, [&temp_device_buffers]() { |
| 1189 | - GE_ASSERT_SUCCESS(GetOm2ModelTensorDesc(graph_node, input_desc, output_desc)); | 1140 | + for (auto *buf : temp_device_buffers) { |
| 1190 | - GE_ASSERT_NOTNULL(input_desc); | 1141 | + if (buf != nullptr) { |
| 1191 | - GE_ASSERT_NOTNULL(output_desc); | 1142 | + (void)aclrtFree(buf); |
| 1192 | - GE_ASSERT_SUCCESS(ValidateOm2Tensors(*input_desc, inputs, "input", graph_id)); | 1143 | + } |
| 1193 | - GE_ASSERT_SUCCESS(ValidateOm2Tensors(*output_desc, outputs, "output", graph_id)); | 1144 | + } |
| 1145 | + }); | ||
| 1194 | 1146 | ||
| 1147 | + std::vector<gert::Tensor> host_input_tensors(inputs.size()); | ||
| 1148 | + std::vector<gert::Tensor *> input_ptrs(inputs.size()); | ||
| 1195 | for (size_t i = 0U; i < inputs.size(); ++i) { | 1149 | for (size_t i = 0U; i < inputs.size(); ++i) { |
| 1196 | if (gert::TensorPlacementUtils::IsOnHost(inputs[i].GetPlacement())) { | 1150 | if (gert::TensorPlacementUtils::IsOnHost(inputs[i].GetPlacement())) { |
| 1197 | - GELOGE(GE_GRAPH_UNSUPPORTED, | 1151 | + const size_t size = inputs[i].GetSize(); |
| 1198 | - "[OM2][Check] Input tensor[%zu] is on host, OM2 executor does not support host input, graph_id=%u.", i, | 1152 | + void *device_addr = nullptr; |
| 1199 | - graph_id); | 1153 | + if (size > 0U) { |
| 1200 | - return GE_GRAPH_UNSUPPORTED; | 1154 | + GE_ASSERT_RT_OK(aclrtMalloc(&device_addr, size, ACL_MEM_MALLOC_HUGE_FIRST)); |
| 1155 | + temp_device_buffers.push_back(device_addr); | ||
| 1156 | + GE_ASSERT_RT_OK(aclrtMemcpy(device_addr, size, inputs[i].GetAddr(), size, ACL_MEMCPY_HOST_TO_DEVICE)); | ||
| 1157 | + } | ||
| 1158 | + host_input_tensors[i].MutableFormat() = inputs[i].GetFormat(); | ||
| 1159 | + host_input_tensors[i].MutableOriginShape() = inputs[i].GetOriginShape(); | ||
| 1160 | + host_input_tensors[i].MutableStorageShape() = inputs[i].GetStorageShape(); | ||
| 1161 | + host_input_tensors[i].SetDataType(inputs[i].GetDataType()); | ||
| 1162 | + host_input_tensors[i].SetData(gert::TensorData(device_addr, nullptr, size, gert::kOnDeviceHbm)); | ||
| 1163 | + input_ptrs[i] = &host_input_tensors[i]; | ||
| 1164 | + } else { | ||
| 1165 | + input_ptrs[i] = const_cast<gert::Tensor *>(&inputs[i]); | ||
| 1201 | } | 1166 | } |
| 1202 | } | 1167 | } |
| 1203 | 1168 | ||
| 1204 | - std::vector<gert::Tensor *> input_ptrs; | 1169 | + std::vector<gert::Tensor> host_output_tensors(outputs.size()); |
| 1205 | - std::vector<gert::Tensor *> output_ptrs; | 1170 | + std::vector<gert::Tensor *> output_ptrs(outputs.size()); |
| 1206 | - // NOTE: RunAsync 仅读取 input tensor 的地址和数据,不会修改其内容。 | 1171 | + std::vector<size_t> host_output_indices; |
| 1207 | - // const_cast 与 OM1 路径 ExecuteGraphWithStream 保持一致。 | 1172 | + for (size_t i = 0U; i < outputs.size(); ++i) { |
| 1208 | - for (const auto &t : inputs) { | 1173 | + if (gert::TensorPlacementUtils::IsOnHost(outputs[i].GetPlacement())) { |
| 1209 | - input_ptrs.push_back(const_cast<gert::Tensor *>(&t)); | 1174 | + const size_t size = outputs[i].GetSize(); |
| 1210 | - } | 1175 | + void *device_addr = nullptr; |
| 1211 | - for (auto &t : outputs) { | 1176 | + if (size > 0U) { |
| 1212 | - output_ptrs.push_back(&t); | 1177 | + GE_ASSERT_RT_OK(aclrtMalloc(&device_addr, size, ACL_MEM_MALLOC_HUGE_FIRST)); |
| 1178 | + temp_device_buffers.push_back(device_addr); | ||
| 1179 | + } | ||
| 1180 | + host_output_indices.push_back(i); | ||
| 1181 | + host_output_tensors[i].MutableFormat() = outputs[i].GetFormat(); | ||
| 1182 | + host_output_tensors[i].MutableOriginShape() = outputs[i].GetOriginShape(); | ||
| 1183 | + host_output_tensors[i].MutableStorageShape() = outputs[i].GetStorageShape(); | ||
| 1184 | + host_output_tensors[i].SetDataType(outputs[i].GetDataType()); | ||
| 1185 | + host_output_tensors[i].SetData(gert::TensorData(device_addr, nullptr, size, gert::kOnDeviceHbm)); | ||
| 1186 | + output_ptrs[i] = &host_output_tensors[i]; | ||
| 1187 | + } else { | ||
| 1188 | + output_ptrs[i] = &outputs[i]; | ||
| 1189 | + } | ||
| 1213 | } | 1190 | } |
| 1214 | 1191 | ||
| 1215 | const ge::Status ret = Om2ModelManager::GetInstance().RunModel(model_id, stream, input_ptrs, output_ptrs); | 1192 | const ge::Status ret = Om2ModelManager::GetInstance().RunModel(model_id, stream, input_ptrs, output_ptrs); |
| 1193 | + if (ret == SUCCESS) { | ||
| 1194 | + for (const size_t i : host_output_indices) { | ||
| 1195 | + const size_t size = outputs[i].GetSize(); | ||
| 1196 | + if (size > 0U) { | ||
| 1197 | + GE_ASSERT_RT_OK( | ||
| 1198 | + aclrtMemcpy(outputs[i].GetAddr(), size, host_output_tensors[i].GetAddr(), size, ACL_MEMCPY_DEVICE_TO_HOST)); | ||
| 1199 | + } | ||
| 1200 | + } | ||
| 1201 | + } | ||
| 1202 | + | ||
| 1216 | graph_node->SetRunFlag(false); | 1203 | graph_node->SetRunFlag(false); |
| 1217 | return ret; | 1204 | return ret; |
| 1218 | } | 1205 | } |
| 1219 | 1206 | ||
| 1220 | -Status ModelExecutor::UnloadOm2Graph(uint32_t graph_id) { | 1207 | +Status ModelExecutor::UnloadOm2Graph(const GeRootModelPtr &ge_root_model, uint32_t graph_id) { |
| 1221 | - uint32_t model_id; | 1208 | + GE_CHECK_NOTNULL(ge_root_model); |
| 1222 | - { | 1209 | + const uint32_t model_id = ge_root_model->GetModelId(); |
| 1223 | - std::lock_guard<std::mutex> lock(om2_map_mutex_); | 1210 | + if (model_id == INVALID_MODEL_ID) { |
| 1224 | - auto it = om2_graph_to_model_map_.find(graph_id); | 1211 | + return SUCCESS; // idempotent |
| 1225 | - if (it == om2_graph_to_model_map_.end()) { | ||
| 1226 | - return SUCCESS; // idempotent | ||
| 1227 | - } | ||
| 1228 | - model_id = it->second; | ||
| 1229 | - om2_graph_to_model_map_.erase(it); | ||
| 1230 | } | 1212 | } |
| 1231 | - return Om2ModelManager::GetInstance().UnloadModel(model_id); | 1213 | + GE_CHK_STATUS_RET(Om2ModelManager::GetInstance().UnloadModel(model_id), |
| 1214 | + "[OM2] Unload model failed, modelId=%u, graphId=%u.", model_id, graph_id); | ||
| 1215 | + return SUCCESS; | ||
| 1232 | } | 1216 | } |
| 1233 | 1217 | ||
| 1234 | } // namespace ge | 1218 | } // namespace ge |
| @@ -139,17 +139,14 @@ class ModelExecutor : public Executor { | |||
| 139 | void RunThread(); | 139 | void RunThread(); |
| 140 | void StopQueue(); | 140 | void StopQueue(); |
| 141 | void ReturnError(const RunAsyncCallbackV2 &callback, const Status ret, const std::string &log_info) const; | 141 | void ReturnError(const RunAsyncCallbackV2 &callback, const Status ret, const std::string &log_info) const; |
| 142 | - bool DoReleaseModel(const GeRootModelPtr &ge_root_model, const GraphNodePtr &loaded_graph_node) const; | ||
| 143 | 142 | ||
| 144 | ge::Status LoadOm2Graph(const GeRootModelPtr &ge_root_model, const GraphNodePtr &graph_node, | 143 | ge::Status LoadOm2Graph(const GeRootModelPtr &ge_root_model, const GraphNodePtr &graph_node, |
| 145 | const aclrtStream stream); | 144 | const aclrtStream stream); |
| 146 | ge::Status RunOm2Graph(const GraphNodePtr &graph_node, uint32_t graph_id, const aclrtStream stream, | 145 | ge::Status RunOm2Graph(const GraphNodePtr &graph_node, uint32_t graph_id, const aclrtStream stream, |
| 147 | const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs); | 146 | const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs); |
| 148 | - ge::Status UnloadOm2Graph(uint32_t graph_id); | 147 | + ge::Status UnloadOm2Graph(const GeRootModelPtr &ge_root_model, uint32_t graph_id); |
| 149 | ge::Status GetOm2ModelTensorDesc(const GraphNodePtr &graph_node, const std::vector<ge::Om2TensorDesc> *&input_desc, | 148 | ge::Status GetOm2ModelTensorDesc(const GraphNodePtr &graph_node, const std::vector<ge::Om2TensorDesc> *&input_desc, |
| 150 | const std::vector<ge::Om2TensorDesc> *&output_desc) const; | 149 | const std::vector<ge::Om2TensorDesc> *&output_desc) const; |
| 151 | - ge::Status ValidateOm2Tensors(const std::vector<ge::Om2TensorDesc> &descs, const std::vector<gert::Tensor> &tensors, | ||
| 152 | - const char *kind, uint32_t graph_id) const; | ||
| 153 | ge::Status PrepareOm2Outputs(const GraphNodePtr &graph_node, std::vector<gert::Tensor> &outputs) const; | 150 | ge::Status PrepareOm2Outputs(const GraphNodePtr &graph_node, std::vector<gert::Tensor> &outputs) const; |
| 154 | 151 | ||
| 155 | bool init_flag_{false}; | 152 | bool init_flag_{false}; |
| @@ -158,8 +155,6 @@ class ModelExecutor : public Executor { | |||
| 158 | 155 | ||
| 159 | std::mutex mutex_; | 156 | std::mutex mutex_; |
| 160 | std::map<GraphId, GraphNodePtr> graph_nodes_; | 157 | std::map<GraphId, GraphNodePtr> graph_nodes_; |
| 161 | - std::map<uint32_t, uint32_t> om2_graph_to_model_map_; | ||
| 162 | - std::mutex om2_map_mutex_; | ||
| 163 | 158 | ||
| 164 | std::thread run_thread_; | 159 | std::thread run_thread_; |
| 165 | std::atomic_bool thread_run_flag_{false}; | 160 | std::atomic_bool thread_run_flag_{false}; |
| @@ -16,6 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + | ||
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | using namespace std; | 22 | using namespace std; |
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | + | ||
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | 17 | ||
| @@ -9,6 +9,7 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + | ||
| 12 | 13 | ||
| 13 | 14 | ||
| 14 | 15 | ||
| @@ -25,6 +26,7 @@ | |||
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | 28 | ||
| 29 | + | ||
| 28 | 30 | ||
| 29 | 31 | ||
| 30 | 32 | ||
| @@ -37,6 +37,7 @@ | |||
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | + | ||
| 40 | 41 | ||
| 41 | 42 | ||
| 42 | 43 | ||
| @@ -473,7 +473,7 @@ TEST_F(Om2OnlineModelExecutorTest, RunGraph_EmptyOutputs_PrepareOm2Outputs) { | |||
| 473 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 473 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| 474 | } | 474 | } |
| 475 | 475 | ||
| 476 | -TEST_F(Om2OnlineModelExecutorTest, RunGraph_HostInput_ReturnsUnsupported) { | 476 | +TEST_F(Om2OnlineModelExecutorTest, RunGraph_HostInput_Success) { |
| 477 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | 477 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); |
| 478 | EnableOm2OnlineMode(); | 478 | EnableOm2OnlineMode(); |
| 479 | 479 | ||
| @@ -510,7 +510,7 @@ TEST_F(Om2OnlineModelExecutorTest, RunGraph_HostInput_ReturnsUnsupported) { | |||
| 510 | inputs.push_back(std::move(host_input)); | 510 | inputs.push_back(std::move(host_input)); |
| 511 | std::vector<gert::Tensor> outputs; | 511 | std::vector<gert::Tensor> outputs; |
| 512 | outputs.push_back(std::move(output)); | 512 | outputs.push_back(std::move(output)); |
| 513 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), GE_GRAPH_UNSUPPORTED); | 513 | + EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), SUCCESS); |
| 514 | 514 | ||
| 515 | EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | 515 | EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); |
| 516 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 516 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| @@ -763,38 +763,6 @@ TEST_F(Om2OnlineModelExecutorTest, LoadGraph_ExternalConstAndFeatureMemory) { | |||
| 763 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 763 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| 764 | } | 764 | } |
| 765 | 765 | ||
| 766 | -TEST_F(Om2OnlineModelExecutorTest, RunGraph_InputCountMismatch_ReturnsParamInvalid) { | ||
| 767 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 768 | - EnableOm2OnlineMode(); | ||
| 769 | - | ||
| 770 | - ModelExecutor model_executor; | ||
| 771 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 772 | - | ||
| 773 | - auto compute_graph = std::make_shared<ComputeGraph>("test_graph"); | ||
| 774 | - GeRootModelPtr ge_root_model = std::make_shared<GeRootModel>(); | ||
| 775 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 776 | - | ||
| 777 | - GeModelPtr ge_model = std::make_shared<GeModel>(); | ||
| 778 | - ge_model->SetGraph(compute_graph); | ||
| 779 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 780 | - | ||
| 781 | - GraphId graph_id = 5011; | ||
| 782 | - GraphNodePtr graph_node = std::make_shared<ge::GraphNode>(graph_id); | ||
| 783 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 784 | - | ||
| 785 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 786 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 787 | - | ||
| 788 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 789 | - | ||
| 790 | - std::vector<gert::Tensor> inputs; | ||
| 791 | - std::vector<gert::Tensor> outputs(1); | ||
| 792 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 793 | - | ||
| 794 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 795 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 796 | -} | ||
| 797 | - | ||
| 798 | TEST_F(Om2OnlineModelExecutorTest, GetCompiledModel_Om2Mode_Success) { | 766 | TEST_F(Om2OnlineModelExecutorTest, GetCompiledModel_Om2Mode_Success) { |
| 799 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | 767 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); |
| 800 | EnableOm2OnlineMode(); | 768 | EnableOm2OnlineMode(); |
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | + | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | 25 | ||
| @@ -39,6 +39,7 @@ | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | + | ||
| 42 | 43 | ||
| 43 | 44 | ||
| 44 | 45 | ||
| @@ -1855,7 +1855,7 @@ class UtestModelExecutorOm2Test : public testing::Test { | |||
| 1855 | std::string UtestModelExecutorOm2Test::test_work_dir_; | 1855 | std::string UtestModelExecutorOm2Test::test_work_dir_; |
| 1856 | std::string UtestModelExecutorOm2Test::fake_so_path_; | 1856 | std::string UtestModelExecutorOm2Test::fake_so_path_; |
| 1857 | 1857 | ||
| 1858 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_HostInput_ReturnsUnsupported) { | 1858 | +TEST_F(UtestModelExecutorOm2Test, RunGraph_HostInput_Success) { |
| 1859 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | 1859 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); |
| 1860 | EnableOm2OnlineMode(); | 1860 | EnableOm2OnlineMode(); |
| 1861 | 1861 | ||
| @@ -1892,7 +1892,7 @@ TEST_F(UtestModelExecutorOm2Test, RunGraph_HostInput_ReturnsUnsupported) { | |||
| 1892 | inputs.push_back(std::move(host_input)); | 1892 | inputs.push_back(std::move(host_input)); |
| 1893 | std::vector<gert::Tensor> outputs; | 1893 | std::vector<gert::Tensor> outputs; |
| 1894 | outputs.push_back(std::move(output)); | 1894 | outputs.push_back(std::move(output)); |
| 1895 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), GE_GRAPH_UNSUPPORTED); | 1895 | + EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), SUCCESS); |
| 1896 | 1896 | ||
| 1897 | EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | 1897 | EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); |
| 1898 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 1898 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| @@ -1944,129 +1944,6 @@ TEST_F(UtestModelExecutorOm2Test, UnloadGraph_NotLoaded_ReturnsSuccess) { | |||
| 1944 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 1944 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| 1945 | } | 1945 | } |
| 1946 | 1946 | ||
| 1947 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_InputCountMismatch_ReturnsParamInvalid) { | ||
| 1948 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 1949 | - EnableOm2OnlineMode(); | ||
| 1950 | - | ||
| 1951 | - ModelExecutor model_executor; | ||
| 1952 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 1953 | - | ||
| 1954 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | ||
| 1955 | - GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | ||
| 1956 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 1957 | - | ||
| 1958 | - GeModelPtr ge_model = MakeShared<GeModel>(); | ||
| 1959 | - ge_model->SetGraph(compute_graph); | ||
| 1960 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 1961 | - | ||
| 1962 | - GraphId graph_id = 3003; | ||
| 1963 | - GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | ||
| 1964 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 1965 | - | ||
| 1966 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 1967 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 1968 | - | ||
| 1969 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 1970 | - | ||
| 1971 | - std::vector<gert::Tensor> inputs; | ||
| 1972 | - std::vector<gert::Tensor> outputs(1); | ||
| 1973 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 1974 | - | ||
| 1975 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 1976 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 1977 | -} | ||
| 1978 | - | ||
| 1979 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_OutputCountMismatch_ReturnsParamInvalid) { | ||
| 1980 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 1981 | - EnableOm2OnlineMode(); | ||
| 1982 | - | ||
| 1983 | - ModelExecutor model_executor; | ||
| 1984 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 1985 | - | ||
| 1986 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | ||
| 1987 | - GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | ||
| 1988 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 1989 | - | ||
| 1990 | - GeModelPtr ge_model = MakeShared<GeModel>(); | ||
| 1991 | - ge_model->SetGraph(compute_graph); | ||
| 1992 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 1993 | - | ||
| 1994 | - GraphId graph_id = 3004; | ||
| 1995 | - GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | ||
| 1996 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 1997 | - | ||
| 1998 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 1999 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 2000 | - | ||
| 2001 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 2002 | - | ||
| 2003 | - std::vector<uint8_t> data(16U, 0U); | ||
| 2004 | - gert::Tensor input; | ||
| 2005 | - input.SetPlacement(gert::kOnDeviceHbm); | ||
| 2006 | - input.SetData(gert::TensorData(data.data(), nullptr, data.size(), gert::kOnDeviceHbm)); | ||
| 2007 | - | ||
| 2008 | - gert::Tensor output1; | ||
| 2009 | - output1.SetPlacement(gert::kOnDeviceHbm); | ||
| 2010 | - output1.SetData(gert::TensorData(data.data(), nullptr, data.size(), gert::kOnDeviceHbm)); | ||
| 2011 | - gert::Tensor output2; | ||
| 2012 | - output2.SetPlacement(gert::kOnDeviceHbm); | ||
| 2013 | - output2.SetData(gert::TensorData(data.data(), nullptr, data.size(), gert::kOnDeviceHbm)); | ||
| 2014 | - | ||
| 2015 | - std::vector<gert::Tensor> inputs; | ||
| 2016 | - inputs.push_back(std::move(input)); | ||
| 2017 | - std::vector<gert::Tensor> outputs; | ||
| 2018 | - outputs.push_back(std::move(output1)); | ||
| 2019 | - outputs.push_back(std::move(output2)); | ||
| 2020 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 2021 | - | ||
| 2022 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 2023 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 2024 | -} | ||
| 2025 | - | ||
| 2026 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_InputSizeInsufficient_ReturnsParamInvalid) { | ||
| 2027 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 2028 | - EnableOm2OnlineMode(); | ||
| 2029 | - | ||
| 2030 | - ModelExecutor model_executor; | ||
| 2031 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 2032 | - | ||
| 2033 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | ||
| 2034 | - GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | ||
| 2035 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 2036 | - | ||
| 2037 | - GeModelPtr ge_model = MakeShared<GeModel>(); | ||
| 2038 | - ge_model->SetGraph(compute_graph); | ||
| 2039 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 2040 | - | ||
| 2041 | - GraphId graph_id = 3005; | ||
| 2042 | - GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | ||
| 2043 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 2044 | - | ||
| 2045 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 2046 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 2047 | - | ||
| 2048 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 2049 | - | ||
| 2050 | - std::vector<uint8_t> small_data(4U, 0U); | ||
| 2051 | - gert::Tensor input; | ||
| 2052 | - input.SetPlacement(gert::kOnDeviceHbm); | ||
| 2053 | - input.SetData(gert::TensorData(small_data.data(), nullptr, small_data.size(), gert::kOnDeviceHbm)); | ||
| 2054 | - | ||
| 2055 | - gert::Tensor output; | ||
| 2056 | - output.SetPlacement(gert::kOnDeviceHbm); | ||
| 2057 | - std::vector<uint8_t> out_data(16U, 0U); | ||
| 2058 | - output.SetData(gert::TensorData(out_data.data(), nullptr, out_data.size(), gert::kOnDeviceHbm)); | ||
| 2059 | - | ||
| 2060 | - std::vector<gert::Tensor> inputs; | ||
| 2061 | - inputs.push_back(std::move(input)); | ||
| 2062 | - std::vector<gert::Tensor> outputs; | ||
| 2063 | - outputs.push_back(std::move(output)); | ||
| 2064 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 2065 | - | ||
| 2066 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 2067 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 2068 | -} | ||
| 2069 | - | ||
| 2070 | TEST_F(UtestModelExecutorOm2Test, RunGraph_EmptyOutputs_PrepareOm2Outputs) { | 1947 | TEST_F(UtestModelExecutorOm2Test, RunGraph_EmptyOutputs_PrepareOm2Outputs) { |
| 2071 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | 1948 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); |
| 2072 | EnableOm2OnlineMode(); | 1949 | EnableOm2OnlineMode(); |
| @@ -2168,7 +2045,8 @@ TEST_F(UtestModelExecutorOm2Test, LoadGraph_ExternalConstAndFeatureMemory_Succes | |||
| 2168 | 2045 | ||
| 2169 | TEST_F(UtestModelExecutorOm2Test, UnloadOm2Graph_UnknownGraph_ReturnsSuccess) { | 2046 | TEST_F(UtestModelExecutorOm2Test, UnloadOm2Graph_UnknownGraph_ReturnsSuccess) { |
| 2170 | ModelExecutor model_executor; | 2047 | ModelExecutor model_executor; |
| 2171 | - EXPECT_EQ(model_executor.UnloadOm2Graph(3012U), SUCCESS); | 2048 | + GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); |
| 2049 | + EXPECT_EQ(model_executor.UnloadOm2Graph(ge_root_model, 3012U), SUCCESS); | ||
| 2172 | } | 2050 | } |
| 2173 | 2051 | ||
| 2174 | TEST_F(UtestModelExecutorOm2Test, RunGraphWithStream_Om2Mode_Success) { | 2052 | TEST_F(UtestModelExecutorOm2Test, RunGraphWithStream_Om2Mode_Success) { |
| @@ -2208,134 +2086,6 @@ TEST_F(UtestModelExecutorOm2Test, RunGraphWithStream_Om2Mode_Success) { | |||
| 2208 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 2086 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| 2209 | } | 2087 | } |
| 2210 | 2088 | ||
| 2211 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_InputNullAddr_ReturnsParamInvalid) { | ||
| 2212 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 2213 | - EnableOm2OnlineMode(); | ||
| 2214 | - | ||
| 2215 | - ModelExecutor model_executor; | ||
| 2216 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 2217 | - | ||
| 2218 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | ||
| 2219 | - GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | ||
| 2220 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 2221 | - | ||
| 2222 | - GeModelPtr ge_model = MakeShared<GeModel>(); | ||
| 2223 | - ge_model->SetGraph(compute_graph); | ||
| 2224 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 2225 | - | ||
| 2226 | - GraphId graph_id = 3008; | ||
| 2227 | - GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | ||
| 2228 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 2229 | - | ||
| 2230 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 2231 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 2232 | - | ||
| 2233 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 2234 | - | ||
| 2235 | - gert::Tensor input; | ||
| 2236 | - input.SetPlacement(gert::kOnDeviceHbm); | ||
| 2237 | - | ||
| 2238 | - gert::Tensor output; | ||
| 2239 | - output.SetPlacement(gert::kOnDeviceHbm); | ||
| 2240 | - std::vector<uint8_t> out_data(16U, 0U); | ||
| 2241 | - output.SetData(gert::TensorData(out_data.data(), nullptr, out_data.size(), gert::kOnDeviceHbm)); | ||
| 2242 | - | ||
| 2243 | - std::vector<gert::Tensor> inputs; | ||
| 2244 | - inputs.push_back(std::move(input)); | ||
| 2245 | - std::vector<gert::Tensor> outputs; | ||
| 2246 | - outputs.push_back(std::move(output)); | ||
| 2247 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 2248 | - | ||
| 2249 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 2250 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 2251 | -} | ||
| 2252 | - | ||
| 2253 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_OutputNullAddr_ReturnsParamInvalid) { | ||
| 2254 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 2255 | - EnableOm2OnlineMode(); | ||
| 2256 | - | ||
| 2257 | - ModelExecutor model_executor; | ||
| 2258 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 2259 | - | ||
| 2260 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | ||
| 2261 | - GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | ||
| 2262 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 2263 | - | ||
| 2264 | - GeModelPtr ge_model = MakeShared<GeModel>(); | ||
| 2265 | - ge_model->SetGraph(compute_graph); | ||
| 2266 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 2267 | - | ||
| 2268 | - GraphId graph_id = 3009; | ||
| 2269 | - GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | ||
| 2270 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 2271 | - | ||
| 2272 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 2273 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 2274 | - | ||
| 2275 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 2276 | - | ||
| 2277 | - std::vector<uint8_t> input_data(16U, 0U); | ||
| 2278 | - gert::Tensor input; | ||
| 2279 | - input.SetPlacement(gert::kOnDeviceHbm); | ||
| 2280 | - input.SetData(gert::TensorData(input_data.data(), nullptr, input_data.size(), gert::kOnDeviceHbm)); | ||
| 2281 | - | ||
| 2282 | - gert::Tensor output; | ||
| 2283 | - output.SetPlacement(gert::kOnDeviceHbm); | ||
| 2284 | - | ||
| 2285 | - std::vector<gert::Tensor> inputs; | ||
| 2286 | - inputs.push_back(std::move(input)); | ||
| 2287 | - std::vector<gert::Tensor> outputs; | ||
| 2288 | - outputs.push_back(std::move(output)); | ||
| 2289 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 2290 | - | ||
| 2291 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 2292 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 2293 | -} | ||
| 2294 | - | ||
| 2295 | -TEST_F(UtestModelExecutorOm2Test, RunGraph_OutputSizeInsufficient_ReturnsParamInvalid) { | ||
| 2296 | - EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | ||
| 2297 | - EnableOm2OnlineMode(); | ||
| 2298 | - | ||
| 2299 | - ModelExecutor model_executor; | ||
| 2300 | - EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||
| 2301 | - | ||
| 2302 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | ||
| 2303 | - GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | ||
| 2304 | - EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | ||
| 2305 | - | ||
| 2306 | - GeModelPtr ge_model = MakeShared<GeModel>(); | ||
| 2307 | - ge_model->SetGraph(compute_graph); | ||
| 2308 | - ge_root_model->SetSubgraphInstanceNameToModel(compute_graph->GetName(), ge_model); | ||
| 2309 | - | ||
| 2310 | - GraphId graph_id = 3010; | ||
| 2311 | - GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | ||
| 2312 | - graph_node->SetGeRootModel(ge_root_model); | ||
| 2313 | - | ||
| 2314 | - auto model_data = std::make_shared<gert::Om2ModelData>(MakeOm2ModelDataWithFakeSo(fake_so_path_)); | ||
| 2315 | - ge_root_model->SetOm2ModelData(model_data); | ||
| 2316 | - | ||
| 2317 | - EXPECT_EQ(model_executor.LoadGraph(ge_root_model, graph_node), SUCCESS); | ||
| 2318 | - | ||
| 2319 | - std::vector<uint8_t> input_data(16U, 0U); | ||
| 2320 | - gert::Tensor input; | ||
| 2321 | - input.SetPlacement(gert::kOnDeviceHbm); | ||
| 2322 | - input.SetData(gert::TensorData(input_data.data(), nullptr, input_data.size(), gert::kOnDeviceHbm)); | ||
| 2323 | - | ||
| 2324 | - std::vector<uint8_t> small_output_data(4U, 0U); | ||
| 2325 | - gert::Tensor output; | ||
| 2326 | - output.SetPlacement(gert::kOnDeviceHbm); | ||
| 2327 | - output.SetData(gert::TensorData(small_output_data.data(), nullptr, small_output_data.size(), gert::kOnDeviceHbm)); | ||
| 2328 | - | ||
| 2329 | - std::vector<gert::Tensor> inputs; | ||
| 2330 | - inputs.push_back(std::move(input)); | ||
| 2331 | - std::vector<gert::Tensor> outputs; | ||
| 2332 | - outputs.push_back(std::move(output)); | ||
| 2333 | - EXPECT_EQ(model_executor.RunGraph(graph_node, graph_id, inputs, outputs), PARAM_INVALID); | ||
| 2334 | - | ||
| 2335 | - EXPECT_EQ(model_executor.UnloadGraph(ge_root_model, graph_id), SUCCESS); | ||
| 2336 | - EXPECT_EQ(model_executor.Finalize(), SUCCESS); | ||
| 2337 | -} | ||
| 2338 | - | ||
| 2339 | TEST_F(UtestModelExecutorOm2Test, UpdateFeatureMemoryBase_ReturnsUnsupported) { | 2089 | TEST_F(UtestModelExecutorOm2Test, UpdateFeatureMemoryBase_ReturnsUnsupported) { |
| 2340 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); | 2090 | EnvValueGuard guard("ENABLE_RUNTIME_OM2"); |
| 2341 | EnableOm2OnlineMode(); | 2091 | EnableOm2OnlineMode(); |


建议移除这个未使用的 stream 参数,而不是用 (void)stream 消除告警。LoadOm2Graph 是 ModelExecutor 的私有接口,load 阶段明确不需要 stream,可以同步修改声明和调用点,避免接口继续携带无效参数;如果必须保留参数,也建议在定义中省略参数名。上下文:https://gitcode.com/cann/ge/blob/13c25bbb2a1214da4b11d20785d795851a07981b2/runtime/v1/graph/execute/model_executor.cc#L1037-L1043