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 numpy as np
from torch import nn
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_convolution_relu_threshold_backward_0(in_out_ptr0,
    in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 1920
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 3 % 40
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x3, tmp4, xmask)
    tl.store(out_ptr0 + x3, tmp6, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 1280
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x2 = xindex
    tmp0 = tl.full([1], 0, tl.int64)
    tmp1 = tmp0 >= tmp0
    tmp2 = tl.full([1], 1, tl.int64)
    tmp3 = tmp0 < tmp2
    tmp4 = tmp1 & tmp3
    tmp5 = -1 + 2 * x0
    tmp6 = tmp5 >= tmp0
    tmp7 = tl.full([1], 3, tl.int64)
    tmp8 = tmp5 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tmp4 & tmp9
    tmp11 = tl.load(in_ptr0 + (-1 + 2 * x0 + 3 * x1), tmp10 & xmask,
        eviction_policy='evict_last', other=float('-inf'))
    tmp12 = 2 * x0
    tmp13 = tmp12 >= tmp0
    tmp14 = tmp12 < tmp7
    tmp15 = tmp13 & tmp14
    tmp16 = tmp4 & tmp15
    tmp17 = tl.load(in_ptr0 + (2 * x0 + 3 * x1), tmp16 & xmask,
        eviction_policy='evict_last', other=float('-inf'))
    tmp18 = tmp17 > tmp11
    tmp19 = tl.full([1], 1, tl.int8)
    tmp20 = tl.full([1], 0, tl.int8)
    tmp21 = tl.where(tmp18, tmp19, tmp20)
    tmp22 = triton_helpers.maximum(tmp17, tmp11)
    tl.store(out_ptr0 + x2, tmp21, xmask)
    tl.store(out_ptr1 + x2, tmp22, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_2(in_out_ptr0,
    in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 640
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 40
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr0 + x2, tmp6, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.full([1], 0, tl.int64)
    tmp1 = tmp0 >= tmp0
    tmp2 = tl.full([1], 1, tl.int64)
    tmp3 = tmp0 < tmp2
    tmp4 = tmp1 & tmp3
    tmp5 = -4 + 10 * x0
    tmp6 = tmp5 >= tmp0
    tmp7 = tl.full([1], 40, tl.int64)
    tmp8 = tmp5 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tmp4 & tmp9
    tmp11 = tl.load(in_ptr0 + (-4 + 10 * x2), tmp10 & xmask,
        eviction_policy='evict_last', other=float('-inf'))
    tmp12 = -3 + 10 * x0
    tmp13 = tmp12 >= tmp0
    tmp14 = tmp12 < tmp7
    tmp15 = tmp13 & tmp14
    tmp16 = tmp4 & tmp15
    tmp17 = tl.load(in_ptr0 + (-3 + 10 * x2), tmp16 & xmask,
        eviction_policy='evict_last', other=float('-inf'))
    tmp18 = triton_helpers.maximum(tmp17, tmp11)
    tmp19 = -2 + 10 * x0
    tmp20 = tmp19 >= tmp0
    tmp21 = tmp19 < tmp7
    tmp22 = tmp20 & tmp21
    tmp23 = tmp4 & tmp22
    tmp24 = tl.load(in_ptr0 + (-2 + 10 * x2), tmp23 & xmask,
        eviction_policy='evict_last', other=float('-inf'))
    tmp25 = triton_helpers.maximum(tmp24, tmp18)
    tmp26 = -1 + 10 * x0
    tmp27 = tmp26 >= tmp0
    tmp28 = tmp26 < tmp7
    tmp29 = tmp27 & tmp28
    tmp30 = tmp4 & tmp29
    tmp31 = tl.load(in_ptr0 + (-1 + 10 * x2), tmp30 & xmask,
        eviction_policy='evict_last', other=float('-inf'))
    tmp32 = triton_helpers.maximum(tmp31, tmp25)
    tmp33 = 10 * x0
    tmp34 = tmp33 >= tmp0
    tmp35 = tmp33 < tmp7
    tmp36 = tmp34 & tmp35
    tmp37 = tmp4 & tmp36
    tmp38 = tl.load(in_ptr0 + 10 * x2, tmp37 & xmask, eviction_policy=
        'evict_last', other=float('-inf'))
    tmp39 = triton_helpers.maximum(tmp38, tmp32)
    tmp40 = 1 + 10 * x0
    tmp41 = tmp40 >= tmp0
    tmp42 = tmp40 < tmp7
    tmp43 = tmp41 & tmp42
    tmp44 = tmp4 & tmp43
    tmp45 = tl.load(in_ptr0 + (1 + 10 * x2), tmp44 & xmask, eviction_policy
        ='evict_last', other=float('-inf'))
    tmp46 = triton_helpers.maximum(tmp45, tmp39)
    tmp47 = 2 + 10 * x0
    tmp48 = tmp47 >= tmp0
    tmp49 = tmp47 < tmp7
    tmp50 = tmp48 & tmp49
    tmp51 = tmp4 & tmp50
    tmp52 = tl.load(in_ptr0 + (2 + 10 * x2), tmp51 & xmask, eviction_policy
        ='evict_last', other=float('-inf'))
    tmp53 = triton_helpers.maximum(tmp52, tmp46)
    tmp54 = 3 + 10 * x0
    tmp55 = tmp54 >= tmp0
    tmp56 = tmp54 < tmp7
    tmp57 = tmp55 & tmp56
    tmp58 = tmp4 & tmp57
    tmp59 = tl.load(in_ptr0 + (3 + 10 * x2), tmp58 & xmask, eviction_policy
        ='evict_last', other=float('-inf'))
    tmp60 = triton_helpers.maximum(tmp59, tmp53)
    tmp61 = 4 + 10 * x0
    tmp62 = tmp61 >= tmp0
    tmp63 = tmp61 < tmp7
    tmp64 = tmp62 & tmp63
    tmp65 = tmp4 & tmp64
    tmp66 = tl.load(in_ptr0 + (4 + 10 * x2), tmp65 & xmask, eviction_policy
        ='evict_last', other=float('-inf'))
    tmp67 = triton_helpers.maximum(tmp66, tmp60)
    tmp68 = 5 + 10 * x0
    tmp69 = tmp68 >= tmp0
    tmp70 = tmp68 < tmp7
    tmp71 = tmp69 & tmp70
    tmp72 = tmp4 & tmp71
    tmp73 = tl.load(in_ptr0 + (5 + 10 * x2), tmp72 & xmask, eviction_policy
        ='evict_last', other=float('-inf'))
    tmp74 = triton_helpers.maximum(tmp73, tmp67)
    tmp75 = tmp17 > tmp11
    tmp76 = tl.full([1], 1, tl.int8)
    tmp77 = tl.full([1], 0, tl.int8)
    tmp78 = tl.where(tmp75, tmp76, tmp77)
    tmp79 = tmp24 > tmp18
    tmp80 = tl.full([1], 2, tl.int8)
    tmp81 = tl.where(tmp79, tmp80, tmp78)
    tmp82 = tmp31 > tmp25
    tmp83 = tl.full([1], 3, tl.int8)
    tmp84 = tl.where(tmp82, tmp83, tmp81)
    tmp85 = tmp38 > tmp32
    tmp86 = tl.full([1], 4, tl.int8)
    tmp87 = tl.where(tmp85, tmp86, tmp84)
    tmp88 = tmp45 > tmp39
    tmp89 = tl.full([1], 5, tl.int8)
    tmp90 = tl.where(tmp88, tmp89, tmp87)
    tmp91 = tmp52 > tmp46
    tmp92 = tl.full([1], 6, tl.int8)
    tmp93 = tl.where(tmp91, tmp92, tmp90)
    tmp94 = tmp59 > tmp53
    tmp95 = tl.full([1], 7, tl.int8)
    tmp96 = tl.where(tmp94, tmp95, tmp93)
    tmp97 = tmp66 > tmp60
    tmp98 = tl.full([1], 8, tl.int8)
    tmp99 = tl.where(tmp97, tmp98, tmp96)
    tmp100 = tmp73 > tmp67
    tmp101 = tl.full([1], 9, tl.int8)
    tmp102 = tl.where(tmp100, tmp101, tmp99)
    tl.store(out_ptr0 + x2, tmp74, xmask)
    tl.store(out_ptr1 + x2, tmp102, 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), (16, 4, 1))
    assert_size_stride(primals_2, (40, 1, 20), (20, 20, 1))
    assert_size_stride(primals_3, (40,), (1,))
    assert_size_stride(primals_4, (40, 40, 40), (1600, 40, 1))
    assert_size_stride(primals_5, (40,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = torch.ops.aten.native_dropout.default(reinterpret_tensor(
            primals_1, (16, 1, 4), (4, 4, 1), 0), 0.5, True)
        del primals_1
        buf1 = buf0[0]
        del buf0
        buf3 = extern_kernels.convolution(buf1, primals_2, stride=(1,),
            padding=(9,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf3, (16, 40, 3), (120, 3, 1))
        buf4 = buf3
        del buf3
        buf12 = empty_strided_cuda((16, 40, 3), (120, 3, 1), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_threshold_backward_0[grid(1920)](buf4
            , primals_3, buf12, 1920, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_3
        buf5 = empty_strided_cuda((16, 40, 1, 2), (80, 2, 2, 1), torch.int8)
        buf6 = empty_strided_cuda((16, 40, 1, 2), (80, 2, 2, 1), torch.float32)
        triton_poi_fused_max_pool2d_with_indices_1[grid(1280)](buf4, buf5,
            buf6, 1280, XBLOCK=256, num_warps=4, num_stages=1)
        buf7 = extern_kernels.convolution(reinterpret_tensor(buf6, (16, 40,
            2), (80, 2, 1), 0), primals_4, stride=(1,), padding=(19,),
            dilation=(1,), transposed=False, output_padding=(0,), groups=1,
            bias=None)
        assert_size_stride(buf7, (16, 40, 1), (40, 1, 1))
        buf8 = buf7
        del buf7
        buf11 = empty_strided_cuda((16, 40, 1), (40, 1, 1), torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_2[grid(640)](buf8,
            primals_5, buf11, 640, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_5
        buf9 = empty_strided_cuda((16, 1, 1, 4), (4, 4, 4, 1), torch.float32)
        buf10 = empty_strided_cuda((16, 1, 1, 4), (4, 4, 4, 1), torch.int8)
        triton_poi_fused_max_pool2d_with_indices_3[grid(64)](buf8, buf9,
            buf10, 64, XBLOCK=64, num_warps=1, num_stages=1)
    return reinterpret_tensor(buf9, (4, 4, 4), (16, 4, 1), 0
        ), primals_2, primals_4, buf1, reinterpret_tensor(buf4, (16, 40, 1,
        3), (120, 3, 3, 1), 0), buf5, reinterpret_tensor(buf6, (16, 40, 2),
        (80, 2, 1), 0), reinterpret_tensor(buf8, (16, 1, 1, 40), (40, 40, 
        40, 1), 0), buf10, buf11, buf12


class Emo16New(nn.Module):

    def __init__(self, input_size: 'int', num_channels: 'int'=40):
        """ 
        Speech emotion recognition model proposed in:
        
        `Trigeorgis, G., Ringeval, F., Brueckner, R., Marchi, E., Nicolaou, M. A., Schuller, B., & Zafeiriou, S. 
        Adieu features? end-to-end speech emotion recognition using a deep convolutional recurrent network. 
        In 2016 IEEE international conference on acoustics, speech and signal processing (ICASSP) (pp. 5200-5204). IEEE.`
        
        Args:
            input_size (int): Input size to the model. 
            num_channels (int): Number of channels to use in the convolution layers (default `40`). 
        """
        super(Emo16New, self).__init__()
        self.conv1 = nn.Conv1d(in_channels=1, out_channels=num_channels,
            kernel_size=20, stride=1, padding=9)
        self.max_pool1 = nn.MaxPool1d(2, 2, padding=1)
        self.conv2 = nn.Conv1d(in_channels=40, out_channels=num_channels,
            kernel_size=40, stride=1, padding=19)
        self.max_pool2 = nn.MaxPool1d(10, 10, padding=4)
        self.num_features = int(np.ceil(input_size / 2)) * 4 - 4
        self.reset_parameters()

    def reset_parameters(self):
        """ Initialize parameters of the model."""
        for m in list(self.modules()):
            self._init_weights(m)

    def _init_weights(self, m):
        """ Helper method to initialize the parameters of the model 
            with Kaiming uniform initialization.
        """
        if type(m) == nn.Conv1d or type(m) == nn.Linear:
            nn.init.kaiming_uniform_(m.weight)
            nn.init.zeros_(m.bias)

    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.105129