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 math
import torch.nn as nn
import torch.nn.functional as F
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_relu_threshold_backward_view_0(in_ptr0, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    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 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp3 = 0.0
    tmp4 = tmp2 <= tmp3
    tl.store(out_ptr0 + x0, tmp2, xmask)
    tl.store(out_ptr1 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused_add_mul_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    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)
    tmp3 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = -3.0
    tmp2 = tmp0 * tmp1
    tmp4 = 4.0
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tl.store(in_out_ptr0 + x0, tmp6, xmask)


@triton.jit
def triton_poi_fused__log_softmax_add_mul_2(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    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')
    tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp21 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = -3.0
    tmp2 = tmp0 * tmp1
    tmp4 = 4.0
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp8 = tmp7 * tmp1
    tmp10 = tmp9 * tmp4
    tmp11 = tmp8 + tmp10
    tmp12 = triton_helpers.maximum(tmp6, tmp11)
    tmp14 = tmp13 * tmp1
    tmp16 = tmp15 * tmp4
    tmp17 = tmp14 + tmp16
    tmp18 = triton_helpers.maximum(tmp12, tmp17)
    tmp20 = tmp19 * tmp1
    tmp22 = tmp21 * tmp4
    tmp23 = tmp20 + tmp22
    tmp24 = triton_helpers.maximum(tmp18, tmp23)
    tmp25 = tmp6 - tmp24
    tmp26 = tl_math.exp(tmp25)
    tmp27 = tmp11 - tmp24
    tmp28 = tl_math.exp(tmp27)
    tmp29 = tmp26 + tmp28
    tmp30 = tmp17 - tmp24
    tmp31 = tl_math.exp(tmp30)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp23 - tmp24
    tmp34 = tl_math.exp(tmp33)
    tmp35 = tmp32 + tmp34
    tl.store(out_ptr0 + x0, tmp24, xmask)
    tl.store(out_ptr1 + x0, tmp35, xmask)


@triton.jit
def triton_poi_fused__log_softmax_add_mul_3(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    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 + x2, xmask)
    tmp3 = tl.load(in_out_ptr0 + x2, xmask)
    tmp7 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp1 = -3.0
    tmp2 = tmp0 * tmp1
    tmp4 = 4.0
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp8 = tmp6 - tmp7
    tmp10 = tl_math.log(tmp9)
    tmp11 = tmp8 - tmp10
    tl.store(in_out_ptr0 + x2, tmp11, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = 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, 1))
    assert_size_stride(primals_4, (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_1, (64, 4), (4, 1), 0),
            primals_2, out=buf0)
        del primals_2
        buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_relu_threshold_backward_view_0[grid(256)](buf0,
            buf1, buf13, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf2 = buf0
        del buf0
        extern_kernels.mm(buf1, primals_3, out=buf2)
        buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_4, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0),
            out=buf3)
        buf4 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf3
        triton_poi_fused_add_mul_1[grid(256)](buf4, buf2, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(primals_4, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf4, (16, 4, 4), (16, 4, 1), 0),
            out=buf5)
        buf6 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf5
        triton_poi_fused_add_mul_1[grid(256)](buf6, buf2, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf7 = reinterpret_tensor(buf4, (16, 4, 4), (16, 4, 1), 0)
        del buf4
        extern_kernels.bmm(reinterpret_tensor(primals_4, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0),
            out=buf7)
        buf8 = reinterpret_tensor(buf7, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf7
        triton_poi_fused_add_mul_1[grid(256)](buf8, buf2, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf9 = reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0)
        del buf6
        extern_kernels.bmm(reinterpret_tensor(primals_4, (16, 4, 4), (16, 4,
            1), 0), reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1), 0),
            out=buf9)
        del buf8
        buf10 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf11 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        triton_poi_fused__log_softmax_add_mul_2[grid(64)](buf9, buf2, buf10,
            buf11, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf12 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf2
        triton_poi_fused__log_softmax_add_mul_3[grid(256)](buf12, buf9,
            buf10, buf11, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf10
        del buf11
        del buf9
    return buf12, buf12, reinterpret_tensor(primals_4, (16, 4, 4), (16, 1, 
        4), 0), reinterpret_tensor(buf1, (4, 64), (1, 4), 0
        ), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0
        ), buf13, reinterpret_tensor(primals_1, (4, 64), (1, 4), 0)


class Linear(nn.Module):

    def __init__(self, in_features, out_features, dropout, bias=False):
        super(Linear, self).__init__()
        self.dropout = dropout
        self.in_features = in_features
        self.out_features = out_features
        self.weight = nn.Parameter(torch.randn(in_features, out_features))
        if bias:
            self.bias = nn.Parameter(torch.randn(out_features))
        else:
            self.register_parameter('bias', None)
        self.reset_parameters()

    def reset_parameters(self):
        nn.init.kaiming_uniform_(self.weight, mode='fan_out', a=math.sqrt(5))
        if self.bias is not None:
            stdv = 1.0 / math.sqrt(self.weight.size(1))
            self.bias.data.uniform_(-stdv, stdv)

    def forward(self, input):
        input = F.dropout(input, self.dropout, training=self.training)
        output = torch.matmul(input, self.weight)
        if self.bias is not None:
            return output + self.bias
        else:
            return output


class APPNPNew(nn.Module):

    def __init__(self, nfeat, nhid, nclass, dropout, K, alpha):
        super(APPNPNew, self).__init__()
        self.Linear1 = Linear(nfeat, nhid, dropout, bias=False)
        self.Linear2 = Linear(nhid, nclass, dropout, bias=False)
        self.alpha = alpha
        self.K = K

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


Measured latency_ms: 0.061136