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

Function ExpandInlineFunctions

tensorflow/core/common_runtime/function.cc:2185–2230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2183}
2184
2185bool ExpandInlineFunctions(FunctionLibraryRuntime* lib, Graph* graph,
2186 const ExpandInlineFunctionsOptions& options) {
2187 std::vector<std::pair<Node*, const FunctionBody*>> candidates;
2188
2189 const FunctionLibraryDefinition* fld = lib->GetFunctionLibraryDefinition();
2190
2191 for (Node* node : graph->nodes()) {
2192 // Skip nodes that are not function calls or SymbolicGradient calls.
2193 if (!IsFunctionCall(*lib->GetFunctionLibraryDefinition(), *node)) {
2194 continue;
2195 }
2196 // Skip function calls that marked noinline.
2197 bool noinline;
2198 if (fld->GetAttr(*node, kNoInlineAttr, &noinline).ok() && noinline) {
2199 VLOG(3) << "noinline: " << SummarizeNode(*node);
2200 continue;
2201 }
2202 FunctionLibraryRuntime::Handle handle;
2203 Status s = InstantiateFunctionCall(node->def(), lib, &handle);
2204 if (!s.ok()) {
2205 LOG(ERROR) << "Failed to instantiate a function: " << s.error_message();
2206 continue;
2207 }
2208 const FunctionBody* fbody = lib->GetFunctionBody(handle);
2209 CHECK_NOTNULL(fbody);
2210 candidates.emplace_back(node, fbody);
2211 }
2212
2213 bool inlined_any = false;
2214 for (const auto& p : candidates) {
2215 Status inlined = InlineFunctionBody(*fld, graph, p.first, p.second,
2216 p.first->IsPartitionedCall()
2217 ? options.multi_device_options
2218 : options.native_options);
2219 if (inlined.ok()) {
2220 inlined_any = true;
2221 } else {
2222 VLOG(1) << "Failed to inline function call: node=" << p.first->name()
2223 << " error=" << inlined.error_message();
2224 }
2225 }
2226
2227 // TODO(ezhulenev): Release handles for inlined function calls.
2228
2229 return inlined_any;
2230}
2231
2232string NewName(const Node* n, bool pretty) {
2233 if (pretty) {

Callers

nothing calls this directly

Calls 12

InstantiateFunctionCallFunction · 0.85
InlineFunctionBodyFunction · 0.85
GetFunctionBodyMethod · 0.80
IsPartitionedCallMethod · 0.80
IsFunctionCallFunction · 0.70
nameMethod · 0.65
SummarizeNodeFunction · 0.50
nodesMethod · 0.45
okMethod · 0.45
GetAttrMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected