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

Lowering step before build into target.

  • 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.

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

Return type:

LoweredFunc or Stmt, args=None, target=None, target_host=None, name='default_function', binds=None)

Build a function with arguments as signiture.

  • sch (tvm.Schedule, or LoweredFunc) – The schedule to be builded
  • args (list of Buffer or Tensor or Var, optional) – The argument lists to the function.
  • target (str or, optional) – The target and option of the compilation.
  • target_host (str or 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.

f – The result function.

Return type:

Function, or pair of functions


See the note on on target string format.


Configure the build behavior by setting config variables.

  • 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, default=False) –

config – The build configuration

Return type: