autotuning
Module
Implements the autotune functionality.
You can import these APIs from the autotune
package. For example:
from autotune import search
autotune
autotune[T: AnyType, *Ts: AnyType](value: T, values: !pop.pack<Ts>) -> T
Forks compilation to evaluate each of the provided values.
Parameters:
- T (
AnyType
): The first value type. - Ts (
*AnyType
): The types of the rest of the parameters.
Args:
- value (
T
): The first value in the pack. - values (
!pop.pack<Ts>
): The tail values.
Returns:
The value being used in the current compilation fork.
autotune_fork
autotune_fork[type: AnyType, *values: *"type"]()
Forks compilation to evaluate each of the provided values.
Return parameters: out: The value being used in the current compilation fork.
Parameters:
- type (
AnyType
): The type of the parameters to be evaluated. - values (
**"type"
): A list of parameters to be evaluated.
search
search[fn_type: AnyType, candidates: VariadicList[fn_type], evaluator: fn(Pointer[fn_type], Int) -> Int]()
Finds the best implementation among all candidates.
The function runs the search among the list of candidates using the provided evaluator. The evaluator function needs to take two inputs: a pointer to array of all candidates and the size of that array - and return an index of the best candidate.
Return parameters: The best found candidate.
Parameters:
- fn_type (
AnyType
): The signature type of the function. - candidates (
VariadicList[fn_type]
): A list of candidates to search from. - evaluator (
fn(Pointer[fn_type], Int) -> Int
): The evaluator function.
cost_of
cost_of[fn_type: AnyType, func: fn_type]() -> Int
Count the number of operations in a function.
This function takes a function reference and estimates the ācostā of invoking the function by counting the number of MLIR operations in the function after elaboration.
FIXME: This function should be marked @consteval
or equivalent to prevent dynamic instantiation of kgen.cost_of
.
Parameters:
- fn_type (
AnyType
): The signature type of the function. - func (
fn_type
): The function to evaluate.
Returns:
The number of post-elaboration operations in the function.