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
from torch import nn
import torch.utils.data
import torch.nn
from torch.nn import RNNCellBase
import torch.multiprocessing
from torch.nn import Identity
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_new_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_lift_fresh_mul_sigmoid_sub_tanh_1(in_ptr0, in_ptr1,
    out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 + (4 + x0 + 12 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (4 + x0 + 12 * x1), xmask)
    tmp4 = tl.load(in_ptr0 + (x0 + 12 * x1), xmask)
    tmp5 = tl.load(in_ptr1 + (x0 + 12 * x1), xmask)
    tmp8 = tl.load(in_ptr0 + (8 + x0 + 12 * x1), xmask)
    tmp9 = tl.load(in_ptr1 + (8 + x0 + 12 * x1), xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = tl.sigmoid(tmp2)
    tmp6 = tmp4 + tmp5
    tmp7 = tl.sigmoid(tmp6)
    tmp10 = tmp7 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.tanh(tmp11)
    tmp13 = 1.0
    tmp14 = tmp13 - tmp3
    tmp15 = tmp14 * tmp12
    tmp16 = 0.0
    tmp17 = tmp3 * tmp16
    tmp18 = tmp15 + tmp17
    tl.store(out_ptr0 + x2, tmp3, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)
    tl.store(out_ptr2 + x2, tmp12, xmask)
    tl.store(out_ptr3 + x2, tmp18, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (12, 4), (4, 1))
    assert_size_stride(primals_3, (12, 4), (4, 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_new_zeros_0[grid(16)](buf0, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 12), (12, 1), torch.float32)
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 12),
            (1, 4), 0), out=buf1)
        del primals_2
        buf2 = empty_strided_cuda((4, 12), (12, 1), torch.float32)
        extern_kernels.mm(buf0, reinterpret_tensor(primals_3, (4, 12), (1, 
            4), 0), out=buf2)
        del primals_3
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_add_lift_fresh_mul_sigmoid_sub_tanh_1[grid(16)](buf1,
            buf2, buf4, buf3, buf5, buf6, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        del buf1
    return buf6, primals_1, buf0, reinterpret_tensor(buf2, (4, 4), (12, 1), 8
        ), buf3, buf4, buf5


class LayerNormGRUCellNew(RNNCellBase):
    """
    Implements GRUCell with layer normalisation and zone-out on top.
    It inherits the base RNN cell whose trainable weight matrices are used.

    References:
    [1] Ba, Jimmy Lei, Jamie Ryan Kiros, and Geoffrey E. Hinton. "Layer Normalization." (2016).
    [2] Krueger, David, et al. "Zoneout: Regularizing RNNs by Randomly Preserving Hidden Activations." (2016).

    :param input_size: Number of input features to the cell
    :param hidden_size: Number of hidden states in the cell
    :param use_layer_norm: If set to True, layer normalisation is applied to
                           reset, update and new tensors before activation.
    :param dropout: Dropout probability for the hidden states [0,1]
    """

    def __init__(self, input_size: 'int', hidden_size: 'int',
        use_layer_norm: 'bool'=False, dropout: 'float'=0.0):
        super(LayerNormGRUCellNew, self).__init__(input_size, hidden_size,
            bias=False, num_chunks=3)
        self.dropout = dropout
        self.ln_r = nn.LayerNorm(self.hidden_size
            ) if use_layer_norm else Identity()
        self.ln_z = nn.LayerNorm(self.hidden_size
            ) if use_layer_norm else Identity()
        self.ln_n = nn.LayerNorm(self.hidden_size
            ) if use_layer_norm else Identity()

    def forward(self, input_0):
        primals_2 = self.weight_ih
        primals_3 = self.weight_hh
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0]


class Identity(nn.Module):
    """
    Implements an identity torch module where input is passed as it is to output.
    There are no parameters in the module.
    """

    def __init__(self) ->None:
        super(Identity, self).__init__()

    def forward(self, input: 'torch.Tensor') ->torch.Tensor:
        return input


Measured latency_ms: 0.045935