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_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp4 & xmask, other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr1 + (x0 + 4 * (-4 + x1)), tmp6 & xmask, other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tmp11 = tl.load(in_ptr2 + (x0 + 4 * x1), tmp4 & xmask, other=0.0)
    tmp12 = tl.where(tmp4, tmp11, tmp9)
    tl.store(out_ptr0 + x2, tmp10, xmask)
    tl.store(out_ptr1 + x2, tmp12, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr0 + (32 + 4 * x1 + (-4 + x0)), tmp6 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tmp11 = tl.load(in_ptr0 + (16 + 4 * x1 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp12 = tl.where(tmp4, tmp11, tmp9)
    tl.store(out_ptr0 + x2, tmp10, xmask)
    tl.store(out_ptr1 + x2, tmp12, xmask)


@triton.jit
def triton_poi_fused_add_2(in_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
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = 0.0
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x0, tmp2, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (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, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        buf1 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, primals_3,
            buf0, buf1, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_1
        del primals_2
        del primals_3
        buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        triton_poi_fused_cat_1[grid(32)](primals_4, buf2, buf3, 32, XBLOCK=
            32, num_warps=1, num_stages=1)
        del primals_4
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf2, buf0, out=buf4)
        buf5 = buf4
        del buf4
        triton_poi_fused_add_2[grid(16)](buf5, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf3, buf1, out=buf6)
        buf7 = buf6
        del buf6
        triton_poi_fused_add_2[grid(16)](buf7, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
    return buf5, buf7, buf1, buf0, reinterpret_tensor(buf3, (8, 4), (1, 8), 0
        ), reinterpret_tensor(buf2, (8, 4), (1, 8), 0)


class EncoderBiasNew(nn.Module):

    def __init__(self, input_dim1, input_dim2, batch_feature, latent_dim,
        bias=False):
        """[summary]
        Args:
            input_dim1 ([type]): [mod1 dimemsion]
            input_dim2 ([type]): [mod2 dimemsion]
            batch_feature ([type]): [batch dimemsion]
            latent_dim ([type]): [latent dimemsion]
            bias (bool, optional): [description]. Defaults to False.
        """
        super().__init__()
        self.dim1_encoder_weight = nn.Parameter(torch.randn(input_dim1,
            latent_dim))
        self.dim2_encoder_weight = nn.Parameter(torch.randn(input_dim2,
            latent_dim))
        self.batch_encoder_weight = nn.Parameter(torch.randn(batch_feature,
            latent_dim))
        if bias:
            self.dim1_bias = nn.Parameter(torch.randn(latent_dim))
            self.dim2_bias = nn.Parameter(torch.randn(latent_dim))
        else:
            self.dim1_bias = 0
            self.dim2_bias = 0

    def forward(self, input_0):
        primals_1 = self.dim1_encoder_weight
        primals_2 = self.dim2_encoder_weight
        primals_3 = self.batch_encoder_weight
        primals_4 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4])
        return output[0], output[1]


Measured latency_ms: 0.06715