tvm.target#
Target description and codgen module.
TVM's target string is in format <target_kind> [-option=value]...
.
备注
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:
GenericFunc node reference. |
|
|
Target device information, use through TVM API. |
Kind of a compilation target |
|
|
A compile time representation for where data is to be stored at runtime, and how to compile code to compute it. |
Functions:
|
Returns a ARM CPU target. |
|
Return an ARM Mali GPU target (Bifrost architecture). |
|
Deprecated. |
|
Returns a cuda target. |
|
Wrap a target generic function. |
|
Get a generic function from the global registry. |
|
Returns a Hexagon target. |
|
Returns an Intel Graphics target. |
Returns a dict of tags, which maps each tag name to its corresponding target. |
|
|
Returns a CompilationConfig appropriate for target and target_host, using the same representation conventions as for the standard build interfaces. |
|
Returns a ARM Mali GPU target. |
|
Override a generic function defined in C++ |
|
Return a Raspberry 3b target. |
|
Returns a RISC-V CPU target. |
|
Returns a ROCM target. |
|
Returns a STM32 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.
备注
Do not construct an instance of this object, it should only ever be used as a return value from calling into C++.
Methods:
Get the packed function specified for the current target.
register
(func, key_list[, allow_override])Register a specialization for this GenericFunc.
set_default
(func[, allow_override])Set the default function to be used if no specializations match the current target.
- get_packed_func()[源代码]#
Get the packed function specified for the current target.
- 返回:
func -- The function specified for the current target. Return the default function if no specializations match the current target.
- 返回类型:
PackedFunc
- class tvm.target.Target(target, host=None)[源代码]#
Target device information, use through TVM API.
备注
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
Attributes:
Returns the cuda arch from the target if it exists.
Returns the mattr from the target if it exists.
Returns the max block size in x-dimension from the target if it exists.
Returns the max block size in y-dimension from the target if it exists.
Returns the max_num_threads from the target if it exists.
Returns the mcpu from the target if it exists.
Returns model from the target if it exists.
Returns the thread_warp_size from the target if it exists.
Methods:
canon_multi_target
(multi_targets)Given a single target-like object, or a collection-like object of target-like objects, returns a TVM Array of TVM Target objects representing then.
canon_multi_target_and_host
(target[, ...])Returns a TVM Array<Target> capturing target and target_host.
canon_target
(target)Given a single target-like object, returns the TVM Target object representing it.
canon_target_and_host
(target[, target_host])Returns a TVM Target capturing target and target_host.
canon_target_map_and_host
(target_map[, ...])Returns target_map as a map from TVM Target's in canonical form to IRModules.
current
([allow_none])Returns the current target.
from_device
(device)Detects Target associated with the given device.
get_kind_attr
(attr_name)Get additional attribute about the target kind.
Returns the device_type for this target.
Returns the list of available target names.
target_or_current
(target)Returns target, or the current target in the environment if target is None
- property arch#
Returns the cuda arch from the target if it exists.
- static canon_multi_target(multi_targets)[源代码]#
Given a single target-like object, or a collection-like object of target-like objects, returns a TVM Array of TVM Target objects representing then. Can convert from: - None (to None). - A single target-like object in a form recognized by canon_target. - A Python list or TVM Array of target-like objects in a form recognized by canon_target. - A Python dict or TVM Map from TVM IntImm objects representing device types to a target-like object in a form recognized by canon_target. (This is a legacy method to represent heterogeneous targets. The keys are ignored.)
- static canon_multi_target_and_host(target, target_host=None)[源代码]#
Returns a TVM Array<Target> capturing target and target_host. The given target can be in any form recognized by Target.canon_multi_target. If given, target_host can be in any form recognized by Target.canon_target. If target_host is given it will be set as the 'host' in each result Target object (and a warning given).
- static canon_target(target)[源代码]#
Given a single target-like object, returns the TVM Target object representing it. Can convert from: - None (to None). - An existing TVM Target object. - A string, eg "cuda" or "cuda -arch=sm_80" - A Python dictionary, eg {"kind": "cuda", "arch": "sm_80" }
- static canon_target_and_host(target, target_host=None)[源代码]#
Returns a TVM Target capturing target and target_host. Also returns the host in canonical form. The given target can be in any form recognized by Target.canon_target. If given, target_host can be in any form recognized by Target.canon_target. If target_host is given it will be set as the 'host' in the result Target object (and a warning given).
Note that this method does not support heterogeneous compilation targets.
- static canon_target_map_and_host(target_map, target_host=None)[源代码]#
Returns target_map as a map from TVM Target's in canonical form to IRModules. The keys of the input target_map can be in any form recognized by Target.canon_target. Similarly, if given, target_host can be in any form recognized by Target.canon_target. The final target_map keys will capture the target_host in canonical form. Also returns the target_host in canonical form.
- static current(allow_none=True)[源代码]#
Returns the current target.
- 参数:
allow_none (bool) -- Whether allow the current target to be none
- 抛出:
ValueError if current target is not set. --
- static from_device(device: str | Device) Target [源代码]#
Detects Target associated with the given device. If the device does not exist, there will be an Error.
- property mattr#
Returns the mattr from the target if it exists.
- property max_block_size_x#
Returns the max block size in x-dimension from the target if it exists.
- property max_block_size_y#
Returns the max block size in y-dimension from the target if it exists.
- property max_num_threads#
Returns the max_num_threads from the target if it exists.
- property mcpu#
Returns the mcpu from the target if it exists.
- property model#
Returns model from the target if it exists.
- static target_or_current(target)[源代码]#
Returns target, or the current target in the environment if target is None
- property thread_warp_size#
Returns the thread_warp_size from the target if it exists.
- class tvm.target.TargetKind[源代码]#
Kind of a compilation target
Attributes:
Returns the dict of available option names and types
Methods:
options_from_name
(kind_name)Returns the dict of available option names and types from a name of TargetKind
- property options#
Returns the dict of available option names and types
- class tvm.target.VirtualDevice(device=None, target=None, memory_scope='')[源代码]#
A compile time representation for where data is to be stored at runtime, and how to compile code to compute it.
- 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.bifrost(model='unknown', options=None)[源代码]#
Return an ARM Mali GPU target (Bifrost architecture).
- tvm.target.create(target)[源代码]#
Deprecated. Use the constructor of
tvm.target.Target
directly.
- 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.
- 参数:
fdefault (function) -- The default function.
- 返回:
fgeneric -- A wrapped generic function.
- 返回类型:
function
示例
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.
- 参数:
name (string) -- The name of the generic function to get
- 返回:
func -- The generic function for the given name
- 返回类型:
- tvm.target.hexagon(cpu_ver='v68', **kwargs)[源代码]#
Returns a Hexagon target.
- 参数:
cpu_ver (str (default: "v68")) -- 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.
llvm_options (str or list of str (default: None)) -- User defined compiler arguments.
use_qfloat (bool (default: True for cpu_ver >= v68, False otherwise)) -- Whether to use QFloat HVX instructions.
use_ieee_fp (bool (default: False)) -- Whether to use IEEE HVX instructions
num_cores (int (default: 4)) -- The number of HVX threads. This attribute is required by meta scheduler.
vtcm_capacity (int (default: 0)) -- Hexagon VTCM capacity limitation. If the value is 0, the capacity is treated as unbounded.
Note (Floating point support in HVX requires LLVM 14+.)
- tvm.target.list_tags() Dict[str, Target] | None [源代码]#
Returns a dict of tags, which maps each tag name to its corresponding target.
- tvm.target.make_compilation_config(ctxt, target, target_host=None)[源代码]#
Returns a CompilationConfig appropriate for target and target_host, using the same representation conventions as for the standard build interfaces. Intended only for unit testing.
- 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.
- 参数:
func_name (string) -- The name of the generic func to be overridden
- 返回:
fgeneric -- A wrapped generic function.
- 返回类型:
function
示例
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))
- tvm.target.riscv_cpu(model='sifive-u54', options=None)[源代码]#
Returns a RISC-V CPU target. Default: sifive-u54 rv64gc