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.nn import Module
import math
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.module import Module
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    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 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 4.0
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_poi_fused_add_leaky_relu_1(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
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tl.store(out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    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).to(tl.int1)
    tmp6 = tl.load(in_ptr1 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp8 = tmp6 + tmp7
    tmp9 = 4.0
    tmp10 = tmp8 * tmp9
    tmp11 = tl.where(tmp5, tmp8, tmp10)
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp17 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp18 = tl.where(tmp4, tmp13, tmp17)
    tl.store(out_ptr0 + x2, tmp18, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_3(in_out_ptr0, 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
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr0 + x2, tmp6, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4, 4), (4, 1))
    assert_size_stride(primals_7, (4, 4), (4, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 4), (4, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 4), (4, 1))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (4, 8), (8, 1))
    assert_size_stride(primals_14, (4,), (1,))
    assert_size_stride(primals_15, (4, 8), (8, 1))
    assert_size_stride(primals_16, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_2, primals_1, out=buf0)
        del primals_1
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf0, out=buf1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf3 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_add_leaky_relu_0[grid(16)](buf1, primals_4, buf2,
            buf3, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_4
        buf4 = buf1
        del buf1
        extern_kernels.mm(primals_6, primals_5, out=buf4)
        del primals_5
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_7, buf4, out=buf5)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf7 = buf4
        del buf4
        triton_poi_fused_add_leaky_relu_0[grid(16)](buf5, primals_8, buf6,
            buf7, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_8
        buf8 = buf5
        del buf5
        extern_kernels.mm(buf3, primals_9, out=buf8)
        buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_7, buf8, out=buf9)
        buf10 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_add_leaky_relu_1[grid(16)](buf9, primals_10, buf10,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf11 = buf8
        del buf8
        extern_kernels.mm(buf7, primals_11, out=buf11)
        buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, buf11, out=buf12)
        del buf11
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_add_leaky_relu_1[grid(16)](buf12, primals_12,
            buf13, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf14 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(32)](buf10, buf9, primals_10, primals_2,
            buf14, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_10
        buf15 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        triton_poi_fused_cat_2[grid(32)](buf13, buf12, primals_12,
            primals_6, buf15, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_12
        buf16 = buf12
        del buf12
        extern_kernels.mm(buf14, reinterpret_tensor(primals_13, (8, 4), (1,
            8), 0), out=buf16)
        buf17 = buf9
        del buf9
        extern_kernels.mm(buf15, reinterpret_tensor(primals_15, (8, 4), (1,
            8), 0), out=buf17)
        buf18 = buf16
        del buf16
        buf21 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_3[grid(16)](buf18,
            primals_14, buf21, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_14
        buf19 = buf17
        del buf17
        buf20 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_3[grid(16)](buf19,
            primals_16, buf20, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_16
    return (buf18, buf19, buf2, buf6, buf10, buf13, buf14, buf15, buf20,
        buf21, primals_15, primals_13, reinterpret_tensor(primals_3, (4, 4),
        (1, 4), 0), reinterpret_tensor(buf7, (4, 4), (1, 4), 0),
        reinterpret_tensor(primals_11, (4, 4), (1, 4), 0),
        reinterpret_tensor(primals_7, (4, 4), (1, 4), 0),
        reinterpret_tensor(buf3, (4, 4), (1, 4), 0), reinterpret_tensor(
        primals_9, (4, 4), (1, 4), 0), reinterpret_tensor(primals_6, (4, 4),
        (1, 4), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0))


class GraphConvolution(Module):

    def __init__(self, in_features, out_features, bias=True):
        super(GraphConvolution, self).__init__()
        self.in_features = in_features
        self.out_features = out_features
        self.weight = nn.Parameter(torch.FloatTensor(in_features, out_features)
            )
        if bias:
            self.bias = nn.Parameter(torch.FloatTensor(out_features))
        else:
            self.register_parameter('bias', None)
        self.reset_parameters()

    def reset_parameters(self):
        stdv = 1.0 / math.sqrt(self.weight.size(1))
        self.weight.data.uniform_(-stdv, stdv)
        if self.bias is not None:
            self.bias.data.uniform_(-stdv, stdv)

    def glorot_init(self, input_dim, output_dim):
        init_range = np.sqrt(6.0 / (input_dim + output_dim))
        initial = torch.rand(input_dim, output_dim
            ) * 2 * init_range - init_range
        return nn.Parameter(initial / 2)

    def forward(self, input, adj):
        support = torch.mm(input, self.weight)
        output = torch.spmm(adj, support)
        if self.bias is not None:
            return output + self.bias
        else:
            return output

    def __repr__(self):
        return self.__class__.__name__ + ' (' + str(self.in_features
            ) + ' -> ' + str(self.out_features) + ')'


class GCN(nn.Module):

    def __init__(self, nfeat, nhid, dropout, alpha):
        super(GCN, self).__init__()
        self.gc1 = GraphConvolution(nfeat, nhid)
        self.dropout = dropout
        self.leakyrelu = nn.LeakyReLU(alpha)

    def forward(self, x, adj):
        x = self.leakyrelu(self.gc1(x, adj))
        return x


class DGCNLayerNew(nn.Module):
    """
        DGCN Module layer
    """

    def __init__(self, opt):
        super(DGCNLayerNew, self).__init__()
        self.opt = opt
        self.dropout = opt['dropout']
        self.gc1 = GCN(nfeat=opt['feature_dim'], nhid=opt['hidden_dim'],
            dropout=opt['dropout'], alpha=opt['leakey'])
        self.gc2 = GCN(nfeat=opt['feature_dim'], nhid=opt['hidden_dim'],
            dropout=opt['dropout'], alpha=opt['leakey'])
        self.gc3 = GCN(nfeat=opt['hidden_dim'], nhid=opt['feature_dim'],
            dropout=opt['dropout'], alpha=opt['leakey'])
        self.gc4 = GCN(nfeat=opt['hidden_dim'], nhid=opt['feature_dim'],
            dropout=opt['dropout'], alpha=opt['leakey'])
        self.user_union = nn.Linear(opt['feature_dim'] + opt['feature_dim'],
            opt['feature_dim'])
        self.item_union = nn.Linear(opt['feature_dim'] + opt['feature_dim'],
            opt['feature_dim'])

    def forward_user(self, ufea, vfea, UV_adj, VU_adj):
        User_ho = self.gc1(ufea, VU_adj)
        User_ho = self.gc3(User_ho, UV_adj)
        User = torch.cat((User_ho, ufea), dim=1)
        User = self.user_union(User)
        return F.relu(User)

    def forward_item(self, ufea, vfea, UV_adj, VU_adj):
        Item_ho = self.gc2(vfea, UV_adj)
        Item_ho = self.gc4(Item_ho, VU_adj)
        Item = torch.cat((Item_ho, vfea), dim=1)
        Item = self.item_union(Item)
        return F.relu(Item)

    def forward_user_share(self, ufea, UV_adj, VU_adj):
        User_ho = self.gc1(ufea, VU_adj)
        User_ho = self.gc3(User_ho, UV_adj)
        User = torch.cat((User_ho, ufea), dim=1)
        User = self.user_union(User)
        return F.relu(User)

    def forward(self, input_0, input_1, input_2, input_3):
        primals_1 = self.gc1.gc1.weight
        primals_4 = self.gc1.gc1.bias
        primals_2 = self.gc2.gc1.weight
        primals_8 = self.gc2.gc1.bias
        primals_3 = self.gc3.gc1.weight
        primals_10 = self.gc3.gc1.bias
        primals_5 = self.gc4.gc1.weight
        primals_12 = self.gc4.gc1.bias
        primals_13 = self.user_union.weight
        primals_14 = self.user_union.bias
        primals_15 = self.item_union.weight
        primals_16 = self.item_union.bias
        primals_6 = input_0
        primals_7 = input_1
        primals_9 = input_2
        primals_11 = input_3
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16])
        return output[0], output[1]


Measured latency_ms: 0.028649