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 import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 768
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 12
    x2 = xindex // 48
    x1 = xindex // 12 % 4
    x3 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x2 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 8, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp9 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp11 = tmp0 >= tmp7
    tl.full([1], 12, tl.int64)
    tmp14 = tl.load(in_ptr0 + (4 * x2 + (-8 + x0)), tmp11 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp15 = tl.load(in_ptr1 + (4 * x1 + (-8 + x0)), tmp11 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp16 = tmp14 * tmp15
    tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype)
    tmp18 = tl.where(tmp11, tmp16, tmp17)
    tmp19 = tl.where(tmp9, tmp10, tmp18)
    tmp20 = tl.where(tmp4, tmp5, tmp19)
    tl.store(out_ptr0 + x3, tmp20, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused_mul_repeat_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    y0 = yindex % 4
    x2 = xindex
    y3 = yindex
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + 4 * y0, ymask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * y0), ymask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * y0), ymask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * y0), ymask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr1 + (y0 + 16 * y1), ymask, eviction_policy=
        'evict_last')
    tmp17 = tl.load(in_ptr1 + (4 + y0 + 16 * y1), ymask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr1 + (8 + y0 + 16 * y1), ymask, eviction_policy=
        'evict_last')
    tmp21 = tl.load(in_ptr1 + (12 + y0 + 16 * y1), ymask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = tl_math.abs(tmp6)
    tmp8 = tl.full([1, 1], 0, tl.int32)
    tmp9 = tmp8 < tmp7
    tmp10 = tmp9.to(tl.int8)
    tmp11 = tmp7 < tmp8
    tmp12 = tmp11.to(tl.int8)
    tmp13 = tmp10 - tmp12
    tmp14 = tmp13.to(tmp7.dtype)
    tmp18 = tmp16 + tmp17
    tmp20 = tmp18 + tmp19
    tmp22 = tmp20 + tmp21
    tmp23 = tmp15 / tmp22
    tmp24 = tmp23 * tmp14
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp14, xmask & ymask)
    tl.store(out_ptr1 + (x2 + 4 * y3), tmp24, xmask & ymask)


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


@triton.jit
def triton_poi_fused_cat_4(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x3 = xindex // 8
    x1 = xindex // 8 % 4
    x2 = xindex // 32
    x4 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x3 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr1 + (x1 + 16 * x2), tmp6 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp10 = tl.load(in_ptr0 + (4 * x3 + (-4 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp11 = tmp9 * tmp10
    tmp12 = tl.load(in_ptr1 + (4 + x1 + 16 * x2), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp13 = tmp12 * tmp10
    tmp14 = tmp11 + tmp13
    tmp15 = tl.load(in_ptr1 + (8 + x1 + 16 * x2), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp16 = tmp15 * tmp10
    tmp17 = tmp14 + tmp16
    tmp18 = tl.load(in_ptr1 + (12 + x1 + 16 * x2), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp19 = tmp18 * tmp10
    tmp20 = tmp17 + tmp19
    tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype)
    tmp22 = tl.where(tmp6, tmp20, tmp21)
    tmp23 = tl.where(tmp4, tmp5, tmp22)
    tl.store(out_ptr0 + x4, tmp23, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (1, 12), (12, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 12), (192, 48, 12, 1), torch.
            float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(768)](primals_1, primals_2, buf0, 768,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (64, 12), (12, 1), 0),
            reinterpret_tensor(primals_3, (12, 1), (1, 12), 0), out=buf1)
        del primals_3
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_mul_repeat_2[grid(16, 4)](primals_2, buf2, buf3,
            buf4, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
        del primals_2
        buf5 = buf2
        del buf2
        triton_poi_fused_mul_sum_3[grid(64)](buf4, primals_1, buf5, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        triton_poi_fused_cat_4[grid(128)](primals_1, buf4, buf6, 128,
            XBLOCK=128, num_warps=4, num_stages=1)
        del buf4
    return buf6, buf5, primals_1, reinterpret_tensor(buf0, (64, 12), (12, 1), 0
        ), buf1, buf3


class AttFlowLayerNew(nn.Module):

    def __init__(self, embed_length):
        super(AttFlowLayerNew, self).__init__()
        self.embed_length = embed_length
        self.alpha = nn.Linear(3 * embed_length, 1, bias=False)

    def forward(self, input_0, input_1):
        primals_3 = self.alpha.weight
        primals_1 = input_0
        primals_2 = input_1
        output = call([primals_1, primals_2, primals_3])
        return output[0], output[1]


Measured latency_ms: 0.078517