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
import torch.nn as nn
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 25
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 96
    y1 = yindex // 96
    tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 96 * x2 + 2400 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_1(in_ptr0, in_ptr1, out_ptr0, ynumel,
    xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 384
    xnumel = 3600
    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 % 96
    y1 = yindex // 96
    tmp0 = tl.load(in_ptr0 + (x2 + 3600 * y3), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1, 1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(out_ptr0 + (y0 + 96 * x2 + 345600 * y1), tmp4, xmask & ymask)


@triton.jit
def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_5(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_add_convolution_relu_6(in_out_ptr0, in_ptr0, in_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x2, None)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.full([1], 0, tl.int32)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tl.store(in_out_ptr0 + x2, tmp6, None)


@triton.jit
def triton_poi_fused_add_convolution_relu_7(in_out_ptr0, in_ptr0, in_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x2, None)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.full([1], 0, tl.int32)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tl.store(in_out_ptr0 + x2, tmp6, None)


@triton.jit
def triton_poi_fused_convolution_relu_8(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 96
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_add_convolution_9(in_out_ptr0, in_ptr0, in_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, None)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp4 = tl.load(in_ptr1 + x0, None)
    tmp3 = tmp0 + tmp2
    tmp5 = tmp3 + tmp4
    tl.store(in_out_ptr0 + x0, tmp5, None)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16, primals_17,
        primals_18, primals_19, primals_20, primals_21) = args
    args.clear()
    assert_size_stride(primals_1, (4, 1, 64, 64), (4096, 4096, 64, 1))
    assert_size_stride(primals_2, (96, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(primals_3, (96,), (1,))
    assert_size_stride(primals_4, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_5, (96,), (1,))
    assert_size_stride(primals_6, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_7, (96,), (1,))
    assert_size_stride(primals_8, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_9, (96,), (1,))
    assert_size_stride(primals_10, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_11, (96,), (1,))
    assert_size_stride(primals_12, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_13, (96,), (1,))
    assert_size_stride(primals_14, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_15, (96,), (1,))
    assert_size_stride(primals_16, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_17, (96,), (1,))
    assert_size_stride(primals_18, (96, 96, 5, 5), (2400, 25, 5, 1))
    assert_size_stride(primals_19, (96,), (1,))
    assert_size_stride(primals_20, (96, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(primals_21, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(9216, 25)](primals_4, buf0, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_4
        buf1 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_6, buf1, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_6
        buf2 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_8, buf2, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_8
        buf3 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_10, buf3, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_10
        buf4 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_12, buf4, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_12
        buf5 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_14, buf5, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_14
        buf6 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_16, buf6, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_16
        buf7 = empty_strided_cuda((96, 96, 5, 5), (2400, 1, 480, 96), torch
            .float32)
        triton_poi_fused_0[grid(9216, 25)](primals_18, buf7, 9216, 25,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_18
        buf8 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 96, 60, 60), (345600, 3600, 60, 1))
        buf9 = empty_strided_cuda((4, 96, 60, 60), (345600, 1, 5760, 96),
            torch.float32)
        triton_poi_fused_convolution_relu_1[grid(384, 3600)](buf8,
            primals_3, buf9, 384, 3600, XBLOCK=64, YBLOCK=64, num_warps=8,
            num_stages=1)
        del buf8
        del primals_3
        buf10 = extern_kernels.convolution(buf9, buf0, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 96, 56, 56), (301056, 1, 5376, 96))
        buf11 = buf10
        del buf10
        triton_poi_fused_convolution_relu_2[grid(1204224)](buf11, primals_5,
            1204224, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_5
        buf12 = extern_kernels.convolution(buf11, buf1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 96, 52, 52), (259584, 1, 4992, 96))
        buf13 = buf12
        del buf12
        triton_poi_fused_convolution_relu_3[grid(1038336)](buf13, primals_7,
            1038336, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_7
        buf14 = extern_kernels.convolution(buf13, buf2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf14, (4, 96, 48, 48), (221184, 1, 4608, 96))
        buf15 = buf14
        del buf14
        triton_poi_fused_convolution_relu_4[grid(884736)](buf15, primals_9,
            884736, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_9
        buf16 = extern_kernels.convolution(buf15, buf3, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf16, (4, 96, 44, 44), (185856, 1, 4224, 96))
        buf17 = buf16
        del buf16
        triton_poi_fused_convolution_relu_5[grid(743424)](buf17, primals_11,
            743424, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_11
        buf18 = extern_kernels.convolution(buf17, buf4, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf18, (4, 96, 48, 48), (221184, 1, 4608, 96))
        buf19 = buf18
        del buf18
        triton_poi_fused_add_convolution_relu_6[grid(884736)](buf19,
            primals_13, buf15, 884736, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_13
        buf20 = extern_kernels.convolution(buf19, buf5, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf20, (4, 96, 52, 52), (259584, 1, 4992, 96))
        buf21 = buf20
        del buf20
        triton_poi_fused_convolution_relu_3[grid(1038336)](buf21,
            primals_15, 1038336, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_15
        buf22 = extern_kernels.convolution(buf21, buf6, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf22, (4, 96, 56, 56), (301056, 1, 5376, 96))
        buf23 = buf22
        del buf22
        triton_poi_fused_add_convolution_relu_7[grid(1204224)](buf23,
            primals_17, buf11, 1204224, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_17
        buf24 = extern_kernels.convolution(buf23, buf7, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf24, (4, 96, 60, 60), (345600, 1, 5760, 96))
        buf25 = buf24
        del buf24
        triton_poi_fused_convolution_relu_8[grid(1382400)](buf25,
            primals_19, 1382400, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_19
        buf26 = extern_kernels.convolution(buf25, primals_20, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf26, (4, 1, 64, 64), (4096, 1, 64, 1))
        buf27 = reinterpret_tensor(buf26, (4, 1, 64, 64), (4096, 4096, 64, 
            1), 0)
        del buf26
        triton_poi_fused_add_convolution_9[grid(16384)](buf27, primals_21,
            primals_1, 16384, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_21
    return (buf27, primals_1, primals_2, buf0, buf1, buf2, buf3, buf4, buf5,
        buf6, buf7, primals_20, buf9, buf11, buf13, buf15, buf17, buf19,
        buf21, buf23, buf25)


class RED_CNNNew(nn.Module):

    def __init__(self, out_ch=96):
        super(RED_CNNNew, self).__init__()
        self.conv1 = nn.Conv2d(1, out_ch, kernel_size=5, stride=1, padding=0)
        self.conv2 = nn.Conv2d(out_ch, out_ch, kernel_size=5, stride=1,
            padding=0)
        self.conv3 = nn.Conv2d(out_ch, out_ch, kernel_size=5, stride=1,
            padding=0)
        self.conv4 = nn.Conv2d(out_ch, out_ch, kernel_size=5, stride=1,
            padding=0)
        self.conv5 = nn.Conv2d(out_ch, out_ch, kernel_size=5, stride=1,
            padding=0)
        self.tconv1 = nn.ConvTranspose2d(out_ch, out_ch, kernel_size=5,
            stride=1, padding=0)
        self.tconv2 = nn.ConvTranspose2d(out_ch, out_ch, kernel_size=5,
            stride=1, padding=0)
        self.tconv3 = nn.ConvTranspose2d(out_ch, out_ch, kernel_size=5,
            stride=1, padding=0)
        self.tconv4 = nn.ConvTranspose2d(out_ch, out_ch, kernel_size=5,
            stride=1, padding=0)
        self.tconv5 = nn.ConvTranspose2d(out_ch, 1, kernel_size=5, stride=1,
            padding=0)
        self.relu = nn.ReLU()

    def forward(self, input_0):
        primals_2 = self.conv1.weight
        primals_3 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_6 = self.conv3.weight
        primals_7 = self.conv3.bias
        primals_8 = self.conv4.weight
        primals_9 = self.conv4.bias
        primals_10 = self.conv5.weight
        primals_11 = self.conv5.bias
        primals_12 = self.tconv1.weight
        primals_13 = self.tconv1.bias
        primals_14 = self.tconv2.weight
        primals_15 = self.tconv2.bias
        primals_16 = self.tconv3.weight
        primals_17 = self.tconv3.bias
        primals_18 = self.tconv4.weight
        primals_19 = self.tconv4.bias
        primals_20 = self.tconv5.weight
        primals_21 = self.tconv5.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19,
            primals_20, primals_21])
        return output[0]


Measured latency_ms: 1.357518