hidet.utils¶
Functions:
|
example: factor(12) => [1, 2, 3, 4, 6, 12] |
|
Decorate an initialization function. |
|
Get the greatest common divisor of non-negative integers a and b. |
|
Get the least common multiple of non-negative integers a and b. |
|
Given two tensors with the same shape and data type, this function finds the minimal e, such that |
|
Benchmark given function. |
Classes:
Directed graph. |
- hidet.utils.initialize(*args, **kwargs)[source]¶
Decorate an initialization function. After decorating with this function, the initialization function will be called after the definition.
- Parameters:
args – The positional arguments of initializing.
kwargs – The keyword arguments of initializing.
- Returns:
A decorator that will call given function with args and kwargs, and return None (to prevent this function to be called again).
- Return type:
ret
- hidet.utils.gcd(a, b)[source]¶
Get the greatest common divisor of non-negative integers a and b.
- Parameters:
a (int) – The lhs operand.
b (int) – The rhs operand.
- Returns:
ret – The greatest common divisor.
- Return type:
int
- hidet.utils.lcm(a, b)[source]¶
Get the least common multiple of non-negative integers a and b. :param a: The lhs operand. :type a: int :param b: The rhs operand. :type b: int
- Returns:
ret – The least common multiple.
- Return type:
int
- Parameters:
a (int) –
b (int) –
- hidet.utils.error_tolerance(a, b)[source]¶
Given two tensors with the same shape and data type, this function finds the minimal e, such that
abs(a - b) <= abs(b) * e + e
- Parameters:
a (Union[np.ndarray, hidet.Tensor]) – The first tensor.
b (Union[np.ndarray, hidet.Tensor]) – The second tensor.
- Returns:
ret – The error tolerance between a and b.
- Return type:
float
- hidet.utils.benchmark_func(run_func, warmup=1, number=5, repeat=5, median=True)[source]¶
Benchmark given function.
The given function
run_func
will be executed \(warmup + repeat * number\) times. Each \(number\) times of execution will be grouped and conducted together.- Parameters:
run_func (Callable[[], Any]) – Any callable function to be benchmarked.
warmup (int) – The number of warm-up executions.
number (int) – The number of executions to be grouped for measurement.
repeat (int) – The number of repeat times of the group measurement.
median (bool) – Whether the median latency is returned, instead of the latency.
- Returns:
ret –
When median == True, a single latency number is returned.
When median == False, the latency of each repeat is returned, as a list of floats.
- Return type:
Union[float, List[float]]
- class hidet.utils.DirectedGraph[source]¶
Directed graph.
A directed graph representation.
Methods:
from_edges
(edges)Create a directed graph from edges.
has_node
(node)Whether the node has been added to the graph.
has_edge
(src, dst)Whether there is an edge (src, dst) in the graph.
add_node
(node)Add a node.
add_edge
(src, dst)Add an edge.
Get a topological order of the nodes in the directed graph.
- static from_edges(edges)[source]¶
Create a directed graph from edges.
The edges should be a list of (src, dst) tuples, and each tuple represents an edge.
- Parameters:
edges (List[Tuple[GraphNode, GraphNode]]) – The edges of the directed graph to be created.
- Returns:
ret – The created directed graph.
- Return type:
- has_node(node)[source]¶
Whether the node has been added to the graph.
- Parameters:
node (GraphNode) – The node to be checked.
- Returns:
ret – True if the node has been added.
- Return type:
bool
- has_edge(src, dst)[source]¶
Whether there is an edge (src, dst) in the graph.
- Parameters:
src (GraphNode) – The source node of the edge.
dst (GraphNode) – The destination node of the edge.
- Returns:
ret – True if the edge (src, dst) is in the graph.
- Return type:
bool
- add_node(node)[source]¶
Add a node.
- Parameters:
node (GraphNode) – The node to be added to the graph.