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
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_poi_fused_add_mul_rsub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp2 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp3 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask)
    tmp7 = tl.load(in_ptr2 + (16 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp28 = tl.load(in_ptr2 + (32 + x0 + 64 * x1), xmask)
    tmp31 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp0 = tl.full([1], 0, tl.int32)
    tmp1 = tmp0 == tmp0
    tmp4 = tmp2 * tmp3
    tmp5 = 0.0
    tmp6 = tl.where(tmp1, tmp4, tmp5)
    tmp8 = 1.0
    tmp9 = tmp8 - tmp7
    tmp11 = tmp2 * tmp10
    tmp13 = tmp12 * tmp3
    tmp14 = tmp11 + tmp13
    tmp15 = tmp9 * tmp14
    tmp16 = tmp6 + tmp15
    tmp17 = tl.full([1], 1, tl.int32)
    tmp18 = tmp17 == tmp0
    tmp19 = tl.where(tmp1, tmp16, tmp6)
    tmp20 = tl.where(tmp18, tmp4, tmp5)
    tmp21 = tl.where(tmp18, tmp16, tmp20)
    tmp22 = tl.where(tmp18, tmp19, tmp21)
    tmp23 = tmp7 * tmp14
    tmp24 = tmp22 + tmp23
    tmp25 = tmp17 == tmp17
    tmp26 = tl.where(tmp25, tmp24, tmp22)
    tmp27 = tl.where(tmp25, tmp26, tmp26)
    tmp29 = tmp8 - tmp28
    tmp30 = tmp12 * tmp10
    tmp32 = tmp31 * tmp3
    tmp33 = tmp30 + tmp32
    tmp34 = tmp29 * tmp33
    tmp35 = tmp27 + tmp34
    tl.store(out_ptr0 + x2, tmp16, xmask)
    tl.store(out_ptr1 + x2, tmp24, xmask)
    tl.store(out_ptr2 + x2, tmp35, xmask)


@triton.jit
def triton_poi_fused_add_copy_mul_rsub_zeros_like_1(in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp3 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp10 = tl.load(in_ptr3 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp11 = tl.load(in_ptr4 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp0 = x1
    tmp1 = tl.full([1], 1, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = tmp1 == tmp1
    tmp6 = tl.full([1], 0, tl.int32)
    tmp7 = tmp1 == tmp6
    tmp8 = tmp6 == tmp6
    tmp12 = tmp10 * tmp11
    tmp13 = 0.0
    tmp14 = tl.where(tmp8, tmp12, tmp13)
    tmp15 = tl.where(tmp8, tmp9, tmp14)
    tmp16 = tl.where(tmp7, tmp12, tmp13)
    tmp17 = tl.where(tmp7, tmp9, tmp16)
    tmp18 = tl.where(tmp7, tmp15, tmp17)
    tmp19 = tl.where(tmp4, tmp5, tmp18)
    tmp20 = tmp0 == tmp6
    tmp21 = tl.where(tmp20, tmp12, tmp13)
    tmp22 = tl.where(tmp20, tmp9, tmp21)
    tmp23 = tl.where(tmp20, tmp15, tmp22)
    tmp24 = tl.where(tmp2, tmp5, tmp23)
    tmp25 = tl.where(tmp2, tmp19, tmp24)
    tmp26 = tl.where(tmp2, tmp3, tmp25)
    tl.store(out_ptr0 + x3, tmp26, xmask)


@triton.jit
def triton_poi_fused_add_mul_rsub_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    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 % 16
    x1 = xindex // 16
    x2 = xindex
    tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp6 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
    tmp7 = tl.load(in_ptr2 + (16 + x0 + 64 * x1), xmask)
    tmp8 = tl.load(in_ptr3 + (16 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr2 + (32 + x0 + 64 * x1), xmask)
    tmp11 = tl.load(in_ptr3 + (x0 + 64 * x1), xmask)
    tmp19 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
    tmp23 = tl.load(in_ptr2 + (48 + x0 + 64 * x1), xmask)
    tmp0 = tl.full([1], 2, tl.int32)
    tmp1 = tl.full([1], 1, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp9 = tmp7 * tmp8
    tmp12 = tmp10 * tmp11
    tmp13 = tmp9 + tmp12
    tmp14 = tmp6 * tmp13
    tmp15 = tmp5 + tmp14
    tmp16 = tmp0 == tmp0
    tmp17 = tl.where(tmp16, tmp15, tmp5)
    tmp18 = tl.where(tmp16, tmp17, tmp17)
    tmp20 = 1.0
    tmp21 = tmp20 - tmp19
    tmp22 = tmp10 * tmp8
    tmp24 = tmp23 * tmp11
    tmp25 = tmp22 + tmp24
    tmp26 = tmp21 * tmp25
    tmp27 = tmp18 + tmp26
    tl.store(out_ptr0 + x2, tmp15, xmask)
    tl.store(out_ptr1 + x2, tmp27, xmask)


@triton.jit
def triton_poi_fused_add_mul_rsub_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp3 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr2 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr2 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp13 = tl.load(in_ptr2 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 2, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = tmp1 == tmp1
    tmp6 = tl.full([1], 1, tl.int32)
    tmp7 = tmp1 == tmp6
    tmp10 = tl.where(tmp7, tmp8, tmp9)
    tmp11 = tl.where(tmp4, tmp5, tmp10)
    tmp12 = tmp0 == tmp6
    tmp14 = tl.where(tmp12, tmp8, tmp13)
    tmp15 = tl.where(tmp2, tmp5, tmp14)
    tmp16 = tl.where(tmp2, tmp11, tmp15)
    tmp17 = tl.where(tmp2, tmp3, tmp16)
    tl.store(out_ptr0 + x3, tmp17, xmask)


@triton.jit
def triton_poi_fused_add_mul_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp4 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp6 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
    tmp7 = tl.load(in_ptr2 + (32 + x0 + 64 * x1), xmask)
    tmp8 = tl.load(in_ptr3 + (16 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr2 + (48 + x0 + 64 * x1), xmask)
    tmp11 = tl.load(in_ptr3 + (x0 + 64 * x1), xmask)
    tmp0 = tl.full([1], 3, tl.int32)
    tmp1 = tl.full([1], 2, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp9 = tmp7 * tmp8
    tmp12 = tmp10 * tmp11
    tmp13 = tmp9 + tmp12
    tmp14 = tmp6 * tmp13
    tmp15 = tmp5 + tmp14
    tl.store(out_ptr0 + x2, tmp15, xmask)


@triton.jit
def triton_poi_fused_clone_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x3 = xindex // 256
    x5 = xindex % 64
    x6 = xindex
    tmp4 = tl.load(in_ptr0 + (x0 + 16 * x3), xmask, eviction_policy=
        'evict_last')
    tmp7 = tl.load(in_ptr1 + (32 + x0 + 64 * x3), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr1 + (48 + x0 + 64 * x3), xmask, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr1 + (x5 + 64 * x3), xmask, eviction_policy=
        'evict_last')
    tmp0 = x1
    tmp1 = tl.full([1], 3, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp3 = tmp1 == tmp1
    tmp5 = tl.full([1], 2, tl.int32)
    tmp6 = tmp1 == tmp5
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tl.where(tmp3, tmp4, tmp9)
    tmp11 = tmp0 == tmp5
    tmp13 = tl.where(tmp11, tmp7, tmp12)
    tmp14 = tl.where(tmp2, tmp4, tmp13)
    tmp15 = tl.where(tmp2, tmp10, tmp14)
    tl.store(out_ptr0 + x6, tmp15, xmask)


@triton.jit
def triton_poi_fused_clone_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 256
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_mul_7(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp4 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp7 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr1 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 3, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp3 = tmp1 == tmp1
    tmp5 = tl.full([1], 2, tl.int32)
    tmp6 = tmp1 == tmp5
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tl.where(tmp3, tmp4, tmp9)
    tmp11 = tmp0 == tmp5
    tmp13 = tl.where(tmp11, tmp7, tmp12)
    tmp14 = tl.where(tmp2, tmp4, tmp13)
    tmp15 = tl.where(tmp2, tmp10, tmp14)
    tl.store(out_ptr0 + x3, tmp15, xmask)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_mul_rsub_0[grid(64)](arg0_1, arg1_1, arg2_1,
            buf0, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_add_copy_mul_rsub_zeros_like_1[grid(256)](buf2,
            buf1, buf0, arg0_1, arg1_1, buf3, 256, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf0
        buf4 = buf2
        del buf2
        buf5 = buf1
        del buf1
        triton_poi_fused_add_mul_rsub_2[grid(64)](buf3, arg2_1, arg0_1,
            arg1_1, buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_add_mul_rsub_3[grid(256)](buf5, buf4, buf3, buf6, 
            256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf4
        buf7 = buf5
        del buf5
        triton_poi_fused_add_mul_4[grid(64)](buf6, arg2_1, arg0_1, arg1_1,
            buf7, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        del arg2_1
        buf8 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_clone_5[grid(1024)](buf7, buf6, buf8, 1024, XBLOCK
            =256, num_warps=4, num_stages=1)
        buf9 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_clone_6[grid(1024)](arg3_1, buf9, 1024, XBLOCK=256,
            num_warps=4, num_stages=1)
        del arg3_1
        buf10 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf8, (64, 4, 4), (16, 4, 1),
            0), reinterpret_tensor(buf9, (64, 4, 4), (16, 4, 1), 0), out=buf10)
        del buf8
        del buf9
        buf11 = buf3
        del buf3
        triton_poi_fused_add_mul_7[grid(256)](buf7, buf6, buf11, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del buf6
        del buf7
    return reinterpret_tensor(buf10, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0
        ), buf11


class StateAttentionNew(nn.Module):

    def __init__(self):
        super(StateAttentionNew, self).__init__()
        self.sm = nn.Softmax(dim=1)

    def forward(self, input_0, input_1, input_2, input_3):
        arg0_1 = input_0
        arg1_1 = input_1
        arg2_1 = input_2
        arg3_1 = input_3
        output = call([arg0_1, arg1_1, arg2_1, arg3_1])
        return output[0], output[1]


Measured latency_ms: 0.127477