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 = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    x2 = 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 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x2, tmp10, xmask)


@triton.jit
def triton_poi_fused_gt_1(in_ptr0, 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 = 0.0
    tmp2 = tmp0 > tmp1
    tl.store(out_ptr0 + x0, tmp2, xmask)


@triton.jit
def triton_poi_fused__softmax_leaky_relu_mul_where_2(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
    x2 = xindex
    x1 = xindex // 2
    tmp0 = tl.load(in_ptr0 + x2, xmask).to(tl.int1)
    tmp1 = tl.load(in_ptr1 + x2, xmask)
    tmp9 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last').to(tl
        .int1)
    tmp10 = tl.load(in_ptr1 + 2 * x1, xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last'
        ).to(tl.int1)
    tmp16 = tl.load(in_ptr1 + (1 + 2 * x1), xmask, eviction_policy='evict_last'
        )
    tmp2 = 0.0
    tmp3 = tmp1 > tmp2
    tmp4 = 4.0
    tmp5 = tmp1 * tmp4
    tmp6 = tl.where(tmp3, tmp1, tmp5)
    tmp7 = -8999999815811072.0
    tmp8 = tl.where(tmp0, tmp6, tmp7)
    tmp11 = tmp10 > tmp2
    tmp12 = tmp10 * tmp4
    tmp13 = tl.where(tmp11, tmp10, tmp12)
    tmp14 = tl.where(tmp9, tmp13, tmp7)
    tmp17 = tmp16 > tmp2
    tmp18 = tmp16 * tmp4
    tmp19 = tl.where(tmp17, tmp16, tmp18)
    tmp20 = tl.where(tmp15, tmp19, tmp7)
    tmp21 = triton_helpers.maximum(tmp14, tmp20)
    tmp22 = tmp8 - tmp21
    tmp23 = tl_math.exp(tmp22)
    tl.store(out_ptr0 + x2, tmp23, xmask)


@triton.jit
def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 2
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 / tmp3
    tl.store(out_ptr0 + x2, tmp4, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (1, 8), (8, 1))
    assert_size_stride(primals_4, (1,), (1,))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((8, 2, 8), (16, 8, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(128)](primals_1, primals_2, buf0, 128,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_1
        buf2 = empty_strided_cuda((16, 1), (1, 1), torch.float32)
        extern_kernels.addmm(primals_4, reinterpret_tensor(buf0, (16, 8), (
            8, 1), 0), reinterpret_tensor(primals_3, (8, 1), (1, 8), 0),
            alpha=1, beta=1, out=buf2)
        del primals_3
        del primals_4
        buf3 = empty_strided_cuda((8, 2), (2, 1), torch.bool)
        triton_poi_fused_gt_1[grid(16)](primals_5, buf3, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del primals_5
        buf4 = empty_strided_cuda((8, 2), (2, 1), torch.float32)
        triton_poi_fused__softmax_leaky_relu_mul_where_2[grid(16)](buf3,
            buf2, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf5 = empty_strided_cuda((8, 2), (2, 1), torch.float32)
        triton_poi_fused__softmax_3[grid(16)](buf4, buf5, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del buf4
        buf6 = empty_strided_cuda((8, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf5, (8, 1, 2), (2, 0, 1), 0
            ), reinterpret_tensor(primals_2, (8, 2, 4), (8, 4, 1), 0), out=buf6
            )
        del buf5
    return reinterpret_tensor(buf6, (4, 2, 4), (8, 4, 1), 0
        ), reinterpret_tensor(buf0, (16, 8), (8, 1), 0
        ), buf2, buf3, reinterpret_tensor(primals_2, (8, 4, 2), (8, 1, 4), 0)


class GraphAttentionNew(nn.Module):

    def __init__(self, d_q, d_v, alpha, dropout=0.1):
        super(GraphAttentionNew, self).__init__()
        self.dropout = nn.Dropout(dropout)
        self.attention = nn.Linear(d_q + d_v, 1)
        self.leaky_relu = nn.LeakyReLU(alpha)

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


Measured latency_ms: 0.048005