# 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_4/inductor_cache/l4/cl4boort6vfsvh6h6bfd4lck36kbmtipkqcrnhckuuxer6sfib77.py
# Topologically Sorted Source Nodes: [hx], Original ATen: [aten.zeros]
# Source node to ATen node mapping:
#   hx => full_default
# Graph fragment:
#   %full_default : [num_users=3] = call_function[target=torch.ops.aten.full.default](args = ([4, 4], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
triton_poi_fused_zeros_0 = async_compile.triton('triton_poi_fused_zeros_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: '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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_zeros_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 0, '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_zeros_0(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 = 0.0
    tl.store(out_ptr0 + (x0), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/cx/ccxtxuhhtbpyre4ztyn5jyjura3cwyurdlbfmhvdn4b3s6ilb5sg.py
# Topologically Sorted Source Nodes: [hardtanh], Original ATen: [aten.hardtanh, aten.hardtanh_backward]
# Source node to ATen node mapping:
#   hardtanh => clamp_max, clamp_min
# Graph fragment:
#   %add_tensor_1 : [num_users=3] = call_function[target=torch.ops.aten.add.Tensor](args = (%mm_default_1, %primals_3), kwargs = {})
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add_tensor_1, -1.0), kwargs = {})
#   %clamp_max : [num_users=2] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min, 1.0), kwargs = {})
#   %le_4 : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%add_tensor_1, -1.0), kwargs = {})
#   %ge_4 : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%add_tensor_1, 1.0), kwargs = {})
#   %bitwise_or_4 : [num_users=1] = call_function[target=torch.ops.aten.bitwise_or.Tensor](args = (%le_4, %ge_4), kwargs = {})
triton_poi_fused_hardtanh_hardtanh_backward_1 = async_compile.triton('triton_poi_fused_hardtanh_hardtanh_backward_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=[32], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*i1', 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_hardtanh_hardtanh_backward_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, '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_hardtanh_hardtanh_backward_1(in_ptr0, in_ptr1, 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
    x2 = xindex
    x0 = xindex % 8
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr1 + (x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = -1.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 1.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tl.store(out_ptr0 + (x2), tmp6, xmask)
    tl.store(out_ptr1 + (x2), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/bi/cbiewmjd2wkd5fkg7ozf5dbnelv7yvwzfdkby27pfs4zavkxjz5l.py
# Topologically Sorted Source Nodes: [add, hardtanh_2, mul, hardsigmoid, mul_1, add_1, hardtanh_3, sub, mul_2, mul_3, add_2, add_3, hy], Original ATen: [aten.add, aten.hardtanh, aten.mul, aten.hardsigmoid, aten.rsub, aten.hardtanh_backward, aten.hardsigmoid_backward]
# Source node to ATen node mapping:
#   add => add
#   add_1 => add_2
#   add_2 => add_3
#   add_3 => add_4
#   hardsigmoid => add_1, clamp_max_3, clamp_min_3, div
#   hardtanh_2 => clamp_max_2, clamp_min_2
#   hardtanh_3 => clamp_max_4, clamp_min_4
#   hy => clamp_max_5, clamp_min_5
#   mul => mul
#   mul_1 => mul_1
#   mul_2 => mul_2
#   mul_3 => mul_3
#   sub => sub
# Graph fragment:
#   %add : [num_users=3] = call_function[target=torch.ops.aten.add.Tensor](args = (%getitem, %getitem_2), kwargs = {})
#   %clamp_min_2 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add, -1.0), kwargs = {})
#   %clamp_max_2 : [num_users=2] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_2, 1.0), kwargs = {})
#   %mul : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%clamp_max_2, 3), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, 3), kwargs = {})
#   %clamp_min_3 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add_1, 0), kwargs = {})
#   %clamp_max_3 : [num_users=1] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_3, 6), kwargs = {})
#   %div : [num_users=4] = call_function[target=torch.ops.aten.div.Tensor](args = (%clamp_max_3, 6), kwargs = {})
#   %mul_1 : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div, %getitem_3), kwargs = {})
#   %add_2 : [num_users=3] = call_function[target=torch.ops.aten.add.Tensor](args = (%getitem_1, %mul_1), kwargs = {})
#   %clamp_min_4 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add_2, -1.0), kwargs = {})
#   %clamp_max_4 : [num_users=3] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_4, 1.0), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (0, %div), kwargs = {})
#   %mul_2 : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %clamp_max_4), kwargs = {})
#   %mul_3 : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div, %full_default), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%clamp_max_4, %mul_2), kwargs = {})
#   %add_4 : [num_users=3] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_3, %mul_3), kwargs = {})
#   %clamp_min_5 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%add_4, -1.0), kwargs = {})
#   %clamp_max_5 : [num_users=1] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_5, 1.0), kwargs = {})
#   %le : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%add_4, -1.0), kwargs = {})
#   %ge : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%add_4, 1.0), kwargs = {})
#   %bitwise_or : [num_users=1] = call_function[target=torch.ops.aten.bitwise_or.Tensor](args = (%le, %ge), kwargs = {})
#   %le_1 : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%add_2, -1.0), kwargs = {})
#   %ge_1 : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%add_2, 1.0), kwargs = {})
#   %bitwise_or_1 : [num_users=1] = call_function[target=torch.ops.aten.bitwise_or.Tensor](args = (%le_1, %ge_1), kwargs = {})
#   %gt : [num_users=1] = call_function[target=torch.ops.aten.gt.Scalar](args = (%mul, -3.0), kwargs = {})
#   %lt : [num_users=1] = call_function[target=torch.ops.aten.lt.Scalar](args = (%mul, 3.0), kwargs = {})
#   %bitwise_and : [num_users=1] = call_function[target=torch.ops.aten.bitwise_and.Tensor](args = (%gt, %lt), kwargs = {})
#   %le_2 : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%add, -1.0), kwargs = {})
#   %ge_2 : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%add, 1.0), kwargs = {})
#   %bitwise_or_2 : [num_users=1] = call_function[target=torch.ops.aten.bitwise_or.Tensor](args = (%le_2, %ge_2), kwargs = {})
triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2 = async_compile.triton('triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2', '''
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: '*i1', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: '*i1', 8: '*fp32', 9: '*fp32', 10: '*fp32', 11: '*i1', 12: '*i1', 13: '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, 5, 6, 7, 8, 9, 10, 11, 12, 13), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 4, '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_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, out_ptr8, out_ptr9, out_ptr10, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = (xindex // 4)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (8*x1)), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + (8*x1)), xmask)
    tmp19 = tl.load(in_ptr1 + (4 + x0 + (8*x1)), xmask)
    tmp21 = tl.load(in_ptr0 + (4 + x0 + (8*x1)), xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = -1.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 1.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tmp10 = 3.0
    tmp11 = tmp6 * tmp10
    tmp12 = tmp11 + tmp10
    tmp13 = 0.0
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = 6.0
    tmp16 = triton_helpers.minimum(tmp14, tmp15)
    tmp17 = 0.16666666666666666
    tmp18 = tmp16 * tmp17
    tmp20 = tmp18 * tmp19
    tmp22 = tmp21 + tmp20
    tmp23 = triton_helpers.maximum(tmp22, tmp3)
    tmp24 = triton_helpers.minimum(tmp23, tmp5)
    tmp25 = tmp22 <= tmp3
    tmp26 = tmp22 >= tmp5
    tmp27 = tmp25 | tmp26
    tmp28 = tmp18 * tmp13
    tmp29 = tmp13 - tmp18
    tmp30 = tmp29 * tmp24
    tmp31 = tmp24 + tmp30
    tmp32 = tmp31 + tmp28
    tmp33 = triton_helpers.maximum(tmp32, tmp3)
    tmp34 = triton_helpers.minimum(tmp33, tmp5)
    tmp35 = tmp32 <= tmp3
    tmp36 = tmp32 >= tmp5
    tmp37 = tmp35 | tmp36
    tmp38 = -3.0
    tmp39 = tmp11 > tmp38
    tmp40 = tmp11 < tmp10
    tmp41 = tmp39 & tmp40
    tl.store(out_ptr0 + (x2), tmp6, xmask)
    tl.store(out_ptr1 + (x2), tmp9, xmask)
    tl.store(out_ptr2 + (x2), tmp18, xmask)
    tl.store(out_ptr3 + (x2), tmp20, xmask)
    tl.store(out_ptr4 + (x2), tmp24, xmask)
    tl.store(out_ptr5 + (x2), tmp27, xmask)
    tl.store(out_ptr6 + (x2), tmp28, xmask)
    tl.store(out_ptr7 + (x2), tmp30, xmask)
    tl.store(out_ptr8 + (x2), tmp34, xmask)
    tl.store(out_ptr9 + (x2), tmp37, xmask)
    tl.store(out_ptr10 + (x2), tmp41, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (8, 4), (4, 1))
    assert_size_stride(primals_3, (8, ), (1, ))
    assert_size_stride(primals_4, (8, 4), (4, 1))
    assert_size_stride(primals_5, (8, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [hx], Original ATen: [aten.zeros]
        stream0 = get_raw_stream(0)
        triton_poi_fused_zeros_0.run(buf0, 16, grid=grid(16), stream=stream0)
        buf1 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 8), (1, 4), 0), out=buf1)
        del primals_2
        buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        buf17 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        # Topologically Sorted Source Nodes: [hardtanh], Original ATen: [aten.hardtanh, aten.hardtanh_backward]
        triton_poi_fused_hardtanh_hardtanh_backward_1.run(buf1, primals_3, buf2, buf17, 32, grid=grid(32), stream=stream0)
        del primals_3
        buf3 = buf1; del buf1  # reuse
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 8), (1, 4), 0), out=buf3)
        del primals_4
        buf4 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        buf16 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        # Topologically Sorted Source Nodes: [hardtanh_1], Original ATen: [aten.hardtanh, aten.hardtanh_backward]
        triton_poi_fused_hardtanh_hardtanh_backward_1.run(buf3, primals_5, buf4, buf16, 32, grid=grid(32), stream=stream0)
        del buf3
        del primals_5
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf15 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf12 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        # Topologically Sorted Source Nodes: [add, hardtanh_2, mul, hardsigmoid, mul_1, add_1, hardtanh_3, sub, mul_2, mul_3, add_2, add_3, hy], Original ATen: [aten.add, aten.hardtanh, aten.mul, aten.hardsigmoid, aten.rsub, aten.hardtanh_backward, aten.hardsigmoid_backward]
        triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2.run(buf2, buf4, buf5, buf15, buf6, buf7, buf8, buf13, buf10, buf9, buf11, buf12, buf14, 16, grid=grid(16), stream=stream0)
    return (buf11, buf10, buf9, buf8, buf7, buf6, buf5, reinterpret_tensor(buf4, (4, 4), (8, 1), 4), reinterpret_tensor(buf4, (4, 4), (8, 1), 0), reinterpret_tensor(buf2, (4, 4), (8, 1), 4), reinterpret_tensor(buf2, (4, 4), (8, 1), 0), buf4, buf2, primals_1, buf0, reinterpret_tensor(buf4, (4, 4), (8, 1), 4), buf6, buf8, buf12, buf13, buf14, buf15, buf16, buf17, )


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((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((8, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((8, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((8, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((8, ), (1, ), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5])
    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 math
import torch
from torch import Tensor
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed


def truncated_normal(t, mean=0.0, std=0.01):
    torch.nn.init.normal_(t, mean=mean, std=std)
    while True:
        cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std)
        if torch.sum(cond):
            t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t),
                mean=mean, std=std), t)
        else:
            break
    return t


class ScaleHardsigmoid(torch.nn.Module):
    """
    This is a scaled addition (x+1)/2.
    """

    def __init__(self, scale=3):
        super(ScaleHardsigmoid, self).__init__()
        self.scale = scale

    def forward(self, x) ->str:
        return torch.nn.Hardsigmoid()(x * self.scale)


class HardMGUCellPT(torch.nn.RNNCellBase):
    """
    This is a minimal gated unit by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True.
    Batch is always the dim[0].
    Refer to "Simplified Minimal Gated Unit Variations for Recurrent Neural Networks" and "Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks" for more details.
    Hardtanh is to bound data to the legal unary range.
    This module is fully unary computing aware, i.e., all intermediate data are bounded to the legal unary range.
    This module follows the PyTorch implementation style (PT).
    """

    def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'=
        True, hard: 'bool'=True) ->None:
        super(HardMGUCellPT, self).__init__(input_size, hidden_size, bias,
            num_chunks=2)
        self.hard = hard
        if hard is True:
            self.forgetgate_sigmoid = ScaleHardsigmoid()
            self.newgate_tanh = nn.Hardtanh()
        else:
            self.forgetgate_sigmoid = nn.Sigmoid()
            self.newgate_tanh = nn.Tanh()
        self.reset_parameters()

    def reset_parameters(self):
        stdv = 1.0 / math.sqrt(self.hidden_size)
        for weight in self.parameters():
            weight.data = truncated_normal(weight, mean=0, std=stdv)

    def forward(self, input: 'Tensor', hx: 'Optional[Tensor]'=None) ->Tensor:
        if hx is None:
            hx = torch.zeros(input.size()[0], self.hidden_size, dtype=input
                .dtype, device=input.device)
        self.gate_i = nn.Hardtanh()(F.linear(input, self.weight_ih, self.
            bias_ih))
        self.gate_h = nn.Hardtanh()(F.linear(hx, self.weight_hh, self.bias_hh))
        self.i_f, self.i_n = self.gate_i.chunk(2, 1)
        self.h_f, self.h_n = self.gate_h.chunk(2, 1)
        self.forgetgate_in = nn.Hardtanh()(self.i_f + self.h_f)
        self.forgetgate = self.forgetgate_sigmoid(self.forgetgate_in)
        self.newgate_prod = self.forgetgate * self.h_n
        self.newgate = self.newgate_tanh(self.i_n + self.newgate_prod)
        self.forgetgate_inv_prod = (0 - self.forgetgate) * self.newgate
        self.forgetgate_prod = self.forgetgate * hx
        hy = nn.Hardtanh()(self.newgate + self.forgetgate_inv_prod + self.
            forgetgate_prod)
        return hy


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


def get_init_inputs():
    return [[], {'input_size': 4, 'hidden_size': 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
from torch._inductor.runtime import triton_helpers
import math
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
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_zeros_0(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 = 0.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_hardtanh_hardtanh_backward_1(in_ptr0, in_ptr1,
    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
    x2 = xindex
    x0 = xindex % 8
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = -1.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 1.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tl.store(out_ptr0 + x2, tmp6, xmask)
    tl.store(out_ptr1 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2(
    in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4,
    out_ptr5, out_ptr6, out_ptr7, out_ptr8, out_ptr9, out_ptr10, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 8 * x1), xmask)
    tmp19 = tl.load(in_ptr1 + (4 + x0 + 8 * x1), xmask)
    tmp21 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = -1.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 1.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tmp10 = 3.0
    tmp11 = tmp6 * tmp10
    tmp12 = tmp11 + tmp10
    tmp13 = 0.0
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = 6.0
    tmp16 = triton_helpers.minimum(tmp14, tmp15)
    tmp17 = 0.16666666666666666
    tmp18 = tmp16 * tmp17
    tmp20 = tmp18 * tmp19
    tmp22 = tmp21 + tmp20
    tmp23 = triton_helpers.maximum(tmp22, tmp3)
    tmp24 = triton_helpers.minimum(tmp23, tmp5)
    tmp25 = tmp22 <= tmp3
    tmp26 = tmp22 >= tmp5
    tmp27 = tmp25 | tmp26
    tmp28 = tmp18 * tmp13
    tmp29 = tmp13 - tmp18
    tmp30 = tmp29 * tmp24
    tmp31 = tmp24 + tmp30
    tmp32 = tmp31 + tmp28
    tmp33 = triton_helpers.maximum(tmp32, tmp3)
    tmp34 = triton_helpers.minimum(tmp33, tmp5)
    tmp35 = tmp32 <= tmp3
    tmp36 = tmp32 >= tmp5
    tmp37 = tmp35 | tmp36
    tmp38 = -3.0
    tmp39 = tmp11 > tmp38
    tmp40 = tmp11 < tmp10
    tmp41 = tmp39 & tmp40
    tl.store(out_ptr0 + x2, tmp6, xmask)
    tl.store(out_ptr1 + x2, tmp9, xmask)
    tl.store(out_ptr2 + x2, tmp18, xmask)
    tl.store(out_ptr3 + x2, tmp20, xmask)
    tl.store(out_ptr4 + x2, tmp24, xmask)
    tl.store(out_ptr5 + x2, tmp27, xmask)
    tl.store(out_ptr6 + x2, tmp28, xmask)
    tl.store(out_ptr7 + x2, tmp30, xmask)
    tl.store(out_ptr8 + x2, tmp34, xmask)
    tl.store(out_ptr9 + x2, tmp37, xmask)
    tl.store(out_ptr10 + x2, tmp41, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (8, 4), (4, 1))
    assert_size_stride(primals_3, (8,), (1,))
    assert_size_stride(primals_4, (8, 4), (4, 1))
    assert_size_stride(primals_5, (8,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_zeros_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf1 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 8),
            (1, 4), 0), out=buf1)
        del primals_2
        buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        buf17 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        triton_poi_fused_hardtanh_hardtanh_backward_1[grid(32)](buf1,
            primals_3, buf2, buf17, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_3
        buf3 = buf1
        del buf1
        extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 8), (1, 4
            ), 0), out=buf3)
        del primals_4
        buf4 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
        buf16 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
        triton_poi_fused_hardtanh_hardtanh_backward_1[grid(32)](buf3,
            primals_5, buf4, buf16, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del buf3
        del primals_5
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf15 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf12 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2[
            grid(16)](buf2, buf4, buf5, buf15, buf6, buf7, buf8, buf13,
            buf10, buf9, buf11, buf12, buf14, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
    return buf11, buf10, buf9, buf8, buf7, buf6, buf5, reinterpret_tensor(buf4,
        (4, 4), (8, 1), 4), reinterpret_tensor(buf4, (4, 4), (8, 1), 0
        ), reinterpret_tensor(buf2, (4, 4), (8, 1), 4), reinterpret_tensor(buf2
        , (4, 4), (8, 1), 0), buf4, buf2, primals_1, buf0, reinterpret_tensor(
        buf4, (4, 4), (8, 1), 4
        ), buf6, buf8, buf12, buf13, buf14, buf15, buf16, buf17


def truncated_normal(t, mean=0.0, std=0.01):
    torch.nn.init.normal_(t, mean=mean, std=std)
    while True:
        cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std)
        if torch.sum(cond):
            t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t),
                mean=mean, std=std), t)
        else:
            break
    return t


class ScaleHardsigmoid(torch.nn.Module):
    """
    This is a scaled addition (x+1)/2.
    """

    def __init__(self, scale=3):
        super(ScaleHardsigmoid, self).__init__()
        self.scale = scale

    def forward(self, x) ->str:
        return torch.nn.Hardsigmoid()(x * self.scale)


class HardMGUCellPTNew(torch.nn.RNNCellBase):
    """
    This is a minimal gated unit by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True.
    Batch is always the dim[0].
    Refer to "Simplified Minimal Gated Unit Variations for Recurrent Neural Networks" and "Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks" for more details.
    Hardtanh is to bound data to the legal unary range.
    This module is fully unary computing aware, i.e., all intermediate data are bounded to the legal unary range.
    This module follows the PyTorch implementation style (PT).
    """

    def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'=
        True, hard: 'bool'=True) ->None:
        super(HardMGUCellPTNew, self).__init__(input_size, hidden_size,
            bias, num_chunks=2)
        self.hard = hard
        if hard is True:
            self.forgetgate_sigmoid = ScaleHardsigmoid()
            self.newgate_tanh = nn.Hardtanh()
        else:
            self.forgetgate_sigmoid = nn.Sigmoid()
            self.newgate_tanh = nn.Tanh()
        self.reset_parameters()

    def reset_parameters(self):
        stdv = 1.0 / math.sqrt(self.hidden_size)
        for weight in self.parameters():
            weight.data = truncated_normal(weight, mean=0, std=stdv)

    def forward(self, input_0):
        primals_2 = self.weight_ih
        primals_4 = self.weight_hh
        primals_3 = self.bias_ih
        primals_5 = self.bias_hh
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]
