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

Method InferStatically

tensorflow/core/grappler/costs/graph_properties.cc:2135–2366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2133}
2134
2135Status GraphProperties::InferStatically(bool assume_valid_feeds,
2136 bool aggressive_shape_inference,
2137 bool include_input_tensor_values,
2138 bool include_output_tensor_values) {
2139 FunctionLibraryDefinition function_library(OpRegistry::Global(),
2140 item_.graph.library());
2141 std::unordered_map<string, std::unordered_set<int>> fed_ports;
2142 if (!assume_valid_feeds) {
2143 for (const auto& feed : item_.feed) {
2144 SafeTensorId tensor_id = ParseTensorName(feed.first);
2145 fed_ports[tensor_id.node()].insert(tensor_id.index());
2146 }
2147 }
2148
2149 GraphView graph_view(&item_.graph);
2150
2151 // List the resources and the nodes using them. Also collect the Merge nodes,
2152 // fed nodes, and primary inputs.
2153 std::unordered_map<const NodeDef*,
2154 std::pair<std::unordered_set<const NodeDef*>,
2155 std::unordered_set<const NodeDef*>>>
2156 resources;
2157 std::unordered_set<const NodeDef*> merge_nodes;
2158 std::unordered_set<const NodeDef*> fed_nodes;
2159 std::unordered_set<const NodeDef*> primary_inputs;
2160 int num_loops = 0;
2161 for (const NodeDef& node : item_.graph.node()) {
2162 if (IsQueue(node)) {
2163 for (const GraphView::InputPort& fanout :
2164 graph_view.GetFanouts(node, false)) {
2165 if (IsEnter(*fanout.node)) {
2166 const NodeDef& enter = *fanout.node;
2167 for (const GraphView::InputPort& fanout :
2168 graph_view.GetFanouts(enter, false)) {
2169 if (IsEnqueue(*fanout.node)) {
2170 resources[&node].first.insert(fanout.node);
2171 } else if (IsDequeue(*fanout.node)) {
2172 resources[&node].second.insert(fanout.node);
2173 }
2174 }
2175 } else {
2176 if (IsEnqueue(*fanout.node)) {
2177 resources[&node].first.insert(fanout.node);
2178 } else if (IsDequeue(*fanout.node)) {
2179 resources[&node].second.insert(fanout.node);
2180 }
2181 }
2182 }
2183 }
2184 if (!HasRegularInputs(node)) {
2185 primary_inputs.insert(&node);
2186 } else if (IsMerge(node)) {
2187 merge_nodes.insert(&node);
2188 } else if (IsNextIteration(node)) {
2189 ++num_loops;
2190 }
2191 if (fed_ports.find(node.name()) != fed_ports.end()) {
2192 fed_nodes.insert(&node);

Callers 1

UpdateFunctionMethod · 0.45

Calls 15

ParseTensorNameFunction · 0.85
IsQueueFunction · 0.85
IsEnqueueFunction · 0.85
IsDequeueFunction · 0.85
HasRegularInputsFunction · 0.85
ComputeTopologicalOrderFunction · 0.85
PropagateShapesFunction · 0.85
MakeTensorProtoFromShapeFunction · 0.85
GetFanoutsMethod · 0.80
GetNodeContextMethod · 0.80

Tested by

no test coverage detected