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

Method FixMklMetaDataEdges

tensorflow/core/graph/mkl_layout_pass.cc:4031–4086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4029}
4030
4031bool MklLayoutRewritePass::FixMklMetaDataEdges(std::unique_ptr<Graph>* g,
4032 Node* n) {
4033 bool result = false;
4034
4035 // If graph node is not OneDNN node, then return.
4036 DataType T = DT_INVALID;
4037 if (!TryGetNodeAttr(n->def(), "T", &T) ||
4038 !mkl_op_registry::IsMklLayoutDependentOp(n->type_string(), T)) {
4039 return result;
4040 }
4041
4042 // If it is OneDNN node, then check if the input edges to this node that carry
4043 // OneDNN metadata are linked up correctly with the source node.
4044
4045 // For OneDNN nodes, we generate twice the number of input tensors (n for OneDNN
4046 // data tensors + n for OneDNN metadata tensors). We need to check for correct
4047 // connection of n metadata tensors only.
4048 int num_data_inputs = n->num_inputs() / 2;
4049 for (int idx = 0; idx < num_data_inputs; idx++) {
4050 // Get the edge connecting input slot with index (idx).
4051 const Edge* e = nullptr;
4052 TF_CHECK_OK(n->input_edge(idx, &e));
4053
4054 // If e is control edge, then skip.
4055 if (e->IsControlEdge()) {
4056 continue;
4057 }
4058
4059 // Check that the source node for edge 'e' is OneDNN node. If it is not an OneDNN
4060 // node, then we don't need to do anything.
4061 Node* e_src = e->src();
4062 if (TryGetNodeAttr(e_src->def(), "T", &T) &&
4063 mkl_op_registry::IsMklLayoutDependentOp(e_src->type_string(), T)) {
4064 // Source node for edge 'e' is OneDNN node.
4065 // Destination node and destination input slot of e is node 'n' and 'idx'
4066 // resp.
4067 CHECK_EQ(e->dst(), n);
4068 CHECK_EQ(e->dst_input(), idx);
4069
4070 // Let's get edge that carries OneDNN metadata corresponding to OneDNN data edge
4071 // 'e'. For that, let's first get the input slot of 'n' where the meta
4072 // edge will feed the value.
4073 int e_meta_in_slot =
4074 GetTensorMetaDataIndex(e->dst_input(), n->num_inputs());
4075 const Edge* e_meta = nullptr;
4076 TF_CHECK_OK(n->input_edge(e_meta_in_slot, &e_meta));
4077
4078 // Let's check if we need to fix this meta edge.
4079 if (FixMklMetaDataEdgeIfNeeded(g, e, e_meta)) {
4080 result = true;
4081 }
4082 }
4083 }
4084
4085 return result;
4086}
4087
4088///////////////////////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 8

IsMklLayoutDependentOpFunction · 0.85
GetTensorMetaDataIndexFunction · 0.85
input_edgeMethod · 0.80
num_inputsMethod · 0.45
IsControlEdgeMethod · 0.45
srcMethod · 0.45
dstMethod · 0.45
dst_inputMethod · 0.45

Tested by

no test coverage detected