- Merge 3 duplicated dispatch blocks into single attn_dispatchers.cuh - Merge compute_num_splits from attn_utils.cuh into dispatcher header - All dim3 grid/block declarations and <<<>>> launches are single-line - Production .cu files (35-42 loc) only handle torch wrapping + pybind11 - Test files include dispatcher header directly, removing all #ifndef ASTRAI_NO_MMA duplication
36 lines
1.0 KiB
Plaintext
36 lines
1.0 KiB
Plaintext
#include "attn_dispatchers.cuh"
|
|
#include "attn_entry_utils.cuh"
|
|
|
|
torch::Tensor attn_prefill(
|
|
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.head_dim % 16 == 0, "head_dim must be multiple of 16");
|
|
|
|
auto O = torch::empty_strided(q.sizes(), q.strides(), q.options());
|
|
auto O_view = (layout == 1) ? O.transpose(1, 2) : O;
|
|
p.o = (bf16*)O_view.data_ptr();
|
|
|
|
DISPATCH_HEAD_DIM(p.head_dim, dispatch_prefill, p);
|
|
return O;
|
|
}
|
|
|
|
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
|
m.def("attn_prefill", &attn_prefill,
|
|
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") = 0,
|
|
"GQA prefill (tensor-core mma on sm_80+, scalar fallback)");
|
|
}
|