[Refactor] Remove kernel dead code (#51051)
Signed-off-by: yewentao256 <zhyanwentao@126.com>
Wentao Ye committed
Aug 7, 2026 at 04:20 UTC
c84789c40b506a40d6a1ec15a704d53397c564a6
8 files changed
-396
csrc/cpu/cpu_attn_fp8.hpp
-27
@@ -116,33 +116,6 @@ inline void reshape_and_cache_fp8_amx_impl(
116
// ---------------------------------------------------------------------------
117
// FP8 E5M2 scalar helpers
118
// ---------------------------------------------------------------------------
119
-
120
-// Reference scalar dequant — used to verify vectorized AMX dequant.
121
-// FP8 E5M2: s[7] e[6:2] m[1:0], exponent bias = 15 (same as FP16).
122
-// Byte b → FP16 bits = b << 8 (no bias correction needed).
123
-inline float fp8e5m2_to_float_scalar(uint8_t b, float scale) noexcept {
124
- const uint8_t exp_bits = (b >> 2) & 0x1F;
125
- const uint8_t mant_bits = b & 0x03;
126
- // NaN: exp=11111, mant!=00
127
- if (exp_bits == 0x1F && mant_bits != 0)
128
- return std::numeric_limits<float>::quiet_NaN();
129
- const uint32_t sign = static_cast<uint32_t>(b & 0x80) << 24;
130
- if (exp_bits == 0x1F)
131
- return sign ? -std::numeric_limits<float>::infinity()
132
- : std::numeric_limits<float>::infinity();
133
- if (exp_bits == 0) { // subnormal: (-1)^s * 2^-14 * mant/4
134
- if (mant_bits == 0) return 0.0f;
135
- float v = mant_bits * 0x1p-16f;
136
- return (sign ? -v : v) * scale;
137
- }
138
- // Normal: FP32 exp = exp5 - 15 + 127, mantissa top 2 bits
139
- uint32_t fp32_bits = sign |
140
- ((static_cast<uint32_t>(exp_bits) - 15 + 127) << 23) |
141
- (static_cast<uint32_t>(mant_bits) << 21);
142
- float val = *reinterpret_cast<const f32_alias_t*>(&fp32_bits);
143
- return val * scale;
144
-}
145
-
119
inline uint8_t float_to_fp8e5m2_scalar(float v, float inv_scale) noexcept {
120
v *= inv_scale;
121
constexpr float fp8_e5m2_max = 57344.0f;
csrc/libtorch_stable/cache_kernels.cu
-51
@@ -186,57 +186,6 @@ void swap_blocks_batch(const torch::stable::Tensor& src_ptrs,
186
187
namespace vllm {
188
189
-// Grid: (num_layers, num_pairs)
190
-template <typename scalar_t>
191
-__global__ void copy_blocks_kernel(int64_t* key_cache_ptrs,
192
- int64_t* value_cache_ptrs,
193
- const int64_t* __restrict__ block_mapping,
194
- const int numel_per_block) {
195
- const int layer_idx = blockIdx.x;
196
- const int pair_idx = blockIdx.y;
197
-
198
- scalar_t* key_cache = reinterpret_cast<scalar_t*>(key_cache_ptrs[layer_idx]);
199
- scalar_t* value_cache =
200
- reinterpret_cast<scalar_t*>(value_cache_ptrs[layer_idx]);
201
- int64_t src_block_number = block_mapping[2 * pair_idx];
202
- int64_t dst_block_number = block_mapping[2 * pair_idx + 1];
203
-
204
- const int64_t src_block_offset = src_block_number * numel_per_block;
205
- const int64_t dst_block_offset = dst_block_number * numel_per_block;
206
- for (int i = threadIdx.x; i < numel_per_block; i += blockDim.x) {
207
- int64_t src_offset = src_block_offset + i;
208
- int64_t dst_offset = dst_block_offset + i;
209
- key_cache[dst_offset] = key_cache[src_offset];
210
- }
211
- for (int i = threadIdx.x; i < numel_per_block; i += blockDim.x) {
212
- int64_t src_offset = src_block_offset + i;
213
- int64_t dst_offset = dst_block_offset + i;
214
- value_cache[dst_offset] = value_cache[src_offset];
215
- }
216
-}
217
-
218
-// Kernel for MLA, which works on a single joint kv_cache
219
-// Grid: (num_layers, num_pairs)
220
-template <typename scalar_t>
221
-__global__ void copy_blocks_mla_kernel(
222
- int64_t* cache_ptrs, const int64_t* __restrict__ block_mapping,
223
- const int mem_footprint_per_block) {
224
- const int layer_idx = blockIdx.x;
225
- const int pair_idx = blockIdx.y;
226
- scalar_t* cache = reinterpret_cast<scalar_t*>(cache_ptrs[layer_idx]);
227
- int64_t src_block = block_mapping[2 * pair_idx];
228
- int64_t dst_block = block_mapping[2 * pair_idx + 1];
229
- int64_t src_offset = src_block * mem_footprint_per_block;
230
- int64_t dst_offset = dst_block * mem_footprint_per_block;
231
- for (int i = threadIdx.x; i < mem_footprint_per_block; i += blockDim.x) {
232
- cache[dst_offset + i] = cache[src_offset + i];
233
- }
234
-}
235
-
236
-} // namespace vllm
237
-
238
-namespace vllm {
239
-
189
// Used to copy/convert one element
190
template <typename OutT, typename InT, Fp8KVCacheDataType kv_dt>
191
struct CopyWithScaleOp {
csrc/libtorch_stable/moe/grouped_topk_kernels.cu
-44
@@ -232,50 +232,6 @@ class WarpSort {
232
}
233
}
234
235
- // load and merge k sorted values
236
- __device__ void load_sorted(T const* __restrict__ in,
237
- idxT const* __restrict__ in_idx, idxT start) {
238
- idxT idx = start + WARP_SIZE - 1 - lane_;
239
- for (int i = max_arr_len_ - 1; i >= 0; --i, idx += WARP_SIZE) {
240
- if (idx < start + k_) {
241
- T t = in[idx];
242
- bool is_better;
243
- if constexpr (is_stable) {
244
- is_better =
245
- is_better_than<greater>(t, val_arr_[i], in_idx[idx], idx_arr_[i]);
246
- } else {
247
- is_better = is_better_than<greater>(t, val_arr_[i]);
248
- }
249
- if (is_better) {
250
- val_arr_[i] = t;
251
- idx_arr_[i] = in_idx[idx];
252
- }
253
- }
254
- }
255
-
256
- BitonicMerge<capacity, greater, !greater, T, idxT, is_stable>::merge(
257
- val_arr_, idx_arr_);
258
- }
259
-
260
- __device__ void dump(T* __restrict__ out, idxT* __restrict__ out_idx) const {
261
- for (int i = 0; i < max_arr_len_; ++i) {
262
- idxT out_i = i * WARP_SIZE + lane_;
263
- if (out_i < k_) {
264
- out[out_i] = val_arr_[i];
265
- out_idx[out_i] = idx_arr_[i];
266
- }
267
- }
268
- }
269
-
270
- __device__ void dumpIdx(idxT* __restrict__ out_idx) const {
271
- for (int i = 0; i < max_arr_len_; ++i) {
272
- idxT out_i = i * WARP_SIZE + lane_;
273
- if (out_i < k_) {
274
- out_idx[out_i] = idx_arr_[i];
275
- }
276
- }
277
- }
278
-
235
// Accessors for per-lane selected value/index.
236
// NOTE: For the common case `capacity == WARP_SIZE`, `max_arr_len_ == 1`
237
// and callers should use `i == 0`.
csrc/libtorch_stable/quantization/fused_kernels/quant_conversions.cuh
-11
@@ -76,15 +76,4 @@ struct ScaledQuant<quant_type_t, is_scale_inverted,
76
}
77
};
78
79
-template <typename scalar_t, typename quant_type_t, bool is_scale_inverted>
80
-__device__ void scaled_quant_conversion(quant_type_t* __restrict__ output,
81
- scalar_t const* __restrict__ input,
82
- float const scale, int const tid,
83
- int const num_elements,
84
- int const step) {
85
- for (int i = tid; i < num_elements; i += step) {
86
- output[i] = ScaledQuant<quant_type_t, is_scale_inverted>(input[i], scale);
87
- }
88
-}
89
-
79
} // namespace vllm
vllm/model_executor/kernels/linear/cute_dsl/skinny_gemm.py
-11
@@ -151,17 +151,6 @@ class ShapeDynamicSkinnyGemm:
151
options="--enable-tvm-ffi --ptxas-options -maxrregcount=64",
152
)
153
154
- def request_warmup(
155
- self,
156
- dtype: torch.dtype,
157
- shapes: Iterable[tuple[int, int, int]],
158
- ) -> None:
159
- """Request compilation of ``(M, N, K)`` shapes before graph capture."""
160
- self.request_warmup_configs(
161
- dtype,
162
- (self._config(m, n, k) for m, n, k in shapes),
163
- )
164
-
154
def request_warmup_configs(
155
self,
156
dtype: torch.dtype,
vllm/models/inkling/amd/ops/gluon/rel_mha_decode_gfx950.py
-113
@@ -501,21 +501,6 @@ class AttentionProgram:
501
cdna4.buffer_store(part_o, self.mid_o_ptr, mid_o_offsets, mask=valid[:, None])
502
cdna4.buffer_store(part_lse, self.mid_lse_ptr, mid_lse_offsets, mask=valid)
503
504
- @gluon.jit
505
- def store_output(self, acc, l_i):
506
- cfg = self.cfg
507
- offs_m = gl.arange(0, cfg.BLOCK_M, layout=gl.SliceLayout(1, cfg.store_layout))
508
- offs_d = gl.arange(0, cfg.HEAD_DIM, layout=gl.SliceLayout(0, cfg.store_layout))
509
- q_heads = self.kv_head * cfg.GROUP_SIZE + self.group_start + offs_m
510
- valid = (self.group_start + offs_m) < cfg.GROUP_SIZE
511
- acc = gl.convert_layout(acc, cfg.store_layout)
512
- l_i = gl.convert_layout(l_i, gl.SliceLayout(1, cfg.store_layout))
513
- output = acc * (1.0 / l_i)[:, None]
514
- output = output.to(self.mid_o_ptr.dtype.element_ty)
515
- offsets = (self.q_index * cfg.NUM_Q_HEADS + q_heads[:, None]) * cfg.HEAD_DIM
516
- offsets += offs_d[None, :]
517
- cdna4.buffer_store(output, self.mid_o_ptr, offsets, mask=valid[:, None])
518
-
504
505
# ===-----------------------------------------------------------------------===#
506
# Entry Point
@@ -625,104 +610,6 @@ def _rel_mha_decode_fp16(
610
program.store_split(acc, l_i, m_i)
611
612
628
-@gluon.jit
629
-def _rel_mha_decode_sliding_fp16(
630
- q_ptr,
631
- rel_logits_ptr,
632
- k_cache_ptr,
633
- v_cache_ptr,
634
- page_table_ptr,
635
- cache_seqlens_ptr,
636
- out_ptr,
637
- Q_STRIDE_B: gl.constexpr,
638
- Q_STRIDE_H: gl.constexpr,
639
- Q_STRIDE_D: gl.constexpr,
640
- K_STRIDE_B: gl.constexpr,
641
- K_STRIDE_P: gl.constexpr,
642
- K_STRIDE_H: gl.constexpr,
643
- K_STRIDE_D: gl.constexpr,
644
- V_STRIDE_B: gl.constexpr,
645
- V_STRIDE_P: gl.constexpr,
646
- V_STRIDE_H: gl.constexpr,
647
- V_STRIDE_D: gl.constexpr,
648
- SM_SCALE: gl.constexpr,
649
- PAGE_TABLE_STRIDE: gl.constexpr,
650
- PAGE_SIZE: gl.constexpr,
651
- MAX_SEQLEN_Q: gl.constexpr,
652
- NUM_Q_HEADS: gl.constexpr,
653
- NUM_KV_HEADS: gl.constexpr,
654
- HEAD_DIM: gl.constexpr,
655
- BLOCK_M: gl.constexpr,
656
- BLOCK_N: gl.constexpr,
657
- IS_SLIDING: gl.constexpr,
658
- WINDOW_LEFT: gl.constexpr,
659
- REL_STRIDE_T: gl.constexpr,
660
- REL_STRIDE_H: gl.constexpr,
661
- REL_STRIDE_E: gl.constexpr,
662
- REL_EXTENT: gl.constexpr,
663
- REL_BIAS_QK_SCALE: gl.constexpr,
664
- IS_FP8: gl.constexpr,
665
-):
666
- cfg = AttentionConfig(
667
- SM_SCALE,
668
- PAGE_TABLE_STRIDE,
669
- PAGE_SIZE,
670
- 1,
671
- MAX_SEQLEN_Q,
672
- NUM_Q_HEADS,
673
- NUM_KV_HEADS,
674
- HEAD_DIM,
675
- BLOCK_M,
676
- BLOCK_N,
677
- IS_SLIDING,
678
- WINDOW_LEFT,
679
- REL_EXTENT,
680
- REL_BIAS_QK_SCALE,
681
- IS_FP8,
682
- InputStrides(Q_STRIDE_B, Q_STRIDE_H, Q_STRIDE_D),
683
- InputStrides(REL_STRIDE_T, REL_STRIDE_H, REL_STRIDE_E),
684
- PagedKVStrides(K_STRIDE_B, K_STRIDE_P, K_STRIDE_H, K_STRIDE_D),
685
- PagedKVStrides(V_STRIDE_B, V_STRIDE_P, V_STRIDE_H, V_STRIDE_D),
686
- )
687
- program = AttentionProgram.create(
688
- cfg,
689
- q_ptr,
690
- rel_logits_ptr,
691
- k_cache_ptr,
692
- v_cache_ptr,
693
- page_table_ptr,
694
- cache_seqlens_ptr,
695
- out_ptr,
696
- out_ptr,
697
- )
698
- k_smem = gl.allocate_shared_memory(
699
- k_cache_ptr.dtype.element_ty, [cfg.BLOCK_N, cfg.HEAD_DIM], cfg.k_smem_layout
700
- )
701
- v_smem = gl.allocate_shared_memory(
702
- v_cache_ptr.dtype.element_ty, [cfg.BLOCK_N, cfg.HEAD_DIM], cfg.v_smem_layout
703
- )
704
-
705
- q = program.load_q()
706
- m_i, l_i, acc = program.init_state()
707
-
708
- for start_n in range(program.split_start, program.split_end, cfg.BLOCK_N):
709
- physical_page = program.load_page(start_n)
710
- program.issue_load_k(physical_page, k_smem)
711
- program.issue_load_v(physical_page, v_smem)
712
- async_copy.wait_group(1)
713
- k = program.shared_load_k(k_smem)
714
- qk = program.compute_qk(q, k)
715
- qk = program.apply_rel_bias(qk, start_n)
716
- qk = program.apply_kv_mask(qk, start_n)
717
- p, m_i, l_i, acc = program.softmax(qk, m_i, l_i, acc)
718
-
719
- async_copy.wait_group(0)
720
- v = program.shared_load_v(v_smem)
721
- acc = program.compute_pv(p, v, acc)
722
-
723
- program.store_output(acc, l_i)
724
-
725
-
613
@gluon.jit
614
def _rel_mha_decode_reduce_fp16(
615
mid_o_ptr,
vllm/models/inkling/amd/ops/gluon/utils.py
-69
@@ -40,75 +40,6 @@ def max(input, axis=None, keep_dims=False):
40
return gl.reduce(input, axis, maximum, keep_dims=keep_dims)
41
42
43
-@gluon.constexpr_function
44
-def attention_layouts(head_dim, block_n, is_fp8, dtype, num_warps, instr_shape):
45
- mfma = gl.amd.AMDMFMALayout(
46
- version=4,
47
- instr_shape=instr_shape,
48
- transposed=True,
49
- warps_per_cta=[num_warps, 1],
50
- )
51
- qk_layout = mfma
52
- pv_layout = mfma
53
- # qk_kw is derived from a 128-bit load / dtype bitwidth; pv_kw is tuned.
54
- qk_kw = 16 if is_fp8 else 8
55
- pv_kw = 8 if is_fp8 else 4
56
- q_layout = gl.DotOperandLayout(0, qk_layout, k_width=qk_kw)
57
- k_layout = gl.DotOperandLayout(1, qk_layout, k_width=qk_kw)
58
- p_layout = gl.DotOperandLayout(0, pv_layout, k_width=pv_kw)
59
- v_layout = gl.DotOperandLayout(1, pv_layout, k_width=pv_kw)
60
- # load_vec = elems/lane (dtype-dependent, == qk_kw); load_threads span HEAD_DIM.
61
- load_vec = 16 if is_fp8 else 8
62
- load_threads = head_dim // load_vec
63
- load_layout = gl.BlockedLayout(
64
- [1, load_vec], [64 // load_threads, load_threads], [num_warps, 1], [1, 0]
65
- )
66
- # store_vec is always 16-bit (128 / 16 = 8) regardless of input dtype.
67
- store_vec = 8
68
- store_threads = head_dim // store_vec
69
- store_layout = gl.BlockedLayout(
70
- [1, store_vec], [64 // store_threads, store_threads], [num_warps, 1], [1, 0]
71
- )
72
- # Take only the built-in's padding, not its swizzle: the swizzle scatters
73
- # head_dim across banks, making the LDS write stride non-constant, so it can't
74
- # lower through async_copy's affine [1, 0] load. Padding-only is affine and
75
- # DMA-legal.
76
- # TODO(perf): to also use the swizzle, co-design a matched load layout so the
77
- # DMA stays legal.
78
- k_api = gl.amd.cdna4.compute_efficient_padded_shared_layout(
79
- k_layout, [block_n, head_dim], dtype, is_k_contig=True
80
- )
81
- v_api = gl.amd.cdna4.compute_efficient_padded_shared_layout(
82
- v_layout, [block_n, head_dim], dtype, is_k_contig=False
83
- )
84
- assert k_api is not None and v_api is not None, (
85
- "no CDNA4 padded shared layout for this operand/dtype"
86
- )
87
- k_pairs = list(k_api.interval_padding_pairs)
88
- v_pairs = list(v_api.interval_padding_pairs)
89
- assert len(k_pairs) == 1 and len(v_pairs) == 1, (
90
- "expected a single interval padding pair from the built-in"
91
- )
92
- k_smem_layout = gl.PaddedSharedLayout.with_identity_for(
93
- [[int(k_pairs[0][0]), int(k_pairs[0][1])]], [block_n, head_dim], [1, 0]
94
- )
95
- v_smem_layout = gl.PaddedSharedLayout.with_identity_for(
96
- [[int(v_pairs[0][0]), int(v_pairs[0][1])]], [block_n, head_dim], [1, 0]
97
- )
98
- return (
99
- qk_layout,
100
- pv_layout,
101
- q_layout,
102
- k_layout,
103
- p_layout,
104
- v_layout,
105
- load_layout,
106
- store_layout,
107
- k_smem_layout,
108
- v_smem_layout,
109
- )
110
-
111
-
43
@aggregate
44
class InputStrides:
45
stride_t: gl.constexpr
vllm/v1/attention/backends/fa_utils.py
-70
@@ -1,11 +1,8 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-from dataclasses import dataclass
4
from typing import Any
5
7
-import torch
8
-
6
import vllm.envs as envs
7
from vllm.logger import init_logger
8
from vllm.platforms import current_platform
@@ -70,73 +67,6 @@ elif current_platform.is_rocm():
67
reshape_and_cache_flash = ops.reshape_and_cache_flash
68
69
73
-@dataclass(frozen=True)
74
-class FlashAttentionCuTeDSLCompileSpec:
75
- """High-level FA4 compile-only request used by vLLM warmup.
76
-
77
- This is not the CuTeDSL cache key. FA4 owns the selector that maps these
78
- serving inputs to the actual compile-static fields: tile sizes, q_stage,
79
- Split-KV, scheduler choice, layout-presence booleans, dtype/head dims,
80
- arch, and related fields.
81
- """
82
-
83
- q_shape: tuple[int, ...]
84
- k_shape: tuple[int, ...]
85
- v_shape: tuple[int, ...]
86
- q_dtype: torch.dtype
87
- max_seqlen_q: int
88
- max_seqlen_k: int
89
- softmax_scale: float
90
- causal: bool
91
- fa_version: int
92
- v_stride: tuple[int, ...] | None = None
93
- cu_seqlens_q_shape: tuple[int, ...] | None = None
94
- cu_seqlens_k_shape: tuple[int, ...] | None = None
95
- window_size: tuple[int, int] | None = None
96
- return_softmax_lse: bool = False
97
- num_splits: int = 0
98
-
99
- def compile(self) -> None:
100
- assert compile_flash_attn_varlen_func_from_specs is not None
101
- window_size = list(self.window_size) if self.window_size is not None else None
102
- compile_flash_attn_varlen_func_from_specs(
103
- q_shape=self.q_shape,
104
- k_shape=self.k_shape,
105
- v_shape=self.v_shape,
106
- q_dtype=self.q_dtype,
107
- v_stride=self.v_stride,
108
- cu_seqlens_q_shape=self.cu_seqlens_q_shape,
109
- cu_seqlens_k_shape=self.cu_seqlens_k_shape,
110
- max_seqlen_q=self.max_seqlen_q,
111
- max_seqlen_k=self.max_seqlen_k,
112
- softmax_scale=self.softmax_scale,
113
- causal=self.causal,
114
- window_size=window_size,
115
- return_softmax_lse=self.return_softmax_lse,
116
- fa_version=self.fa_version,
117
- num_splits=self.num_splits,
118
- )
119
-
120
- def request_key(self) -> tuple[object, ...]:
121
- return (
122
- self.q_shape,
123
- self.k_shape,
124
- self.v_shape,
125
- self.q_dtype,
126
- self.max_seqlen_q,
127
- self.max_seqlen_k,
128
- self.softmax_scale,
129
- self.causal,
130
- self.fa_version,
131
- self.v_stride,
132
- self.cu_seqlens_q_shape,
133
- self.cu_seqlens_k_shape,
134
- self.window_size,
135
- self.return_softmax_lse,
136
- self.num_splits,
137
- )
138
-
139
-
70
def get_flash_attn_version(
71
requires_alibi: bool = False,
72
head_size: int | None = None,