heterocl.tvm.ir_builder module¶
Developer API of IR node builder make function.
-
class
BufferVar
(builder, buffer_var, content_type)[source]¶ Bases:
heterocl.tvm._ffi.node_generic.NodeGeneric
Buffer variable with content type, makes load store easily.
Do not create it directly, create use IRBuilder.
Examples
In the follow example, x is BufferVar.
x[0] = ...
directly emit a store to the IRBuilder,x[10]
translates to Load.# The following code generate IR for x[0] = x[ ib = tvm.ir_builder.create() x = ib.pointer("float32") x[0] = x[10] + 1
-
dtype
¶
-
-
class
IRBuilder
[source]¶ Bases:
object
Auxiliary builder to build IR for testing and dev.
Examples
ib = tvm.ir_builder.create() n = tvm.var("n") A = ib.allocate("float32", n, name="A") with ib.for_range(0, n, name="i") as i: with ib.if_scope((i % 2) == 0): A[i] = A[i] + 1 # The result stmt. stmt = ib.get()
-
buffer_ptr
(buf)[source]¶ Create pointer variable corresponds to buffer ptr.
- Parameters
buf (Buffer) – The buffer to be extracted.
- Returns
ptr – The buffer var representing the buffer.
- Return type
-
else_scope
()[source]¶ Create an else scope.
This can only be used right after an if scope.
- Returns
else_scope – The result else scope.
- Return type
Examples
ib = tvm.ir_builder.create() i = tvm.var("i") x = ib.pointer("float32") with ib.if_scope((i % 2) == 0): x[i] = x[i - 1] + 1 with ib.else_scope(): x[i] = x[i - 1] + 2
-
emit
(stmt)[source]¶ Emit a statement to the end of current scope.
- Parameters
stmt (Stmt or callable.) – The statement to be emitted or callable that build stmt given body.
-
for_range
(begin, end, name='i', dtype='int32', for_type='serial')[source]¶ Create a for iteration scope.
- Parameters
begin (Expr) – The min iteration scope.
end (Expr) – The end iteration scope
name (str, optional) – The name of iteration variable, if no input names, using typical index names i, j, k, then i_nidx
dtype (str, optional) – The data type of iteration variable.
for_type (str, optional) – The special tag on the for loop.
- Returns
loop_scope – The for scope, when enters returns loop_var
- Return type
With.Scope of Var
Examples
ib = tvm.ir_builder.create() x = ib.pointer("float32") with ib.for_range(1, 10, name="i") as i: x[i] = x[i - 1] + 1
-
if_scope
(cond)[source]¶ Create an if scope.
- Parameters
cond (Expr) – The condition.
- Returns
if_scope – The result if scope.
- Return type
Examples
ib = tvm.ir_builder.create() i = tvm.var("i") x = ib.pointer("float32") with ib.if_scope((i % 2) == 0): x[i] = x[i - 1] + 1
-
likely
(expr)[source]¶ Add likely tag for expression. :param expr: The expression. Usually a condition expression. :type expr: Expr
- Returns
expr – The expression will likely tag.
- Return type
-
new_scope
()[source]¶ Create new scope,
this is useful to set boundary of attr and allocate.
- Returns
new_scope – The result new scope.
- Return type
-