import torch
import torch.nn as nn
import torch.nn.functional as F


class Conv2D(nn.Module):

    def __init__(self, in_channels, out_channels, kernel_size, same_padding
        =False, stride=1, relu=True, bn=False):
        super(Conv2D, self).__init__()
        padding = int((kernel_size - 1) / 2) if same_padding else 0
        self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
            stride, padding=padding)
        self.bn = nn.BatchNorm2d(out_channels, eps=0.001, momentum=0,
            affine=True) if bn else None
        self.relu = nn.ReLU(inplace=True) if relu else None

    def forward(self, x):
        x = self.conv(x)
        if self.bn is not None:
            x = self.bn(x)
        if self.relu is not None:
            x = self.relu(x)
        return x


class M3(nn.Module):

    def __init__(self, in_channels):
        super(M3, self).__init__()
        self.m3_ssh_3x3 = Conv2D(in_channels, 256, 3, True, 1, False)
        self.m3_ssh_dimred = Conv2D(in_channels, 128, 3, True, 1, True)
        self.m3_ssh_5x5 = Conv2D(128, 128, 3, True, 1, False)
        self.m3_ssh_7x7_1 = Conv2D(128, 128, 3, True, 1, True)
        self.m3_ssh_7x7 = Conv2D(128, 128, 3, True, 1, False)
        self.m3_ssh_cls_score = Conv2D(128 * 2 + 256, 4, 1, False, 1, False)
        self.m3_ssh_bbox_pred = Conv2D(128 * 2 + 256, 8, 1, False, 1, False)

    def forward(self, pool6):
        m3_ssh_3x3 = self.m3_ssh_3x3(pool6)
        m3_ssh_dimred = self.m3_ssh_dimred(pool6)
        m3_ssh_5x5 = self.m3_ssh_5x5(m3_ssh_dimred)
        m3_ssh_7x7_1 = self.m3_ssh_7x7_1(m3_ssh_dimred)
        m3_ssh_7x7 = self.m3_ssh_7x7(m3_ssh_7x7_1)
        m3_ssh_output = F.relu(torch.cat((m3_ssh_3x3, m3_ssh_5x5,
            m3_ssh_7x7), dim=1))
        m3_ssh_cls_score = self.m3_ssh_cls_score(m3_ssh_output)
        m3_ssh_bbox_pred = self.m3_ssh_bbox_pred(m3_ssh_output)
        return m3_ssh_cls_score, m3_ssh_bbox_pred


def get_inputs():
    return [torch.rand([4, 4, 4, 4])]


def get_init_inputs():
    return [[], {'in_channels': 4}]

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
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 = 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 % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
        )
    tl.store(out_ptr0 + (y0 + 4 * x2 + 36 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_1(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_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 512
    xnumel = 9
    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 + 9 * y3), xmask & ymask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 4 * x2 + 36 * y1), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_3(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_convolution_relu_4(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)
    x2 = xindex
    x0 = xindex % 128
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_cat_relu_5(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)
    x0 = xindex % 512
    x1 = xindex // 512
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 256, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (256 * x1 + x0), tmp4, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tmp11 = tl.full([1], 384, tl.int64)
    tmp12 = tmp0 < tmp11
    tmp13 = tmp10 & tmp12
    tmp14 = tl.load(in_ptr2 + (128 * x1 + (-256 + x0)), tmp13,
        eviction_policy='evict_last', other=0.0)
    tmp15 = tl.load(in_ptr3 + (-256 + x0), tmp13, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tmp14 + tmp15
    tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype)
    tmp18 = tl.where(tmp13, tmp16, tmp17)
    tmp19 = tmp0 >= tmp11
    tl.full([1], 512, tl.int64)
    tmp22 = tl.load(in_ptr4 + (128 * x1 + (-384 + x0)), tmp19,
        eviction_policy='evict_last', other=0.0)
    tmp23 = tl.load(in_ptr5 + (-384 + x0), tmp19, eviction_policy=
        'evict_last', other=0.0)
    tmp24 = tmp22 + tmp23
    tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
    tmp26 = tl.where(tmp19, tmp24, tmp25)
    tmp27 = tl.where(tmp13, tmp18, tmp26)
    tmp28 = tl.where(tmp4, tmp9, tmp27)
    tmp29 = tl.full([1], 0, tl.int32)
    tmp30 = triton_helpers.maximum(tmp29, tmp28)
    tl.store(out_ptr0 + x2, tmp30, None)


@triton.jit
def triton_poi_fused_convolution_6(in_ptr0, in_ptr1, 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
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask)


@triton.jit
def triton_poi_fused_convolution_7(in_ptr0, in_ptr1, out_ptr0, ynumel,
    xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 32
    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
    y0 = yindex % 8
    y1 = yindex // 8
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 8 * x2 + 128 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask)


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, primals_14, primals_15) = args
    args.clear()
    assert_size_stride(primals_1, (256, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (256,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (128, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_5, (128,), (1,))
    assert_size_stride(primals_6, (128, 128, 3, 3), (1152, 9, 3, 1))
    assert_size_stride(primals_7, (128,), (1,))
    assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1))
    assert_size_stride(primals_9, (128,), (1,))
    assert_size_stride(primals_10, (128, 128, 3, 3), (1152, 9, 3, 1))
    assert_size_stride(primals_11, (128,), (1,))
    assert_size_stride(primals_12, (4, 512, 1, 1), (512, 1, 1, 1))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (8, 512, 1, 1), (512, 1, 1, 1))
    assert_size_stride(primals_15, (8,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((256, 4, 3, 3), (36, 1, 12, 4), torch.float32
            )
        get_raw_stream(0)
        triton_poi_fused_0[grid(1024, 9)](primals_1, buf0, 1024, 9, XBLOCK=
            16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        triton_poi_fused_1[grid(16, 16)](primals_3, buf1, 16, 16, XBLOCK=16,
            YBLOCK=16, num_warps=4, num_stages=1)
        del primals_3
        buf2 = empty_strided_cuda((128, 4, 3, 3), (36, 1, 12, 4), torch.float32
            )
        triton_poi_fused_2[grid(512, 9)](primals_4, buf2, 512, 9, XBLOCK=16,
            YBLOCK=64, num_warps=4, num_stages=1)
        del primals_4
        buf3 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128),
            torch.float32)
        triton_poi_fused_3[grid(16384, 9)](primals_6, buf3, 16384, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_6
        buf4 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128),
            torch.float32)
        triton_poi_fused_3[grid(16384, 9)](primals_8, buf4, 16384, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_8
        buf5 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128),
            torch.float32)
        triton_poi_fused_3[grid(16384, 9)](primals_10, buf5, 16384, 9,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_10
        buf6 = extern_kernels.convolution(buf1, buf0, stride=(1, 1),
            padding=(1, 1), 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(buf1, buf2, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 128, 4, 4), (2048, 1, 512, 128))
        buf8 = buf7
        del buf7
        triton_poi_fused_convolution_relu_4[grid(8192)](buf8, primals_5, 
            8192, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_5
        buf9 = extern_kernels.convolution(buf8, buf3, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 128, 4, 4), (2048, 1, 512, 128))
        buf10 = extern_kernels.convolution(buf8, buf4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 128, 4, 4), (2048, 1, 512, 128))
        buf11 = buf10
        del buf10
        triton_poi_fused_convolution_relu_4[grid(8192)](buf11, primals_9, 
            8192, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_9
        buf12 = extern_kernels.convolution(buf11, buf5, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 128, 4, 4), (2048, 1, 512, 128))
        buf13 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512),
            torch.float32)
        triton_poi_fused_cat_relu_5[grid(32768)](buf6, primals_2, buf9,
            primals_7, buf12, primals_11, buf13, 32768, XBLOCK=256,
            num_warps=4, num_stages=1)
        del buf12
        del buf6
        del buf9
        del primals_11
        del primals_2
        del primals_7
        buf14 = extern_kernels.convolution(buf13, primals_12, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf14, (4, 4, 4, 4), (64, 1, 16, 4))
        buf15 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_convolution_6[grid(16, 16)](buf14, primals_13,
            buf15, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
        del buf14
        del primals_13
        buf16 = extern_kernels.convolution(buf13, primals_14, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf16, (4, 8, 4, 4), (128, 1, 32, 8))
        buf17 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
            )
        triton_poi_fused_convolution_7[grid(32, 16)](buf16, primals_15,
            buf17, 32, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
        del buf16
        del primals_15
    return (buf15, buf17, buf0, buf1, buf2, buf3, buf4, buf5, primals_12,
        primals_14, buf8, buf11, buf13)


class Conv2D(nn.Module):

    def __init__(self, in_channels, out_channels, kernel_size, same_padding
        =False, stride=1, relu=True, bn=False):
        super(Conv2D, self).__init__()
        padding = int((kernel_size - 1) / 2) if same_padding else 0
        self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
            stride, padding=padding)
        self.bn = nn.BatchNorm2d(out_channels, eps=0.001, momentum=0,
            affine=True) if bn else None
        self.relu = nn.ReLU(inplace=True) if relu else None

    def forward(self, x):
        x = self.conv(x)
        if self.bn is not None:
            x = self.bn(x)
        if self.relu is not None:
            x = self.relu(x)
        return x


class M3New(nn.Module):

    def __init__(self, in_channels):
        super(M3New, self).__init__()
        self.m3_ssh_3x3 = Conv2D(in_channels, 256, 3, True, 1, False)
        self.m3_ssh_dimred = Conv2D(in_channels, 128, 3, True, 1, True)
        self.m3_ssh_5x5 = Conv2D(128, 128, 3, True, 1, False)
        self.m3_ssh_7x7_1 = Conv2D(128, 128, 3, True, 1, True)
        self.m3_ssh_7x7 = Conv2D(128, 128, 3, True, 1, False)
        self.m3_ssh_cls_score = Conv2D(128 * 2 + 256, 4, 1, False, 1, False)
        self.m3_ssh_bbox_pred = Conv2D(128 * 2 + 256, 8, 1, False, 1, False)

    def forward(self, input_0):
        primals_1 = self.m3_ssh_3x3.conv.weight
        primals_2 = self.m3_ssh_3x3.conv.bias
        primals_4 = self.m3_ssh_dimred.conv.weight
        primals_5 = self.m3_ssh_dimred.conv.bias
        primals_6 = self.m3_ssh_5x5.conv.weight
        primals_7 = self.m3_ssh_5x5.conv.bias
        primals_8 = self.m3_ssh_7x7_1.conv.weight
        primals_9 = self.m3_ssh_7x7_1.conv.bias
        primals_10 = self.m3_ssh_7x7.conv.weight
        primals_11 = self.m3_ssh_7x7.conv.bias
        primals_12 = self.m3_ssh_cls_score.conv.weight
        primals_13 = self.m3_ssh_cls_score.conv.bias
        primals_14 = self.m3_ssh_bbox_pred.conv.weight
        primals_15 = self.m3_ssh_bbox_pred.conv.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,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15])
        return output[0], output[1]
