MCPcopy Create free account
hub / github.com/alibaba/MNN / opFuse

Function opFuse

codegen/OpFuse.cpp:417–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417bool opFuse(std::vector<Schedule::OpCacheInfo>& infos, MNNForwardType type, BackendConfig::PrecisionMode precision) {
418 std::unordered_map<const Tensor*, Node*> outputTensor;
419 // build graph
420 std::vector<std::unique_ptr<Node>> graph;
421 auto insertEdge = [&outputTensor](const Tensor* inputTensor, Node* succNode) {
422 if (outputTensor.find(inputTensor) != outputTensor.end()) {
423 auto preNode = outputTensor[inputTensor];
424 succNode->pred.push_back(preNode);
425 preNode->succ.push_back(succNode);
426 }
427 };
428 for (int i = 0; i < infos.size(); i++) {
429 auto& info = infos[i];
430 auto& cmdBuffer = info.executeBuffer;
431 for (int j = 0; j < cmdBuffer.command.size(); j++) {
432 auto iter = cmdBuffer.command[j];
433 /*
434 if (iter->buffer.get()) {
435 iter->op = flatbuffers::GetMutableRoot<Op>((void*)iter->buffer);
436 }
437 */
438 std::unique_ptr<Node> node(new Node);
439 node->cmd = iter.get();
440 node->topoIndex = i;
441 for (auto input : iter->inputs) {
442 insertEdge(input, node.get());
443 }
444 for (auto output : iter->outputs) {
445 outputTensor[output] = node.get();
446 }
447 graph.push_back(std::move(node));
448 }
449 }
450
451 if(type == MNN_FORWARD_OPENCL){
452 for(int i = 0; i < graph.size(); ++i){
453 mergeConvolutionAndPrelu(graph[i].get(), type);
454 }
455 for(auto iter = graph.begin(); iter != graph.end();){
456 if(iter->get()->cmd->op == nullptr){
457 iter = graph.erase(iter);
458 }else{
459 ++iter;
460 }
461 }
462 }
463
464 std::queue<Node*> postDominateNodeQueue;
465 // build dominate tree
466 for (int i = static_cast<int>(graph.size()) - 1; i >= 0; i--) {
467 auto node = graph[i].get();
468 if (!node->succ.empty()) {
469 auto parent = node->succ[0];
470 for (int j = 1; j < node->succ.size(); j++) {
471 parent = LCA(parent, node->succ[j]);
472 }
473 node->domainatePred = parent;
474 if (parent) {

Callers 1

Calls 15

mergeConvolutionAndPreluFunction · 0.85
LCAFunction · 0.85
isLegalFunction · 0.85
fuseNodeFunction · 0.85
dumpCmdFunction · 0.85
codegenFunction · 0.85
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected