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.triton_helpers import libdevice
import math
import torch.nn as nn
import torch.utils.data
import torch.utils.data.distributed
import torch.nn.parallel
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_zeros_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = 0.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_mul_sigmoid_sigmoid_backward_tanh_1(in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, out_ptr2, out_ptr3,
    out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask)
    tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
    tmp9 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask)
    tmp12 = tl.load(in_ptr3 + (12 + x0), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
    tmp17 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask)
    tmp20 = tl.load(in_ptr3 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
    tmp25 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask)
    tmp28 = tl.load(in_ptr3 + (4 + x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = tmp2 + tmp5
    tmp7 = tl.sigmoid(tmp6)
    tmp10 = tmp8 + tmp9
    tmp13 = tmp11 + tmp12
    tmp14 = tmp10 + tmp13
    tmp15 = tl.sigmoid(tmp14)
    tmp18 = tmp16 + tmp17
    tmp21 = tmp19 + tmp20
    tmp22 = tmp18 + tmp21
    tmp23 = libdevice.tanh(tmp22)
    tmp26 = tmp24 + tmp25
    tmp29 = tmp27 + tmp28
    tmp30 = tmp26 + tmp29
    tmp31 = tl.sigmoid(tmp30)
    tmp32 = 0.0
    tmp33 = tmp31 * tmp32
    tmp34 = tmp7 * tmp23
    tmp35 = tmp33 + tmp34
    tmp36 = 1.0
    tmp37 = tmp36 - tmp31
    tmp38 = tmp31 * tmp37
    tmp39 = libdevice.tanh(tmp35)
    tmp40 = tmp15 * tmp39
    tl.store(out_ptr0 + x2, tmp7, xmask)
    tl.store(out_ptr1 + x2, tmp15, xmask)
    tl.store(out_ptr2 + x2, tmp23, xmask)
    tl.store(out_ptr3 + x2, tmp35, xmask)
    tl.store(out_ptr4 + x2, tmp38, xmask)
    tl.store(out_ptr5 + x2, tmp40, 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, (16, 4), (4, 1))
    assert_size_stride(primals_3, (16,), (1,))
    assert_size_stride(primals_4, (16, 4), (4, 1))
    assert_size_stride(primals_5, (16,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_zeros_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf1 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 16),
            (1, 4), 0), out=buf1)
        del primals_2
        buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 16), (1, 
            4), 0), out=buf2)
        del primals_4
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_add_mul_sigmoid_sigmoid_backward_tanh_1[grid(16)](buf1
            , primals_3, buf2, primals_5, buf3, buf5, buf4, buf6, buf8,
            buf7, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf1
        del buf2
        del primals_3
        del primals_5
    return buf7, buf6, primals_1, buf0, buf3, buf4, buf5, buf6, buf8


class RNNLinear(nn.Linear):
    """Applies a linear transformation to the incoming data: :math:`y = xA^T + b`

    This module is the same as a ``torch.nn.Linear``` layer, except that in the backward pass
    the grad_samples get accumulated (instead of being concatenated as in the standard
    nn.Linear).

    When used with `PackedSequence`s, additional attribute `max_batch_len` is defined to determine
    the size of per-sample grad tensor.
    """
    max_batch_len: 'int'

    def __init__(self, in_features: 'int', out_features: 'int', bias:
        'bool'=True):
        super().__init__(in_features, out_features, bias)


class DPRNNCellBase(nn.Module):
    has_cell_state: 'bool' = False

    def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool',
        num_chunks: 'int') ->None:
        super().__init__()
        self.input_size = input_size
        self.hidden_size = hidden_size
        self.bias = bias
        self.ih = RNNLinear(input_size, num_chunks * hidden_size, bias)
        self.hh = RNNLinear(hidden_size, num_chunks * hidden_size, bias)
        self.reset_parameters()

    def reset_parameters(self) ->None:
        stdv = 1.0 / math.sqrt(self.hidden_size)
        for weight in self.parameters():
            nn.init.uniform_(weight, -stdv, stdv)

    def set_max_batch_length(self, max_batch_length: 'int') ->None:
        self.ih.max_batch_len = max_batch_length
        self.hh.max_batch_len = max_batch_length


class DPLSTMCellNew(DPRNNCellBase):
    """A long short-term memory (LSTM) cell.

    DP-friendly drop-in replacement of the ``torch.nn.LSTMCell`` module to use in ``DPLSTM``.
    Refer to ``torch.nn.LSTMCell`` documentation for the model description, parameters and inputs/outputs.
    """
    has_cell_state = True

    def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'
        ) ->None:
        super().__init__(input_size, hidden_size, bias, num_chunks=4)

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


Measured latency_ms: 0.01503