use coeus_core::{ComputeBackend, Float, Layout, Scalar};
pub trait AttentionScalar: Float {}
impl AttentionScalar for f32 {}
impl AttentionScalar for f64 {}
pub trait AttentionOps<T: Scalar>: ComputeBackend {
fn sdp_attention(
&self,
query: &Self::DeviceBuffer<T>,
query_layout: &Layout,
key: &Self::DeviceBuffer<T>,
key_layout: &Layout,
value: &Self::DeviceBuffer<T>,
value_layout: &Layout,
key_padding_mask: Option<&Self::DeviceBuffer<T>>,
key_padding_mask_layout: Option<&Layout>,
is_causal: bool,
scale: T,
output: &mut Self::DeviceBuffer<T>,
output_layout: &Layout,
attn_weights: &mut Self::DeviceBuffer<T>,
attn_weights_layout: &Layout,
) -> Result<(), Self::Error>
where
T: AttentionScalar;
#[expect(
clippy::too_many_arguments,
reason = "the method carries the complete differentiable attention contract"
)]
fn sdp_attention_backward(
&self,
grad_out: &Self::DeviceBuffer<T>,
grad_out_layout: &Layout,
query: &Self::DeviceBuffer<T>,
query_layout: &Layout,
key: &Self::DeviceBuffer<T>,
key_layout: &Layout,
value: &Self::DeviceBuffer<T>,
value_layout: &Layout,
attn_weights: &Self::DeviceBuffer<T>,
attn_weights_layout: &Layout,
scale: T,
grad_q: Option<(&mut Self::DeviceBuffer<T>, &Layout)>,
grad_k: Option<(&mut Self::DeviceBuffer<T>, &Layout)>,
grad_v: Option<(&mut Self::DeviceBuffer<T>, &Layout)>,
) -> Result<(), Self::Error>
where
T: AttentionScalar;
}