# AOT ID: ['0_forward']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_8/inductor_cache/go/cgohlkvam4wpuk26mincmvur3a4wb5e4gswd42nrli4pibikbshn.py
# Topologically Sorted Source Nodes: [stack], Original ATen: [aten.stack]
# Source node to ATen node mapping:
#   stack => cat_1
# Graph fragment:
#   %cat_1 : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%slice_1, %slice_2, %slice_3, %slice_4],), kwargs = {})
triton_poi_fused_stack_0 = async_compile.triton('triton_poi_fused_stack_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_stack_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 9, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_stack_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp15 = tl.load(in_ptr1 + (0))
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK])
    tmp0 = x0
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = 3 + x0
    tmp6 = tmp5 >= tmp1
    tmp7 = tl.full([1], 3, tl.int64)
    tmp8 = tmp5 < tmp7
    tmp9 = tmp8 & tmp4
    tmp10 = tl.load(in_ptr0 + (3 + x0), tmp9 & xmask, eviction_policy='evict_last', other=0.0)
    tmp11 = tmp5 >= tmp7
    tmp12 = tmp5 < tmp3
    tmp13 = tmp11 & tmp12
    tmp14 = tmp13 & tmp4
    tmp17 = 1.0
    tmp18 = tmp16 + tmp17
    tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype)
    tmp20 = tl.where(tmp14, tmp18, tmp19)
    tmp21 = tmp5 >= tmp3
    tmp22 = tl.full([1], 7, tl.int64)
    tmp23 = tmp5 < tmp22
    tmp24 = tmp21 & tmp4
    tmp25 = tl.load(in_ptr2 + ((-1) + x0), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp26 = tl.where(tmp13, tmp20, tmp25)
    tmp27 = tl.where(tmp8, tmp10, tmp26)
    tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
    tmp29 = tl.where(tmp4, tmp27, tmp28)
    tmp30 = tmp0 >= tmp3
    tmp31 = tl.full([1], 8, tl.int64)
    tmp32 = tmp0 < tmp31
    tmp33 = tmp30 & tmp32
    tmp34 = 2 + ((-4) + x0)
    tmp35 = tmp34 >= tmp1
    tmp36 = tmp34 < tmp7
    tmp37 = tmp36 & tmp33
    tmp38 = tl.load(in_ptr0 + (2 + ((-4) + x0)), tmp37 & xmask, eviction_policy='evict_last', other=0.0)
    tmp39 = tmp34 >= tmp7
    tmp40 = tmp34 < tmp3
    tmp41 = tmp39 & tmp40
    tmp42 = tmp41 & tmp33
    tmp43 = tl.where(tmp42, tmp18, tmp19)
    tmp44 = tmp34 >= tmp3
    tmp45 = tmp34 < tmp22
    tmp46 = tmp44 & tmp33
    tmp47 = tl.load(in_ptr2 + ((-2) + ((-4) + x0)), tmp46 & xmask, eviction_policy='evict_last', other=0.0)
    tmp48 = tl.where(tmp41, tmp43, tmp47)
    tmp49 = tl.where(tmp36, tmp38, tmp48)
    tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype)
    tmp51 = tl.where(tmp33, tmp49, tmp50)
    tmp52 = tmp0 >= tmp31
    tmp53 = tl.full([1], 12, tl.int64)
    tmp54 = tmp0 < tmp53
    tmp55 = tmp52 & tmp54
    tmp56 = 1 + ((-8) + x0)
    tmp57 = tmp56 >= tmp1
    tmp58 = tmp56 < tmp7
    tmp59 = tmp58 & tmp55
    tmp60 = tl.load(in_ptr0 + (1 + ((-8) + x0)), tmp59 & xmask, eviction_policy='evict_last', other=0.0)
    tmp61 = tmp56 >= tmp7
    tmp62 = tmp56 < tmp3
    tmp63 = tmp61 & tmp62
    tmp64 = tmp63 & tmp55
    tmp65 = tl.where(tmp64, tmp18, tmp19)
    tmp66 = tmp56 >= tmp3
    tmp67 = tmp56 < tmp22
    tmp68 = tmp66 & tmp55
    tmp69 = tl.load(in_ptr2 + ((-3) + ((-8) + x0)), tmp68 & xmask, eviction_policy='evict_last', other=0.0)
    tmp70 = tl.where(tmp63, tmp65, tmp69)
    tmp71 = tl.where(tmp58, tmp60, tmp70)
    tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype)
    tmp73 = tl.where(tmp55, tmp71, tmp72)
    tmp74 = tmp0 >= tmp53
    tmp75 = tl.full([1], 16, tl.int64)
    tmp76 = tmp0 < tmp75
    tmp77 = (-12) + x0
    tmp78 = tmp77 >= tmp1
    tmp79 = tmp77 < tmp7
    tmp80 = tmp79 & tmp74
    tmp81 = tl.load(in_ptr0 + ((-12) + x0), tmp80 & xmask, eviction_policy='evict_last', other=0.0)
    tmp82 = tmp77 >= tmp7
    tmp83 = tmp77 < tmp3
    tmp84 = tmp82 & tmp83
    tmp85 = tmp84 & tmp74
    tmp86 = tl.where(tmp85, tmp18, tmp19)
    tmp87 = tmp77 >= tmp3
    tmp88 = tmp77 < tmp22
    tmp89 = tmp87 & tmp74
    tmp90 = tl.load(in_ptr2 + ((-4) + ((-12) + x0)), tmp89 & xmask, eviction_policy='evict_last', other=0.0)
    tmp91 = tl.where(tmp84, tmp86, tmp90)
    tmp92 = tl.where(tmp79, tmp81, tmp91)
    tmp93 = tl.full(tmp92.shape, 0.0, tmp92.dtype)
    tmp94 = tl.where(tmp74, tmp92, tmp93)
    tmp95 = tl.where(tmp55, tmp73, tmp94)
    tmp96 = tl.where(tmp33, tmp51, tmp95)
    tmp97 = tl.where(tmp4, tmp29, tmp96)
    tl.store(out_ptr0 + (x0), tmp97, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_8/inductor_cache/ln/clnjzph6f6ljwdpi223cif3gjupa56icp7ouy2ii6hkgcopz7ssl.py
# Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   matmul => clone
# Graph fragment:
#   %clone : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%permute,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_1 = async_compile.triton('triton_poi_fused_clone_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64, 4], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_clone_1(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)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (1, ), (1, ))
    assert_size_stride(primals_2, (3, ), (1, ))
    assert_size_stride(primals_3, (3, ), (1, ))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [stack], Original ATen: [aten.stack]
        stream0 = get_raw_stream(0)
        triton_poi_fused_stack_0.run(primals_3, primals_1, primals_2, buf0, 16, grid=grid(16), stream=stream0)
        del primals_1
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.clone]
        triton_poi_fused_clone_1.run(primals_4, buf1, 64, 4, grid=grid(64, 4), stream=stream0)
        del primals_4
        buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.mm]
        extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf2)
        del buf0
        buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.clone]
        triton_poi_fused_clone_1.run(buf2, buf3, 64, 4, grid=grid(64, 4), stream=stream0)
        del buf2
    return (buf3, reinterpret_tensor(buf1, (64, 4), (4, 1), 0), )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((1, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((3, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((3, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import torch
import torch.nn as nn


def expand_toeplitz(diag, lower_diags, upper_diags):
    pattern = torch.cat([upper_diags, diag, lower_diags], 0)
    d = lower_diags.size(0)
    columns = []
    for i in range(d + 1):
        columns.append(pattern[d - i:d - i + d + 1])
    return torch.stack(columns, 0)


class ToeplitzBlock(nn.Module):

    def __init__(self, dim):
        super().__init__()
        self.diag = nn.Parameter(torch.Tensor([0]))
        self.lower_diags = nn.Parameter(torch.Tensor(dim - 1).zero_())
        self.upper_diags = nn.Parameter(torch.Tensor(dim - 1).zero_())

    def diagonals(self):
        return [self.diag + 1, self.lower_diags, self.upper_diags]

    def forward(self, x):
        return torch.matmul(expand_toeplitz(*self.diagonals()), x)


def get_inputs():
    return [torch.rand([4, 4, 4, 4])]


def get_init_inputs():
    return [[], {'dim': 4}]

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_stack_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp15 = tl.load(in_ptr1 + 0)
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK])
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = 3 + x0
    tmp7 = tl.full([1], 3, tl.int64)
    tmp8 = tmp5 < tmp7
    tmp9 = tmp8 & tmp4
    tmp10 = tl.load(in_ptr0 + (3 + x0), tmp9 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = tmp5 >= tmp7
    tmp12 = tmp5 < tmp3
    tmp13 = tmp11 & tmp12
    tmp14 = tmp13 & tmp4
    tmp17 = 1.0
    tmp18 = tmp16 + tmp17
    tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype)
    tmp20 = tl.where(tmp14, tmp18, tmp19)
    tmp21 = tmp5 >= tmp3
    tl.full([1], 7, tl.int64)
    tmp24 = tmp21 & tmp4
    tmp25 = tl.load(in_ptr2 + (-1 + x0), tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp26 = tl.where(tmp13, tmp20, tmp25)
    tmp27 = tl.where(tmp8, tmp10, tmp26)
    tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
    tmp29 = tl.where(tmp4, tmp27, tmp28)
    tmp30 = tmp0 >= tmp3
    tmp31 = tl.full([1], 8, tl.int64)
    tmp32 = tmp0 < tmp31
    tmp33 = tmp30 & tmp32
    tmp34 = 2 + (-4 + x0)
    tmp36 = tmp34 < tmp7
    tmp37 = tmp36 & tmp33
    tmp38 = tl.load(in_ptr0 + (2 + (-4 + x0)), tmp37 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp39 = tmp34 >= tmp7
    tmp40 = tmp34 < tmp3
    tmp41 = tmp39 & tmp40
    tmp42 = tmp41 & tmp33
    tmp43 = tl.where(tmp42, tmp18, tmp19)
    tmp44 = tmp34 >= tmp3
    tmp46 = tmp44 & tmp33
    tmp47 = tl.load(in_ptr2 + (-2 + (-4 + x0)), tmp46 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp48 = tl.where(tmp41, tmp43, tmp47)
    tmp49 = tl.where(tmp36, tmp38, tmp48)
    tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype)
    tmp51 = tl.where(tmp33, tmp49, tmp50)
    tmp52 = tmp0 >= tmp31
    tmp53 = tl.full([1], 12, tl.int64)
    tmp54 = tmp0 < tmp53
    tmp55 = tmp52 & tmp54
    tmp56 = 1 + (-8 + x0)
    tmp58 = tmp56 < tmp7
    tmp59 = tmp58 & tmp55
    tmp60 = tl.load(in_ptr0 + (1 + (-8 + x0)), tmp59 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp61 = tmp56 >= tmp7
    tmp62 = tmp56 < tmp3
    tmp63 = tmp61 & tmp62
    tmp64 = tmp63 & tmp55
    tmp65 = tl.where(tmp64, tmp18, tmp19)
    tmp66 = tmp56 >= tmp3
    tmp68 = tmp66 & tmp55
    tmp69 = tl.load(in_ptr2 + (-3 + (-8 + x0)), tmp68 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp70 = tl.where(tmp63, tmp65, tmp69)
    tmp71 = tl.where(tmp58, tmp60, tmp70)
    tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype)
    tmp73 = tl.where(tmp55, tmp71, tmp72)
    tmp74 = tmp0 >= tmp53
    tl.full([1], 16, tl.int64)
    tmp77 = -12 + x0
    tmp79 = tmp77 < tmp7
    tmp80 = tmp79 & tmp74
    tmp81 = tl.load(in_ptr0 + (-12 + x0), tmp80 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp82 = tmp77 >= tmp7
    tmp83 = tmp77 < tmp3
    tmp84 = tmp82 & tmp83
    tmp85 = tmp84 & tmp74
    tmp86 = tl.where(tmp85, tmp18, tmp19)
    tmp87 = tmp77 >= tmp3
    tmp89 = tmp87 & tmp74
    tmp90 = tl.load(in_ptr2 + (-4 + (-12 + x0)), tmp89 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp91 = tl.where(tmp84, tmp86, tmp90)
    tmp92 = tl.where(tmp79, tmp81, tmp91)
    tmp93 = tl.full(tmp92.shape, 0.0, tmp92.dtype)
    tmp94 = tl.where(tmp74, tmp92, tmp93)
    tmp95 = tl.where(tmp55, tmp73, tmp94)
    tmp96 = tl.where(tmp33, tmp51, tmp95)
    tmp97 = tl.where(tmp4, tmp29, tmp96)
    tl.store(out_ptr0 + x0, tmp97, xmask)


@triton.jit
def triton_poi_fused_clone_1(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)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (1,), (1,))
    assert_size_stride(primals_2, (3,), (1,))
    assert_size_stride(primals_3, (3,), (1,))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16,), (1,), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_stack_0[grid(16)](primals_3, primals_1, primals_2,
            buf0, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_1
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_1[grid(64, 4)](primals_4, buf1, 64, 4,
            XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_4
        buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
            reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf2)
        del buf0
        buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_1[grid(64, 4)](buf2, buf3, 64, 4, XBLOCK=4,
            YBLOCK=32, num_warps=4, num_stages=1)
        del buf2
    return buf3, reinterpret_tensor(buf1, (64, 4), (4, 1), 0)


def expand_toeplitz(diag, lower_diags, upper_diags):
    pattern = torch.cat([upper_diags, diag, lower_diags], 0)
    d = lower_diags.size(0)
    columns = []
    for i in range(d + 1):
        columns.append(pattern[d - i:d - i + d + 1])
    return torch.stack(columns, 0)


class ToeplitzBlockNew(nn.Module):

    def __init__(self, dim):
        super().__init__()
        self.diag = nn.Parameter(torch.Tensor([0]))
        self.lower_diags = nn.Parameter(torch.Tensor(dim - 1).zero_())
        self.upper_diags = nn.Parameter(torch.Tensor(dim - 1).zero_())

    def diagonals(self):
        return [self.diag + 1, self.lower_diags, self.upper_diags]

    def forward(self, input_0):
        primals_1 = self.diag
        primals_2 = self.lower_diags
        primals_3 = self.upper_diags
        primals_4 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4])
        return output[0]
