Skip to content

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

Txpr() =default

function AddVar

VarId AddVar(
    Shape shape,
    DType dtype,
    std::string name =""
)

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

void MarkInput(
    VarId var
)

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

void MarkOutput(
    VarId var
)

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

inline const std::vector< VarDef > & Variables() const

Accessors.

function Equations

inline const std::vector< TxprEqn > & Equations() const

function Instructions

inline const std::vector< TxprEqn > & Instructions() const

function InBinders

inline const std::vector< VarId > & InBinders() const

function OutBinders

inline const std::vector< VarId > & OutBinders() const

function NumVars

inline size_t NumVars() const

function NumEquations

inline size_t NumEquations() const

function NumInstructions

inline size_t NumInstructions() const

function Var

inline const VarDef & Var(
    VarId id
) const

function Variable

inline const VarDef & Variable(
    VarId id
) const

function ShapeOf

inline const Shape & ShapeOf(
    VarId id
) const

function DtypeOf

inline DType DtypeOf(
    VarId id
) const

function Validate

bool Validate(
    std::string * error_msg =nullptr
) const

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

std::string ToString() const

Render readable Jaxpr-style text representation.

Return: Textual representation of the graph.

Render the graph in the textual lambda; let ... in (...) form.