MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / RunPass

Method RunPass

tensorflow/core/graph/mkl_layout_pass.cc:4091–4195  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// Run function for the pass //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

4089// Run function for the pass
4090///////////////////////////////////////////////////////////////////////////////
4091bool MklLayoutRewritePass::RunPass(std::unique_ptr<Graph>* g) {
4092 bool result = false;
4093 CHECK_NOTNULL(g);
4094
4095 DumpGraph("Before running MklLayoutRewritePass", &**g);
4096
4097 std::vector<Node*> order;
4098 GetReversePostOrder(**g, &order); // This will give us topological sort.
4099 for (Node* n : order) {
4100 // If node is not an op or it cannot run on CPU device, then skip.
4101 if (!n->IsOp() || !CanOpRunOnCPUDevice(n)) {
4102 continue;
4103 }
4104
4105 Node* m = nullptr;
4106 if ((m = CheckForNodeMerge(n)) != nullptr && CanOpRunOnCPUDevice(m)) {
4107 // Check if the node 'n' can be merged with any other node. If it can
4108 // be 'm' contains the node with which it can be merged.
4109 string n1_name = n->name();
4110 string n2_name = m->name();
4111
4112 VLOG(1) << "MklLayoutRewritePass: Scheduled nodes " << n1_name << " and "
4113 << n2_name << " for merging";
4114
4115 if (MergeNode(g, n, m) == Status::OK()) {
4116 VLOG(1) << "MklLayoutRewritePass: Merged nodes " << n1_name << " and "
4117 << n2_name;
4118 result = true;
4119 }
4120 }
4121 }
4122
4123 DumpGraph("After running MklLayoutRewritePass(NodeMerge)", &**g);
4124
4125 order.clear();
4126 GetReversePostOrder(**g, &order); // This will give us topological sort.
4127 for (Node* n : order) {
4128 // If node is not an op or it cannot run on CPU device, then skip.
4129 if (!n->IsOp() || !CanOpRunOnCPUDevice(n)) {
4130 continue;
4131 }
4132
4133 auto check_result = CheckForNodeFusion(n);
4134 bool found_pattern = std::get<0>(check_result);
4135 std::vector<Node*> nodes = std::get<1>(check_result);
4136 const FusionInfo fi = std::get<2>(check_result);
4137
4138 // if "found_pattern" is true, we can do the fusion.
4139 if (found_pattern) {
4140 if (FuseNode(g, nodes, fi) == Status::OK()) {
4141 result = true;
4142 }
4143 }
4144 }
4145 DumpGraph("After running MklLayoutRewritePass(NodeFusion)", &**g);
4146
4147 order.clear();
4148 GetReversePostOrder(**g, &order); // This will give us topological sort.

Callers 1

RunMklLayoutRewritePassFunction · 0.45

Calls 5

DumpGraphFunction · 0.85
GetReversePostOrderFunction · 0.85
IsOpMethod · 0.80
nameMethod · 0.65
clearMethod · 0.45

Tested by

no test coverage detected