refactor: rename gqa_* to attn_*, split-KV for all decode paths
- Rename all csrc/kernels/gqa_*.cuh/cu to attn_*, with _split_q / _split_kv strategy suffix and optional _mma compute suffix - Remove non-split MMA decode kernel, keep only split-KV path - Convert scalar decode fallback to split-KV (o_part/ml_part + combine) - Move combine kernel to attn_decode_split_kv.cuh (shared by both paths) - Rename GQAParams to AttentionParams - Update all C++ #include, PYBIND11, and Python extension references
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <torch/extension.h>
|
||||
#include "attn_common.cuh"
|
||||
|
||||
inline void attn_pack_params(
|
||||
torch::Tensor q,
|
||||
torch::Tensor k,
|
||||
torch::Tensor v,
|
||||
c10::optional<torch::Tensor> mask,
|
||||
bool is_causal,
|
||||
int64_t causal_offset,
|
||||
c10::optional<double> scale,
|
||||
AttentionParams& p
|
||||
) {
|
||||
TORCH_CHECK(q.is_cuda() && k.is_cuda() && v.is_cuda());
|
||||
TORCH_CHECK(q.dtype() == torch::kBFloat16);
|
||||
TORCH_CHECK(k.dtype() == torch::kBFloat16);
|
||||
TORCH_CHECK(v.dtype() == torch::kBFloat16);
|
||||
|
||||
p.batch = (int)q.size(0);
|
||||
p.q_head = (int)q.size(1);
|
||||
p.kv_head = (int)k.size(1);
|
||||
p.q_len = (int)q.size(2);
|
||||
p.kv_len = (int)k.size(2);
|
||||
p.head_dim = (int)q.size(3);
|
||||
p.use_mask = mask.has_value() ? 1 : 0;
|
||||
p.is_causal = is_causal ? 1 : 0;
|
||||
p.causal_offset = (int)causal_offset;
|
||||
p.scale = scale.has_value() ? (float)scale.value() : 1.0f / sqrtf((float)p.head_dim);
|
||||
p.q = (const bf16*)q.data_ptr();
|
||||
p.k = (const bf16*)k.data_ptr();
|
||||
p.v = (const bf16*)v.data_ptr();
|
||||
if (p.use_mask) {
|
||||
TORCH_CHECK(mask.value().dtype() == torch::kBool);
|
||||
TORCH_CHECK(mask.value().dim() == 2);
|
||||
TORCH_CHECK(mask.value().size(0) == p.batch);
|
||||
TORCH_CHECK(mask.value().size(1) == p.kv_len);
|
||||
p.mask = mask.value().data_ptr<bool>();
|
||||
} else {
|
||||
p.mask = nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user