import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torchvision.transforms import functional as F
from torch import nn
from torch.nn import functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_convolution_full_mul_0(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, out_ptr2, out_ptr3, ynumel, xnumel, YBLOCK: tl.constexpr,
    XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask)
    tmp1 = tl.load(in_ptr1 + (x2 + 16 * y3), xmask & ymask)
    tmp2 = tmp0 * tmp1
    tmp3 = tmp0 * tmp0
    tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp2, xmask & ymask)
    tl.store(out_ptr1 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask)
    tl.store(out_ptr2 + (y0 + 4 * x2 + 64 * y1), tmp3, xmask & ymask)
    tl.store(out_ptr3 + (y0 + 4 * x2 + 64 * y1), tmp1, xmask & ymask)


@triton.jit
def triton_poi_fused_full_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 36
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = 0.1111111111111111
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_div_mul_sub_2(
    in_out_ptr2, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    x5 = xindex
    tmp97 = tl.load(in_ptr4 + x5, xmask)
    tmp0 = x1
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 1.0
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tl.full([1], 1, tl.int64)
    tmp11 = tmp9 + tmp10
    tmp12 = tl.full([1], 3, tl.int64)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tmp14 = x0
    tmp15 = tmp14.to(tl.float32)
    tmp16 = tmp15 + tmp2
    tmp17 = tmp16 * tmp4
    tmp18 = tmp17 - tmp2
    tmp19 = triton_helpers.maximum(tmp18, tmp7)
    tmp20 = tmp19.to(tl.int32)
    tmp21 = tmp20 + tmp10
    tmp22 = triton_helpers.minimum(tmp21, tmp12)
    tmp23 = tl.load(in_ptr0 + (x2 + 4 * tmp22 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr1 + (x2 + 4 * tmp22 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr2 + (x2 + 4 * tmp22 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp26 = tmp24 * tmp25
    tmp27 = tmp23 - tmp26
    tmp28 = tl.load(in_ptr3 + (x2 + 4 * tmp22 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp29 = tmp24 * tmp24
    tmp30 = tmp28 - tmp29
    tmp31 = 1e-05
    tmp32 = tmp30 + tmp31
    tmp33 = tmp27 / tmp32
    tmp34 = tl.load(in_ptr0 + (x2 + 4 * tmp20 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp35 = tl.load(in_ptr1 + (x2 + 4 * tmp20 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp36 = tl.load(in_ptr2 + (x2 + 4 * tmp20 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp37 = tmp35 * tmp36
    tmp38 = tmp34 - tmp37
    tmp39 = tl.load(in_ptr3 + (x2 + 4 * tmp20 + 16 * tmp13 + 64 * x3),
        xmask, eviction_policy='evict_last')
    tmp40 = tmp35 * tmp35
    tmp41 = tmp39 - tmp40
    tmp42 = tmp41 + tmp31
    tmp43 = tmp38 / tmp42
    tmp44 = tl.load(in_ptr0 + (x2 + 4 * tmp22 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp45 = tl.load(in_ptr1 + (x2 + 4 * tmp22 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp46 = tl.load(in_ptr2 + (x2 + 4 * tmp22 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp47 = tmp45 * tmp46
    tmp48 = tmp44 - tmp47
    tmp49 = tl.load(in_ptr3 + (x2 + 4 * tmp22 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp50 = tmp45 * tmp45
    tmp51 = tmp49 - tmp50
    tmp52 = tmp51 + tmp31
    tmp53 = tmp48 / tmp52
    tmp54 = tl.load(in_ptr0 + (x2 + 4 * tmp20 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp55 = tl.load(in_ptr1 + (x2 + 4 * tmp20 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp56 = tl.load(in_ptr2 + (x2 + 4 * tmp20 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp57 = tmp55 * tmp56
    tmp58 = tmp54 - tmp57
    tmp59 = tl.load(in_ptr3 + (x2 + 4 * tmp20 + 16 * tmp9 + 64 * x3), xmask,
        eviction_policy='evict_last')
    tmp60 = tmp55 * tmp55
    tmp61 = tmp59 - tmp60
    tmp62 = tmp61 + tmp31
    tmp63 = tmp58 / tmp62
    tmp64 = tmp53 - tmp63
    tmp65 = tmp20.to(tl.float32)
    tmp66 = tmp19 - tmp65
    tmp67 = triton_helpers.maximum(tmp66, tmp7)
    tmp68 = triton_helpers.minimum(tmp67, tmp4)
    tmp69 = tmp64 * tmp68
    tmp70 = tmp63 + tmp69
    tmp71 = tmp33 * tmp24
    tmp72 = tmp25 - tmp71
    tmp73 = tmp43 * tmp35
    tmp74 = tmp36 - tmp73
    tmp75 = tmp53 * tmp45
    tmp76 = tmp46 - tmp75
    tmp77 = tmp63 * tmp55
    tmp78 = tmp56 - tmp77
    tmp79 = tmp76 - tmp78
    tmp80 = tmp79 * tmp68
    tmp81 = tmp78 + tmp80
    tmp82 = tmp33 - tmp43
    tmp83 = tmp82 * tmp68
    tmp84 = tmp43 + tmp83
    tmp85 = tmp84 - tmp70
    tmp86 = tmp9.to(tl.float32)
    tmp87 = tmp8 - tmp86
    tmp88 = triton_helpers.maximum(tmp87, tmp7)
    tmp89 = triton_helpers.minimum(tmp88, tmp4)
    tmp90 = tmp85 * tmp89
    tmp91 = tmp72 - tmp74
    tmp92 = tmp91 * tmp68
    tmp93 = tmp74 + tmp92
    tmp94 = tmp93 - tmp81
    tmp95 = tmp94 * tmp89
    tmp96 = tmp70 + tmp90
    tmp98 = tmp96 * tmp97
    tmp99 = tmp81 + tmp95
    tmp100 = tmp98 + tmp99
    tl.store(in_out_ptr2 + x5, tmp100, xmask)


def call(args):
    arg0_1, arg1_1, arg2_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        buf15 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_convolution_full_mul_0[grid(16, 16)](arg0_1,
            arg1_1, buf0, buf6, buf15, buf11, 16, 16, XBLOCK=16, YBLOCK=16,
            num_warps=4, num_stages=1)
        del arg0_1
        del arg1_1
        buf1 = empty_strided_cuda((4, 1, 1, 9), (9, 9, 9, 1), torch.float32)
        triton_poi_fused_full_1[grid(36)](buf1, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf2 = extern_kernels.convolution(buf0, buf1, stride=(1, 1),
            padding=(0, 4), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf2, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf0
        buf3 = reinterpret_tensor(buf1, (4, 1, 9, 1), (9, 9, 1, 1), 0)
        del buf1
        triton_poi_fused_full_1[grid(36)](buf3, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf4 = extern_kernels.convolution(buf2, buf3, stride=(1, 1),
            padding=(4, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf4, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf2
        buf5 = reinterpret_tensor(buf3, (4, 1, 1, 9), (9, 9, 9, 1), 0)
        del buf3
        triton_poi_fused_full_1[grid(36)](buf5, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf7 = extern_kernels.convolution(buf6, buf5, stride=(1, 1),
            padding=(0, 4), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf7, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf6
        buf8 = reinterpret_tensor(buf5, (4, 1, 9, 1), (9, 9, 1, 1), 0)
        del buf5
        triton_poi_fused_full_1[grid(36)](buf8, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf9 = extern_kernels.convolution(buf7, buf8, stride=(1, 1),
            padding=(4, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf9, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf7
        buf10 = reinterpret_tensor(buf8, (4, 1, 1, 9), (9, 9, 9, 1), 0)
        del buf8
        triton_poi_fused_full_1[grid(36)](buf10, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf12 = extern_kernels.convolution(buf11, buf10, stride=(1, 1),
            padding=(0, 4), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf12, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf11
        buf13 = reinterpret_tensor(buf10, (4, 1, 9, 1), (9, 9, 1, 1), 0)
        del buf10
        triton_poi_fused_full_1[grid(36)](buf13, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf14 = extern_kernels.convolution(buf12, buf13, stride=(1, 1),
            padding=(4, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf14, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf12
        buf16 = reinterpret_tensor(buf13, (4, 1, 1, 9), (9, 9, 9, 1), 0)
        del buf13
        triton_poi_fused_full_1[grid(36)](buf16, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf17 = extern_kernels.convolution(buf15, buf16, stride=(1, 1),
            padding=(0, 4), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf17, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf15
        buf18 = reinterpret_tensor(buf16, (4, 1, 9, 1), (9, 9, 1, 1), 0)
        del buf16
        triton_poi_fused_full_1[grid(36)](buf18, 36, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf19 = extern_kernels.convolution(buf17, buf18, stride=(1, 1),
            padding=(4, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf19, (4, 4, 4, 4), (64, 1, 16, 4))
        del buf18
        buf20 = reinterpret_tensor(buf17, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf17
        buf25 = buf20
        del buf20
        buf32 = buf25
        del buf25
        triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_div_mul_sub_2[
            grid(256)](buf32, buf4, buf9, buf14, buf19, arg2_1, 256, XBLOCK
            =128, num_warps=4, num_stages=1)
        del arg2_1
        del buf14
        del buf19
        del buf4
        del buf9
    return buf32,


class BoxFilter(nn.Module):

    def __init__(self, r):
        super(BoxFilter, self).__init__()
        self.r = r

    def forward(self, x):
        kernel_size = 2 * self.r + 1
        kernel_x = torch.full((x.data.shape[1], 1, 1, kernel_size), 1 /
            kernel_size, device=x.device, dtype=x.dtype)
        kernel_y = torch.full((x.data.shape[1], 1, kernel_size, 1), 1 /
            kernel_size, device=x.device, dtype=x.dtype)
        x = F.conv2d(x, kernel_x, padding=(0, self.r), groups=x.data.shape[1])
        x = F.conv2d(x, kernel_y, padding=(self.r, 0), groups=x.data.shape[1])
        return x


class FastGuidedFilterNew(nn.Module):

    def __init__(self, r: 'int', eps: 'float'=1e-05):
        super().__init__()
        self.r = r
        self.eps = eps
        self.boxfilter = BoxFilter(r)

    def forward(self, input_0, input_1, input_2):
        arg0_1 = input_0
        arg1_1 = input_1
        arg2_1 = input_2
        output = call([arg0_1, arg1_1, arg2_1])
        return output[0]


Measured latency_ms: 0.225196