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
import torch.utils.data
from torch.utils import data as data
from torch import nn as nn
from torch.nn import init as init
from torch.nn.modules.batchnorm import _BatchNorm
from torchvision.models import vgg as vgg
from torch import autograd as autograd
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 4096 % 96
    x0 = xindex % 4096
    x2 = xindex // 393216
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 64, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 262144 * x2), tmp4, other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 96, tl.int64)
    tmp9 = tl.load(in_ptr1 + (x0 + 4096 * (-64 + x1) + 131072 * x2), tmp6,
        other=0.0)
    tmp10 = tl.load(in_ptr2 + (-64 + x1), tmp6, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = tmp9 + tmp10
    tmp12 = 0.0
    tmp13 = tmp11 > tmp12
    tmp14 = 0.2
    tmp15 = tmp11 * tmp14
    tmp16 = tl.where(tmp13, tmp11, tmp15)
    tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype)
    tmp18 = tl.where(tmp6, tmp16, tmp17)
    tmp19 = tl.where(tmp4, tmp5, tmp18)
    tl.store(out_ptr0 + x3, tmp19, None)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 4096 % 128
    x0 = xindex % 4096
    x2 = xindex // 524288
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 64, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 262144 * x2), tmp4, other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 96, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (x0 + 4096 * (-64 + x1) + 131072 * x2), tmp9,
        other=0.0)
    tmp11 = tl.load(in_ptr2 + (-64 + x1), tmp9, eviction_policy=
        'evict_last', other=0.0)
    tmp12 = tmp10 + tmp11
    tmp13 = 0.0
    tmp14 = tmp12 > tmp13
    tmp15 = 0.2
    tmp16 = tmp12 * tmp15
    tmp17 = tl.where(tmp14, tmp12, tmp16)
    tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
    tmp19 = tl.where(tmp9, tmp17, tmp18)
    tmp20 = tmp0 >= tmp7
    tl.full([1], 128, tl.int64)
    tmp23 = tl.load(in_ptr3 + (x0 + 4096 * (-96 + x1) + 131072 * x2), tmp20,
        other=0.0)
    tmp24 = tl.load(in_ptr4 + (-96 + x1), tmp20, eviction_policy=
        'evict_last', other=0.0)
    tmp25 = tmp23 + tmp24
    tmp26 = tmp25 > tmp13
    tmp27 = tmp25 * tmp15
    tmp28 = tl.where(tmp26, tmp25, tmp27)
    tmp29 = tl.full(tmp28.shape, 0.0, tmp28.dtype)
    tmp30 = tl.where(tmp20, tmp28, tmp29)
    tmp31 = tl.where(tmp9, tmp19, tmp30)
    tmp32 = tl.where(tmp4, tmp5, tmp31)
    tl.store(out_ptr0 + x3, tmp32, None)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 4096 % 160
    x0 = xindex % 4096
    x2 = xindex // 655360
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 64, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 262144 * x2), tmp4, other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 96, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (x0 + 4096 * (-64 + x1) + 131072 * x2), tmp9,
        other=0.0)
    tmp11 = tl.load(in_ptr2 + (-64 + x1), tmp9, eviction_policy=
        'evict_last', other=0.0)
    tmp12 = tmp10 + tmp11
    tmp13 = 0.0
    tmp14 = tmp12 > tmp13
    tmp15 = 0.2
    tmp16 = tmp12 * tmp15
    tmp17 = tl.where(tmp14, tmp12, tmp16)
    tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
    tmp19 = tl.where(tmp9, tmp17, tmp18)
    tmp20 = tmp0 >= tmp7
    tmp21 = tl.full([1], 128, tl.int64)
    tmp22 = tmp0 < tmp21
    tmp23 = tmp20 & tmp22
    tmp24 = tl.load(in_ptr3 + (x0 + 4096 * (-96 + x1) + 131072 * x2), tmp23,
        other=0.0)
    tmp25 = tl.load(in_ptr4 + (-96 + x1), tmp23, eviction_policy=
        'evict_last', other=0.0)
    tmp26 = tmp24 + tmp25
    tmp27 = tmp26 > tmp13
    tmp28 = tmp26 * tmp15
    tmp29 = tl.where(tmp27, tmp26, tmp28)
    tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype)
    tmp31 = tl.where(tmp23, tmp29, tmp30)
    tmp32 = tmp0 >= tmp21
    tl.full([1], 160, tl.int64)
    tmp35 = tl.load(in_ptr5 + (x0 + 4096 * (-128 + x1) + 131072 * x2),
        tmp32, other=0.0)
    tmp36 = tl.load(in_ptr6 + (-128 + x1), tmp32, eviction_policy=
        'evict_last', other=0.0)
    tmp37 = tmp35 + tmp36
    tmp38 = tmp37 > tmp13
    tmp39 = tmp37 * tmp15
    tmp40 = tl.where(tmp38, tmp37, tmp39)
    tmp41 = tl.full(tmp40.shape, 0.0, tmp40.dtype)
    tmp42 = tl.where(tmp32, tmp40, tmp41)
    tmp43 = tl.where(tmp23, tmp31, tmp42)
    tmp44 = tl.where(tmp9, tmp19, tmp43)
    tmp45 = tl.where(tmp4, tmp5, tmp44)
    tl.store(out_ptr0 + x3, tmp45, None)


@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, in_ptr6, in_ptr7, in_ptr8, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 4096 % 192
    x0 = xindex % 4096
    x2 = xindex // 786432
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 64, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 262144 * x2), tmp4, other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 96, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (x0 + 4096 * (-64 + x1) + 131072 * x2), tmp9,
        other=0.0)
    tmp11 = tl.load(in_ptr2 + (-64 + x1), tmp9, eviction_policy=
        'evict_last', other=0.0)
    tmp12 = tmp10 + tmp11
    tmp13 = 0.0
    tmp14 = tmp12 > tmp13
    tmp15 = 0.2
    tmp16 = tmp12 * tmp15
    tmp17 = tl.where(tmp14, tmp12, tmp16)
    tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
    tmp19 = tl.where(tmp9, tmp17, tmp18)
    tmp20 = tmp0 >= tmp7
    tmp21 = tl.full([1], 128, tl.int64)
    tmp22 = tmp0 < tmp21
    tmp23 = tmp20 & tmp22
    tmp24 = tl.load(in_ptr3 + (x0 + 4096 * (-96 + x1) + 131072 * x2), tmp23,
        other=0.0)
    tmp25 = tl.load(in_ptr4 + (-96 + x1), tmp23, eviction_policy=
        'evict_last', other=0.0)
    tmp26 = tmp24 + tmp25
    tmp27 = tmp26 > tmp13
    tmp28 = tmp26 * tmp15
    tmp29 = tl.where(tmp27, tmp26, tmp28)
    tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype)
    tmp31 = tl.where(tmp23, tmp29, tmp30)
    tmp32 = tmp0 >= tmp21
    tmp33 = tl.full([1], 160, tl.int64)
    tmp34 = tmp0 < tmp33
    tmp35 = tmp32 & tmp34
    tmp36 = tl.load(in_ptr5 + (x0 + 4096 * (-128 + x1) + 131072 * x2),
        tmp35, other=0.0)
    tmp37 = tl.load(in_ptr6 + (-128 + x1), tmp35, eviction_policy=
        'evict_last', other=0.0)
    tmp38 = tmp36 + tmp37
    tmp39 = tmp38 > tmp13
    tmp40 = tmp38 * tmp15
    tmp41 = tl.where(tmp39, tmp38, tmp40)
    tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype)
    tmp43 = tl.where(tmp35, tmp41, tmp42)
    tmp44 = tmp0 >= tmp33
    tl.full([1], 192, tl.int64)
    tmp47 = tl.load(in_ptr7 + (x0 + 4096 * (-160 + x1) + 131072 * x2),
        tmp44, other=0.0)
    tmp48 = tl.load(in_ptr8 + (-160 + x1), tmp44, eviction_policy=
        'evict_last', other=0.0)
    tmp49 = tmp47 + tmp48
    tmp50 = tmp49 > tmp13
    tmp51 = tmp49 * tmp15
    tmp52 = tl.where(tmp50, tmp49, tmp51)
    tmp53 = tl.full(tmp52.shape, 0.0, tmp52.dtype)
    tmp54 = tl.where(tmp44, tmp52, tmp53)
    tmp55 = tl.where(tmp35, tmp43, tmp54)
    tmp56 = tl.where(tmp23, tmp31, tmp55)
    tmp57 = tl.where(tmp9, tmp19, tmp56)
    tmp58 = tl.where(tmp4, tmp5, tmp57)
    tl.store(out_ptr0 + x3, tmp58, None)


@triton.jit
def triton_poi_fused_add_convolution_mul_4(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)
    x3 = xindex
    x1 = xindex // 4096 % 64
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + x3, None)
    tmp2 = tmp0 + tmp1
    tmp3 = 0.2
    tmp4 = tmp2 * tmp3
    tmp6 = tmp4 + tmp5
    tl.store(in_out_ptr0 + x3, tmp6, None)


@triton.jit
def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 4096 % 32
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.2
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tmp8 = tmp7 > tmp3
    tl.store(out_ptr0 + x3, tmp8, 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) = args
    args.clear()
    assert_size_stride(primals_1, (32, 64, 3, 3), (576, 9, 3, 1))
    assert_size_stride(primals_2, (32,), (1,))
    assert_size_stride(primals_3, (4, 64, 64, 64), (262144, 4096, 64, 1))
    assert_size_stride(primals_4, (32, 96, 3, 3), (864, 9, 3, 1))
    assert_size_stride(primals_5, (32,), (1,))
    assert_size_stride(primals_6, (32, 128, 3, 3), (1152, 9, 3, 1))
    assert_size_stride(primals_7, (32,), (1,))
    assert_size_stride(primals_8, (32, 160, 3, 3), (1440, 9, 3, 1))
    assert_size_stride(primals_9, (32,), (1,))
    assert_size_stride(primals_10, (64, 192, 3, 3), (1728, 9, 3, 1))
    assert_size_stride(primals_11, (64,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 32, 64, 64), (131072, 4096, 64, 1))
        buf1 = empty_strided_cuda((4, 96, 64, 64), (393216, 4096, 64, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(1572864)](primals_3, buf0, primals_2,
            buf1, 1572864, XBLOCK=1024, num_warps=4, num_stages=1)
        buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 32, 64, 64), (131072, 4096, 64, 1))
        buf3 = empty_strided_cuda((4, 128, 64, 64), (524288, 4096, 64, 1),
            torch.float32)
        triton_poi_fused_cat_1[grid(2097152)](primals_3, buf0, primals_2,
            buf2, primals_5, buf3, 2097152, XBLOCK=1024, num_warps=4,
            num_stages=1)
        buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 32, 64, 64), (131072, 4096, 64, 1))
        buf5 = empty_strided_cuda((4, 160, 64, 64), (655360, 4096, 64, 1),
            torch.float32)
        triton_poi_fused_cat_2[grid(2621440)](primals_3, buf0, primals_2,
            buf2, primals_5, buf4, primals_7, buf5, 2621440, XBLOCK=1024,
            num_warps=4, num_stages=1)
        buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 32, 64, 64), (131072, 4096, 64, 1))
        buf7 = empty_strided_cuda((4, 192, 64, 64), (786432, 4096, 64, 1),
            torch.float32)
        triton_poi_fused_cat_3[grid(3145728)](primals_3, buf0, primals_2,
            buf2, primals_5, buf4, primals_7, buf6, primals_9, buf7, 
            3145728, XBLOCK=512, num_warps=8, num_stages=1)
        buf8 = extern_kernels.convolution(buf7, primals_10, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 64, 64, 64), (262144, 4096, 64, 1))
        buf9 = buf8
        del buf8
        triton_poi_fused_add_convolution_mul_4[grid(1048576)](buf9,
            primals_11, primals_3, 1048576, XBLOCK=1024, num_warps=4,
            num_stages=1)
        del primals_11
        buf10 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
            torch.bool)
        triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5[grid(
            524288)](buf6, primals_9, buf10, 524288, XBLOCK=1024, num_warps
            =4, num_stages=1)
        del buf6
        del primals_9
        buf11 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
            torch.bool)
        triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5[grid(
            524288)](buf4, primals_7, buf11, 524288, XBLOCK=1024, num_warps
            =4, num_stages=1)
        del buf4
        del primals_7
        buf12 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
            torch.bool)
        triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5[grid(
            524288)](buf2, primals_5, buf12, 524288, XBLOCK=1024, num_warps
            =4, num_stages=1)
        del buf2
        del primals_5
        buf13 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
            torch.bool)
        triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5[grid(
            524288)](buf0, primals_2, buf13, 524288, XBLOCK=1024, num_warps
            =4, num_stages=1)
        del buf0
        del primals_2
    return (buf9, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, buf1, buf3, buf5, buf7, buf10, buf11, buf12, buf13)


@torch.no_grad()
def default_init_weights(module_list, scale=1, bias_fill=0, **kwargs):
    """Initialize network weights.

    Args:
        module_list (list[nn.Module] | nn.Module): Modules to be initialized.
        scale (float): Scale initialized weights, especially for residual
            blocks. Default: 1.
        bias_fill (float): The value to fill bias. Default: 0
        kwargs (dict): Other arguments for initialization function.
    """
    if not isinstance(module_list, list):
        module_list = [module_list]
    for module in module_list:
        for m in module.modules():
            if isinstance(m, nn.Conv2d):
                init.kaiming_normal_(m.weight, **kwargs)
                m.weight.data *= scale
                if m.bias is not None:
                    m.bias.data.fill_(bias_fill)
            elif isinstance(m, nn.Linear):
                init.kaiming_normal_(m.weight, **kwargs)
                m.weight.data *= scale
                if m.bias is not None:
                    m.bias.data.fill_(bias_fill)
            elif isinstance(m, _BatchNorm):
                init.constant_(m.weight, 1)
                if m.bias is not None:
                    m.bias.data.fill_(bias_fill)


class ResidualDenseBlockNew(nn.Module):
    """Residual Dense Block.

    Used in RRDB block in ESRGAN.

    Args:
        num_feat (int): Channel number of intermediate features.
        num_grow_ch (int): Channels for each growth.
    """

    def __init__(self, num_feat=64, num_grow_ch=32):
        super(ResidualDenseBlockNew, self).__init__()
        self.conv1 = nn.Conv2d(num_feat, num_grow_ch, 3, 1, 1)
        self.conv2 = nn.Conv2d(num_feat + num_grow_ch, num_grow_ch, 3, 1, 1)
        self.conv3 = nn.Conv2d(num_feat + 2 * num_grow_ch, num_grow_ch, 3, 1, 1
            )
        self.conv4 = nn.Conv2d(num_feat + 3 * num_grow_ch, num_grow_ch, 3, 1, 1
            )
        self.conv5 = nn.Conv2d(num_feat + 4 * num_grow_ch, num_feat, 3, 1, 1)
        self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
        default_init_weights([self.conv1, self.conv2, self.conv3, self.
            conv4, self.conv5], 0.1)

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = 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_3 = 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])
        return output[0]


Measured latency_ms: 0.015288