tvm.target¶
Target description and codgen module.
TVM’s target string is in format <target_kind> [-option=value]...
.
Note
The list of options include:
-device=<device name>
The device name.
-mtriple=<target triple>
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.
-mabi=<abi>
Generate code for the specified ABI, for example “lp64d”.
-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.runtime.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 tvm.target.Target()
to create a tvm.target.Target from the target string.
We can also use other specific function in this module to create specific targets.
Classes:
|
Target device information, use through TVM API. |
GenericFunc node reference. |
Functions:
|
Deprecated. |
|
Returns a cuda target. |
|
Returns a ROCM target. |
|
Returns a ARM Mali GPU target. |
|
Returns an Intel Graphics target. |
|
Returns a ARM CPU target. |
|
Return a Raspberry 3b target. |
|
Return an ARM Mali GPU target (Bifrost architecture). |
|
Returns a RISC-V CPU target. |
|
Returns a Hexagon target. |
|
Returns a CompilationConfig appropriate for targets and an optional host_target. |
Returns a dict of tags, which maps each tag name to its corresponding target. |
|
|
Wrap a target generic function. |
|
Get a generic function from the global registry. |
|
Override a generic function defined in C++ |
- class tvm.target.Target(target, host=None)¶
Target device information, use through TVM API.
Note
You can create target using the constructor or the following functions
tvm.target.arm_cpu()
create arm_cpu targettvm.target.cuda()
create CUDA targettvm.target.rocm()
create ROCM targettvm.target.mali()
create Mali targettvm.target.intel_graphics()
create Intel Graphics target
Methods:
current
([allow_none])Returns the current target.
Returns the list of available target names.
check_and_update_host_consist
(target[, ...])A helper function that merges a legacy "target, target_host" pair, then returns the merged target and its host field.
Attributes:
Returns model from the target if it exists.
Returns the mcpu from the target if it exists.
Returns the mattr from the target if it exists.
- static current(allow_none=True)¶
Returns the current target.
- Parameters
allow_none (bool) – Whether allow the current target to be none
- Raises
ValueError if current target is not set. –
- property model¶
Returns model from the target if it exists.
- property mcpu¶
Returns the mcpu from the target if it exists.
- property mattr¶
Returns the mattr from the target if it exists.
- static list_kinds()¶
Returns the list of available target names.
- static check_and_update_host_consist(target, host=None, target_is_dict_key=True)¶
A helper function that merges a legacy “target, target_host” pair, then returns the merged target and its host field. The function is for legacy target and target host pair only, and should not be used in the new target system.
- tvm.target.create(target)¶
Deprecated. Use the constructor of
tvm.target.Target
directly.
- tvm.target.cuda(model='unknown', options=None)¶
Returns a cuda target.
- tvm.target.rocm(model='unknown', options=None)¶
Returns a ROCM target.
- tvm.target.mali(model='unknown', options=None)¶
Returns a ARM Mali GPU target.
- tvm.target.intel_graphics(model='unknown', options=None)¶
Returns an Intel Graphics target.
- tvm.target.arm_cpu(model='unknown', options=None)¶
Returns a ARM CPU target. This function will also download pre-tuned op parameters when there is none.
- tvm.target.rasp(options=None)¶
Return a Raspberry 3b target.
- Parameters
options (str or list of str) – Additional options
- tvm.target.bifrost(model='unknown', options=None)¶
Return an ARM Mali GPU target (Bifrost architecture).
- Parameters
options (str or list of str) – Additional options
- tvm.target.riscv_cpu(model='sifive-u54', options=None)¶
Returns a RISC-V CPU target. Default: sifive-u54 rv64gc
- tvm.target.hexagon(cpu_ver='v66', **kwargs)¶
Returns a Hexagon target.
- Parameters
cpu_ver (str (default: "v66")) – CPU version used for code generation. Not all allowed cpu str will be valid, LLVM will throw an error.
parameters (Recognized keyword) –
----------------------------- –
hvx (int (default: 128)) – Size of HVX vector in bytes. Value of 0 disables HVX codegen.
sim_options (str or list of str (default: None)) – User defined sim arguments. CPU version defaults to cpu_ver. Otherwise, separate versions are used for codegen and sim. Not all allowed cpu strings will be valid, simulator will throw an error if invalid. Does not affect codegen.
llvm_options (str or list of str (default: None)) – User defined compiler arguments.
link_params (bool (default: False)) – Whether to link graph parameters into the LLVM module.
- tvm.target.make_compilation_config(ctxt, targets, host_target=None)¶
Returns a CompilationConfig appropriate for targets and an optional host_target. Currently intended just for unit tests and will be replaced by a Python CompilationConfig class in the future. Note that targets must be a dictionary from IntImm objects to Targets and we do not support any of the lighter-weight conventions used by the various build(…) APIs.
- tvm.target.list_tags() Optional[Dict[str, tvm.target.target.Target]] ¶
Returns a dict of tags, which maps each tag name to its corresponding target.
- class tvm.target.GenericFunc¶
GenericFunc node reference. This represents a generic function that may be specialized for different targets. When this object is called, a specialization is chosen based on the current target.
Note
Do not construct an instance of this object, it should only ever be used as a return value from calling into C++.
Methods:
set_default
(func[, allow_override])Set the default function to be used if no specializations match the current target.
register
(func, key_list[, allow_override])Register a specialization for this GenericFunc.
- tvm.target.generic_func(fdefault)¶
Wrap a target generic function.
Generic function allows registration 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
Example
import tvm # wrap function as target generic @tvm.target.generic_func def my_func(a): return a + 1 # register specialization of my_func under target cuda @my_func.register("cuda") def my_func_cuda(a): return a + 2 # displays 3, because my_func is called print(my_func(2)) # displays 4, because my_func_cuda is called with tvm.target.cuda(): print(my_func(2))
- tvm.target.get_native_generic_func(name)¶
Get a generic function from the global registry. If no function is registered under the given name, a new generic function is created.
- Parameters
name (string) – The name of the generic function to get
- Returns
func – The generic function for the given name
- Return type
- tvm.target.override_native_generic_func(func_name)¶
Override a generic function defined in C++
Generic function allows registration of further functions that can be dispatched on current target context. If no registered dispatch is matched, the fdefault will be called.
- Parameters
func_name (string) – The name of the generic func to be overridden
- Returns
fgeneric – A wrapped generic function.
- Return type
function
Example
import tvm # wrap function as target generic @tvm.target.override_native_generic_func("my_func") def my_func(a): return a + 1 # register specialization of my_func under target cuda @my_func.register("cuda") def my_func_cuda(a): return a + 2 # displays 3, because my_func is called print(my_func(2)) # displays 4, because my_func_cuda is called with tvm.target.cuda(): print(my_func(2))