import torch
from torch._inductor.select_algorithm import extern_kernels
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
import torch.nn as 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_for_fused_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1):
    pid = tl.program_id(0)
    XBLOCK: tl.constexpr = 1024
    num_xblocks_0 = tl.cdiv(16, XBLOCK)
    num_xblocks_1 = num_xblocks_0 + tl.cdiv(16, XBLOCK)
    if pid < num_xblocks_0:
        pid_offset = pid
        xnumel = 16
        xoffset = pid_offset * XBLOCK
        xindex = xoffset + tl.arange(0, XBLOCK)[:]
        xmask = xindex < xnumel
        x2 = xindex
        x0 = xindex % 4
        x1 = xindex // 4
        tmp0 = tl.load(in_ptr0 + x2, xmask)
        tl.store(out_ptr0 + (x0 + 12 * x1), tmp0, xmask)
    elif pid < num_xblocks_1:
        pid_offset = pid - num_xblocks_0
        xnumel = 16
        xoffset = pid_offset * XBLOCK
        xindex = xoffset + tl.arange(0, XBLOCK)[:]
        xmask = xindex < xnumel
        x5 = xindex
        x3 = xindex % 4
        x4 = xindex // 4
        tmp1 = tl.load(in_ptr1 + x5, xmask)
        tl.store(out_ptr1 + (x3 + 12 * x4), tmp1, xmask)
    else:
        pass


@triton.jit
def triton_poi_fused_mul_sigmoid_1(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
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask)
    tmp2 = tl.sigmoid(tmp1)
    tmp3 = tmp0 * tmp2
    tl.store(out_ptr0 + x0, tmp3, xmask)


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


class MemoryReaderNew(nn.Module):

    def __init__(self, state_size, memory_size, h_size, device):
        super(MemoryReaderNew, self).__init__()
        self.device = device
        self.state_size = state_size
        self.memory_size = memory_size
        self.h_size = h_size
        self.fc_h = nn.Linear(state_size, h_size)
        self.fc_k = nn.Linear(state_size + h_size + memory_size, memory_size)

    def forward(self, input_0, input_1):
        primals_1 = self.fc_h.weight
        primals_2 = self.fc_h.bias
        primals_5 = self.fc_k.weight
        primals_6 = self.fc_k.bias
        primals_3 = input_0
        primals_4 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6])
        return output[0]


Measured latency_ms: 0.067046