use crate::{kernel, FloatElement, IntElement, JitBackend, JitRuntime};
use burn_tensor::ops::{
ConvOptions, ConvTransposeOptions, InterpolateOptions, MaxPool2dBackward, MaxPool2dWithIndices,
ModuleOps,
};
use burn_tensor::ops::{FloatTensor, IntTensor};
impl<R, F, I> ModuleOps<Self> for JitBackend<R, F, I>
where
R: JitRuntime,
F: FloatElement,
I: IntElement,
{
fn conv2d(
x: FloatTensor<Self, 4>,
weight: FloatTensor<Self, 4>,
bias: Option<FloatTensor<Self, 1>>,
options: ConvOptions<2>,
) -> FloatTensor<Self, 4> {
kernel::conv::conv2d(x, weight, bias, options)
}
fn conv3d(
x: FloatTensor<Self, 5>,
weight: FloatTensor<Self, 5>,
bias: Option<FloatTensor<Self, 1>>,
options: ConvOptions<3>,
) -> FloatTensor<Self, 5> {
kernel::conv::conv3d(x, weight, bias, options)
}
fn conv_transpose2d(
x: FloatTensor<Self, 4>,
weight: FloatTensor<Self, 4>,
bias: Option<FloatTensor<Self, 1>>,
options: ConvTransposeOptions<2>,
) -> FloatTensor<Self, 4> {
kernel::conv::conv_transpose2d(x, weight, bias, options)
}
fn conv_transpose3d(
x: FloatTensor<Self, 5>,
weight: FloatTensor<Self, 5>,
bias: Option<FloatTensor<Self, 1>>,
options: ConvTransposeOptions<3>,
) -> FloatTensor<Self, 5> {
kernel::conv::conv_transpose3d(x, weight, bias, options)
}
fn avg_pool2d(
x: FloatTensor<Self, 4>,
kernel_size: [usize; 2],
stride: [usize; 2],
padding: [usize; 2],
count_include_pad: bool,
) -> FloatTensor<Self, 4> {
kernel::pool::avg_pool2d(x, kernel_size, stride, padding, count_include_pad)
}
fn avg_pool2d_backward(
x: FloatTensor<Self, 4>,
grad: FloatTensor<Self, 4>,
kernel_size: [usize; 2],
stride: [usize; 2],
padding: [usize; 2],
count_include_pad: bool,
) -> FloatTensor<Self, 4> {
kernel::pool::avg_pool2d_backward(x, grad, kernel_size, stride, padding, count_include_pad)
}
fn max_pool2d(
x: FloatTensor<Self, 4>,
kernel_size: [usize; 2],
stride: [usize; 2],
padding: [usize; 2],
dilation: [usize; 2],
) -> FloatTensor<Self, 4> {
kernel::pool::max_pool2d(x, kernel_size, stride, padding, dilation)
}
fn max_pool2d_with_indices(
x: FloatTensor<Self, 4>,
kernel_size: [usize; 2],
stride: [usize; 2],
padding: [usize; 2],
dilation: [usize; 2],
) -> MaxPool2dWithIndices<Self> {
let (output, indices) =
kernel::pool::max_pool2d_with_indices(x, kernel_size, stride, padding, dilation);
MaxPool2dWithIndices::new(output, indices)
}
fn max_pool2d_with_indices_backward(
x: FloatTensor<Self, 4>,
kernel_size: [usize; 2],
stride: [usize; 2],
padding: [usize; 2],
dilation: [usize; 2],
output_grad: FloatTensor<Self, 4>,
indices: IntTensor<Self, 4>,
) -> MaxPool2dBackward<Self> {
MaxPool2dBackward::new(kernel::pool::max_pool2d_with_indices_backward(
x,
output_grad,
indices,
kernel_size,
stride,
padding,
dilation,
))
}
fn adaptive_avg_pool2d(
x: FloatTensor<Self, 4>,
output_size: [usize; 2],
) -> FloatTensor<Self, 4> {
kernel::pool::adaptive_avg_pool2d(x, output_size)
}
fn adaptive_avg_pool2d_backward(
x: FloatTensor<Self, 4>,
grad: FloatTensor<Self, 4>,
) -> FloatTensor<Self, 4> {
kernel::pool::adaptive_avg_pool2d_backward(x, grad)
}
fn interpolate(
x: FloatTensor<Self, 4>,
output_size: [usize; 2],
options: InterpolateOptions,
) -> FloatTensor<Self, 4> {
kernel::interpolate::interpolate(x, output_size, options)
}
fn interpolate_backward(
x: FloatTensor<Self, 4>,
grad: FloatTensor<Self, 4>,
output_size: [usize; 2],
options: InterpolateOptions,
) -> FloatTensor<Self, 4> {
kernel::interpolate::interpolate_backward(x, grad, output_size, options)
}
}