| 270 | return legal; |
| 271 | } |
| 272 | std::vector<Node*> fuseNode(Node* root, std::vector<Node*>& edges, MNNForwardType type) { |
| 273 | std::vector<Node*> fuseSet; |
| 274 | std::queue<Node*> q; |
| 275 | q.push(root); |
| 276 | int rasterCount = 0; |
| 277 | bool insert = false; |
| 278 | while (!q.empty()) { |
| 279 | insert = false; |
| 280 | auto node = q.front(); |
| 281 | if(node->cmd->op->type() == OpType_Raster) { |
| 282 | // Current only fuse single raster |
| 283 | rasterCount++; |
| 284 | if(rasterCount < 2) { |
| 285 | fuseSet.insert(fuseSet.begin(), node); |
| 286 | insert = true; |
| 287 | } |
| 288 | } else { |
| 289 | fuseSet.insert(fuseSet.begin(), node); |
| 290 | insert = true; |
| 291 | } |
| 292 | |
| 293 | q.pop(); |
| 294 | if(insert) { |
| 295 | for (auto child : node->domainateSucc) { |
| 296 | if (isLegal(child->cmd, type) && allPathLegal(child, root, type)) { |
| 297 | q.push(child); |
| 298 | } else { |
| 299 | edges.push_back(child); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | return fuseSet; |
| 305 | } |
| 306 | |
| 307 | bool codegen(std::vector<Schedule::OpCacheInfo>& infos, std::vector<std::vector<Node*>>& fuseSets, MNNForwardType type, BackendConfig::PrecisionMode precision) { |
| 308 | // generate Kernel |