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 libdevice, math as tl_math
import torch.nn as nn
from torch.nn.parameter import Parameter
from torch.autograd import Variable
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_linalg_vector_norm_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = libdevice.sqrt(tmp10)
    tl.store(out_ptr0 + x0, tmp11, xmask)


@triton.jit
def triton_poi_fused_add_div_1(in_out_ptr0, in_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_out_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask)
    tmp2 = 1e-07
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 / tmp3
    tl.store(in_out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused__softmax_add_mul_rsub_2(in_ptr0, in_ptr1, in_ptr2,
    out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp24 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp26 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp3 = tmp1 * tmp2
    tmp5 = 1.0
    tmp6 = tmp5 - tmp4
    tmp7 = -1000000000.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp3 + tmp8
    tmp11 = tmp1 * tmp10
    tmp13 = tmp5 - tmp12
    tmp14 = tmp13 * tmp7
    tmp15 = tmp11 + tmp14
    tmp16 = triton_helpers.maximum(tmp9, tmp15)
    tmp18 = tmp1 * tmp17
    tmp20 = tmp5 - tmp19
    tmp21 = tmp20 * tmp7
    tmp22 = tmp18 + tmp21
    tmp23 = triton_helpers.maximum(tmp16, tmp22)
    tmp25 = tmp1 * tmp24
    tmp27 = tmp5 - tmp26
    tmp28 = tmp27 * tmp7
    tmp29 = tmp25 + tmp28
    tmp30 = triton_helpers.maximum(tmp23, tmp29)
    tmp31 = tmp9 - tmp30
    tmp32 = tl_math.exp(tmp31)
    tmp33 = tmp15 - tmp30
    tmp34 = tl_math.exp(tmp33)
    tmp35 = tmp32 + tmp34
    tmp36 = tmp22 - tmp30
    tmp37 = tl_math.exp(tmp36)
    tmp38 = tmp35 + tmp37
    tmp39 = tmp29 - tmp30
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp38 + tmp40
    tl.store(out_ptr0 + x0, tmp30, xmask)
    tl.store(out_ptr1 + x0, tmp41, xmask)


@triton.jit
def triton_poi_fused__softmax_add_mul_rsub_3(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, 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 // 4
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + x2, xmask)
    tmp4 = tl.load(in_ptr2 + x2, xmask)
    tmp10 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp5 = 1.0
    tmp6 = tmp5 - tmp4
    tmp7 = -1000000000.0
    tmp8 = tmp6 * tmp7
    tmp9 = tmp3 + tmp8
    tmp11 = tmp9 - tmp10
    tmp12 = tl_math.exp(tmp11)
    tmp14 = tmp12 / tmp13
    tl.store(out_ptr0 + x2, tmp14, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (1,), (1,))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4,), (1,), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_linalg_vector_norm_0[grid(4)](primals_1, buf0, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_1, (4, 4),
            (1, 4), 0), out=buf1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (4, 1), (1, 0), 0),
            reinterpret_tensor(buf0, (1, 4), (0, 1), 0), out=buf2)
        buf3 = buf1
        del buf1
        triton_poi_fused_add_div_1[grid(16)](buf3, buf2, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf4 = reinterpret_tensor(buf0, (4, 1), (1, 4), 0)
        del buf0
        buf5 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused__softmax_add_mul_rsub_2[grid(4)](primals_2, buf3,
            primals_3, buf4, buf5, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf6 = buf2
        del buf2
        triton_poi_fused__softmax_add_mul_rsub_3[grid(16)](primals_2, buf3,
            primals_3, buf4, buf5, buf6, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        del buf4
        del buf5
        del primals_2
        del primals_3
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf6, primals_1, out=buf7)
    return buf7, reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), buf3, buf6


class GraphAttentionLayerNew(nn.Module):

    def __init__(self, requires_grad=True):
        super(GraphAttentionLayerNew, self).__init__()
        if requires_grad:
            self.beta = Parameter(torch.Tensor(1).uniform_(0, 1),
                requires_grad=requires_grad)
        else:
            self.beta = Variable(torch.zeros(1), requires_grad=requires_grad)

    def __repr__(self):
        return self.__class__.__name__ + ' (16 -> 16)'

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


Measured latency_ms: 0.076996