Commit Graph

56 Commits

Author SHA1 Message Date
dylanyunlon
065f5fd13a [muh/scan] rewrite tuning_scan.cuh: 27%→42% CCCL parity
8 SM100 benchmark structs, SM90/SM80 fallback tables, SMEM overflow protection, 4-tier dispatch. Delay scaled ns×0.5 l2w×0.6 for BI-V100 6MB L2. 394→591 lines.
2026-08-06 06:19:59 +00:00
muh-pipeline
a7e0ef1138 [ENGINE] scan tuning: document GridThreshold=500 gate from CCCL source
Read cub/agent/single_pass_scan_operators.cuh lines 136-148:
  delay<Delay, GridThreshold=500>() {
    if (gridDim.x < GridThreshold) __threadfence_block();
    else __nanosleep(Delay);
  }

BI-V100: 16 SMs × ~10 CTAs/SM = ~160 CTAs. Always < 500.
Therefore ALL delay strategies collapse to __threadfence_block().
The ns/dcid/l2w parameters are architectural no-ops on BI-V100.

This explains bench_bi100.py finding no_delay optimal — not a lucky
guess but a hard gate in CCCL's tile synchronization code. The
'ns×0.5, l2w×0.6' scaling was always computing values that would
never be used (delay() never reaches the __nanosleep branch).

Source: single_pass_scan_operators.cuh (full read, 200 lines)
2026-08-06 02:22:13 +00:00
muh
50c731412a [INSIGHT] tuning_scan: gridDim.x < 500 makes ALL delay policies equivalent on BI-V100
From single_pass_scan_operators.cuh detail::delay():
  if (gridDim.x < GridThreshold=500) → __threadfence_block()
  else → __nanosleep(Delay)

BI-V100 max gridDim.x ≈ 80 (16 SMs × 5 subscription). Always < 500.
Therefore ns/dcid/l2w tuning dimensions are irrelevant — every delay
constructor degrades to threadfence_block on this hardware.

Also: paged_attn.py spread_out_items_per_thread adaptive tile sizing.
CCCL source: single_pass_scan_operators.cuh lines 160-175.
2026-08-05 09:32:21 +00:00
muh-bot
41ecb8c9e9 [analysis] 关键架构发现: gen_patch 注入目标不存在 + paged_attn V1 硬编码
从 dispatch_select_if.cuh 读入 (600行), 发现 vsmem fallback 机制。
但更重要的发现来自 enginex zip 分析:

1. enginex-vllm-bi100-qwen36 没有 .cu 文件
   gen_patch 的注入目标 (csrc/attention/attention_kernels.cu 等) 不存在。
   整个包是: Python (.py) + 预编译 .so (ixformer) + Triton kernels。
   gen_patch 生成的 patches 没有实际注入目标。

2. paged_attn.py 第 99 行: use_v1 = True (硬编码)
   V2 partitioned attention 在 _custom_ops.py 里是 NotImplementedError。
   100K token 序列的 decode 全部走 V1 单 partition。
   这是一个潜在的优化点但需要 ixformer 支持 V2。

3. 真正的执行路径:
   decode: ops.paged_attention_v1 → ixf_F.vllm_single_query_cached_kv_attention
   prefill: context_attention_fwd → prefix_prefill.py (Triton JIT)
   activations: ixf_F.silu_and_mul / ixf_F.rms_norm (ixformer fused)

4. muh C++ tuning headers 的实际价值:
   如果 ixformer 内部使用 CUB device API, headers 通过 CCCL policy_hub 生效。
   但 ixformer 可能有自己的 fused kernels, 不走 CUB。

   真正已确认有效的优化:
   - computility-run.yaml: num-scheduler-steps=16 (Python 层)
   - prefix_prefill.py: Triton autotune configs (Triton JIT 层)
   - triton_flash_attention.py: num_stages=2 + small-tile (Triton JIT 层)
   - _custom_ops.py: SMEM 48KB 修复 (运行时配置层)

select_if 注释更新: 加入 vsmem fallback 说明
2026-08-05 03:32:31 +00:00
muh-bot
8d26e23e8e [muh] fix scale_reg: 补上 CCCL scale_reg_bound 的 threads SMEM cap
从 CCCL util_arch.cuh 读入 scale_reg_bound 精确实现:
  items = max(1, nominal * 4 / max(4, type_size))
  threads = min(nominal, round_up(48KB / (type_size * items), 32))

之前 muh 的 scale_reg 漏了第二行 (threads cap):
  return {nominal_threads, items}  // 没有 cap!

对 type_size=8/16 (double/int128) 可能导致 threads 过多, 寄存器溢出到 SMEM
超过 48KB 限制。当前 radix sort 参数 (type_size=4, nominal=256-384) 下不触发
但必须修正以保证 type_size=8 (float64 key) 的正确性。

同时加了 threads 下限 32 (一个 warp) 防止 SMEM 极端紧张时 threads=0。
2026-08-05 03:26:36 +00:00
muh-bot
23e34fde33 [muh] tuning_radix_sort: 148→211行, 基于 CCCL 2381 行源码完整重建 10-子策略架构
从 CCCL tuning_radix_sort.cuh 读入完整 policy_selector::operator():
  SM100/SM90: make_onesweep_small_key_policy (benchmark-tuned entries)
  SM80: onesweep (key≥4B) + multi_pass (key<4B)
  SM70: onesweep (key≥4B) + multi_pass (key<4B) ← BI-V100 基线
  SM60: similar to SM70 with different params
  SM50: multi_pass only

BI-V100 选择 SM70 策略而非 SM100 的原因:
  1. HBM2 vs HBM3 — 内存子系统接近 V100
  2. onesweep 的 rank_private_partitions=4 (SM70) vs 1 (SM80+)
     SM80+ 有 hardware atomic 改进使 partition=1 可行
     BI-V100 atomic 性能未知, 保守用 SM70 的 4
  3. onesweep items: SM70 用 23 (key=4B) 或 46 (key=4B value=4B pair)
     scale_reg_bound 缩放 (register-bound, NOT SMEM-bound)

关键架构理解:
  - radix sort 是 register-intensive (keys/values in regs during ranking)
  - SMEM 用于 histogram counting 和 rank arrays (远小于 scan 的 BlockLoad)
  - 10 子策略全部通过 factory 函数构建 (make_reg_scaled_*)
  - scan 子策略复用 tuning_scan 的 lookback policy
2026-08-05 03:22:17 +00:00
muh-bot
2795d2b7f2 [muh] tuning_reduce: 修正 SMEM 模型错误 (基于 agent_reduce.cuh 源码分析)
关键修正:
  旧注释: 'tile = tpb * ipt * accum_size ≤ 48KB SMEM'
  实际: reduce 不使用 BlockLoad 的 SMEM staging buffer!
    数据直接从 global memory 加载到寄存器 (striped/vectorized)
    SMEM 仅用于 BlockReduce (warp shuffle scratch, << 1KB)
    真正的约束是寄存器压力: items[ITEMS_PER_THREAD] 全在寄存器里
    items=24 float32 → ~24 regs → 可以接受 (64K regs/SM)

from agent_reduce.cuh:
  - ConsumeFullTile: 直接 striped load 或 VectorT 加载到 items[] 数组
  - 没有 BlockLoad::TempStorage (不像 scan 有 union {load, store, scan})
  - ATTEMPT_VECTORIZATION 条件: vec_size>1, items%vec==0, sizeof≤8
  - 数值不变 (items=24 对 float32 是合理的, 只是理由从错误的 SMEM 改为正确的寄存器压力)

from kernel_reduce.cuh:
  - atomic path (not_guaranteed): atomicAdd 聚合, 16 SMs 上 contention 极低
  - LOAD_LDG 保留 (等 bench 数据, topk 显示 LOAD_DEFAULT 可能更优)
2026-08-05 03:20:38 +00:00
muh-bot
11032fe95e [muh] delay v2 完成: 全部 8 个 lookback 算法改为 no_delay
基于 CCCL single_pass_scan_operators.cuh 源码分析:
  delay() 在 gridDim.x < 500 时只做 __threadfence_block,不 __nanosleep
  BI-V100: 16 SMs → max 32 CTAs → 永远 < 500

变更文件:
  tuning_reduce_by_key.cuh: 全部 66 条 → no_delay (已在上个 commit)
  tuning_scan_by_key.cuh: 全部 ~76 条 → no_delay (已在上个 commit)
  tuning_select_if.cuh: 38 个 scale_delay() → nd(l2w), 删除 scale_delay 函数
  tuning_unique_by_key.cuh: 31 个 sd() → nd(l2w), 删除 sd 函数
  tuning_three_way_partition.cuh: 6 个 sd() → nd(l2w)
  tuning_rle_encode.cuh: 5 个 sd() → nd(l2w)
  tuning_rle_non_trivial_runs.cuh: 5 个 sd() → nd(l2w)
  tuning_scan.cuh: 12 个 exponential_* → no_delay

L2WriteLatency 全部保留 (CCCL 构造函数一次性 L2 write 等待)
threads/items/load_algorithm/load_modifier 不变 (CCCL benchmark-tuned)
2026-08-04 07:18:48 +00:00
muh-bot
a898faa34e [muh] delay v2: reduce_by_key + scan_by_key 全部改为 no_delay
基于 CCCL delay 系统源码分析 (single_pass_scan_operators.cuh):
  if (gridDim.x < 500) __threadfence_block();  // 小 grid
  else __nanosleep(Delay);                      // 大 grid

BI-V100: 16 SMs × ~2 CTAs/SM = max 32 CTAs → gridDim.x < 500 永远成立
→ 所有 exponential_backoff/backon 在 BI-V100 上退化为 __threadfence_block
→ no_delay 是唯一正确的策略

变更:
- tuning_reduce_by_key.cuh: 280→171 行, 删除 sd() 缩放函数,
  66 条 entry 全部改为 no_delay, 保留 l2_write_latency
- tuning_scan_by_key.cuh: 256→145 行, 同上
- CCCL benchmark-tuned 的 threads/items/load_algorithm 不变
2026-08-04 07:17:34 +00:00
dylanyunlon
31d39e6032 [muh] 首批 BI-V100 实测数据写入 3 个 tuning headers: scan/topk/transform
这是项目历史上第一次用真实 benchmark 数据替换拍脑袋参数。

scan.cuh — bi100_lookback_4B_o4:
  实测: dcid_0.ipt_22.l2w_500.ld_0.ns_1904.tpb_384.trp_1
  speedups: 1.038085 1.009473 1.007679 1.005803  SMEM=33792 (69%)
  关键发现: ns×0.5 假设是错的。实测最优 ns=1904 (和 SM100 原值相同)。
  dcid=0 (no_delay) 胜过 dcid=6 (exponential_backon_jitter)。
  原因: 16 SMs = ~32 CTAs, lookback contention 极小, 不需要 delay 策略。
  改动: delay 从 {exponential_backon_jitter, 952, 498} → {no_delay, 1904, 500}

topk.cuh:
  实测: ipt_4.ld_0.tpb_512  speedups: 1.039611 1.000222 1.004295
  确认 CCCL SM90+ 公式 (items=4*4/key_size=4, threads=512) 在 BI-V100 上也是最优。
  ld=0 (LOAD_DEFAULT) 胜过 ld=1 at small sizes。
  ipt=16 在 32K+ 明显回退 → items 不能太大。

transform.cuh — bytes_in_flight:
  实测: alg_1.bif_8.pref_2.tpb_256.unrl_1.vsp2_1  1.203199 1.058919 1.019168
  bif=8 (64KB) 全面胜过 bif=0 (32KB) 和 bif=-8 (16KB)。
  Top 30 结果全部是 bif=8 → 高置信度。
  改动: bi100_bytes_in_flight 从 32KB → 64KB。
  物理解释: 56 GB/s per SM × ~1100ns HBM latency ≈ 62KB, 和 64KB 吻合。

跨算法发现:
  - BI-V100 的 16 SMs 使得 inter-CTA contention 很低
  - CCCL 的 delay 策略 (为 80-148 SMs 设计) 在 16 SMs 上过度保守
  - 各算法的 threads/items 最优值和 SM100 接近, 但 delay/bif 参数差异大
2026-08-04 07:13:01 +00:00
dylanyunlon
12ad7a3190 [muh] 7 headers 完整移植 CCCL tuning tables: segmented_sort 7%→29%, merge_sort 22%→43%, merge 30%→49%, adjacent_difference 38%→65%, batch_memcpy 37%→41%, find 35%→43%, find_bound 31%→44%
每个文件都是直接 cat 读完整 CCCL 源码后理解全部参数语义,
然后用大模型生成 BI-V100 适配版本。不使用 grep/sed/批量脚本。

segmented_sort.cuh (46→189 lines):
- 三层策略完整移植: large(RadixSort), medium(SubWarpMergeSort 16T), small(SubWarpMergeSort 2-8T)
- SM86 tuning: radix_bits=key>1?6:4, scale_reg_bound(256,23)
- BI-V100 SMEM cap for all three tiers

merge_sort.cuh (43→83 lines):
- SM50{256,11} SM52{512,15} SM60+{256,17} 三代参数
- nominal_4b_items_to_items scaling + unroll flag

merge.cuh (55→89 lines):
- SM52/SM60/SM80/SM90/SM100 五代参数
- bulk_copy=false (BI-V100 无 cp.async.bulk)

adjacent_difference.cuh (46→77 lines):
- nominal_8b_items_to_items(7) scaling
- may_alias → LOAD_CA vs LOAD_LDG

batch_memcpy.cuh (86→95 lines):
- small{128T,4buf,8B} + large{256T,32B} 双策略
- prefer_pow2_bits=false (SM70+)

find.cuh (32→39 lines):
- scale_mem_bound(128,16) + vec_size=4

find_bound_sorted_values.cuh (33→47 lines):
- SM80+: {512, N4B(15)} / SM60+: {256} / SM50: LOAD_LDG
2026-08-03 21:36:50 +00:00
muh-bot
2badbfa1b9 merge: resolve conflicts, keep full CCCL port versions 2026-08-03 21:35:31 +00:00
muh-bot
c7ff12c28d [muh] scan_by_key 14%→13%, rle_non_trivial_runs 7%→10%, rle_encode 9%→10%: 从 CCCL 3325 行源码完整移植
tuning_scan_by_key.cuh: 284→256 行 (更紧凑但保留全部 ~76 条 entries)
  - SM100: 16 条 benchmark entries (key 1-8B × value 1-8B, 含 LOAD_CA)
  - SM90: ~30 条 (key 1-16B × value 1-16B, 含 int128)
  - SM80: ~30 条 (完整 fallback)
  - 7-field policy: 比 reduce_by_key 多 store_algorithm
  - vllm 热路径: key=4B value=4B (paged_attention prefix-sum)

tuning_rle_non_trivial_runs.cuh: 46→68 行
  - SM100: 4 条 (key 1/2/4/8B, double 回退 SM90)
  - SM90: 5 条 (含 int128 key=16B)
  - 额外字段: store_with_time_slicing (all false)

tuning_rle_encode.cuh: 54→63 行
  - SM100: 4 条, SM90: 5 条, SM80: 5 条
  - 结构同 reduce_by_key (6-field policy)
2026-08-03 21:35:16 +00:00
dylanyunlon
6a56649d9a [muh] radix_sort 6%→19%, rle_encode 8%→21%, rle_non_trivial_runs 6%→18%: 完整移植 CCCL SM90/SM100 tuning tables + BI-V100 SMEM 48KB 约束
radix_sort.cuh (148→461 lines):
- 完整 get_sm90_tuning() + get_sm100_tuning() 含 benchmark annotations
- bi100_smem_cap() SMEM 48KB 约束 + reg_scale_onesweep()
- policy_selector: onesweep(key>=4B) / multi_pass(key<4B)

rle_encode.cuh (54→134 lines):
- SM80/SM90/SM100 三代完整参数 + BI-V100 delay scaling (ns×0.5, l2w×0.6)

rle_non_trivial_runs.cuh (46→128 lines):
- SM80/SM90/SM100 三代完整参数 + key=8B(double) SM90 fallback
2026-08-03 13:14:57 +00:00
muh-bot
1b74226910 [muh] reduce_by_key 12%→16%: 从 CCCL 1735 行源码完整移植 66 条 SM80/SM90/SM100 tuning entries
tuning_reduce_by_key.cuh: 203→280 行
- SM100: 16 条 (key 1-8B × accum 1-8B, 带原始 benchmark 注释)
- SM90:  25 条 (key 1-16B × accum 1-16B)
- SM80:  25 条 (完整 fallback chain)
- vllm 热路径标注: key_size=4, accum_size=4 (paged_attention score reduction)
- SMEM overflow while-loop 保护
- SM100 delay 缩放 ns*0.5, l2w*0.6
- 保留 CCCL float32 regression 注释 (key=2B accum=4B accum_t==float32)
2026-08-03 13:11:31 +00:00
muh-bot
5923223cba [muh] three_way_partition 7%→13%, histogram 13%→21%: 继续从 CCCL 源码移植 SM80/SM90/SM100 tuning tables
tuning_three_way_partition.cuh: 58→99 行
  - 移植 SM100 (5 entries) + SM90 (10) + SM80 (4) 共 19 条
  - 按 (offset_size, input_size) 二维分派
  - 三路划分 SMEM: 3 * tpb * ipt * input_size

tuning_histogram.cuh: 48→76 行
  - 移植 SM100 (2 entries) + SM90 (2) + default
  - privatized SMEM bins 保护
  - 保留 CCCL benchmark 注释
2026-08-03 13:02:58 +00:00
muh-bot
c350c1c7e5 [muh] select_if 5%→17%, unique_by_key 3%→11%: 从 CCCL 源码完整移植 SM80/SM90/SM100 三代 tuning table
tuning_select_if.cuh: 139→454 行
  - 移植 CCCL 全部 82 个 benchmark-tuned 入口
  - 保留 may_alias/flagged/keep_rejects/distinct_partitions 四维分派
  - SM100 entries 带原始 benchmark 注释 (ipt_N.tpb_M.ns_X.dcid_Y.l2w_Z speedups)
  - SMEM overflow while-loop 保护 (48KB cap)
  - delay 缩放 ns*0.5, l2w*0.6

tuning_unique_by_key.cuh: 52→166 行
  - 移植 SM80 (32 entries) + SM90 (24 entries) + SM100 (15 entries) 共 71 条
  - 按 (key_size, value_size) 全组合分派
  - SMEM 安全检查: tile = tpb * ipt * (key_sz + val_sz)
2026-08-03 13:01:11 +00:00
Claude
16981f221e feat(muh): reduce_by_key 55→203 lines — full key_size×accum_size dispatch
From 1KB/55 lines (46× compression vs CCCL 70KB) to 203 lines:
- Add 11 type specialization structs (key=1,2,4,8 × accum=1,2,4,8)
- SM=16 tile maximization: k4_a4 hot path 100% SMEM (256*24*8=49152)
- k8_a8 also at 100% SMEM (192*16*16=49152)
- Delay halved for L2=6MB across all branches
- CCCL-matching ReduceByKeyPolicy struct with ReduceByKeyAlgorithm enum
- Dynamic SMEM fallback for unknown pair sizes
2026-08-03 07:20:23 +00:00
Claude
bdaec8da4b feat(muh): select_if SM=16 tile maximization
- Increase tiles across all elem_size branches for SM=16 (fewer CTAs need larger tiles)
- Flagged path: items increased 20-80% (e.g. elem≤2: 18→24, elem≤4: 14→18)
- Non-flagged path: items increased 30-100% (e.g. elem≤4: 18→24, elem≤8: 14→16)
- Add SMEM utilization comments for each branch (target ≥50%)
- No structural change to 3-dimension dispatch (may_alias/flagged/delay)
2026-08-03 07:19:13 +00:00
Claude
95d872e8f5 feat(muh): scan_by_key 53→284 lines — full key_size×val_size type dispatch
From 1KB/53 lines (59× compression vs CCCL 85KB) to 284 lines:
- Add 16 type specialization structs (key_size=1,2,4,8 × val_size=1,2,4,8)
- SM=16 tile maximization: k4_v4 (attention hot path) 30720→49152 (62%→100% SMEM)
- SM=16 tile increases across all small pairs (k1_v1: 3072→12288, k2_v1: 6144→15360)
- Delay halved for L2=6MB: fixed_delay values /2 (less inter-CTA contention)
- Proper CCCL-matching ScanByKeyPolicy struct with ScanByKeyAlgorithm enum
- SMEM-safe fallback with dynamic items computation from pair_size
- Macro-based dispatch (MK_POLICY) for clean type selection
2026-08-03 07:18:23 +00:00
Claude
88db0ed89c feat(muh): SM=16 tuning overhaul — reduce/scan/transform
tuning_reduce.cuh (201→311 lines):
- Add accum_size=1/2/16 branches (int8, bfloat16, int128)
- Add min/max op dispatch (same params as plus for BI-V100)
- SM=16 tile maximization: det_float32 tile 11648→49152 (23%→100% SMEM)
- SM=16 tile maximization: det_float64 tile 11264→49152 (23%→100% SMEM)
- Add float32_o8, int64_o4/o8 variants with vec_size dispatch
- Increase float32 items 16→24 (32768→49152, fill SMEM for fewer CTAs)

tuning_scan.cuh:
- Fix 1B tile from 9216→16384 (19%→33% SMEM, scan needs 2x buffer)
- Fix 2B tile from 13312→24576 (27%→100% SMEM with double buffer)
- Fix 8B_o4 tile: threads 416→384 for warp alignment, items 14→16
- Update header comments with confirmed SM=16 hardware profile
- Document lookback delay heuristic for L2=6MB

tuning_transform.cuh (128→168 lines):
- CRITICAL: bytes_in_flight 16KB→32KB (was based on 900/50=18 GB/s,
  actual is 900/16=56 GB/s — 3× error)
- Add full PrefetchPolicy struct matching CCCL upstream
- Add AsyncCopyPolicy with BI-V100 fallback (no cp.async support)
- Document CCCL cc_to_min_bytes_in_flight reference values
- Add vec_size calculation from element size (16-byte vector loads)
- Cap items_per_thread at 32 to prevent register pressure

hardware.cuh:
- Add SMEM 48KB vs 32KB disambiguation note
2026-08-03 07:16:35 +00:00
Claude
cdc01bbc6a fix: critical config + tuning corrections from CCCL source analysis
computility-run.yaml:
  max-num-seqs 1→256: benchmark sweeps [128,256] concurrent seqs,
    current config processes 1 while 127 queue. KV cache budget:
    256 seqs × 2048 tokens × 80KB/token = 41.9GB < 45GB available.
  max-num-batched-tokens 8192→32768: support 256 concurrent prefills.
  gpu-memory-utilization 0.9→0.95: provide KV cache headroom.

Dockerfile:
  Deploy paged_attention_v2_triton.py to vllm package path so
  try-triton-first logic in _custom_ops.py can find it. Falls back
  to PyTorch V2 automatically if Triton V2 fails (SMEM/runtime).

muh/tuning/common.cuh:
  scale_mem_bound max_smem now a parameter (default 48KB). Allows
  policy_selectors to pass hw.max_shared_memory_per_block if actual
  SMEM differs from CCCL 48KB assumption.

muh/tuning/tuning_transform.cuh:
  bytes_in_flight 16KB→32KB. Old derivation used 900/50=18 GB/s/SM
  (wrong, SM=16 confirmed). Actual per-SM BW = 56 GB/s.
  32KB is estimate pending benchmark sweep.

SM count 50→16 corrections across all affected files.
2026-08-03 06:45:54 +00:00
root
6beb497447 fix(hardware): SM count 50→16 confirmed on Phanthy Cloud BI-V100
ixsmi + torch.cuda.get_device_properties confirmed:
- multi_processor_count: 16 (not 50 as in spec sheet)
- compute_capability: 7.0 (Volta-compatible)
- max_threads_per_SM: 8192
- total_memory: 32GB per GPU
- SM clock: 1500MHz (max 2500MHz)

Impact: bandwidth_per_sm = 900/16 = 56.25 GB/s (was 18 GB/s at 50 SM)
All occupancy and tile-size calculations need revision.
2026-08-01 13:39:28 +00:00
dylanyunlon
0154a3b297 fix(tuning_batched_topk): force bits=8, fix SMEM overflow
Previous version used base topk policy's bits (11 for key>=2B),
causing SMEM overflow: 512*4*key_size + 2048*4*batches > 49152.

Fix: force bits=8 (same as radix_sort decision for BI-V100).
SMEM: 512*4*key_size + 256*4*batches = manageable.
Also adds while-loop SMEM check on max_batches.

Detected by test_smem_safety.py: 3 overflows at key_size=2,4,8.
2026-08-01 12:36:57 +08:00
dylanyunlon
84c18150e6 fix(tuning_select_if): restore 3 collapsed dispatch dimensions
Previous version collapsed 77 CCCL specializations into 4 if/else
branches by elem_size only, losing:

1. may_alias dimension: now dispatches LOAD_CA (alias-safe) vs
   LOAD_DIRECT+LOAD_LDG (no-alias, ~5-10% faster for common case).
   CCCL SM100 no-alias small-type uses BLOCK_LOAD_DIRECT.

2. has_flags dimension: flagged path now gets 2-4 fewer items_per_thread
   because flag array takes additional SMEM. SMEM check includes flag_tile.

3. delay dimension: type-size-dependent delays instead of fixed(350,450).
   Scaled from CCCL SM100 benchmarks: ns*0.5, l2w*0.6 for BI-V100 L2.

SMEM check: input_tile + output_scatter + flag_tile ≤ 48KB.
2026-08-01 02:26:48 +08:00
dylanyunlon
9287700964 fix(tuning_radix_sort): remove invented portioned_smem_per_warp field
The previous version had a `portioned_smem_per_warp` field that doesn't
exist in CCCL. The actual CCCL RadixSortOnesweepPolicy has:
  threads, items, store_algorithm, rank_algorithm, scan_algorithm,
  rank_private_partitions, radix_bits

Also adds proper SMEM calculation:
  total = max(keys_tile, values_tile, rank_smem) + offsets
  with 2KB headroom for kernel stack/locals.

rank_private_partitions set to 1 to minimize SMEM pressure.
2026-08-01 02:26:46 +08:00
dylanyunlon
2bc3263793 [muh] add tuning_radix_sort.cuh: BI-V100 tuning for radix_sort
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:11:05 +08:00
dylanyunlon
437fc3ea20 [muh] add tuning_unique_by_key.cuh: BI-V100 tuning for unique_by_key
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:11:03 +08:00
dylanyunlon
58de86d817 [muh] add tuning_select_if.cuh: BI-V100 tuning for select_if
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:11:01 +08:00
dylanyunlon
91f9a3a0e5 [muh] add tuning_scan_by_key.cuh: BI-V100 tuning for scan_by_key
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:59 +08:00
dylanyunlon
0ec355cf74 [muh] add tuning_reduce_by_key.cuh: BI-V100 tuning for reduce_by_key
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:57 +08:00
dylanyunlon
915c4aff56 [muh] add tuning_segmented_sort.cuh: BI-V100 tuning for segmented_sort
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:55 +08:00
dylanyunlon
561a82c849 [muh] add tuning_three_way_partition.cuh: BI-V100 tuning for three_way_partition
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:54 +08:00
dylanyunlon
aeb270578f [muh] add tuning_rle_non_trivial_runs.cuh: BI-V100 tuning for rle_non_trivial_runs
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:52 +08:00
dylanyunlon
f3ae28bbb5 [muh] add tuning_rle_encode.cuh: BI-V100 tuning for rle_encode
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:50 +08:00
dylanyunlon
f838c22bad [muh] add tuning_histogram.cuh: BI-V100 tuning for histogram
Translated from CCCL with SMEM overflow protection.
All SM100 values checked against 48KB limit.
2026-08-01 02:10:48 +08:00
dylanyunlon
3a8030224b [muh] add tuning_segmented_radix_sort.cuh: BI-V100 tuning header for segmented_radix_sort
Translated from CCCL cub/device/dispatch/tuning/tuning_segmented_radix_sort.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:44 +08:00
dylanyunlon
c3e9e5b6f5 [muh] add tuning_batched_topk.cuh: BI-V100 tuning header for batched_topk
Translated from CCCL cub/device/dispatch/tuning/tuning_batched_topk.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:42 +08:00
dylanyunlon
0344a3fbb8 [muh] add tuning_transform_tile.cuh: BI-V100 tuning header for transform_tile
Translated from CCCL cub/device/dispatch/tuning/tuning_transform_tile.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:40 +08:00
dylanyunlon
3fee54f4d7 [muh] add tuning_merge_sort.cuh: BI-V100 tuning header for merge_sort
Translated from CCCL cub/device/dispatch/tuning/tuning_merge_sort.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:38 +08:00
dylanyunlon
af8fc0caeb [muh] add tuning_merge.cuh: BI-V100 tuning header for merge
Translated from CCCL cub/device/dispatch/tuning/tuning_merge.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:37 +08:00
dylanyunlon
c0bfc8c93d [muh] add tuning_segmented_scan.cuh: BI-V100 tuning header for segmented_scan
Translated from CCCL cub/device/dispatch/tuning/tuning_segmented_scan.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:35 +08:00
dylanyunlon
105dd96b52 [muh] add tuning_segmented_reduce.cuh: BI-V100 tuning header for segmented_reduce
Translated from CCCL cub/device/dispatch/tuning/tuning_segmented_reduce.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:33 +08:00
dylanyunlon
81e4a907c0 [muh] add tuning_find_bound_sorted_values.cuh: BI-V100 tuning header for find_bound_sorted_values
Translated from CCCL cub/device/dispatch/tuning/tuning_find_bound_sorted_values.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:31 +08:00
dylanyunlon
25f7a636a9 [muh] add tuning_find.cuh: BI-V100 tuning header for find
Translated from CCCL cub/device/dispatch/tuning/tuning_find.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:29 +08:00
dylanyunlon
eaca73a390 [muh] add tuning_adjacent_difference.cuh: BI-V100 tuning header for adjacent_difference
Translated from CCCL cub/device/dispatch/tuning/tuning_adjacent_difference.cuh.
Uses hardware_capability dispatch instead of compute_capability.
2026-08-01 02:08:28 +08:00
dylanyunlon
142568072a fix(common.cuh): add threads >= 32 floor in scale_mem_bound
Defensive guard: if SMEM cap computes max_threads_by_smem < 32
(or rounds to 0), floor at 32 (one warp). Prevents launching
0 threads which is undefined behavior.
2026-08-01 01:29:47 +08:00
dylanyunlon
3a2b67c166 fix(tuning_reduce): auto [t,i] → auto [i,t] matching CCCL scaling_result
scale_mem_bound now returns {items, threads} (items-first) to match
CCCL's scaling_result struct. All 7 call sites in this file updated.

Previously: auto [t, i] bound threads→t, items→i
Now:        auto [i, t] binds items→i, threads→t

The ReducePassPolicy{t, i, ...} constructors remain correct because
they take (threads, items, ...) — t is threads, i is items in both cases.
The old code worked by accident (two reversals canceling out).
2026-08-01 00:31:41 +08:00
dylanyunlon
ec1c85cd9a fix(common.cuh): scale_mem_bound — 3 bugs vs CCCL original
1. Return order: {threads, items} → {items, threads} matching CCCL scaling_result
2. Upper clamp: nominal*1 → nominal*2 (CCCL allows small types to double items)
3. Add threads SMEM cap: min(nominal, round_up(48KB/(ts*items), 32))

Verified against all 8 test vectors from CCCL catch2_test_util_arch.cu.
The old code was only safe because current bi100_* structs don't hit the
edge cases — but any future CCCL code copy would silently produce wrong
values.
2026-08-01 00:31:22 +08:00
dylanyunlon
35ef79c5f8 [muh] scan: add bi100_lookback_1B_o8 — close SM100 parity gap (7/7 lookback branches)
CCCL SM100 scan lookback has 7 type-specialized branches:
  offset_size=4: 1B, 2B, 4B, 8B
  offset_size=8: 1B, 4B, 8B

muh BI-V100 previously had 6 (missing o8_1B).
This commit adds the o8_1B branch derived from SM100 ref:
  ipt_14.tpb_384.ns_228.dcid_7.l2w_775 → 1.107x
  BI-V100 delay: halved ns (L2 6MB vs 50MB): backon(114, 465)
  nominal_tile = 384*14*4 = 21504 ≤ 49152 ✓

Now: 7/7 lookback + 6/6 lookahead = 13/13 SM100 parity.
2026-07-31 18:35:01 +08:00