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._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_per_fused__native_batch_norm_legit_cat_repeat_0(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, out_ptr3,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    x0 = xindex
    r1 = rindex
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, 1])
    tmp2 = tl.load(in_ptr1 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, 1])
    tmp4 = tl.load(in_ptr2 + (r1 + 16 * x0), xmask, other=0.0)
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp5, 0)
    tmp8 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp5 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tmp21 = 16.0
    tmp22 = tmp20 / tmp21
    tmp23 = 1e-05
    tmp24 = tmp22 + tmp23
    tmp25 = libdevice.rsqrt(tmp24)
    tmp26 = tmp4 - tmp14
    tmp27 = tmp26 * tmp25
    tmp28 = tmp27 * tmp1
    tmp29 = tmp28 + tmp3
    tmp30 = tl.full([1, 1], 0, tl.int32)
    tmp31 = triton_helpers.maximum(tmp30, tmp29)
    tl.store(out_ptr0 + x0, tmp1, xmask)
    tl.store(out_ptr1 + x0, tmp3, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp25, xmask)
    tl.store(out_ptr3 + (4 * r1 + 64 * x0), tmp31, xmask)
    tl.store(out_ptr2 + x0, tmp14, xmask)


@triton.jit
def triton_per_fused__native_batch_norm_legit_cat_repeat_1(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, out_ptr3,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    x0 = xindex
    r1 = rindex
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, 1])
    tmp2 = tl.load(in_ptr1 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, 1])
    tmp4 = tl.load(in_ptr2 + (r1 + 16 * x0), xmask, other=0.0)
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp5, 0)
    tmp8 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp5 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tmp21 = 16.0
    tmp22 = tmp20 / tmp21
    tmp23 = 1e-05
    tmp24 = tmp22 + tmp23
    tmp25 = libdevice.rsqrt(tmp24)
    tmp26 = tmp4 - tmp14
    tmp27 = tmp26 * tmp25
    tmp28 = tmp27 * tmp1
    tmp29 = tmp28 + tmp3
    tmp30 = tl.full([1, 1], 0, tl.int32)
    tmp31 = triton_helpers.maximum(tmp30, tmp29)
    tl.store(out_ptr0 + x0, tmp1, xmask)
    tl.store(out_ptr1 + x0, tmp3, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp25, xmask)
    tl.store(out_ptr3 + (4 * r1 + 64 * x0), tmp31, xmask)
    tl.store(out_ptr2 + x0, tmp14, xmask)


@triton.jit
def triton_poi_fused_cat_2(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
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
    tl.store(out_ptr0 + (x2 + 16 * y3), tmp0, 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) = args
    args.clear()
    assert_size_stride(primals_1, (1, 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, (1,), (1,))
    assert_size_stride(primals_4, (1,), (1,))
    assert_size_stride(primals_5, (1, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_6, (1,), (1,))
    assert_size_stride(primals_7, (1,), (1,))
    assert_size_stride(primals_8, (1, 4, 5, 5), (100, 25, 5, 1))
    assert_size_stride(primals_9, (1,), (1,))
    assert_size_stride(primals_10, (1,), (1,))
    assert_size_stride(primals_11, (1, 4, 7, 7), (196, 49, 7, 1))
    assert_size_stride(primals_12, (1,), (1,))
    assert_size_stride(primals_13, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_2, 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, 1, 4, 4), (16, 16, 4, 1))
        buf1 = empty_strided_cuda((4,), (1,), torch.float32)
        buf2 = empty_strided_cuda((4,), (1,), torch.float32)
        buf3 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
        buf4 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
        buf6 = reinterpret_tensor(buf4, (1, 4, 1, 1), (4, 1, 1, 1), 0)
        del buf4
        buf32 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        buf28 = reinterpret_tensor(buf32, (4, 1, 4, 4), (64, 1, 16, 4), 0)
        get_raw_stream(0)
        triton_per_fused__native_batch_norm_legit_cat_repeat_0[grid(4)](buf6,
            primals_3, primals_4, buf0, buf1, buf2, buf3, buf28, 4, 16,
            XBLOCK=1, num_warps=2, num_stages=1)
        del primals_3
        del primals_4
        buf7 = extern_kernels.convolution(primals_2, primals_5, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 1, 4, 4), (16, 16, 4, 1))
        buf8 = empty_strided_cuda((4,), (1,), torch.float32)
        buf9 = empty_strided_cuda((4,), (1,), torch.float32)
        buf10 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
        buf11 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
        buf13 = reinterpret_tensor(buf11, (1, 4, 1, 1), (4, 1, 1, 1), 0)
        del buf11
        buf29 = reinterpret_tensor(buf32, (4, 1, 4, 4), (64, 1, 16, 4), 1)
        triton_per_fused__native_batch_norm_legit_cat_repeat_1[grid(4)](buf13,
            primals_6, primals_7, buf7, buf8, buf9, buf10, buf29, 4, 16,
            XBLOCK=1, num_warps=2, num_stages=1)
        del primals_6
        del primals_7
        buf14 = extern_kernels.convolution(primals_2, primals_8, stride=(1,
            1), padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf14, (4, 1, 4, 4), (16, 16, 4, 1))
        buf15 = empty_strided_cuda((4,), (1,), torch.float32)
        buf16 = empty_strided_cuda((4,), (1,), torch.float32)
        buf17 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
        buf18 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
        buf20 = reinterpret_tensor(buf18, (1, 4, 1, 1), (4, 1, 1, 1), 0)
        del buf18
        buf30 = reinterpret_tensor(buf32, (4, 1, 4, 4), (64, 1, 16, 4), 2)
        triton_per_fused__native_batch_norm_legit_cat_repeat_1[grid(4)](buf20,
            primals_9, primals_10, buf14, buf15, buf16, buf17, buf30, 4, 16,
            XBLOCK=1, num_warps=2, num_stages=1)
        del primals_10
        del primals_9
        buf21 = extern_kernels.convolution(primals_2, primals_11, stride=(1,
            1), padding=(3, 3), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf21, (4, 1, 4, 4), (16, 16, 4, 1))
        buf22 = empty_strided_cuda((4,), (1,), torch.float32)
        buf23 = empty_strided_cuda((4,), (1,), torch.float32)
        buf24 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
        buf25 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
        buf27 = reinterpret_tensor(buf25, (1, 4, 1, 1), (4, 1, 1, 1), 0)
        del buf25
        buf31 = reinterpret_tensor(buf32, (4, 1, 4, 4), (64, 1, 16, 4), 3)
        triton_per_fused__native_batch_norm_legit_cat_repeat_1[grid(4)](buf27,
            primals_12, primals_13, buf21, buf22, buf23, buf24, buf31, 4, 
            16, XBLOCK=1, num_warps=2, num_stages=1)
        del primals_12
        del primals_13
        buf33 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_cat_2[grid(16, 16)](buf32, buf33, 16, 16, XBLOCK=
            16, YBLOCK=16, num_warps=4, num_stages=1)
        del buf28
        del buf29
        del buf30
        del buf31
        del buf32
    return (buf33, primals_1, primals_2, primals_5, primals_8, primals_11,
        buf0, buf1, buf2, buf3, buf6, buf7, buf8, buf9, buf10, buf13, buf14,
        buf15, buf16, buf17, buf20, buf21, buf22, buf23, buf24, buf27)


class BasicConv(nn.Module):

    def __init__(self, in_channels, out_channels, use_bn=False, **kwargs):
        super(BasicConv, self).__init__()
        self.use_bn = use_bn
        self.conv = nn.Conv2d(in_channels, out_channels, bias=not self.
            use_bn, **kwargs)
        self.bn = nn.InstanceNorm2d(out_channels, affine=True
            ) if self.use_bn else None

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


class SAModule_HeadNew(nn.Module):

    def __init__(self, in_channels, out_channels, use_bn):
        super(SAModule_HeadNew, self).__init__()
        branch_out = out_channels // 4
        self.branch1x1 = BasicConv(in_channels, branch_out, use_bn=use_bn,
            kernel_size=1)
        self.branch3x3 = BasicConv(in_channels, branch_out, use_bn=use_bn,
            kernel_size=3, padding=1)
        self.branch5x5 = BasicConv(in_channels, branch_out, use_bn=use_bn,
            kernel_size=5, padding=2)
        self.branch7x7 = BasicConv(in_channels, branch_out, use_bn=use_bn,
            kernel_size=7, padding=3)

    def forward(self, input_0):
        primals_1 = self.branch1x1.conv.weight
        primals_3 = self.branch1x1.bn.weight
        primals_4 = self.branch1x1.bn.bias
        primals_5 = self.branch3x3.conv.weight
        primals_6 = self.branch3x3.bn.weight
        primals_7 = self.branch3x3.bn.bias
        primals_8 = self.branch5x5.conv.weight
        primals_9 = self.branch5x5.bn.weight
        primals_10 = self.branch5x5.bn.bias
        primals_11 = self.branch7x7.conv.weight
        primals_12 = self.branch7x7.bn.weight
        primals_13 = self.branch7x7.bn.bias
        primals_2 = 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])
        return output[0]


Measured latency_ms: 0.142728