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 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_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 4 * y3), xmask & ymask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr1 + (x2 + 4 * y0), xmask & ymask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tl.store(out_ptr0 + (y0 + 4 * x2 + 16 * y1), tmp2, xmask & ymask)


@triton.jit
def triton_poi_fused_clone_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x2 = xindex
    tmp0 = x0 + x1
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_new_zeros_2(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 160
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = 0.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_index_add_new_zeros_3(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
    x1 = xindex // 2 % 8
    x2 = xindex // 16 % 4
    x3 = xindex // 64
    x4 = xindex % 16
    x0 = xindex % 2
    x5 = xindex // 16
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + (4 * x2 + 16 * (x4 // 4) + 64 * x3 + 64 * ((x4 +
        16 * x2) // 64) + x4 % 4), xmask)
    tmp1 = tl.full([XBLOCK], 5, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 5) | ~xmask,
        'index out of bounds: 0 <= tmp4 < 5')
    tl.atomic_add(out_ptr0 + (x0 + 2 * tmp4 + 10 * x5), tmp6, xmask, sem=
        'relaxed')


def call(args):
    primals_1, primals_2, primals_3 = 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, (16, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1, 4, 4), (16, 1, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_clone_0[grid(16, 4)](primals_1, primals_2, buf0, 
            16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
        del primals_1
        del primals_2
        buf1 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_3, (4, 16), (1, 4), 0), out=buf1)
        del primals_3
        buf2 = empty_strided_cuda((4, 2), (2, 1), torch.int64)
        triton_poi_fused_clone_1[grid(8)](buf2, 8, XBLOCK=8, num_warps=1,
            num_stages=1)
        buf3 = empty_strided_cuda((4, 1, 4, 5, 2), (40, 40, 10, 2, 1),
            torch.float32)
        triton_poi_fused_new_zeros_2[grid(160)](buf3, 160, XBLOCK=256,
            num_warps=4, num_stages=1)
        triton_poi_fused_index_add_new_zeros_3[grid(256)](buf2, buf1, buf3,
            256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf1
    return reinterpret_tensor(buf3, (4, 1, 4, 10), (40, 40, 10, 1), 0
        ), reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(
        buf2, (8,), (1,), 0)


def overlap_and_add(signal, frame_step):
    outer_dimensions = signal.size()[:-2]
    frames, frame_length = signal.size()[-2:]
    subframe_length = math.gcd(frame_length, frame_step)
    subframe_step = frame_step // subframe_length
    subframes_per_frame = frame_length // subframe_length
    output_size = frame_step * (frames - 1) + frame_length
    output_subframes = output_size // subframe_length
    subframe_signal = signal.view(*outer_dimensions, -1, subframe_length)
    frame = torch.arange(0, output_subframes, device=signal.device).unfold(
        0, subframes_per_frame, subframe_step)
    frame = frame.long()
    frame = frame.contiguous().view(-1)
    result = signal.new_zeros(*outer_dimensions, output_subframes,
        subframe_length)
    result.index_add_(-2, frame, subframe_signal)
    result = result.view(*outer_dimensions, -1)
    return result


class DecoderNew(nn.Module):

    def __init__(self, N, L, audio_channels):
        super(DecoderNew, self).__init__()
        self.N, self.L = N, L
        self.audio_channels = audio_channels
        self.basis_signals = nn.Linear(N, audio_channels * L, bias=False)
        """
        m = nn.Linear(20, 30)
        >>> input = torch.randn(128, 20)
        >>> output = m(input)
        >>> print(output.size())
        torch.Size([128, 30])
        """

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


Measured latency_ms: 0.063318