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, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 64
    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
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, 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 = 640
    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 = 1024
    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 % 4
    x4 = xindex // 256
    x5 = xindex % 16
    x0 = xindex % 2
    x6 = xindex // 16
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + (4 * x2 + 16 * (x5 // 4) + 64 * x3 + 64 * ((x5 +
        16 * x2) // 64) + 256 * x4 + 256 * ((x5 + 16 * x2 + 64 * x3) // 256
        ) + x5 % 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 * x6), tmp6, xmask, sem=
        'relaxed')


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (16, 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_clone_0[grid(64, 4)](primals_1, buf0, 64, 4,
            XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((64, 16), (16, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0),
            reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf1)
        del primals_2
        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, 4, 4, 5, 2), (160, 40, 10, 2, 1),
            torch.float32)
        triton_poi_fused_new_zeros_2[grid(640)](buf3, 640, XBLOCK=256,
            num_warps=4, num_stages=1)
        triton_poi_fused_index_add_new_zeros_3[grid(1024)](buf2, buf1, buf3,
            1024, XBLOCK=128, num_warps=4, num_stages=1)
        del buf1
    return reinterpret_tensor(buf3, (4, 4, 4, 10), (160, 40, 10, 1), 0
        ), reinterpret_tensor(buf0, (64, 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, enc_dim, transform_window, audio_channels):
        super(DecoderNew, self).__init__()
        self.transform_window = transform_window
        self.audio_channels = audio_channels
        self.basis_signals = nn.Linear(enc_dim, audio_channels *
            transform_window, bias=False)

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


Measured latency_ms: 0.061726