Target management API of TVM.

TVM’s target string is in fomat <target_name> [-option=value]....


The list of options include:

  • -device=<device name>

    The device name.

  • -mtriple=<target triple> or -target

    Specify the target triple, which is useful for cross compilation.

  • -mcpu=<cpuname>

    Specify a specific chip in the current architecture to generate code for. By default this is infered from the target triple and autodetected to the current architecture.

  • -mattr=a1,+a2,-a3,…

    Override or control specific attributes of the target, such as whether SIMD operations are enabled or not. The default set of attributes is set by the current CPU.

  • -system-lib

    Build TVM system library module. System lib is a global module that contains self registered functions in program startup. User can get the module using tvm.module.system_lib. It is useful in environments where dynamic loading api like dlopen is banned. The system lib will be available as long as the result code is linked by the program.

We can use to create a from the target string. We can also use other specific function in this module to create specific targets.

Wrap a target generic function.

Generic function allows registeration of further functions that can be dispatched on current target context. If no registered dispatch is matched, the fdefault will be called.

Parameters:fdefault (function) – The default function.
Returns:fgeneric – A wrapped generic function.
Return type:function


import tvm
# wrap function as target generic
def my_func(a):
    return a + 1
# register specialization of my_func under target cuda
def my_func_cuda(a):
    return a + 2
# displays 3, because my_func is called
# displays 4, because my_func_cuda is called
class, options=None)

Target device information, use through TVM API.

  • target_name ({"llvm", "cuda", "opencl", "metal", "rocm", "stackvm", "opengl", "ext_dev"}) – The major target name.
  • options (list of str, optional) – Additional arguments appended to the target.


Do not use class constructor, you can create target using the following functions

Returns a cuda target.

Parameters:options (list of str) – Additional options

Returns a ROCM target.

Parameters:options (list of str) – Additional options

Returns a rasp target.

Parameters:options (list of str) – Additional options

Get a target given target string.

Parameters:target_str (str) – The target string.
Returns:target – The target object
Return type:Target


See the note on on target string format.