1+ // CUDA registers via the Torch stable ABI in torch_binding_stable.cpp /
2+ // flash_attn/flash_api.cpp; the ATen headers below are only available (and
3+ // only needed) for the CPU and XPU backends.
4+ #if !defined(CUDA_KERNEL)
15#include < torch/library.h>
26
37#include " registration.h"
48#include " torch_binding.h"
9+ #endif
510
611// TODO: Add all of the functions listed
712// PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
1318// m.def("fwd_kvcache", &FLASH_NAMESPACE::mha_fwd_kvcache, "Forward pass, with KV-cache");
1419// }
1520
21+ // CUDA registers via the Torch stable ABI in flash_attn/flash_api.cpp;
22+ // this original ATen registration is only for the CPU and XPU backends.
23+ #if !defined(CUDA_KERNEL)
24+
1625TORCH_LIBRARY_EXPAND (TORCH_EXTENSION_NAME , ops) {
1726 ops.def (" fwd("
1827 " Tensor! q, "
@@ -28,9 +37,7 @@ TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
2837 " float softcap, "
2938 " bool return_softmax, "
3039 " Generator? gen_) -> Tensor[]" );
31- #if defined(CUDA_KERNEL)
32- ops.impl (" fwd" , torch::kCUDA , &mha_fwd);
33- #elif defined(XPU_KERNEL)
40+ #if defined(XPU_KERNEL)
3441 ops.impl (" fwd" , torch::kXPU , &mha_fwd);
3542#endif
3643
@@ -56,9 +63,7 @@ TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
5663 " float softcap, "
5764 " bool return_softmax, "
5865 " Generator? gen_) -> Tensor[]" );
59- #if defined(CUDA_KERNEL)
60- ops.impl (" varlen_fwd" , torch::kCUDA , &mha_varlen_fwd);
61- #elif defined(XPU_KERNEL)
66+ #if defined(XPU_KERNEL)
6267 ops.impl (" varlen_fwd" , torch::kXPU , &mha_varlen_fwd);
6368#elif defined(CPU_KERNEL)
6469 ops.impl (" varlen_fwd" , torch::kCPU , &mha_varlen_fwd);
@@ -85,9 +90,7 @@ TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
8590 " bool deterministic, "
8691 " Generator? gen_, "
8792 " Tensor? rng_state) -> Tensor[]" );
88- #if defined(CUDA_KERNEL)
89- ops.impl (" bwd" , torch::kCUDA , &mha_bwd);
90- #elif defined(XPU_KERNEL)
93+ #if defined(XPU_KERNEL)
9194 ops.impl (" bwd" , torch::kXPU , &mha_bwd);
9295#endif
9396
@@ -115,9 +118,7 @@ TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
115118 " bool deterministic, "
116119 " Generator? gen_, "
117120 " Tensor? rng_state) -> Tensor[]" );
118- #if defined(CUDA_KERNEL)
119- ops.impl (" varlen_bwd" , torch::kCUDA , &mha_varlen_bwd);
120- #elif defined(XPU_KERNEL)
121+ #if defined(XPU_KERNEL)
121122 ops.impl (" varlen_bwd" , torch::kXPU , &mha_varlen_bwd);
122123#endif
123124
@@ -142,11 +143,11 @@ TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
142143 " float softcap, "
143144 " bool is_rotary_interleaved, "
144145 " int num_splits) -> Tensor[]" );
145- #if defined(CUDA_KERNEL)
146- ops.impl (" fwd_kvcache" , torch::kCUDA , &mha_fwd_kvcache);
147- #elif defined(XPU_KERNEL)
146+ #if defined(XPU_KERNEL)
148147 ops.impl (" fwd_kvcache" , torch::kXPU , &mha_fwd_kvcache);
149148#endif
150149}
151150
152151REGISTER_EXTENSION (TORCH_EXTENSION_NAME )
152+
153+ #endif // !defined(CUDA_KERNEL)
0 commit comments