tvm.codegen#

Code generation related functions.

tvm.codegen.build_module(mod, target)#

Build IRModule into Module.

Parameters:
  • mod (tvm.IRModule) – The ir module.

  • target (str) – The target module type.

Returns:

module – The corresponding module.

Return type:

runtime.Module

tvm.codegen.target_has_features(cpu_features, target=None)#

Check CPU features for the target’s -mtriple and -mcpu and -mattr.

Parameters:
  • target (Target) – The TVM target.

  • cpu_features (str or Array) – CPU Feature(s) to check.

Returns:

has_features – True if target has the feature(s).

Return type:

bool

tvm.codegen.llvm_lookup_intrinsic_id(name)#

Lookup LLVM intrinsic id by name.

Parameters:

name (str) – The name of the intrinsic.

Returns:

intrin_id – The intrinsic id.

Return type:

int

tvm.codegen.llvm_get_intrinsic_name(intrin_id: int) → str#

Get the name of an intrinsic for a given id.

Parameters:

intrin_id (int) – The id of the intrinsic.

Returns:

name – The name of the intrinsic.

Return type:

str

tvm.codegen.llvm_get_system_x86_vendor()#

Get system x86 vendor info.

Returns:

vendor – The current system’s cpu vendor.

Return type:

str

tvm.codegen.llvm_get_system_triple()#

Get system host triple.

Returns:

triple – The current system’s triple.

Return type:

str

tvm.codegen.llvm_get_system_cpu()#

Get system host cpu name.

Returns:

cpu_name – The current system’s cpu name.

Return type:

str

tvm.codegen.llvm_get_targets()#

Get LLVM target list.

Returns:

llvm_targets – List of available LLVM targets.

Return type:

list[str]

tvm.codegen.llvm_get_cpu_archlist(target=None)#

Get CPU architectures for the target’s -mtriple.

Parameters:

target (Target) – The TVM target.

Returns:

cpu_archlist – List of available CPU architectures.

Return type:

list[str]

tvm.codegen.llvm_get_cpu_features(target=None)#

Get CPU features for the target’s -mtriple and -mcpu and considering -mattr.

Parameters:

target (Target) – The TVM target.

Returns:

cpu_features – List of available CPU features.

Return type:

list[str]

tvm.codegen.llvm_cpu_has_features(cpu_features, target=None)#

Check CPU features for the target’s -mtriple and -mcpu and considering -mattr.

Parameters:
  • target (Target) – The TVM target.

  • cpu_features (str or Array) – CPU Feature(s) to check.

Returns:

has_features – True if target CPU has the feature(s).

Return type:

bool

tvm.codegen.llvm_get_vector_width(target=None)#

Get vector width from LLVM target’s -mtriple and -mcpu and considering -mattr.

Parameters:

target (Target) – The TVM target.

Returns:

vector_width – Vector with of target in number of bits, -1 on error.

Return type:

int

tvm.codegen.llvm_is_valid_cpu(cpu, triple)#

Check if a CPU name is valid for the given LLVM triple.

Parameters:
  • cpu (str) – The CPU name to check (e.g. “apple-m1”).

  • triple (str) – The LLVM target triple (e.g. “arm64-apple-macos”).

Returns:

is_valid – True if the CPU name is recognized by LLVM for the given triple.

Return type:

bool

tvm.codegen.llvm_version_major(allow_none=False)#

Get the major LLVM version.

Parameters:

allow_none (bool) – Whether do we allow none.

Returns:

major – The major LLVM version.

Return type:

int