tvm.build

tvm.lower(sch, args, name='default_function', binds=None, simple_mode=False)

Lowering step before build into target.

Parameters:
  • sch (tvm.Schedule) – The schedule to be builded
  • args (list of Buffer or Tensor or Var) – The argument lists to the function.
  • name (str, optional) – The name of result function.
  • binds (dict of Tensor to Buffer, optional) – Dictionary that maps the Tensor to Buffer which specified the data layout requirement of the function. By default, a new compact buffer is created for each tensor in the argument.
  • simple_mode (bool, optional) – Whether only output simple and compact statement, this will skip LoopPartition, api wrapper generation and Unrolling.
Returns:

f – The result function, if with_api_wrapper=False Then the Stmt before make api is returned.

Return type:

LoweredFunc or Stmt

tvm.build(inputs, args=None, target=None, target_host=None, name='default_function', binds=None)

Build a function with arguments as signature. Code will be generated for devices coupled with target information.

Parameters:
  • inputs (tvm.Schedule, LoweredFunc, or dict of target to LoweredFunc list) – The schedule to be built
  • args (list of Buffer or Tensor or Var, optional) – The argument lists to the function.
  • target (str or tvm.target.Target, optional) – The target and option of the compilation.
  • target_host (str or tvm.target.Target optional) – Host compilation target, if target is device. When TVM compiles device specific program such as CUDA, we also need host(CPU) side code to interact with the driver setup the dimensions and parameters correctly. target_host is used to specify the host side codegen target. By default, llvm is used if it is enabled, otherwise a stackvm intepreter is used.
  • name (str, optional) – The name of result function.
  • binds (dict, optional) – Dictionary that maps the binding of symbolic buffer to Tensor. By default, a new buffer is created for each tensor in the argument.
Returns:

ret – A module that combines both host and device code.

Return type:

tvm.module

Examples

There are two typical example uses of this function depending on the type of the argument inputs: 1. it is a list of lowered functions:

n = 2
A = tvm.placeholder((n,), name='A')
B = tvm.placeholder((n,), name='B')
C = tvm.compute(A.shape, lambda *i: A(*i) + B(*i), name='C')
s = tvm.create_schedule(C.op)
f = tvm.lower(s, [A, B, C], name="test_add")
m = tvm.build(f, target="llvm")
  1. it is a dict of compilation target to list of lowered functions:
n = 2
A = tvm.placeholder((n,), name='A')
B = tvm.placeholder((n,), name='B')
C = tvm.compute(A.shape, lambda *i: A(*i) + B(*i), name='C')
s1 = tvm.create_schedule(C.op)
s2 = topi.cpp.cuda.schedule_injective("cuda", [C])
f1 = tvm.lower(s1, [A, B, C], name="test_add1")
f2 = tvm.lower(s2, [A, B, C], name="test_add2")
m = tvm.build({"llvm": [f1], "cuda": [f2]}, target_host="llvm")

Note

See the note on tvm.target on target string format.

tvm.build_config(**kwargs)

Configure the build behavior by setting config variables.

Parameters:
  • auto_unroll_max_step (int, default=0) – Threshold of number of steps in the loop to be automatically unrolled. This takes inner loop count into consideration.
  • auto_unroll_max_depth (int, default=8) – The maximum nested level of loops that can be automatically unrolled.
  • unroll_explicit (bool, default=True) – Whether explicitly unroll the loop, if set false, the unroll hint will be passed to the CodeGen phase, which may generate pragma unroll hint. Set this to be true if CodeGen support unroll pragma and when we want to be more readable.
  • detect_global_barrier (bool, default=True) – Whether detect global barrier.
  • partition_const_loop (bool, default=False) – Whether partition const loop
  • data_alignment (int, optional) – The alignment of data pointer in bytes. If -1 is passed, the alignment will be set to TVM’s internal default.
  • offset_factor (int, default=0) – The factor used in default buffer declaration. If specified as 0, offset field is not used.
  • restricted_func (bool, default=True) – Whether build restricted function. That is each buffer argument to the function are guaranteed not to overlap. This enables more optimization. Corresponds to restricted keyword in C99
  • double_buffer_split_loop (int, default=2) – Whether split the loop with factor. If it is zero, no splitting will happen. It it is bigger than one, the logic will do a split with factor equals the integer and unroll the inner loop. This allows the buffer fetching won’t contain condition.
  • add_lower_pass (list of tuple (phase, function(Stmt->Stmt)), default=None) – phase contains an integer on which optimization pass we apply the pass. Additional lowering passes to be applied before make_api.
  • dump_pass_ir (dump ir of each pass into file idx_passname_ir.cc, default=False) –
Returns:

config – The build configuration

Return type:

BuildConfig