tenzr::txpr::Txpr¶
SSA-style intermediate representation of a computation as typed variables and equations; produced by tracing and consumed by emitters and validators.
#include <txpr.h>
Public Functions¶
| Name | |
|---|---|
| Txpr() =default | |
| VarId | AddVar(Shape shape, DType dtype, std::string name ="") Allocate a new symbolic variable in the Txpr. |
| VarId | AppendInstruction(OpCode op, std::vector< VarId > in_vars, Shape out_shape, DType out_dtype, AttributePayload attrs ={}) Append a single-output equation to the Txpr. |
| std::vector< VarId > | AppendMultiOutInstruction(OpCode op, std::vector< VarId > in_vars, const std::vector< Shape > & out_shapes, const std::vector< DType > & out_dtypes, AttributePayload attrs ={}) Append a multi-output equation to the Txpr. |
| void | MarkInput(VarId var) Declare a variable as a function input parameter. |
| void | MarkOutput(VarId var) Declare a variable as a function output result. |
| const std::vector< VarDef > & | Variables() const Accessors. |
| const std::vector< TxprEqn > & | Equations() const |
| const std::vector< TxprEqn > & | Instructions() const |
| const std::vector< VarId > & | InBinders() const |
| const std::vector< VarId > & | OutBinders() const |
| size_t | NumVars() const |
| size_t | NumEquations() const |
| size_t | NumInstructions() const |
| const VarDef & | Var(VarId id) const |
| const VarDef & | Variable(VarId id) const |
| const Shape & | ShapeOf(VarId id) const |
| DType | DtypeOf(VarId id) const |
| bool | Validate(std::string * error_msg =nullptr) const Perform strict SSA and type validation. |
| std::string | ToString() const Render readable Jaxpr-style text representation. |
Public Functions Documentation¶
function Txpr¶
function AddVar¶
Allocate a new symbolic variable in the Txpr.
Parameters:
- shape Shape of the variable.
- dtype Dtype of the variable.
- name Optional debug name.
Return: The new variable's id.
Append a new variable definition to the graph.
function AppendInstruction¶
VarId AppendInstruction(
OpCode op,
std::vector< VarId > in_vars,
Shape out_shape,
DType out_dtype,
AttributePayload attrs ={}
)
Append a single-output equation to the Txpr.
Parameters:
- op Operation to execute.
- in_vars Input variable ids.
- out_shape Result shape.
- out_dtype Result dtype.
- attrs Operation attributes.
Return: The instruction's output variable id.
Append a single-output instruction and return its result variable.
function AppendMultiOutInstruction¶
std::vector< VarId > AppendMultiOutInstruction(
OpCode op,
std::vector< VarId > in_vars,
const std::vector< Shape > & out_shapes,
const std::vector< DType > & out_dtypes,
AttributePayload attrs ={}
)
Append a multi-output equation to the Txpr.
Parameters:
- op Operation to execute.
- in_vars Input variable ids.
- out_shapes Result shapes.
- out_dtypes Result dtypes, matching out_shapes.
- attrs Operation attributes.
Return: The instruction's output variable ids.
Append a multi-output instruction and return its result variables.
function MarkInput¶
Declare a variable as a function input parameter.
Parameters:
- var Variable to mark as input.
Register var as an input binder of the graph.
function MarkOutput¶
Declare a variable as a function output result.
Parameters:
- var Variable to mark as output.
Register var as an output binder of the graph.
function Variables¶
Accessors.
function Equations¶
function Instructions¶
function InBinders¶
function OutBinders¶
function NumVars¶
function NumEquations¶
function NumInstructions¶
function Var¶
function Variable¶
function ShapeOf¶
function DtypeOf¶
function Validate¶
Perform strict SSA and type validation.
Parameters:
- error_msg Optional out-parameter receiving the first failure reason.
Return: true when the graph is well-formed.
Check that binders are unique and every use is SSA-defined before it.
function ToString¶
Render readable Jaxpr-style text representation.
Return: Textual representation of the graph.
Render the graph in the textual lambda; let ... in (...) form.