There are a number of functions for creating XlaOps 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 anotherConstantLiteralfor our value ofx, or - encode
xusingParameterand build anXlaComputationfrom the correspondingXlaBuilder. That said, I'm not clear on how to actually call theXlaComputationwith aLiteral, other than withLocalClientwhich doesn't work with to multipleXlaComputations 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 XlaComputations.
Next there's
Infeed, which I'd guess is a streaming version ofParameter.Recvwhich looks like a way to pass data between computations, but doesn't actually create a completely newXlaOpitself.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?