Relay References¶
The TVM codebase is large and can be very confusing to reference. Things are not always placed where'd you expect them to be. The two classes below aim to aid the developer or user in the navigation and referencing of TVM's codebase.
forge.relay.relay.Relay
¶
Bases: Enum
An enumeration of Relay objects.
Provides a flattened reference of Relay objects. This allows one to more easily navigate TVM's codebase of objects without in-depth knowledge of TVM's codebase structure.
Examples: .. code-block:: python
Relay.Var.help() # Print the docstring of the TVM Var object
Relay.Var.str # Get the string of the TVM object - 'Var'
Relay.Var.obj # Reference to the TVM Var object
Relay.Var(*args, **kwargs) # Invoke the constructor
Methods:
| Name | Description |
|---|---|
help |
Print the docstrings of the enumerated TVM object |
__call__ |
Invocation of the enumerated TVM object's constructor |
Attributes:
| Name | Type | Description |
|---|---|---|
str |
str
|
String of the enumerated TVM object |
obj |
Any
|
Reference to the enumerated TVM object |
Function |
|
|
Call |
|
|
Var |
|
|
Constant |
|
|
Tuple |
|
|
TupleGetItem |
|
|
GlobalVar |
|
|
Op |
|
|
Attrs |
|
|
NDArray |
|
|
ADT |
|
|
Node |
|
|
Clause |
|
|
Match |
|
|
TypeData |
|
|
Constructor |
|
|
PatternConstructor |
|
|
PatternVar |
|
|
PatternWildcard |
|
|
PatternTuple |
|
|
Array |
|
|
Map |
|
|
Span |
|
|
SourceName |
|
|
Let |
|
|
If |
|
|
RefCreate |
|
|
RefRead |
|
|
RefWrite |
|
|
TupleWrapper |
|
|
TypeVar |
|
|
IncompleteType |
|
|
TensorType |
|
|
FuncType |
|
|
TupleType |
|
|
TypeRelation |
|
|
RefType |
|
|
GlobalTypeVar |
|
|
TypeCall |
|
|
Any |
|
|
IntImm |
|
|
String |
|
__call__
¶
__call__(*args, **kwargs) -> Any
Invocation of the enumerated TVM object's constructor
Use the member help() method to get details on correct usage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
*Any
|
Positional arguments for the constructor |
()
|
**kwargs
|
**Any
|
Keyword arguments for the constructor |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
TVM object |
Examples: .. code-block:: python
var = Relay.Var("data", shape=(100,), dtype="float32")
mod = Relay.IRModule(var)
forge.relay.relay.RelayOp
¶
RelayOp(op_name: str)
Provide a quick reference to TVM's python API of Relay Operators
via the identifying op-name string. This is a very useful since
all the operators are encoded as strings in Forge. Additionally,
there is a minor quirk the the structure of the TVM operator
codebase such that QNN operators are not placed in the codebase
in a path that matches its string-form, e.g. 'qnn.conv2d' sits at
tvm.relay.qnn.op.conv2d. This class resolves this quirk.
Lookup and reference the TVM operator function by operator's name string
Provided a valid operator name string, the returned instance is ready to be called as if it were the referenced TVM operator function. When a TVM operator function is called correctly, a Relay expression is formed.
Examples: .. code-block:: python
RelayOp("nn.conv2d") # Get the `tvm.relay.nn.conv2d` function
RelayOp("nn.conv2d")(*args, **kwargs) # Invoke operator and get a 'conv2d' expression
RelayOp("nn.conv2d").help() # Print the TVM operator function docstring
RelayOp.list_op_names() # Get a list of all op-name strings
Methods:
| Name | Description |
|---|---|
__call__ |
Invoke the referenced TVM operator function |
help |
Print the docstrings of the TVM operator function |
list_op_names |
Returns a sorted list of op-name strings |
Functions¶
__call__
¶
__call__(*args, **kwargs) -> obj
Invoke the referenced TVM operator function
Use the instance help() method to get details on correct usage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
*Any
|
Positional arguments for the TVM operator function |
()
|
**kwargs
|
**Any
|
Keyword arguments for the TVM operator function |
{}
|
Returns:
| Type | Description |
|---|---|
obj
|
TVM Relay expression |