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 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_clone_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x4 = xindex
    x5 = xindex // 4 % 16
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x4, xmask)
    tmp1 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp2, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (16, 4, 4, 1), (16, 4, 1, 1))
    assert_size_stride(primals_2, (16,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 16, 1, 4), (64, 4, 4, 1))
        buf1 = empty_strided_cuda((4, 4, 4, 4, 1, 1), (64, 16, 4, 1, 1, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_clone_0[grid(256)](buf0, primals_2, buf1, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        del buf0
        del primals_2
        buf2 = empty_strided_cuda((1, 16, 4), (64, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf1, (1, 16, 16), (0, 16, 1),
            0), reinterpret_tensor(primals_4, (1, 16, 4), (64, 4, 1), 0),
            out=buf2)
        del buf1
    return reinterpret_tensor(buf2, (4, 4, 1, 4), (16, 4, 4, 1), 0
        ), primals_1, primals_3, reinterpret_tensor(primals_4, (1, 4, 16),
        (64, 1, 4), 0)


class ConvTemporalGraphicalNew(nn.Module):
    """The basic module for applying a graph convolution.

    Args:
        in_channels (int): Number of channels in the input sequence data
        out_channels (int): Number of channels produced by the convolution
        A_channels (int): Number of channels in the spatial adjacency matrix
        temporal_kernel_size (int): Size of temporal convolve kernel
        temporal_stride (int, optional): Stride of the temporal convolution. Default: 1
        temporal_padding (int, optional): Temporal zero-padding added to both sides of
            the input. Default: 0
        temporal_dilation (int, optional): Spacing between temporal kernel elements.
            Default: 1
        bias (bool, optional): If ``True``, adds a learnable bias to the output.
            Default: ``True``

    Shape:
        - Input[0]: Input graph sequence in :math:`(N, in_channels, T_{in}, V)` format
        - Input[1]: Input graph adjacency matrix in :math:`(K, V, V)` format
        - Output[0]: Output graph sequence in :math:`(N, out_channels, T_{out}, V)` format
        - Output[1]: Graph adjacency matrix for output data in :math:`(K, V, V)` format

        where
            :math:`N` is a batch size,
            :math:`K` is the spatial kernel size, as :math:`K == kernel_size[1]`,
            :math:`T_{in}/T_{out}` is a length of input/output sequence,
            :math:`V` is the number of graph nodes. 
    """

    def __init__(self, in_channels, out_channels, A_channels,
        temporal_kernel_size, temporal_stride=1, temporal_padding=0,
        temporal_dilation=1, bias=True):
        super().__init__()
        self.conv = nn.Conv2d(in_channels, out_channels * A_channels,
            kernel_size=(temporal_kernel_size, 1), padding=(
            temporal_padding, 0), stride=(temporal_stride, 1), dilation=(
            temporal_dilation, 1), bias=bias)

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


Measured latency_ms: 0.033439