- Add TensorLayout enum (C++ + Python) to replace magic layout ints - Add C10_CUDA_CHECK post-launch error checking to all kernel entries - Add CUDAGuard + freqs_cis shape validation to rotary_emb.cu - Cache SM count to eliminate per-call cudaDeviceGetAttribute - Add DISPATCH_CAUSAL_MASK macro to deduplicate dispatcher if/else - Convert mask type hints from X|None to Optional[X]
39 lines
1.2 KiB
Plaintext
39 lines
1.2 KiB
Plaintext
#include "attn_dispatchers.cuh"
|
|
#include "attn_entry_utils.cuh"
|
|
|
|
torch::Tensor attn_decode(
|
|
torch::Tensor q,
|
|
torch::Tensor k,
|
|
torch::Tensor v,
|
|
c10::optional<torch::Tensor> mask,
|
|
int64_t causal_offset,
|
|
double scale,
|
|
int64_t layout
|
|
) {
|
|
AttentionParams<bf16> p;
|
|
attn_pack_params(q, k, v, mask, causal_offset, scale, layout, p);
|
|
TORCH_CHECK(p.q_len == 1, "Q seq_len must be 1");
|
|
TORCH_CHECK(p.head_dim % 32 == 0, "head_dim must be multiple of 32");
|
|
|
|
auto O = torch::empty_strided(q.sizes(), q.strides(), q.options());
|
|
auto O_view = (layout == BLHD) ? O.transpose(1, 2) : O;
|
|
p.o = (bf16*)O_view.data_ptr();
|
|
|
|
alloc_split_partials(p);
|
|
DISPATCH_HEAD_DIM(p.head_dim, dispatch_decode, p);
|
|
C10_CUDA_CHECK(cudaGetLastError());
|
|
return O;
|
|
}
|
|
|
|
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
|
m.def("attn_decode", &attn_decode,
|
|
py::arg("q"),
|
|
py::arg("k"),
|
|
py::arg("v"),
|
|
py::arg("mask") = py::none(),
|
|
py::arg("causal_offset") = -1,
|
|
py::arg("scale") = 0.0,
|
|
py::arg("layout") = (int64_t)BHLD,
|
|
"GQA decode (tensor-core head-packing on sm_80+, scalar fallback)");
|
|
}
|