TileGym-CuTile自动调优Skill tilegym-cutile-autotuning

该技能用于 CuTile 内核的自动调优配置,主要涉及搜索空间设计、exhaustive_search 调用、缓存与直接启动模式、replace_hints 应用和 ct.launch 启动。通过决策树与内核类型模板,帮助针对计算密集、均衡或内存密集内核选择合适搜索维度(tile大小、occupancy、num_ctas),支持多架构(sm80-sm120)配置与调优流程,并总结了 7 个常见陷阱及解决方案。关键词:CuTile、自动调优、exhaustive_search、TileGym、内核优化、搜索空间、occupancy、num_ctas、ct.launch。

TileGym内核优化 0 次安装 0 次浏览 更新于 9/7/2026

CuTile 自动调优

使用 exhaustive_search API,并通过“一次性调优/缓存/直接启动”模式为 CuTile 内核添加自动调优功能。

说明

  1. 分类:使用决策树确定搜索维度(仅占用率或完整 tile 搜索)。
  2. 设计搜索空间:选择匹配模板,通过架构过滤器将配置控制在 ≤30 个。
  3. 实现:添加 exhaustive_search + 缓存 + ct.launch;原地操作使用拆分缓冲。
  4. 测试:验证自动调优开启及 DISABLE_AUTOTUNE=1 时的正确性。
  5. 验证:与固定最佳配置进行 A/B 对比。
  6. 缩减:剪枝无效配置,目标每架构 ≤8 个。

快速参考(仅占用率)

from types import SimpleNamespace
from cuda.tile.tune import exhaustive_search
import cuda.tile as ct

def _my_autotune_configs():
    for occ in [1, 2, 4, 8]:
        yield SimpleNamespace(occupancy=occ)

_autotune_cache = {}

def my_op(x, output):
    stream = torch.cuda.current_stream()
    NUM_SM = torch.cuda.get_device_properties(x.device).multi_processor_count
    cache_key = (x.shape, x.dtype, str(x.device))
    if cache_key not in _autotune_cache:
        configs = list(_my_autotune_configs())
        result = exhaustive_search(
            configs, stream,
            grid_fn=lambda cfg: (min(NUM_SM * cfg.occupancy, M), 1, 1),
            kernel=my_kernel,
            args_fn=lambda cfg: (x, output),
            hints_fn=lambda cfg: {"occupancy": cfg.occupancy},
        )
        best_cfg = result.best.config
        tuned_kernel = my_kernel.replace_hints(occupancy=best_cfg.occupancy)
        _autotune_cache[cache_key] = (best_cfg, tuned_kernel)
    cfg, tuned_kernel = _autotune_cache[cache_key]
    grid = (min(NUM_SM * cfg.occupancy, M), 1, 1)
    ct.launch(stream, grid, tuned_kernel, (x, output))

关键规则:缓存配置与内核对象;原地内核使用拆分缓冲;exhaustive_search 需要 Sequence;搜索空间必须包含原始固定配置。

决策树

  • 计算密集型且有多个可调维度 → 完整搜索(TILE_M × TILE_N × TILE_K × occupancy × num_ctas
  • 双 GEMM 融合 → 低占用率 1–2,保守 tile
  • 均衡型 / 内存密集型 → 仅占用率搜索 [1,2,4,8]

常见陷阱

  1. 原地内核未使用拆分缓冲导致数据损坏
  2. 自动调优编译超时(配置过多)
  3. 冷缓存导致性能偏差
  4. NCU 性能分析干扰调优
  5. search_space 生成器耗尽
  6. FP8 精度损失
  7. 热路径上重复 replace_hints 导致重编译

参考文档

  • API 参考、工作流、陷阱、参数设计、搜索策略、模板、硬件约束等详细内容见 references/ 目录。

范围

仅涵盖自动调优配置(搜索空间、exhaustive_search、缓存、ct.launchDISABLE_AUTOTUNE 回退),不修改内核代码、数学标志、性能提示、内存访问模式、代码生成或算法。