| 1106 | blob->dataType = DataType_DT_##TYPE; |
| 1107 | |
| 1108 | void Variable::save(const std::vector<VARP>& vars, NetT* dest) { |
| 1109 | auto executeOrder = getExecuteOrder(vars); |
| 1110 | // Search subgraphs |
| 1111 | std::map<std::string, std::shared_ptr<Executor::SubGraph>> subgraphs; |
| 1112 | auto exe = ExecutorScope::Current(); |
| 1113 | #ifndef MNN_REDUCE_SIZE |
| 1114 | for (int index = 0; index < executeOrder.size(); ++index) { |
| 1115 | auto expr = executeOrder[index]; |
| 1116 | auto op = expr->get(); |
| 1117 | if (nullptr == op || op->type() != OpType_While) { |
| 1118 | continue; |
| 1119 | } |
| 1120 | if (op->main_type() != OpParameter_WhileParam) { |
| 1121 | continue; |
| 1122 | } |
| 1123 | auto whileParam = op->main_as_WhileParam(); |
| 1124 | auto name = whileParam->body_graph()->str(); |
| 1125 | auto subgraph = exe->findSubGraph(name); |
| 1126 | if (nullptr == subgraph) { |
| 1127 | #ifdef MNN_EXPRESS_ERROR_REPORT |
| 1128 | MNN_ERROR("Variable::save: Invalid subgraph name: %s\n", name.c_str()); |
| 1129 | #endif |
| 1130 | continue; |
| 1131 | } |
| 1132 | MNN_ASSERT(subgraph->depends.size() == 0); |
| 1133 | subgraphs.insert(std::make_pair(name, subgraph)); |
| 1134 | } |
| 1135 | // Save Subgraphs |
| 1136 | dest->subgraphs.clear(); |
| 1137 | for (auto& graphIter : subgraphs) { |
| 1138 | // Copy Subgraph info |
| 1139 | flatbuffers::FlatBufferBuilder builder; |
| 1140 | builder.Finish(MNN::SubGraphProto::Pack(builder, graphIter.second->info.get())); |
| 1141 | std::unique_ptr<MNN::SubGraphProtoT> subgraph(flatbuffers::GetRoot<MNN::SubGraphProto>(builder.GetBufferPointer())->UnPack()); |
| 1142 | dest->subgraphs.emplace_back(std::move(subgraph)); |
| 1143 | } |
| 1144 | #endif |
| 1145 | // Get Expr - TensorOffset Map |
| 1146 | std::map<EXPRP, int> varIndexInfo; |
| 1147 | { |
| 1148 | int tensorOffset = 0; |
| 1149 | for (int i=0; i<executeOrder.size(); ++i) { |
| 1150 | auto expr = executeOrder[i]; |
| 1151 | auto outputSize = executeOrder[i]->outputSize(); |
| 1152 | varIndexInfo[expr] = tensorOffset; |
| 1153 | tensorOffset += outputSize; |
| 1154 | } |
| 1155 | dest->tensorName.resize(tensorOffset); |
| 1156 | } |
| 1157 | |
| 1158 | // Create All Op |
| 1159 | for (int index = 0; index < executeOrder.size(); ++index) { |
| 1160 | auto expr = executeOrder[index]; |
| 1161 | auto mOp = expr->get(); |
| 1162 | std::unique_ptr<OpT> op; |
| 1163 | if (nullptr != mOp) { |
| 1164 | op.reset(mOp->UnPack()); |
| 1165 | } else { |
no test coverage detected