2 years ago
#55933

joel
How to construct an XlaOp?
There are a number of functions for creating XlaOp
s from native C++ values. I'm trying to figure out how to use each to construct a graph. I've gone through xla_builder.h and picked out some candidates, omitting overloads and convenience wrappers. The two most likely candidates seem to be
// Enqueues a "retrieve parameter value" instruction for a parameter that was
// passed to the computation.
XlaOp Parameter(XlaBuilder* builder, int64 parameter_number, const Shape& shape,
const string& name);
// Enqueues a constant with the value of the given literal onto the
// computation.
XlaOp ConstantLiteral(XlaBuilder* builder, const LiteralSlice& literal);
Am I right in thinking Parameter
is for "symbols", while ConstantLiteral
is for constant values? For example, in f(x) = x + 1
, we'd encode 1
as a ConstantLiteral
, and then for x
we could either
- write
f(x)
as a C++ function, and at application site use anotherConstantLiteral
for our value ofx
, or - encode
x
usingParameter
and build anXlaComputation
from the correspondingXlaBuilder
. That said, I'm not clear on how to actually call theXlaComputation
with aLiteral
, other than withLocalClient
which doesn't work with to multipleXlaComputation
s afaict.
What's the difference between these two approaches? Is one better than the other? I notice the former doesn't appear possible for higher-order functions: those which accept XlaComputation
s.
Next there's
Infeed
, which I'd guess is a streaming version ofParameter
.Recv
which looks like a way to pass data between computations, but doesn't actually create a completely newXlaOp
itself.ReplicaId
,Iota
, andXlaOp CreateToken(XlaBuilder* builder);
appear largely irrelevant for this discussion.
Have I got this right? Are there any other important functions I've missed?
c++
tensorflow
tensorflow-xla
0 Answers
Your Answer