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.nn.functional as F
from torch.nn import init as init
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):
    ynumel = 16
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask)
    tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 9
    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 % 128
    y1 = yindex // 128
    tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
        )
    tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_relu_2(in_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_out_ptr0 + x0, None)
    tmp1 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tl.store(in_out_ptr0 + x0, tmp2, None)


@triton.jit
def triton_poi_fused_add_relu_threshold_backward_3(in_ptr0, in_ptr1,
    out_ptr0, out_ptr1, out_ptr2, ynumel, xnumel, YBLOCK: tl.constexpr,
    XBLOCK: tl.constexpr):
    ynumel = 64
    xnumel = 256
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 16
    y1 = yindex // 16
    tmp0 = tl.load(in_ptr0 + (x2 + 256 * y3), xmask & ymask,
        eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + (x2 + 256 * y3), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.full([1, 1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp1, tmp3)
    tmp5 = tmp2 + tmp4
    tmp6 = 0.0
    tmp7 = tmp4 <= tmp6
    tmp8 = tmp2 <= tmp6
    tl.store(out_ptr0 + (y0 + 16 * x2 + 4096 * y1), tmp5, xmask & ymask)
    tl.store(out_ptr1 + (x2 + 256 * y3), tmp7, xmask & ymask)
    tl.store(out_ptr2 + (x2 + 256 * y3), tmp8, xmask & ymask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (128, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (128, 128, 3, 3), (1152, 9, 3, 1))
    assert_size_stride(primals_4, (256, 128, 1, 1), (128, 1, 1, 1))
    assert_size_stride(primals_5, (256, 4, 1, 1), (4, 1, 1, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(16, 16)](primals_2, buf0, 16, 16, XBLOCK=16,
            YBLOCK=16, num_warps=4, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128),
            torch.float32)
        triton_poi_fused_1[grid(16384, 9)](primals_3, buf1, 16384, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_3
        buf2 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 128, 4, 4), (2048, 1, 512, 128))
        buf3 = buf2
        del buf2
        triton_poi_fused_relu_2[grid(8192)](buf3, 8192, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf4 = extern_kernels.convolution(buf3, buf1, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 128, 4, 4), (2048, 1, 512, 128))
        buf5 = buf4
        del buf4
        triton_poi_fused_relu_2[grid(8192)](buf5, 8192, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf6 = extern_kernels.convolution(buf5, primals_4, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 256, 4, 4), (4096, 1, 1024, 256))
        buf7 = extern_kernels.convolution(buf0, primals_5, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 256, 4, 4), (4096, 1, 1024, 256))
        buf8 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.
            float32)
        buf9 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256),
            torch.bool)
        buf10 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256),
            torch.bool)
        triton_poi_fused_add_relu_threshold_backward_3[grid(64, 256)](buf6,
            buf7, buf8, buf9, buf10, 64, 256, XBLOCK=32, YBLOCK=32,
            num_warps=4, num_stages=1)
        del buf6
        del buf7
    return (buf8, primals_1, buf0, buf1, primals_4, primals_5, buf3, buf5,
        buf9, buf10)


class conv_relu(nn.Module):
    """docstring for conv_relu"""

    def __init__(self, in_channels, out_channels, **kwargs):
        super(conv_relu, self).__init__()
        self.conv = nn.Conv2d(in_channels, out_channels, bias=False, **kwargs)

    def forward(self, x):
        out = F.relu(self.conv(x), inplace=True)
        return out


class ResBlockNew(nn.Module):
    """docstring for ResBlock"""

    def __init__(self, in_channels):
        super(ResBlockNew, self).__init__()
        self.res1a = conv_relu(in_channels, 128, kernel_size=1)
        self.res1b = conv_relu(128, 128, kernel_size=3, padding=1)
        self.res1c = conv_relu(128, 256, kernel_size=1)
        self.res2a = conv_relu(in_channels, 256, kernel_size=1)

    def forward(self, input_0):
        primals_1 = self.res1a.conv.weight
        primals_3 = self.res1b.conv.weight
        primals_4 = self.res1c.conv.weight
        primals_5 = self.res2a.conv.weight
        primals_2 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.120737