import torch
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.functional as F
import torch.nn as nn
from torch.nn import Parameter
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_add_leaky_relu_mul_sum_0(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x2), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (2 + 4 * x2), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (3 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr2 + 4 * x2, xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr2 + (1 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr2 + (2 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp23 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp26 = tl.load(in_ptr2 + (3 + 4 * x2), xmask, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr3 + (3 + 4 * x0), 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
    tmp17 = tmp15 * tmp16
    tmp20 = tmp18 * tmp19
    tmp21 = tmp17 + tmp20
    tmp24 = tmp22 * tmp23
    tmp25 = tmp21 + tmp24
    tmp28 = tmp26 * tmp27
    tmp29 = tmp25 + tmp28
    tmp30 = tmp14 + tmp29
    tmp31 = tmp15 * tmp1
    tmp32 = tmp18 * tmp4
    tmp33 = tmp31 + tmp32
    tmp34 = tmp22 * tmp8
    tmp35 = tmp33 + tmp34
    tmp36 = tmp26 * tmp12
    tmp37 = tmp35 + tmp36
    tmp38 = tmp0 * tmp16
    tmp39 = tmp3 * tmp19
    tmp40 = tmp38 + tmp39
    tmp41 = tmp7 * tmp23
    tmp42 = tmp40 + tmp41
    tmp43 = tmp11 * tmp27
    tmp44 = tmp42 + tmp43
    tmp45 = tmp37 + tmp44
    tmp46 = 0.0
    tmp47 = tmp30 > tmp46
    tmp48 = 0.2
    tmp49 = tmp30 * tmp48
    tmp50 = tl.where(tmp47, tmp30, tmp49)
    tmp51 = tmp50 + tmp45
    tl.store(out_ptr1 + x2, tmp47, xmask)
    tl.store(in_out_ptr0 + x2, tmp51, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (1, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (1, 4, 4), (16, 4, 1))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        buf3 = buf2
        del buf2
        get_raw_stream(0)
        triton_poi_fused_add_leaky_relu_mul_sum_0[grid(64)](buf3, primals_2,
            primals_1, primals_4, primals_3, buf1, 64, XBLOCK=64, num_warps
            =1, num_stages=1)
        del primals_1
        del primals_3
    return buf3, primals_2, primals_4, buf1


class ConstAttention(nn.Module):

    def __init__(self, **kwargs):
        super(ConstAttention, self).__init__()

    def forward(self, neighbor_vecs, self_vecs):
        return 1


class GatAttention(ConstAttention):

    def __init__(self, num_heads, out_channels):
        super(GatAttention, self).__init__()
        self.num_heads = num_heads
        self.out_channels = out_channels
        self.att_self_weight = Parameter(torch.Tensor(1, self.num_heads,
            self.out_channels))
        self.att_neighbor_weight = Parameter(torch.Tensor(1, self.num_heads,
            self.out_channels))
        self.reset_parameters()

    def reset_parameters(self):
        pass

    def forward(self, neighbor_vecs, self_vecs):
        alpha = (self_vecs * self.att_self_weight).sum(dim=-1) + (neighbor_vecs
             * self.att_neighbor_weight).sum(dim=-1)
        alpha = F.leaky_relu(alpha, negative_slope=0.2)
        return alpha


class GatSymAttentionNew(GatAttention):

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


Measured latency_ms: 0.018329