Util

Utility functions for TVM dialects

lorien.dialect.tvm_dial.util.check_tvm_version(curr: str, min_req: str) bool

Check if the current TVM version satisfies the minimum requirement.

Parameters
  • curr (str) -- The current version.

  • min_req (str) -- The minimum requirement version.

Returns

check -- Return true if the current version satisfies the minimum requirement.

Return type

bool

lorien.dialect.tvm_dial.util.gen_target_id_keys(target: str) str

Generate a string that includes TVM target ID and keys.

Parameters

target (str) -- TVM target string.

Returns

target_id_keys -- A string including target ID and keys.

Return type

str

lorien.dialect.tvm_dial.util.get_canonical_tvm_target_str(target: Union[str, tvm.target.target.Target], task: Optional[tvm.autotvm.task.task.Task] = None, remove_libs: bool = False) str

Generate a canonical TVM target string. Note that we do not use the builtin string function in TVM target object because we need to sort all attributes and their values to guarantee the target strings from the functional equivalent targets are identical.

Parameters
  • target (Union[str, Target]) -- TVM target or target string.

  • task (Optional[Task]) -- The task of the given target. The canonical target depends on the required libraries of the task. If None, then no additional process will be applied to the target.

  • remove_libs (bool) -- Whether to remove the -libs in the target string.

Returns

ret -- Canonical TVM target string.

Return type

str

lorien.dialect.tvm_dial.util.get_tvm_build_config() Dict[str, str]

Get the TVM build config such as commit, LLVM and CUDA version.

Returns

tvm_config -- A dict of build config.

Return type

Dict[str, str]

lorien.dialect.tvm_dial.util.get_tvm_container_value_str(val: Any)

Get the primitive value in string from a TVM container.

Parameters

val (Any) -- The TVM container.

Returns

ret -- The container value in string.

Return type

str

lorien.dialect.tvm_dial.util.is_cover(target1: str, target2: str) bool

Check if target 1 covers target 2. We define target 1 covers target 2 if all specified attributes in target 1 are same as target 2.

Parameters
  • target1 (str) -- The TVM taret string.

  • target2 (str) -- The TVM taret string.

Returns

cover -- True if target 1 covers target 2.

Return type

bool

lorien.dialect.tvm_dial.util.prune_table(table_name: str, nbest: int = 3, **db_kwargs) None

Prune the best configs in a given table. Specifically, it scans a table, prune each item in the table and puts items back. See prune_items().

Parameters
  • table_name (str) -- The target table name to be pruned.

  • nbest (int) -- Keep the number of the most recent unique configs. Default 3.

  • **db_kwargs -- The kwargs of boto3 client. For example, use "endpoint_url=http://localhost:8000" for local DynamoDB.

lorien.dialect.tvm_dial.util.prune_table_item(item: Dict[str, Any], nbest: int = 3) Dict[str, Any]

Prune the best configs in a DynamoDB item by the following steps: 1. Group by TVM build config and keep the best one for each group. 2. Group by config and keep the most recent one for each group. 3. Prune the rest configs based on user-strategy.

Parameters
  • item (Dict[str, Any]) -- The item to be pruned.

  • nbest (int) -- Keep the number of the most recent unique configs. Default 3.

Returns

ret -- A pruned item.

Return type

Dict[str, Any]