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.triton_helpers import math as tl_math
import torch.nn as nn
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_abs_index_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 64
    x0 = xindex % 64
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp4 < 4')
    tmp6 = tl.load(in_ptr1 + (x0 + 64 * tmp4), xmask)
    tmp8 = tmp7 + tmp1
    tmp9 = tmp7 < 0
    tmp10 = tl.where(tmp9, tmp8, tmp7)
    tl.device_assert((0 <= tmp10) & (tmp10 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp10 < 4')
    tmp12 = tl.load(in_ptr1 + (x0 + 64 * tmp10), xmask)
    tmp13 = tmp6 - tmp12
    tmp14 = tl_math.abs(tmp13)
    tl.store(out_ptr0 + x2, tmp14, 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,), (1,))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_abs_index_sub_0[grid(256)](primals_2, primals_1,
            primals_3, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_1
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0),
            primals_4, out=buf1)
        del primals_4
    return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0
        ), reinterpret_tensor(buf0, (4, 64), (1, 4), 0)


class MLPDecoderNew(nn.Module):
    """
    MLP based decoder model for edge prediction.
    """

    def __init__(self, input_dim, num_classes, dropout=0.0, bias=False,
        init='xav_uniform'):
        super(MLPDecoderNew, self).__init__()
        assert init in ('xav_uniform', 'kaiming_uniform', 'xav_normal',
            'kaiming_normal')
        self.weight = nn.Parameter(torch.empty(input_dim, num_classes if 
            num_classes > 2 else 1))
        self.bias = None
        if bias:
            self.bias = nn.Parameter(torch.empty(num_classes if num_classes >
                2 else 1))
        self.dropout = nn.Dropout(p=dropout)
        if init == 'xav_uniform':
            torch.nn.init.xavier_uniform_(self.weight.data)
        elif init == 'kaiming_uniform':
            torch.nn.init.kaiming_uniform_(self.weight.data)
        elif init == 'xav_normal':
            torch.nn.init.xavier_normal_(self.weight.data)
        else:
            torch.nn.init.kaiming_normal_(self.weight.data)
        if bias:
            torch.nn.init.zeros_(self.bias.data)

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


Measured latency_ms: 0.024524