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 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_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 25600
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 1600
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x2, tmp2, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (1600, 4), (4, 1))
    assert_size_stride(primals_3, (1600,), (1,))
    assert_size_stride(primals_4, (1600, 4), (4, 1))
    assert_size_stride(primals_5, (1600,), (1,))
    assert_size_stride(primals_6, (1600, 1600, 1600), (2560000, 1600, 1))
    assert_size_stride(primals_7, (1600,), (1,))
    assert_size_stride(primals_8, (4, 1600), (1600, 1))
    assert_size_stride(primals_9, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 1600), (1600, 1), torch.float32)
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 1600), (1, 4),
            0), alpha=1, beta=1, out=buf0)
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((16, 1600), (1600, 1), torch.float32)
        extern_kernels.addmm(primals_5, reinterpret_tensor(primals_1, (16, 
            4), (4, 1), 64), reinterpret_tensor(primals_4, (4, 1600), (1, 4
            ), 0), alpha=1, beta=1, out=buf1)
        del primals_4
        del primals_5
        buf2 = torch.ops.aten._trilinear.default(buf0, primals_6, buf1, [1,
            3], [0], [1, 2], [2, 3])
        buf3 = buf2
        del buf2
        buf4 = reinterpret_tensor(buf3, (4, 4, 1600), (6400, 1600, 1), 0)
        del buf3
        get_raw_stream(0)
        triton_poi_fused_add_0[grid(25600)](buf4, primals_7, 25600, XBLOCK=
            128, num_warps=4, num_stages=1)
        del primals_7
        buf5 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_9, reinterpret_tensor(buf4, (16, 1600),
            (1600, 1), 0), reinterpret_tensor(primals_8, (1600, 4), (1, 
            1600), 0), alpha=1, beta=1, out=buf5)
        del primals_9
    return reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0
        ), primals_6, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
        ), reinterpret_tensor(primals_1, (16, 4), (4, 1), 64
        ), buf0, buf1, reinterpret_tensor(buf4, (16, 1600), (1600, 1), 0
        ), primals_8


class TuckerNew(nn.Module):

    def __init__(self, input_dims, output_dim, mm_dim=1600, shared=False,
        normalize=False, dropout_input=0.0, dropout_pre_lin=0.0,
        dropout_output=0.0):
        super(TuckerNew, self).__init__()
        self.input_dims = input_dims
        self.shared = shared
        self.mm_dim = mm_dim
        self.output_dim = output_dim
        self.normalize = normalize
        self.dropout_input = dropout_input
        self.dropout_pre_lin = dropout_pre_lin
        self.dropout_output = dropout_output
        self.linear0 = nn.Linear(input_dims[0], mm_dim)
        if shared:
            self.linear1 = self.linear0
        else:
            self.linear1 = nn.Linear(input_dims[1], mm_dim)
        self.linear1 = nn.Linear(input_dims[1], mm_dim)
        self.bilinear = nn.Bilinear(mm_dim, mm_dim, mm_dim)
        self.linear_out = nn.Linear(mm_dim, output_dim)
        self.n_params = sum(p.numel() for p in self.parameters() if p.
            requires_grad)

    def forward(self, input_0):
        primals_2 = self.linear0.weight
        primals_3 = self.linear0.bias
        primals_4 = self.linear1.weight
        primals_5 = self.linear1.bias
        primals_6 = self.bilinear.weight
        primals_7 = self.bilinear.bias
        primals_8 = self.linear_out.weight
        primals_9 = self.linear_out.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9])
        return output[0]


Measured latency_ms: 49.264881