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
from torch.nn import Module
import math
from torch.nn.modules import Module
import torch.nn.functional as F
from torch.nn.parameter import Parameter
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_relu_threshold_backward_0(in_out_ptr0, in_out_ptr1,
    in_out_ptr2, in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    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')
    tmp7 = tl.load(in_out_ptr1 + x2, xmask)
    tmp11 = tl.load(in_out_ptr2 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tmp8 = tmp7 + tmp1
    tmp9 = triton_helpers.maximum(tmp3, tmp8)
    tmp10 = tmp9 <= tmp5
    tmp12 = tmp11 + tmp1
    tmp13 = triton_helpers.maximum(tmp3, tmp12)
    tmp14 = tmp13 <= tmp5
    tl.store(in_out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr0 + x2, tmp6, xmask)
    tl.store(in_out_ptr1 + x2, tmp9, xmask)
    tl.store(out_ptr1 + x2, tmp10, xmask)
    tl.store(in_out_ptr2 + x2, tmp13, xmask)
    tl.store(out_ptr2 + x2, tmp14, xmask)


@triton.jit
def triton_per_fused_add_div_eq_masked_fill_norm_sub_1(in_out_ptr0,
    in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + r1 % 4, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (r1 + 64 * x0), xmask, other=0.0)
    tmp13 = tl.load(in_ptr3 + (r1 + 64 * x0), xmask, other=0.0)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp3 + tmp1
    tmp5 = tmp2 - tmp4
    tmp6 = 1e-06
    tmp7 = tmp5 + tmp6
    tmp8 = tmp7 * tmp7
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.where(xmask, tmp9, 0)
    tmp12 = tl.sum(tmp11, 1)[:, None]
    tmp14 = tmp13 + tmp1
    tmp15 = tmp2 - tmp14
    tmp16 = tmp15 + tmp6
    tmp17 = tmp16 * tmp16
    tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK])
    tmp20 = tl.where(xmask, tmp18, 0)
    tmp21 = tl.sum(tmp20, 1)[:, None]
    tmp22 = libdevice.sqrt(tmp12)
    tmp23 = libdevice.sqrt(tmp21)
    tmp24 = 0.0
    tmp25 = tmp23 == tmp24
    tmp26 = tmp16 / tmp23
    tmp27 = tl.where(tmp25, tmp24, tmp26)
    tmp28 = tmp22 == tmp24
    tmp29 = tmp7 / tmp22
    tmp30 = tl.where(tmp28, tmp24, tmp29)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp22, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + x0, tmp23, xmask)
    tl.store(out_ptr0 + (r1 + 64 * x0), tmp27, xmask)
    tl.store(out_ptr1 + (r1 + 64 * x0), tmp30, 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
        ) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (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, 4), (64, 16, 4, 1))
    assert_size_stride(primals_10, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_11, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_12, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
            primals_2, out=buf0)
        buf1 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_1, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0),
            out=buf1)
        buf16 = buf0
        del buf0
        extern_kernels.mm(reinterpret_tensor(primals_12, (64, 4), (4, 1), 0
            ), primals_2, out=buf16)
        buf17 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_11, (16, 4, 4), (16, 
            4, 1), 0), reinterpret_tensor(buf16, (16, 4, 4), (16, 4, 1), 0),
            out=buf17)
        buf8 = buf16
        del buf16
        extern_kernels.mm(reinterpret_tensor(primals_10, (64, 4), (4, 1), 0
            ), primals_2, out=buf8)
        del primals_2
        buf9 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_9, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1), 0),
            out=buf9)
        buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf1
        buf35 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf10 = reinterpret_tensor(buf9, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf9
        buf33 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf18 = reinterpret_tensor(buf17, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf17
        buf31 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_add_relu_threshold_backward_0[grid(256)](buf2,
            buf10, buf18, primals_4, buf35, buf33, buf31, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del primals_4
        buf3 = buf8
        del buf8
        extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0),
            primals_5, out=buf3)
        buf4 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_1, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1), 0),
            out=buf4)
        buf11 = buf3
        del buf3
        extern_kernels.mm(reinterpret_tensor(buf10, (64, 4), (4, 1), 0),
            primals_5, out=buf11)
        buf12 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_9, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf11, (16, 4, 4), (16, 4, 1), 0),
            out=buf12)
        buf19 = buf11
        del buf11
        extern_kernels.mm(reinterpret_tensor(buf18, (64, 4), (4, 1), 0),
            primals_5, out=buf19)
        buf20 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_11, (16, 4, 4), (16, 
            4, 1), 0), reinterpret_tensor(buf19, (16, 4, 4), (16, 4, 1), 0),
            out=buf20)
        buf5 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf4
        buf34 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf13 = reinterpret_tensor(buf12, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf12
        buf32 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf21 = reinterpret_tensor(buf20, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf20
        buf30 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_poi_fused_add_relu_threshold_backward_0[grid(256)](buf5,
            buf13, buf21, primals_6, buf34, buf32, buf30, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del primals_6
        buf6 = buf19
        del buf19
        extern_kernels.mm(reinterpret_tensor(buf5, (64, 4), (4, 1), 0),
            primals_7, out=buf6)
        buf7 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_1, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0),
            out=buf7)
        buf14 = buf6
        del buf6
        extern_kernels.mm(reinterpret_tensor(buf13, (64, 4), (4, 1), 0),
            primals_7, out=buf14)
        buf15 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_9, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf14, (16, 4, 4), (16, 4, 1), 0),
            out=buf15)
        buf22 = buf14
        del buf14
        extern_kernels.mm(reinterpret_tensor(buf21, (64, 4), (4, 1), 0),
            primals_7, out=buf22)
        buf23 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_11, (16, 4, 4), (16, 
            4, 1), 0), reinterpret_tensor(buf22, (16, 4, 4), (16, 4, 1), 0),
            out=buf23)
        buf24 = empty_strided_cuda((4,), (1,), torch.float32)
        buf26 = empty_strided_cuda((4,), (1,), torch.float32)
        buf25 = buf24
        del buf24
        buf27 = buf26
        del buf26
        buf28 = reinterpret_tensor(buf22, (4, 64), (64, 1), 0)
        del buf22
        buf29 = empty_strided_cuda((4, 64), (64, 1), torch.float32)
        triton_per_fused_add_div_eq_masked_fill_norm_sub_1[grid(4)](buf25,
            buf27, buf7, primals_8, buf15, buf23, buf28, buf29, 4, 64,
            XBLOCK=1, num_warps=2, num_stages=1)
        del buf15
        del buf23
        del buf7
        del primals_8
    return buf25, buf27, buf28, buf29, reinterpret_tensor(primals_11, (16, 
        4, 4), (16, 1, 4), 0), reinterpret_tensor(buf21, (4, 64), (1, 4), 0
        ), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0
        ), buf30, reinterpret_tensor(buf18, (4, 64), (1, 4), 0
        ), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0
        ), buf31, reinterpret_tensor(primals_12, (4, 64), (1, 4), 0
        ), reinterpret_tensor(primals_9, (16, 4, 4), (16, 1, 4), 0
        ), reinterpret_tensor(buf13, (4, 64), (1, 4), 0
        ), buf32, reinterpret_tensor(buf10, (4, 64), (1, 4), 0
        ), buf33, reinterpret_tensor(primals_10, (4, 64), (1, 4), 0
        ), reinterpret_tensor(primals_1, (16, 4, 4), (16, 1, 4), 0
        ), reinterpret_tensor(buf5, (4, 64), (1, 4), 0
        ), buf34, reinterpret_tensor(buf2, (4, 64), (1, 4), 0
        ), buf35, reinterpret_tensor(primals_3, (4, 64), (1, 4), 0)


class GraphConvolution(Module):
    """
    Simple GCN layer, similar to https://arxiv.org/abs/1609.02907
    Z = f(X, A) = softmax(A` * ReLU(A` * X * W0)* W1)
    A` = D'^(-0.5) * A * D'^(-0.5)
    """

    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 = Parameter(torch.FloatTensor(in_features, out_features))
        if bias:
            self.bias = 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 forward(self, input, adj):
        support = torch.matmul(input, self.weight)
        output = torch.matmul(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(Module):
    """
    simple GCN layer, similar to https://arxiv.org/abs/1609.02907
    """

    def __init__(self, nfeat, dropout):
        super(GCN, self).__init__()
        self.gc1 = GraphConvolution(nfeat, nfeat)
        self.gc2 = GraphConvolution(nfeat, nfeat)
        self.gc3 = GraphConvolution(nfeat, nfeat)
        self.dropout = dropout

    def forward(self, x, adj):
        batch_size = adj.size(0)
        x = F.relu(self.gc1(x, adj))
        x = F.dropout(x, self.dropout, training=self.training)
        x = F.relu(self.gc2(x, adj))
        x = self.gc3(x, adj)
        out = x.view(batch_size, -1)
        return out


class TripletGCNNew(Module):
    """
    Triplet network with GCN
    This GCN without any FC layer
    """

    def __init__(self, nfeat, dropout):
        super(TripletGCNNew, self).__init__()
        self.gcn = GCN(nfeat, dropout)

    def forward_once(self, x, adj):
        return self.gcn(x, adj)

    def forward(self, input_0, input_1, input_2, input_3, input_4, input_5):
        primals_2 = self.gcn.gc1.weight
        primals_4 = self.gcn.gc1.bias
        primals_5 = self.gcn.gc2.weight
        primals_6 = self.gcn.gc2.bias
        primals_7 = self.gcn.gc3.weight
        primals_8 = self.gcn.gc3.bias
        primals_1 = input_0
        primals_3 = input_1
        primals_9 = input_2
        primals_10 = input_3
        primals_11 = input_4
        primals_12 = input_5
        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])
        return output[0], output[1]


Measured latency_ms: 0.086733