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
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_copy_mul_sigmoid_0(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 20 % 5
    x0 = xindex % 20
    x2 = xindex // 100
    x3 = xindex
    tmp3 = tl.load(in_ptr0 + (40 + x0 + 100 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 2, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = tl.sigmoid(tmp3)
    tmp5 = 0.2
    tmp6 = tmp4 * tmp5
    tmp7 = 0.01
    tmp8 = tmp6 + tmp7
    tmp10 = tl.where(tmp2, tmp8, tmp9)
    tl.store(out_ptr0 + x3, tmp10, xmask)


@triton.jit
def triton_poi_fused_select_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 80
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 5
    x1 = xindex // 5 % 4
    x2 = xindex // 20
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (60 + x0 + 5 * x1 + 100 * x2 + 100 * ((12 + x1
        ) // 20)), xmask)
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_copy_mul_sigmoid_2(in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 20 % 5
    x3 = xindex // 100
    x4 = xindex % 20
    x6 = xindex
    tmp3 = tl.load(in_ptr0 + (x4 + 20 * x3), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr1 + x6, xmask)
    tmp0 = x2
    tmp1 = tl.full([1], 3, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = tl.sigmoid(tmp3)
    tmp5 = 0.2
    tmp6 = tmp4 * tmp5
    tmp7 = 0.01
    tmp8 = tmp6 + tmp7
    tmp10 = tl.where(tmp2, tmp8, tmp9)
    tl.store(out_ptr0 + x6, tmp10, xmask)


@triton.jit
def triton_poi_fused_select_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 80
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 5
    x1 = xindex // 5 % 4
    x2 = xindex // 20
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (80 + x0 + 5 * x1 + 100 * x2 + 100 * ((16 + x1
        ) // 20)), xmask)
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_copy_mul_sigmoid_4(in_out_ptr0, in_ptr0, in_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 20 % 5
    x3 = xindex // 100
    x5 = xindex % 20
    x6 = xindex
    tmp3 = tl.load(in_ptr0 + (x5 + 20 * x3), xmask, eviction_policy=
        'evict_last')
    tmp7 = tl.load(in_ptr1 + x6, xmask)
    tmp0 = x2
    tmp1 = tl.full([1], 4, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = tl.sigmoid(tmp3)
    tmp5 = 0.7
    tmp6 = tmp4 * tmp5
    tmp8 = tl.where(tmp2, tmp6, tmp7)
    tl.store(in_out_ptr0 + x6, tmp8, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (5, 4), (4, 1))
    assert_size_stride(primals_2, (5,), (1,))
    assert_size_stride(primals_3, (4, 5, 4, 4), (80, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((80, 5), (5, 1), torch.float32)
        extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (80, 
            4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 5), (1, 4), 0
            ), alpha=1, beta=1, out=buf0)
        del primals_1
        del primals_2
        buf1 = empty_strided_cuda((4, 5, 4, 5), (100, 20, 5, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_copy_mul_sigmoid_0[grid(400)](buf0, buf1, 400,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32)
        triton_poi_fused_select_1[grid(80)](buf1, buf2, 80, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((4, 5, 4, 5), (100, 20, 5, 1), torch.float32)
        triton_poi_fused_add_copy_mul_sigmoid_2[grid(400)](buf2, buf1, buf3,
            400, XBLOCK=256, num_warps=4, num_stages=1)
        buf4 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32)
        triton_poi_fused_select_3[grid(80)](buf3, buf4, 80, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf5 = buf1
        del buf1
        buf6 = buf5
        del buf5
        triton_poi_fused_copy_mul_sigmoid_4[grid(400)](buf6, buf4, buf3, 
            400, XBLOCK=256, num_warps=4, num_stages=1)
        del buf3
    return buf6, reinterpret_tensor(primals_3, (80, 4), (4, 1), 0
        ), reinterpret_tensor(buf0, (4, 4, 5), (100, 5, 1), 40), buf2, buf4


class Hidden2NormalNew(torch.nn.Module):

    def __init__(self, hidden_dim):
        super(Hidden2NormalNew, self).__init__()
        self.linear = torch.nn.Linear(hidden_dim, 5)

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


Measured latency_ms: 0.073824