tf_1.8_xla_doc
|
#include <xla_compiler.h>
Public Member Functions | |
Status | CompileGraph (const CompileOptions &options, string const &name, std::unique_ptr< Graph > graph, const std::vector< Argument > &args, CompilationResult *result) |
Compiles a tensorflow::Graph into an xla::Computation. More... | |
Private Member Functions | |
Status | BuildArguments (const Graph &graph, const std::vector< XlaCompiler::Argument > &args, bool use_tuple_arg, xla::ComputationBuilder *builder, XlaContext *context, std::vector< int > *arg_cores, std::vector< XlaExpression > *arg_expressions, std::vector< int > *input_mapping, std::vector< xla::Shape > *input_shapes, bool is_entry_computation) |
Build XLA computations for each of the arguments to the UserComputation . More... | |
The XlaCompiler class is responsible for compilation of a self-contained subgraph of a TensorFlow computation using the XLA linear algebra runtime. It does a symbolic execution of the graph starting from specific input shapes, using a JIT device to convert operators into XLA computations.
XlaCompiler is typically invoked from an
_XlaLaunch
operator once the shapes of all input parameters to the computation are known. This is because the symbolic execution requires known shapes for all operations.XlaCompiler compiles Tensorflow graphs that received inputs via _Arg nodes, and return outputs via _Retval nodes.
The XlaCompiler requires one Argument struct for each _Arg index, that describes each argument. Arguments can be compile-time constants (kind kConstant), run-time parameters (kind kParameter), or resources (kind kResource).
Only kParameter and initialized kResource arguments become runtime parameters to the generated XLA computation. The XLA computation will have run-time parameters in the following order: +------------------—+--------------------------------------—+ | kParameter values | Initial values of kResource arguments | +------------------—+--------------------------------------—+ Within each block, the arguments are arranged by the _Arg index from which they were derived.
The run-time outputs of the XLA computation are arranged in the following order: +---------------—+--------------------------------------—+ | _Retval values | Updated values of kResource arguments | +---------------—+--------------------------------------—+ _Retval values are ordered by _Retval index, whereas kResource values are ordered by the original _Arg position of the variable.
In both inputs and outputs, kResource values are placed the end. When emitting While loop bodies, we must ensure that the loop body has identical input and output signatures. By moving variable values to the end of the argument list and using the
return_updated_values_for_all_variables
option, we can ensure that the input and output values of resources appear at the same positions.Resources are passed as parameters or returned as resource updates in "packed" form. kStack resources are packed as (array, size of stack) XLA tuples. kTensorArray resources without gradients are packed as the array that backs the TensorArray. If gradients are present (
tensor_array_gradients
), the packed representation is a (array, gradient0, gradient1, ...) tuple, where gradient_k is the value of the k-th gradient in thetensor_array_gradients
ordered set.
|
private |
Build XLA computations for each of the arguments to the UserComputation
.
args
(arguments to the UserComputation
) to set index of non-constant arguments in input_mapping
(in order of kParameter
to kResource
) and set up arg_expressions
.input_mapping
to compute the shapes of non-constant arguments and record in arg_shapes
. Based on the option use_tuple_arg
, it decides how to store arg_shapes
to input_shapes
._Arg
nodes in graph to resolve core assignments. The result is written in function argument arg_cores
.arg_expressions
set up in 1.).Unclear parts:
XlaResource
in 1.kParameter
& kResource
in 1.input_shapes
be used in the future? in 2.Status tensorflow::XlaCompiler::CompileGraph | ( | const CompileOptions & | options, |
string const & | name, | ||
std::unique_ptr< Graph > | graph, | ||
const std::vector< Argument > & | args, | ||
CompilationResult * | result | ||
) |
Compiles a tensorflow::Graph into an xla::Computation.
ComputationBuilder
& XlaContext
objects.UserComputation
.)