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
import torch.utils.data
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 16
    yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(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 % 512
    y1 = yindex // 512
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 512 * x2 + 8192 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 36
    yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(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 % 512
    y1 = yindex // 512
    tmp0 = tl.load(in_ptr0 + (x2 + 36 * y3), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 512 * x2 + 18432 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, ynumel,
    xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    xnumel = 4
    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 % 2
    x3 = xindex // 2
    y4 = yindex
    x5 = xindex
    y0 = yindex % 512
    y1 = yindex // 512
    tmp0 = tl.load(in_ptr0 + (2 * x2 + 8 * x3 + 16 * y4), xmask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x2 + 8 * x3 + 16 * y4), xmask,
        eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (4 + 2 * x2 + 8 * x3 + 16 * y4), xmask,
        eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (5 + 2 * x2 + 8 * x3 + 16 * y4), xmask,
        eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tl.store(out_ptr0 + (y0 + 512 * x5 + 2048 * y1), tmp6, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, 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_ptr0 + 16 * x0, None, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), None, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), None, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), None, eviction_policy='evict_last'
        )
    tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), None, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), None, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), None, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), None, eviction_policy=
        'evict_last')
    tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), None, eviction_policy=
        'evict_last')
    tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), None, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), None, eviction_policy=
        'evict_last')
    tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), None, eviction_policy=
        'evict_last')
    tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), None, eviction_policy=
        'evict_last')
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tmp8 = triton_helpers.maximum(tmp7, tmp6)
    tmp10 = triton_helpers.maximum(tmp9, tmp8)
    tmp12 = triton_helpers.maximum(tmp11, tmp10)
    tmp14 = triton_helpers.maximum(tmp13, tmp12)
    tmp16 = triton_helpers.maximum(tmp15, tmp14)
    tmp18 = triton_helpers.maximum(tmp17, tmp16)
    tmp20 = triton_helpers.maximum(tmp19, tmp18)
    tmp22 = triton_helpers.maximum(tmp21, tmp20)
    tmp24 = triton_helpers.maximum(tmp23, tmp22)
    tmp26 = triton_helpers.maximum(tmp25, tmp24)
    tmp28 = triton_helpers.maximum(tmp27, tmp26)
    tmp30 = triton_helpers.maximum(tmp29, tmp28)
    tl.store(out_ptr0 + x0, tmp30, None)


@triton.jit
def triton_poi_fused_add_convolution_max_pool2d_with_indices_4(in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, ynumel, xnumel, YBLOCK:
    tl.constexpr, XBLOCK: tl.constexpr):
    xnumel = 16
    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 % 512
    y1 = yindex // 512
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr1 + (y0 + 512 * x2 + 8192 * y1), xmask,
        eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + y0, None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr3 + (y0 + 512 * x2 + 8192 * y1), xmask,
        eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr4 + y0, None, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 + tmp3
    tmp7 = tmp5 + tmp6
    tmp8 = tmp4 + tmp7
    tl.store(out_ptr0 + (x2 + 16 * y3), tmp8, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 512, 4, 4), (8192, 16, 4, 1))
    assert_size_stride(primals_2, (512, 512, 4, 4), (8192, 16, 4, 1))
    assert_size_stride(primals_3, (512,), (1,))
    assert_size_stride(primals_4, (512, 512, 6, 6), (18432, 36, 6, 1))
    assert_size_stride(primals_5, (512,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((512, 512, 4, 4), (8192, 1, 2048, 512),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(262144, 16)](primals_2, buf0, 262144, 16,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((512, 512, 6, 6), (18432, 1, 3072, 512),
            torch.float32)
        triton_poi_fused_1[grid(262144, 36)](primals_4, buf1, 262144, 36,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_4
        buf2 = empty_strided_cuda((4, 512, 2, 2), (2048, 1, 1024, 512),
            torch.float32)
        triton_poi_fused_max_pool2d_with_indices_2[grid(2048, 4)](primals_1,
            buf2, 2048, 4, XBLOCK=4, YBLOCK=256, num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((4, 512, 1, 1), (512, 1, 512, 512), torch
            .float32)
        triton_poi_fused_max_pool2d_with_indices_3[grid(2048)](primals_1,
            buf3, 2048, XBLOCK=128, num_warps=4, num_stages=1)
        buf4 = extern_kernels.convolution(buf2, buf0, stride=(2, 2),
            padding=(1, 1), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 512, 4, 4), (8192, 1, 2048, 512))
        buf5 = extern_kernels.convolution(buf3, buf1, stride=(4, 4),
            padding=(1, 1), dilation=(1, 1), transposed=True,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 512, 4, 4), (8192, 1, 2048, 512))
        buf6 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.
            float32)
        triton_poi_fused_add_convolution_max_pool2d_with_indices_4[grid(
            2048, 16)](primals_1, buf4, primals_3, buf5, primals_5, buf6, 
            2048, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
        del buf4
        del buf5
        del primals_1
        del primals_3
        del primals_5
    return buf6, buf0, buf1, buf2, buf3


class R2CNNattetionNew(nn.Module):

    def __init__(self):
        super(R2CNNattetionNew, self).__init__()
        self.pool1 = nn.MaxPool2d(kernel_size=1)
        self.pool2 = nn.MaxPool2d(kernel_size=2)
        self.pool3 = nn.MaxPool2d(kernel_size=4)
        self.deconv2 = nn.ConvTranspose2d(512, 512, kernel_size=(4, 4),
            stride=(2, 2), padding=(1, 1))
        self.deconv3 = nn.ConvTranspose2d(512, 512, kernel_size=(6, 6),
            stride=(4, 4), padding=(1, 1))

    def forward(self, input_0):
        primals_2 = self.deconv2.weight
        primals_3 = self.deconv2.bias
        primals_4 = self.deconv3.weight
        primals_5 = self.deconv3.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.420902