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.nn as 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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
    out_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_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.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x3, tmp4, None)
    tl.store(out_ptr1 + x3, tmp7, None)


@triton.jit
def triton_poi_fused_convolution_1(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 // 4096 % 64
    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) = args
    args.clear()
    assert_size_stride(primals_1, (64, 16, 3, 3), (144, 9, 3, 1))
    assert_size_stride(primals_2, (64,), (1,))
    assert_size_stride(primals_3, (4, 16, 64, 64), (65536, 4096, 64, 1))
    assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1))
    assert_size_stride(primals_5, (64,), (1,))
    assert_size_stride(primals_6, (64, 64, 3, 3), (576, 9, 3, 1))
    assert_size_stride(primals_7, (64,), (1,))
    assert_size_stride(primals_8, (64, 64, 3, 3), (576, 9, 3, 1))
    assert_size_stride(primals_9, (64,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1))
        buf1 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
            torch.bool)
        buf2 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf0,
            primals_2, buf1, buf2, 1048576, XBLOCK=1024, num_warps=4,
            num_stages=1)
        del primals_2
        buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 64, 64, 64), (262144, 4096, 64, 1))
        buf4 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
            torch.bool)
        buf5 = buf0
        del buf0
        triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf3,
            primals_5, buf4, buf5, 1048576, XBLOCK=1024, num_warps=4,
            num_stages=1)
        del primals_5
        buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 64, 64, 64), (262144, 4096, 64, 1))
        buf7 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
            torch.bool)
        buf8 = buf3
        del buf3
        triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf6,
            primals_7, buf7, buf8, 1048576, XBLOCK=1024, num_warps=4,
            num_stages=1)
        del buf6
        del primals_7
        buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 64, 64, 64), (262144, 4096, 64, 1))
        buf10 = buf9
        del buf9
        triton_poi_fused_convolution_1[grid(1048576)](buf10, primals_9, 
            1048576, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_9
    return (buf10, primals_1, primals_3, primals_4, primals_6, primals_8,
        buf1, buf2, buf4, buf5, buf7, buf8)


class MidNet2New(nn.Module):

    def __init__(self, in_channels=16):
        """FIXME! briefly describe function

        :param in_channels: Input channels
        :returns: N/A
        :rtype: N/A

        """
        super(MidNet2New, self).__init__()
        self.lrelu = nn.LeakyReLU()
        self.conv1 = nn.Conv2d(in_channels, 64, 3, 1, 2, 2)
        self.conv2 = nn.Conv2d(64, 64, 3, 1, 2, 2)
        self.conv3 = nn.Conv2d(64, 64, 3, 1, 2, 2)
        self.conv4 = nn.Conv2d(64, 64, 3, 1, 2, 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_6 = self.conv3.weight
        primals_7 = self.conv3.bias
        primals_8 = self.conv4.weight
        primals_9 = self.conv4.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])
        return output[0]


Measured latency_ms: 0.024974