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
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_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tl.store(out_ptr0 + x0, tmp8, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.load(in_out_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr0 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp4 = tmp1 + tmp3
    tmp5 = tl.full([1], 0, tl.int32)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tmp7 = 0.0
    tmp8 = tmp6 <= tmp7
    tl.store(in_out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp6, None)
    tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp8, None)


@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask)
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x0, tmp2, xmask)


@triton.jit
def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.sigmoid(tmp1)
    tmp3 = tmp0 * tmp2
    tl.store(out_ptr0 + x2, tmp3, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (1, 4, 1), (4, 1, 1))
    assert_size_stride(primals_3, (1,), (1,))
    assert_size_stride(primals_4, (4, 1, 1), (1, 1, 1))
    assert_size_stride(primals_5, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mean_0[grid(4)](primals_1, buf0, 4, XBLOCK=4,
            num_warps=1, num_stages=1)
        buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (1, 4, 1
            ), (0, 1, 0), 0), primals_2, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf1, (1, 1, 1), (1, 1, 1))
        buf2 = reinterpret_tensor(buf1, (1, 1), (1, 1), 0)
        del buf1
        buf6 = empty_strided_cuda((1, 1), (1, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_1[grid(1)](buf2, primals_3,
            buf6, 1, XBLOCK=1, num_warps=1, num_stages=1)
        del primals_3
        buf3 = extern_kernels.convolution(reinterpret_tensor(buf2, (1, 1, 1
            ), (0, 0, 0), 0), primals_4, stride=(1,), padding=(0,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf3, (1, 4, 1), (4, 1, 1))
        buf4 = buf3
        del buf3
        triton_poi_fused_convolution_2[grid(4)](buf4, primals_5, 4, XBLOCK=
            4, num_warps=1, num_stages=1)
        del primals_5
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_mul_sigmoid_3[grid(16)](primals_1, buf4, buf5, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
    return buf5, primals_1, primals_2, primals_4, reinterpret_tensor(buf0,
        (1, 4, 1), (4, 1, 1), 0), reinterpret_tensor(buf2, (1, 1, 1), (1, 1,
        1), 0), buf4, buf6


class Swish(nn.Module):

    def __init__(self):
        super(Swish, self).__init__()

    def forward(self, x):
        return x * x.sigmoid()


class Conv1d(nn.Conv1d):

    def __init__(self, in_channels, out_channels, kernel_size, stride=1,
        padding='same', dilation=1, groups=1, bias=True):
        super(Conv1d, self).__init__(in_channels=in_channels, out_channels=
            out_channels, kernel_size=kernel_size, stride=stride, padding=0,
            dilation=dilation, groups=groups, bias=bias, padding_mode='zeros')
        assert padding in ['valid', 'same', 'causal']
        if padding == 'valid':
            self.pre_padding = None
        elif padding == 'same':
            self.pre_padding = nn.ConstantPad1d(padding=((kernel_size - 1) //
                2, (kernel_size - 1) // 2), value=0)
        elif padding == 'causal':
            self.pre_padding = nn.ConstantPad1d(padding=(kernel_size - 1, 0
                ), value=0)
        self.noise = None
        self.vn_std = None

    def init_vn(self, vn_std):
        self.vn_std = vn_std

    def sample_synaptic_noise(self, distributed):
        self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
            ), device=self.weight.device, dtype=self.weight.dtype)
        if distributed:
            torch.distributed.broadcast(self.noise, 0)

    def forward(self, input):
        weight = self.weight
        if self.noise is not None and self.training:
            weight = weight + self.vn_std * self.noise
        if self.pre_padding is not None:
            input = self.pre_padding(input)
        return F.conv1d(input, weight, self.bias, self.stride, self.padding,
            self.dilation, self.groups)


class SqueezeAndExcitationModuleNew(nn.Module):
    """Squeeze And Excitation Module

    Args:
        input_dim: input feature dimension
        reduction_ratio: bottleneck reduction ratio
        inner_act: bottleneck inner activation function

    Input: (batch_size, in_dim, in_length)
    Output: (batch_size, out_dim, out_length)
    
    """

    def __init__(self, input_dim, reduction_ratio, inner_act='relu'):
        super(SqueezeAndExcitationModuleNew, self).__init__()
        assert input_dim % reduction_ratio == 0
        self.conv1 = Conv1d(input_dim, input_dim // reduction_ratio,
            kernel_size=1)
        self.conv2 = Conv1d(input_dim // reduction_ratio, input_dim,
            kernel_size=1)
        assert inner_act in ['relu', 'swish']
        if inner_act == 'relu':
            self.inner_act = nn.ReLU()
        elif inner_act == 'swish':
            self.inner_act = Swish()

    def forward(self, input_0):
        primals_2 = self.conv1.weight
        primals_3 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.014017