|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | +from typing import Literal |
| 5 | + |
| 6 | +AutotuneEffort = Literal["none", "quick", "full"] |
| 7 | + |
| 8 | + |
| 9 | +@dataclass(frozen=True) |
| 10 | +class PatternSearchConfig: |
| 11 | + initial_population: int |
| 12 | + copies: int |
| 13 | + max_generations: int |
| 14 | + |
| 15 | + |
| 16 | +@dataclass(frozen=True) |
| 17 | +class DifferentialEvolutionConfig: |
| 18 | + population_size: int |
| 19 | + max_generations: int |
| 20 | + |
| 21 | + |
| 22 | +@dataclass(frozen=True) |
| 23 | +class RandomSearchConfig: |
| 24 | + count: int |
| 25 | + |
| 26 | + |
| 27 | +# Default values for each algorithm (single source of truth) |
| 28 | +PATTERN_SEARCH_DEFAULTS = PatternSearchConfig( |
| 29 | + initial_population=100, |
| 30 | + copies=5, |
| 31 | + max_generations=20, |
| 32 | +) |
| 33 | + |
| 34 | +DIFFERENTIAL_EVOLUTION_DEFAULTS = DifferentialEvolutionConfig( |
| 35 | + population_size=40, |
| 36 | + max_generations=40, |
| 37 | +) |
| 38 | + |
| 39 | +RANDOM_SEARCH_DEFAULTS = RandomSearchConfig( |
| 40 | + count=1000, |
| 41 | +) |
| 42 | + |
| 43 | + |
| 44 | +@dataclass(frozen=True) |
| 45 | +class AutotuneEffortProfile: |
| 46 | + pattern_search: PatternSearchConfig | None |
| 47 | + differential_evolution: DifferentialEvolutionConfig | None |
| 48 | + random_search: RandomSearchConfig | None |
| 49 | + rebenchmark_threshold: float = 1.5 |
| 50 | + |
| 51 | + |
| 52 | +_PROFILES: dict[AutotuneEffort, AutotuneEffortProfile] = { |
| 53 | + "none": AutotuneEffortProfile( |
| 54 | + pattern_search=None, |
| 55 | + differential_evolution=None, |
| 56 | + random_search=None, |
| 57 | + ), |
| 58 | + "quick": AutotuneEffortProfile( |
| 59 | + pattern_search=PatternSearchConfig( |
| 60 | + initial_population=30, |
| 61 | + copies=2, |
| 62 | + max_generations=5, |
| 63 | + ), |
| 64 | + differential_evolution=DifferentialEvolutionConfig( |
| 65 | + population_size=20, |
| 66 | + max_generations=8, |
| 67 | + ), |
| 68 | + random_search=RandomSearchConfig( |
| 69 | + count=100, |
| 70 | + ), |
| 71 | + rebenchmark_threshold=0.9, # <1.0 effectively disables rebenchmarking |
| 72 | + ), |
| 73 | + "full": AutotuneEffortProfile( |
| 74 | + pattern_search=PATTERN_SEARCH_DEFAULTS, |
| 75 | + differential_evolution=DIFFERENTIAL_EVOLUTION_DEFAULTS, |
| 76 | + random_search=RANDOM_SEARCH_DEFAULTS, |
| 77 | + ), |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +def get_effort_profile(effort: AutotuneEffort) -> AutotuneEffortProfile: |
| 82 | + return _PROFILES[effort] |
0 commit comments