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
import math
from torch import 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__unsafe_view_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4 * x1 + 16 * (x0 % 4) + x0 // 4), xmask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_mul_sub_1(in_out_ptr0, in_ptr0, 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_out_ptr0 + x0, xmask)
    tmp3 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = 2.0
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 - tmp3
    tl.store(in_out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 3, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 2, tl.int64)
    tmp6 = tmp0 < tmp5
    tmp7 = tmp6 & tmp4
    tmp8 = tl.full([1], 1, tl.int64)
    tmp9 = tmp0 < tmp8
    tmp10 = tmp9 & tmp7
    tmp11 = tl.load(in_ptr0 + x0, tmp10 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp12 = tmp0 >= tmp8
    tmp13 = tmp12 & tmp7
    tmp14 = tl.load(in_ptr1 + x0, tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tl.where(tmp9, tmp11, tmp14)
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp7, tmp15, tmp16)
    tmp18 = tmp0 >= tmp5
    tmp19 = tmp18 & tmp4
    tmp20 = tl.load(in_ptr2 + x0, tmp19 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp21 = tl.where(tmp6, tmp17, tmp20)
    tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
    tmp23 = tl.where(tmp4, tmp21, tmp22)
    tmp24 = tmp0 >= tmp3
    tl.full([1], 4, tl.int64)
    tmp27 = tl.load(in_ptr3 + x0, tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp28 = tl.where(tmp4, tmp23, tmp27)
    tl.store(out_ptr0 + x2, tmp28, xmask)


@triton.jit
def triton_poi_fused_mul_sub_3(in_out_ptr0, in_ptr0, 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 + x0, xmask)
    tmp3 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = 2.0
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 - tmp3
    tl.store(in_out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 448
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 64
    x0 = xindex % 64
    x2 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 6, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 5, tl.int64)
    tmp6 = tmp0 < tmp5
    tmp7 = tmp6 & tmp4
    tmp8 = tl.full([1], 4, tl.int64)
    tmp9 = tmp0 < tmp8
    tmp10 = tmp9 & tmp7
    tmp11 = tl.load(in_ptr0 + (x0 + 64 * x1), tmp10 & xmask, other=0.0)
    tmp12 = tmp0 >= tmp8
    tmp13 = tmp12 & tmp7
    tmp14 = tl.load(in_ptr1 + x0, tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = 2.0
    tmp16 = tmp14 * tmp15
    tmp17 = tl.load(in_ptr2 + x0, tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp18 = tmp16 - tmp17
    tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype)
    tmp20 = tl.where(tmp13, tmp18, tmp19)
    tmp21 = tl.where(tmp9, tmp11, tmp20)
    tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
    tmp23 = tl.where(tmp7, tmp21, tmp22)
    tmp24 = tmp0 >= tmp5
    tmp25 = tmp24 & tmp4
    tmp26 = tl.load(in_ptr3 + x0, tmp25 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp27 = tl.where(tmp6, tmp23, tmp26)
    tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
    tmp29 = tl.where(tmp4, tmp27, tmp28)
    tmp30 = tmp0 >= tmp3
    tl.full([1], 7, tl.int64)
    tmp33 = tl.load(in_ptr4 + x0, tmp30 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp34 = tl.where(tmp4, tmp29, tmp33)
    tl.store(out_ptr0 + x2, tmp34, xmask)


@triton.jit
def triton_poi_fused_clone_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 9
    x3 = xindex // 9
    x1 = xindex // 9 % 4
    x2 = xindex // 36
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 8, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 7, tl.int64)
    tmp6 = tmp0 < tmp5
    tmp7 = tmp6 & tmp4
    tmp8 = tl.load(in_ptr0 + (x3 + 64 * x0), tmp7 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp9 = tmp0 >= tmp5
    tmp10 = tmp9 & tmp4
    tmp11 = tl.load(in_ptr1 + x3, tmp10 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp12 = tl.where(tmp6, tmp8, tmp11)
    tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype)
    tmp14 = tl.where(tmp4, tmp12, tmp13)
    tmp15 = tmp0 >= tmp3
    tl.full([1], 9, tl.int64)
    tmp18 = tl.load(in_ptr2 + x3, tmp15 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp19 = 2.0
    tmp20 = tmp18 * tmp19
    tmp21 = tl.load(in_ptr3 + x3, tmp15 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp22 = tmp20 - tmp21
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp15, tmp22, tmp23)
    tmp25 = tl.where(tmp4, tmp14, tmp24)
    tl.store(out_ptr0 + (x0 + 9 * x2 + 144 * x1), tmp25, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_6(in_out_ptr0, in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    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')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr0 + x2, tmp6, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (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, (36, 4), (4, 1))
    assert_size_stride(primals_5, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__unsafe_view_clone_0[grid(64)](primals_1, buf0, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        extern_kernels.mm(primals_2, buf0, out=buf1)
        buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        extern_kernels.mm(primals_2, buf1, out=buf2)
        buf3 = buf2
        del buf2
        triton_poi_fused_mul_sub_1[grid(64)](buf3, buf0, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        extern_kernels.mm(primals_2, buf3, out=buf4)
        buf5 = buf4
        del buf4
        triton_poi_fused_mul_sub_1[grid(64)](buf5, buf1, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32)
        triton_poi_fused_cat_2[grid(256)](buf0, buf1, buf3, buf5, buf6, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf7 = buf1
        del buf1
        extern_kernels.mm(primals_2, buf5, out=buf7)
        del primals_2
        buf8 = buf0
        del buf0
        extern_kernels.mm(primals_3, buf5, out=buf8)
        buf9 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
        extern_kernels.mm(primals_3, buf8, out=buf9)
        buf10 = buf5
        del buf5
        triton_poi_fused_mul_sub_3[grid(64)](buf10, buf9, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del buf9
        buf11 = empty_strided_cuda((7, 4, 16), (64, 16, 1), torch.float32)
        triton_poi_fused_cat_4[grid(448)](buf6, buf7, buf3, buf8, buf10,
            buf11, 448, XBLOCK=256, num_warps=4, num_stages=1)
        del buf3
        del buf6
        buf12 = buf7
        del buf7
        extern_kernels.mm(primals_3, buf10, out=buf12)
        buf13 = buf12
        del buf12
        triton_poi_fused_mul_sub_1[grid(64)](buf13, buf8, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf14 = buf8
        del buf8
        extern_kernels.mm(primals_3, buf13, out=buf14)
        del primals_3
        buf15 = empty_strided_cuda((4, 4, 4, 9), (144, 36, 9, 1), torch.float32
            )
        triton_poi_fused_clone_5[grid(576)](buf11, buf13, buf14, buf10,
            buf15, 576, XBLOCK=256, num_warps=4, num_stages=1)
        del buf10
        del buf11
        del buf13
        buf16 = reinterpret_tensor(buf14, (16, 4), (4, 1), 0)
        del buf14
        extern_kernels.mm(reinterpret_tensor(buf15, (16, 36), (36, 1), 0),
            primals_4, out=buf16)
        del primals_4
        buf17 = reinterpret_tensor(buf16, (4, 4, 4), (16, 4, 1), 0)
        del buf16
        buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_6[grid(64)](buf17,
            primals_5, buf18, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_5
    return buf17, buf18, reinterpret_tensor(buf15, (36, 16), (1, 36), 0)


class D_GCNNew(nn.Module):
    """
    Neural network block that applies a diffusion graph convolution to sampled location
    """

    def __init__(self, in_channels, out_channels, orders, activation='relu'):
        """
        :param in_channels: Number of time step.
        :param out_channels: Desired number of output features at each node in
        each time step.
        :param order: The diffusion steps.
        """
        super(D_GCNNew, self).__init__()
        self.orders = orders
        self.activation = activation
        self.num_matrices = 2 * self.orders + 1
        self.Theta1 = nn.Parameter(torch.FloatTensor(in_channels * self.
            num_matrices, out_channels))
        self.bias = nn.Parameter(torch.FloatTensor(out_channels))
        self.reset_parameters()

    def reset_parameters(self):
        stdv = 1.0 / math.sqrt(self.Theta1.shape[1])
        self.Theta1.data.uniform_(-stdv, stdv)
        stdv1 = 1.0 / math.sqrt(self.bias.shape[0])
        self.bias.data.uniform_(-stdv1, stdv1)

    def _concat(self, x, x_):
        x_ = x_.unsqueeze(0)
        return torch.cat([x, x_], dim=0)

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


Measured latency_ms: 0.173127