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 torch.nn as nn
from sklearn.metrics import *
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_add_mul_rsub_sigmoid_tanh_0(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    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), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (4 + x0 + 12 * x1), xmask)
    tmp6 = tl.load(in_ptr0 + (x0 + 12 * x1), xmask)
    tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (x0 + 12 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (8 + x0 + 12 * x1), xmask)
    tmp13 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr2 + (8 + x0 + 12 * x1), xmask)
    tmp19 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr4 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = tl.sigmoid(tmp4)
    tmp8 = tmp6 + tmp7
    tmp10 = tmp8 + tmp9
    tmp11 = tl.sigmoid(tmp10)
    tmp14 = tmp12 + tmp13
    tmp16 = tmp11 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = libdevice.tanh(tmp17)
    tmp20 = tmp19 * tmp5
    tmp21 = 1.0
    tmp22 = tmp21 - tmp20
    tmp24 = tmp22 * tmp23
    tmp25 = tmp20 * tmp18
    tmp26 = tmp24 + tmp25
    tl.store(out_ptr0 + x2, tmp5, xmask)
    tl.store(out_ptr1 + x2, tmp11, xmask)
    tl.store(out_ptr2 + x2, tmp18, xmask)
    tl.store(out_ptr3 + x2, tmp26, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
    args.clear()
    assert_size_stride(primals_1, (12, 4), (4, 1))
    assert_size_stride(primals_2, (12,), (1,))
    assert_size_stride(primals_3, (64, 4), (4, 1))
    assert_size_stride(primals_4, (12, 4), (4, 1))
    assert_size_stride(primals_5, (64, 4), (4, 1))
    assert_size_stride(primals_6, (16, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 12), (12, 1), torch.float32)
        extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 12),
            (1, 4), 0), out=buf0)
        del primals_1
        buf1 = empty_strided_cuda((64, 12), (12, 1), torch.float32)
        extern_kernels.addmm(primals_2, primals_5, reinterpret_tensor(
            primals_4, (4, 12), (1, 4), 0), alpha=1, beta=1, out=buf1)
        del primals_4
        buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_mul_rsub_sigmoid_tanh_0[grid(256)](buf0,
            primals_2, buf1, primals_6, primals_5, buf3, buf2, buf4, buf5, 
            256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf0
        del primals_2
    return buf5, primals_3, primals_5, primals_6, reinterpret_tensor(buf1,
        (64, 4), (12, 1), 8), buf2, buf3, buf4


class AUGRUCellNew(nn.Module):
    """ Effect of GRU with attentional update gate (AUGRU)

        Reference:
        -  Deep Interest Evolution Network for Click-Through Rate Prediction[J]. arXiv preprint arXiv:1809.03672, 2018.
    """

    def __init__(self, input_size, hidden_size, bias=True):
        super(AUGRUCellNew, self).__init__()
        self.input_size = input_size
        self.hidden_size = hidden_size
        self.bias = bias
        self.weight_ih = nn.Parameter(torch.Tensor(3 * hidden_size, input_size)
            )
        self.register_parameter('weight_ih', self.weight_ih)
        self.weight_hh = nn.Parameter(torch.Tensor(3 * hidden_size,
            hidden_size))
        self.register_parameter('weight_hh', self.weight_hh)
        if bias:
            self.bias_ih = nn.Parameter(torch.Tensor(3 * hidden_size))
            self.register_parameter('bias_ih', self.bias_ih)
            self.bias_hh = nn.Parameter(torch.Tensor(3 * hidden_size))
            self.register_parameter('bias_ih', self.bias_hh)
            for tensor in [self.bias_ih, self.bias_hh]:
                nn.init.zeros_(tensor)
        else:
            self.register_parameter('bias_ih', None)
            self.register_parameter('bias_hh', None)

    def forward(self, input_0, input_1, input_2):
        primals_1 = self.weight_ih
        primals_4 = self.weight_hh
        primals_2 = self.bias_ih
        primals_3 = input_0
        primals_5 = input_1
        primals_6 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6])
        return output[0]


Measured latency_ms: 0.078979