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
import torch.nn.functional as F
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_cat_0(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
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tl.store(out_ptr0 + (x0 + 12 * x1), tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_1(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
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tl.store(out_ptr0 + (x0 + 12 * x1), tmp0, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = 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, 12), (12, 1))
    assert_size_stride(primals_4, (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)
        buf4 = empty_strided_cuda((4, 12), (12, 1), torch.float32)
        buf1 = reinterpret_tensor(buf4, (4, 4), (12, 1), 8)
        extern_kernels.mm(primals_2, buf0, out=buf1)
        del primals_2
        buf2 = reinterpret_tensor(buf4, (4, 4), (12, 1), 0)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(16)](primals_1, buf2, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del primals_1
        buf3 = reinterpret_tensor(buf4, (4, 4), (12, 1), 4)
        triton_poi_fused_cat_1[grid(16)](buf0, buf3, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf5 = buf0
        del buf0
        extern_kernels.addmm(primals_4, buf4, reinterpret_tensor(primals_3,
            (12, 4), (1, 12), 0), alpha=1, beta=1, out=buf5)
        del primals_3
        del primals_4
    return buf5, buf4


class TAGConvNew(nn.Module):
    """

    Description
    -----------
    TAGCN convolutional layer.

    Parameters
    ----------
    in_features : int
        Dimension of input features.
    out_features : int
        Dimension of output features.
    k : int, optional
        Hyper-parameter, refer to original paper. Default: ``2``.
    activation : func of torch.nn.functional, optional
        Activation function. Default: ``None``.

    batch_norm : bool, optional
        Whether to apply batch normalization. Default: ``False``.
    dropout : float, optional
        Rate of dropout. Default: ``0.0``.

    """

    def __init__(self, in_features, out_features, k=2, activation=None,
        batch_norm=False, dropout=0.0):
        super(TAGConvNew, self).__init__()
        self.in_features = in_features
        self.out_features = out_features
        self.linear = nn.Linear(in_features * (k + 1), out_features)
        self.batch_norm = batch_norm
        if batch_norm:
            self.norm_func = nn.BatchNorm1d(out_features, affine=False)
        self.activation = activation
        if dropout > 0.0:
            self.dropout = nn.Dropout(dropout)
        else:
            self.dropout = None
        self.k = k
        self.reset_parameters()

    def reset_parameters(self):
        """Reset parameters."""
        if self.activation == F.leaky_relu:
            gain = nn.init.calculate_gain('leaky_relu')
        else:
            gain = nn.init.calculate_gain('relu')
        nn.init.xavier_normal_(self.linear.weight, gain=gain)

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


Measured latency_ms: 0.033905