tvm.target

Target description and codegen module.

TVM uses JSON-based target configuration. Targets can be constructed via:

  • A config dictionary: Target({"kind": "cuda", "arch": "sm_80"})

  • A tag name: Target("nvidia/nvidia-a100")

  • A tag with overrides: Target({"tag": "nvidia/nvidia-a100", "l2_cache_size_bytes": 12345})

  • A kind name: Target("cuda")

Use target.attrs["key"] to access target attributes such as "arch", "max_num_threads", "mcpu", "libs", etc.

Use tvm.target.list_tags() to list all available target tags, and tvm.target.register_tag() to register new tags.

Classes:

Target(target[, host])

Target device information, use through TVM API.

TargetKind(*args, **kwargs)

Kind of a compilation target

VirtualDevice([device, target, memory_scope])

A compile time representation for where data is to be stored at runtime, and how to compile code to compute it.

Functions:

list_tags()

Returns a dict of tags, which maps each tag name to its corresponding target.

register_tag(name, config[, override])

Add a user-defined tag into the target tag registry.

class tvm.target.Target(target, host=None)

Target device information, use through TVM API.

Targets can be constructed from:

  • A JSON config dictionary: Target({"kind": "cuda", "arch": "sm_80"})

  • A tag name: Target("nvidia/nvidia-a100")

  • A tag with overrides: Target({"tag": "nvidia/nvidia-a100", "l2_cache_size_bytes": 12345})

  • A kind name: Target("cuda")

Use target.attrs["key"] to access target attributes.

Examples

# From a tag
target = Target("nvidia/nvidia-a100")

# From a tag with attribute overrides
target = Target({"tag": "qcom/hexagon-v68", "vtcm-capacity": 70000})

# From a config dictionary
target = Target({"kind": "cuda", "arch": "sm_80"})

Methods:

from_device(device)

Detects Target associated with the given device.

current([allow_none])

Returns the current target.

get_kind_attr(attr_name)

Get additional attribute about the target kind.

get_target_device_type()

Returns the device_type for this target.

list_kinds()

Returns the list of available target names.

target_or_current(target)

Returns target, or the current target in the environment if target is None

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.

Parameters:

dev (Union[str, Device]) – The device to detect the target for. Supported device types: [“cuda”, “metal”, “rocm”, “vulkan”, “opencl”, “cpu”]

Returns:

target – The detected target.

Return type:

Target

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.

get_kind_attr(attr_name)

Get additional attribute about the target kind.

Parameters:

attr_name (str) – The attribute name.

Returns:

value – The attribute value

Return type:

object

get_target_device_type()

Returns the device_type for this target.

static list_kinds()

Returns the list of available target names.

static target_or_current(target)

Returns target, or the current target in the environment if target is None

class tvm.target.TargetKind(*args: Any, **kwargs: Any)

Kind of a compilation target

Attributes:

options

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

static options_from_name(kind_name: str)

Returns the dict of available option names and types from a name of TargetKind

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.

Attributes:

device_type_int

The type of the virtual device.

memory_scope

The area of memory w.r.t.

target

The target describing how to compile for the virtual device.

virtual_device_id

The device id of the virtual device.

property device_type_int

The type of the virtual device.

property memory_scope

The area of memory w.r.t. the virtual device where data is stored.

property target

The target describing how to compile for the virtual device.

property virtual_device_id

The device id of the virtual device.

tvm.target.list_tags() dict[str, Target] | None

Returns a dict of tags, which maps each tag name to its corresponding target.

Returns:

tag_dict – The dict of tags mapping each tag name to its corresponding target. None if TVM is built in runtime-only mode.

Return type:

Optional[Dict[str, Target]]

tvm.target.register_tag(name: str, config: dict[str, Any], override: bool = False) Target | None

Add a user-defined tag into the target tag registry.

Parameters:
  • name (str) – Name of the target, e.g. “nvidia/gtx1080ti”

  • config (Dict[str, Any]) – The config dict used to create the target

  • override (bool) – A boolean flag indicating if overriding existing tags are allowed. If False and the tag has been registered already, an exception will be thrown.

Returns:

target – The target corresponding to the tag None if TVM is built in runtime-only mode.

Return type:

Optional[Target]

Examples

register_tag("nvidia/gtx1080ti", config={
    "kind": "cuda",
    "arch": "sm_61",
})