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


@triton.jit
def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 288000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 3600 % 20
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_relu_1(in_ptr0, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 72000
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 30
    x3 = xindex // 30
    x2 = xindex // 18000
    x4 = xindex % 18000
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (2 * x0 + 120 * x3), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 120 * x3), xmask,
        eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (60 + 2 * x0 + 120 * x3), xmask,
        eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (61 + 2 * x0 + 120 * x3), xmask,
        eviction_policy='evict_last')
    tmp2 = tmp1 > tmp0
    tmp3 = tl.full([1], 1, tl.int8)
    tmp4 = tl.full([1], 0, tl.int8)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp6 = triton_helpers.maximum(tmp1, tmp0)
    tmp8 = tmp7 > tmp6
    tmp9 = tl.full([1], 2, tl.int8)
    tmp10 = tl.where(tmp8, tmp9, tmp5)
    tmp11 = triton_helpers.maximum(tmp7, tmp6)
    tmp13 = tmp12 > tmp11
    tmp14 = tl.full([1], 3, tl.int8)
    tmp15 = tl.where(tmp13, tmp14, tmp10)
    tmp16 = triton_helpers.maximum(tmp12, tmp11)
    tmp17 = tl.full([1], 0, tl.int32)
    tmp18 = triton_helpers.maximum(tmp17, tmp16)
    tl.store(out_ptr0 + (x4 + 18048 * x2), tmp15, xmask)
    tl.store(out_ptr1 + x5, tmp18, xmask)


@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 135200
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 676 % 50
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_relu_threshold_backward_3(in_ptr0,
    out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 33800
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 13
    x3 = xindex // 13
    x2 = xindex // 8450
    x4 = xindex % 8450
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (2 * x0 + 52 * x3), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 52 * x3), xmask, eviction_policy
        ='evict_last')
    tmp7 = tl.load(in_ptr0 + (26 + 2 * x0 + 52 * x3), xmask,
        eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (27 + 2 * x0 + 52 * x3), xmask,
        eviction_policy='evict_last')
    tmp2 = tmp1 > tmp0
    tmp3 = tl.full([1], 1, tl.int8)
    tmp4 = tl.full([1], 0, tl.int8)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp6 = triton_helpers.maximum(tmp1, tmp0)
    tmp8 = tmp7 > tmp6
    tmp9 = tl.full([1], 2, tl.int8)
    tmp10 = tl.where(tmp8, tmp9, tmp5)
    tmp11 = triton_helpers.maximum(tmp7, tmp6)
    tmp13 = tmp12 > tmp11
    tmp14 = tl.full([1], 3, tl.int8)
    tmp15 = tl.where(tmp13, tmp14, tmp10)
    tmp16 = triton_helpers.maximum(tmp12, tmp11)
    tmp17 = tl.full([1], 0, tl.int32)
    tmp18 = triton_helpers.maximum(tmp17, tmp16)
    tmp19 = 0.0
    tmp20 = tmp18 <= tmp19
    tl.store(out_ptr0 + (x4 + 8576 * x2), tmp15, xmask)
    tl.store(out_ptr1 + x5, tmp18, xmask)
    tl.store(out_ptr2 + (x4 + 8576 * x2), tmp20, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (20, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(primals_2, (20,), (1,))
    assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
    assert_size_stride(primals_4, (50, 20, 5, 5), (500, 25, 5, 1))
    assert_size_stride(primals_5, (50,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 20, 60, 60), (72000, 3600, 60, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_0[grid(288000)](buf1, primals_2, 
            288000, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_2
        buf2 = empty_strided_cuda((4, 20, 30, 30), (18048, 900, 30, 1),
            torch.int8)
        buf3 = empty_strided_cuda((4, 20, 30, 30), (18000, 900, 30, 1),
            torch.float32)
        triton_poi_fused_max_pool2d_with_indices_relu_1[grid(72000)](buf1,
            buf2, buf3, 72000, XBLOCK=512, num_warps=8, num_stages=1)
        buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 50, 26, 26), (33800, 676, 26, 1))
        buf5 = buf4
        del buf4
        triton_poi_fused_convolution_2[grid(135200)](buf5, primals_5, 
            135200, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_5
        buf6 = empty_strided_cuda((4, 50, 13, 13), (8576, 169, 13, 1),
            torch.int8)
        buf7 = empty_strided_cuda((4, 50, 13, 13), (8450, 169, 13, 1),
            torch.float32)
        buf8 = empty_strided_cuda((4, 50, 13, 13), (8576, 169, 13, 1),
            torch.bool)
        triton_poi_fused_max_pool2d_with_indices_relu_threshold_backward_3[grid
            (33800)](buf5, buf6, buf7, buf8, 33800, XBLOCK=256, num_warps=4,
            num_stages=1)
    return (buf7, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5,
        buf6, buf8)


class SuccessorNew(nn.Module):
    """Successor successorEncoder model for ADDA."""

    def __init__(self):
        """Init Successor successorEncoder."""
        super(SuccessorNew, self).__init__()
        self.restored = False
        self.conv1 = nn.Conv2d(1, 20, kernel_size=5)
        self.pool1 = nn.MaxPool2d(kernel_size=2)
        self.conv2 = nn.Conv2d(20, 50, kernel_size=5)
        self.dropout2 = nn.Dropout2d()
        self.pool2 = nn.MaxPool2d(kernel_size=2)

    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_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.040673