| 227 | } // namespace |
| 228 | |
| 229 | Status GraphCompiler::CompileFunctionalNode(Node* n, |
| 230 | OpKernelContext* op_context) { |
| 231 | TF_RET_CHECK(IsFunctionCall(*flib_->GetFunctionLibraryDefinition(), *n)); |
| 232 | // For functional nodes, compile them using compiler from the context and call |
| 233 | // into the functions. |
| 234 | XlaOpKernelContext xla_op_context(op_context); |
| 235 | |
| 236 | XlaContext& context = XlaContext::Get(op_context); |
| 237 | auto* b = context.builder(); |
| 238 | |
| 239 | XlaCompiler* compiler = xla_op_context.compiler(); |
| 240 | |
| 241 | NameAttrList func; |
| 242 | TF_RETURN_IF_ERROR(GetFunctionNameAndAttr(*flib_, *n, &func)); |
| 243 | |
| 244 | std::vector<const XlaExpression*> expressions; |
| 245 | |
| 246 | for (auto tensor : tensor_inputs_) { |
| 247 | auto expression = |
| 248 | reinterpret_cast<const XlaExpression*>(tensor->tensor_data().data()); |
| 249 | expressions.push_back(expression); |
| 250 | } |
| 251 | |
| 252 | // Prepare the arguments and compile the function. |
| 253 | std::vector<XlaCompiler::Argument> arguments; |
| 254 | const FunctionBody* fbody; |
| 255 | TF_RETURN_IF_ERROR(compiler->FindFunctionBody(func, &fbody)); |
| 256 | |
| 257 | auto graph = compiler->GetGraph(fbody); |
| 258 | |
| 259 | TF_RETURN_IF_ERROR( |
| 260 | PrepareArguments(&xla_op_context, graph.get(), expressions, &arguments)); |
| 261 | |
| 262 | bool add_token_input_output = |
| 263 | func.attr().find(kXlaTokenInputNodesAttrName) != func.attr().end(); |
| 264 | |
| 265 | XlaCompiler::CompileOptions compile_options; |
| 266 | compile_options.is_entry_computation = false; |
| 267 | compile_options.add_token_input_output = add_token_input_output; |
| 268 | XlaCompiler::CompilationResult result; |
| 269 | TF_RETURN_IF_ERROR( |
| 270 | compiler->CompileFunction(compile_options, func, arguments, &result)); |
| 271 | |
| 272 | TF_RET_CHECK(arguments.size() == expressions.size()); |
| 273 | |
| 274 | std::vector<xla::XlaOp> handles; |
| 275 | for (int64 i = 0; i < expressions.size(); ++i) { |
| 276 | if (arguments[i].kind == XlaCompiler::Argument::kConstant) { |
| 277 | continue; |
| 278 | } |
| 279 | if (arguments[i].kind == XlaCompiler::Argument::kResource) { |
| 280 | handles.push_back(expressions[i]->resource()->value()); |
| 281 | } else { |
| 282 | handles.push_back(expressions[i]->handle()); |
| 283 | } |
| 284 | } |
| 285 | if (add_token_input_output) { |
| 286 | std::vector<string> token_input_nodes; |
nothing calls this directly
no test coverage detected