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 torch import 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_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
    tl.constexpr):
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), None)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.sum(tmp1, 1)[:, None]
    tmp4 = 16.0
    tmp5 = tmp3 / tmp4
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp5, None)


@triton.jit
def triton_poi_fused__to_copy_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.25
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp9, xmask)


@triton.jit
def triton_poi_fused_add_clamp_2(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.25
    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], 0, tl.int64)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tl.store(out_ptr0 + x0, tmp13, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3(out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.25
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 - tmp10
    tmp12 = triton_helpers.maximum(tmp11, tmp7)
    tmp13 = 1.0
    tmp14 = triton_helpers.minimum(tmp12, tmp13)
    tl.store(out_ptr0 + x0, tmp14, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_add_convolution_mul_sub_4(in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, 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 // 4 % 4
    x0 = xindex % 4
    x5 = xindex // 16
    x2 = xindex // 16 % 256
    x6 = xindex
    tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + x5, None, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 1, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tl.where(tmp3, tmp2, tmp0)
    tmp6 = tmp5 + tmp1
    tmp7 = tmp5 < 0
    tl.where(tmp7, tmp6, tmp5)
    tmp11 = tmp9 + tmp10
    tmp13 = tmp12 + tmp1
    tmp14 = tmp12 < 0
    tl.where(tmp14, tmp13, tmp12)
    tmp16 = tmp11 - tmp11
    tmp18 = tmp16 * tmp17
    tmp19 = tmp11 + tmp18
    tl.store(out_ptr0 + x6, tmp19, None)


@triton.jit
def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11,
    in_ptr12, in_ptr13, in_ptr14, in_ptr15, out_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 // 16 % 1280
    x3 = xindex // 20480
    x4 = xindex % 16
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x5 = xindex
    tmp0 = x2
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 256, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x4 + 16 * x2 + 4096 * x3), tmp4, other=0.0)
    tmp6 = tl.load(in_ptr1 + x1, tmp4, eviction_policy='evict_last', other=0.0)
    tmp7 = tl.full([XBLOCK], 1, tl.int32)
    tmp8 = tmp6 + tmp7
    tmp9 = tmp6 < 0
    tl.where(tmp9, tmp8, tmp6)
    tmp11 = tl.load(in_ptr2 + x0, tmp4, eviction_policy='evict_last', other=0.0
        )
    tmp12 = tmp11 + tmp7
    tmp13 = tmp11 < 0
    tl.where(tmp13, tmp12, tmp11)
    tmp15 = tl.load(in_ptr3 + (256 * x3 + x2), tmp4, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tl.load(in_ptr4 + x2, tmp4, eviction_policy='evict_last', other=0.0
        )
    tmp17 = tmp15 + tmp16
    tmp18 = tl.load(in_ptr5 + x0, tmp4, eviction_policy='evict_last', other=0.0
        )
    tmp19 = tmp18 + tmp7
    tmp20 = tmp18 < 0
    tl.where(tmp20, tmp19, tmp18)
    tmp22 = tmp17 - tmp17
    tmp23 = tl.load(in_ptr6 + x0, tmp4, eviction_policy='evict_last', other=0.0
        )
    tmp24 = tmp22 * tmp23
    tmp25 = tmp17 + tmp24
    tmp26 = tmp25 - tmp5
    tmp27 = tl.load(in_ptr7 + x1, tmp4, eviction_policy='evict_last', other=0.0
        )
    tmp28 = tmp26 * tmp27
    tmp29 = tmp5 + tmp28
    tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype)
    tmp31 = tl.where(tmp4, tmp29, tmp30)
    tmp32 = tmp0 >= tmp3
    tmp33 = tl.full([1], 512, tl.int64)
    tmp34 = tmp0 < tmp33
    tmp35 = tmp32 & tmp34
    tmp36 = tl.load(in_ptr8 + (x4 + 16 * (-256 + x2) + 4096 * x3), tmp35,
        other=0.0)
    tmp37 = tl.load(in_ptr9 + (-256 + x2), tmp35, eviction_policy=
        'evict_last', other=0.0)
    tmp38 = tmp36 + tmp37
    tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype)
    tmp40 = tl.where(tmp35, tmp38, tmp39)
    tmp41 = tmp0 >= tmp33
    tmp42 = tl.full([1], 768, tl.int64)
    tmp43 = tmp0 < tmp42
    tmp44 = tmp41 & tmp43
    tmp45 = tl.load(in_ptr10 + (x4 + 16 * (-512 + x2) + 4096 * x3), tmp44,
        other=0.0)
    tmp46 = tl.load(in_ptr11 + (-512 + x2), tmp44, eviction_policy=
        'evict_last', other=0.0)
    tmp47 = tmp45 + tmp46
    tmp48 = tl.full(tmp47.shape, 0.0, tmp47.dtype)
    tmp49 = tl.where(tmp44, tmp47, tmp48)
    tmp50 = tmp0 >= tmp42
    tmp51 = tl.full([1], 1024, tl.int64)
    tmp52 = tmp0 < tmp51
    tmp53 = tmp50 & tmp52
    tmp54 = tl.load(in_ptr12 + (x4 + 16 * (-768 + x2) + 4096 * x3), tmp53,
        other=0.0)
    tmp55 = tl.load(in_ptr13 + (-768 + x2), tmp53, eviction_policy=
        'evict_last', other=0.0)
    tmp56 = tmp54 + tmp55
    tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype)
    tmp58 = tl.where(tmp53, tmp56, tmp57)
    tmp59 = tmp0 >= tmp51
    tl.full([1], 1280, tl.int64)
    tmp62 = tl.load(in_ptr14 + (x4 + 16 * (-1024 + x2) + 4096 * x3), tmp59,
        other=0.0)
    tmp63 = tl.load(in_ptr15 + (-1024 + x2), tmp59, eviction_policy=
        'evict_last', other=0.0)
    tmp64 = tmp62 + tmp63
    tmp65 = tl.full(tmp64.shape, 0.0, tmp64.dtype)
    tmp66 = tl.where(tmp59, tmp64, tmp65)
    tmp67 = tl.where(tmp53, tmp58, tmp66)
    tmp68 = tl.where(tmp44, tmp49, tmp67)
    tmp69 = tl.where(tmp35, tmp40, tmp68)
    tmp70 = tl.where(tmp4, tmp31, tmp69)
    tl.store(out_ptr0 + x5, tmp70, None)


@triton.jit
def triton_poi_fused_convolution_6(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)
    x3 = xindex
    x1 = xindex // 16 % 256
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, 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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 512, 4, 4), (8192, 16, 4, 1))
    assert_size_stride(primals_2, (256, 512, 1, 1), (512, 1, 1, 1))
    assert_size_stride(primals_3, (256,), (1,))
    assert_size_stride(primals_4, (256, 512, 1, 1), (512, 1, 1, 1))
    assert_size_stride(primals_5, (256,), (1,))
    assert_size_stride(primals_6, (256, 512, 3, 3), (4608, 9, 3, 1))
    assert_size_stride(primals_7, (256,), (1,))
    assert_size_stride(primals_8, (256, 512, 3, 3), (4608, 9, 3, 1))
    assert_size_stride(primals_9, (256,), (1,))
    assert_size_stride(primals_10, (256, 512, 3, 3), (4608, 9, 3, 1))
    assert_size_stride(primals_11, (256,), (1,))
    assert_size_stride(primals_12, (256, 1280, 1, 1), (1280, 1, 1, 1))
    assert_size_stride(primals_13, (256,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 512, 1, 1), (512, 1, 2048, 2048),
            torch.float32)
        buf1 = reinterpret_tensor(buf0, (4, 512, 1, 1), (512, 1, 1, 1), 0)
        del buf0
        get_raw_stream(0)
        triton_per_fused_mean_0[grid(2048)](buf1, primals_1, 2048, 16,
            XBLOCK=128, num_warps=8, num_stages=1)
        buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 256, 1, 1), (256, 1, 1, 1))
        buf3 = empty_strided_cuda((4, 1), (1, 1), torch.int64)
        triton_poi_fused__to_copy_1[grid(4)](buf3, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf4 = empty_strided_cuda((4, 1), (1, 1), torch.int64)
        triton_poi_fused_add_clamp_2[grid(4)](buf4, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf5 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused__to_copy_1[grid(4)](buf5, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf6 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused_add_clamp_2[grid(4)](buf6, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf7 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3[grid(4)](buf7,
            4, XBLOCK=4, num_warps=1, num_stages=1)
        buf8 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.
            float32)
        triton_poi_fused__unsafe_index_add_convolution_mul_sub_4[grid(16384)](
            buf3, buf5, buf2, primals_3, buf6, buf7, buf8, 16384, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf9 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3[grid(4)](buf9,
            4, XBLOCK=4, num_warps=1, num_stages=1)
        buf10 = extern_kernels.convolution(primals_1, primals_4, stride=(1,
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 256, 4, 4), (4096, 16, 4, 1))
        buf11 = extern_kernels.convolution(primals_1, primals_6, stride=(1,
            1), padding=(6, 6), dilation=(6, 6), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf11, (4, 256, 4, 4), (4096, 16, 4, 1))
        buf12 = extern_kernels.convolution(primals_1, primals_8, stride=(1,
            1), padding=(12, 12), dilation=(12, 12), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 256, 4, 4), (4096, 16, 4, 1))
        buf13 = extern_kernels.convolution(primals_1, primals_10, stride=(1,
            1), padding=(18, 18), dilation=(18, 18), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf13, (4, 256, 4, 4), (4096, 16, 4, 1))
        buf14 = empty_strided_cuda((4, 1280, 4, 4), (20480, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_5[grid(81920)](buf8, buf4, buf5, buf2,
            primals_3, buf6, buf7, buf9, buf10, primals_5, buf11, primals_7,
            buf12, primals_9, buf13, primals_11, buf14, 81920, XBLOCK=512,
            num_warps=8, num_stages=1)
        del buf10
        del buf11
        del buf12
        del buf13
        del buf2
        del buf8
        del primals_11
        del primals_3
        del primals_5
        del primals_7
        del primals_9
        buf15 = extern_kernels.convolution(buf14, primals_12, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf15, (4, 256, 4, 4), (4096, 16, 4, 1))
        buf16 = buf15
        del buf15
        triton_poi_fused_convolution_6[grid(16384)](buf16, primals_13, 
            16384, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_13
    return (buf16, primals_1, primals_2, primals_4, primals_6, primals_8,
        primals_10, primals_12, buf1, buf3, buf4, buf5, buf6, buf7, buf9, buf14
        )


class ASPPNew(nn.Module):
    """
    Atrous spatial pyramid pooling used in object detection and segmentation.
    """

    def __init__(self, in_channel=512, depth=256):
        super().__init__()
        self.mean = nn.AdaptiveAvgPool2d((1, 1))
        self.conv = nn.Conv2d(in_channel, depth, 1, 1)
        self.atrous_block1 = nn.Conv2d(in_channel, depth, 1, 1)
        self.atrous_block6 = nn.Conv2d(in_channel, depth, 3, 1, padding=6,
            dilation=6)
        self.atrous_block12 = nn.Conv2d(in_channel, depth, 3, 1, padding=12,
            dilation=12)
        self.atrous_block18 = nn.Conv2d(in_channel, depth, 3, 1, padding=18,
            dilation=18)
        self.conv_1x1_output = nn.Conv2d(depth * 5, depth, 1, 1)

    def forward(self, input_0):
        primals_2 = self.conv.weight
        primals_3 = self.conv.bias
        primals_4 = self.atrous_block1.weight
        primals_5 = self.atrous_block1.bias
        primals_6 = self.atrous_block6.weight
        primals_7 = self.atrous_block6.bias
        primals_8 = self.atrous_block12.weight
        primals_9 = self.atrous_block12.bias
        primals_10 = self.atrous_block18.weight
        primals_11 = self.atrous_block18.bias
        primals_12 = self.conv_1x1_output.weight
        primals_13 = self.conv_1x1_output.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])
        return output[0]


Measured latency_ms: 0.033465