# AOT ID: ['0_inference']
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_6/inductor_cache/xq/cxq2qmrgyky7dqwgqwftj6uhbj5vdl2rg7fomifs252vwbdicjhh.py
# Topologically Sorted Source Nodes: [pos_sig, pos_sig_1, neg_sig, neg_sig_1, sum_sig, x], Original ATen: [aten.sigmoid, aten.max_pool2d_with_indices, aten.mul, aten.add]
# Source node to ATen node mapping:
#   neg_sig => mul
#   neg_sig_1 => _low_memory_max_pool2d_with_offsets_1
#   pos_sig => sigmoid
#   pos_sig_1 => _low_memory_max_pool2d_with_offsets
#   sum_sig => add
#   x => mul_1
# Graph fragment:
#   %sigmoid : [num_users=2] = call_function[target=torch.ops.aten.sigmoid.default](args = (%arg0_1,), kwargs = {})
#   %_low_memory_max_pool2d_with_offsets : [num_users=1] = call_function[target=torch.ops.prims._low_memory_max_pool2d_with_offsets.default](args = (%sigmoid, [3, 3], [1, 1], [1, 1], [1, 1], False), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sigmoid, -1), kwargs = {})
#   %_low_memory_max_pool2d_with_offsets_1 : [num_users=1] = call_function[target=torch.ops.prims._low_memory_max_pool2d_with_offsets.default](args = (%mul, [3, 3], [1, 1], [1, 1], [1, 1], False), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%getitem, %getitem_2), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%arg0_1, %add), kwargs = {})
triton_poi_fused_add_max_pool2d_with_indices_mul_sigmoid_0 = async_compile.triton('triton_poi_fused_add_max_pool2d_with_indices_mul_sigmoid_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=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '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_add_max_pool2d_with_indices_mul_sigmoid_0', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 10, '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_max_pool2d_with_indices_mul_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 4) % 4
    x0 = xindex % 4
    x3 = xindex
    tmp115 = tl.load(in_ptr0 + (x3), xmask)
    tmp0 = (-1) + x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tmp2 & tmp4
    tmp6 = (-1) + x0
    tmp7 = tmp6 >= tmp1
    tmp8 = tmp6 < tmp3
    tmp9 = tmp7 & tmp8
    tmp10 = tmp5 & tmp9
    tmp11 = tl.load(in_ptr0 + ((-5) + x3), tmp10 & xmask, other=0.0)
    tmp12 = tl.sigmoid(tmp11)
    tmp13 = tl.full(tmp12.shape, float("-inf"), tmp12.dtype)
    tmp14 = tl.where(tmp10, tmp12, tmp13)
    tmp15 = x0
    tmp16 = tmp15 >= tmp1
    tmp17 = tmp15 < tmp3
    tmp18 = tmp16 & tmp17
    tmp19 = tmp5 & tmp18
    tmp20 = tl.load(in_ptr0 + ((-4) + x3), tmp19 & xmask, other=0.0)
    tmp21 = tl.sigmoid(tmp20)
    tmp22 = tl.full(tmp21.shape, float("-inf"), tmp21.dtype)
    tmp23 = tl.where(tmp19, tmp21, tmp22)
    tmp24 = triton_helpers.maximum(tmp23, tmp14)
    tmp25 = 1 + x0
    tmp26 = tmp25 >= tmp1
    tmp27 = tmp25 < tmp3
    tmp28 = tmp26 & tmp27
    tmp29 = tmp5 & tmp28
    tmp30 = tl.load(in_ptr0 + ((-3) + x3), tmp29 & xmask, other=0.0)
    tmp31 = tl.sigmoid(tmp30)
    tmp32 = tl.full(tmp31.shape, float("-inf"), tmp31.dtype)
    tmp33 = tl.where(tmp29, tmp31, tmp32)
    tmp34 = triton_helpers.maximum(tmp33, tmp24)
    tmp35 = x1
    tmp36 = tmp35 >= tmp1
    tmp37 = tmp35 < tmp3
    tmp38 = tmp36 & tmp37
    tmp39 = tmp38 & tmp9
    tmp40 = tl.load(in_ptr0 + ((-1) + x3), tmp39 & xmask, other=0.0)
    tmp41 = tl.sigmoid(tmp40)
    tmp42 = tl.full(tmp41.shape, float("-inf"), tmp41.dtype)
    tmp43 = tl.where(tmp39, tmp41, tmp42)
    tmp44 = triton_helpers.maximum(tmp43, tmp34)
    tmp45 = tmp38 & tmp18
    tmp46 = tl.load(in_ptr0 + (x3), tmp45 & xmask, other=0.0)
    tmp47 = tl.sigmoid(tmp46)
    tmp48 = tl.full(tmp47.shape, float("-inf"), tmp47.dtype)
    tmp49 = tl.where(tmp45, tmp47, tmp48)
    tmp50 = triton_helpers.maximum(tmp49, tmp44)
    tmp51 = tmp38 & tmp28
    tmp52 = tl.load(in_ptr0 + (1 + x3), tmp51 & xmask, other=0.0)
    tmp53 = tl.sigmoid(tmp52)
    tmp54 = tl.full(tmp53.shape, float("-inf"), tmp53.dtype)
    tmp55 = tl.where(tmp51, tmp53, tmp54)
    tmp56 = triton_helpers.maximum(tmp55, tmp50)
    tmp57 = 1 + x1
    tmp58 = tmp57 >= tmp1
    tmp59 = tmp57 < tmp3
    tmp60 = tmp58 & tmp59
    tmp61 = tmp60 & tmp9
    tmp62 = tl.load(in_ptr0 + (3 + x3), tmp61 & xmask, other=0.0)
    tmp63 = tl.sigmoid(tmp62)
    tmp64 = tl.full(tmp63.shape, float("-inf"), tmp63.dtype)
    tmp65 = tl.where(tmp61, tmp63, tmp64)
    tmp66 = triton_helpers.maximum(tmp65, tmp56)
    tmp67 = tmp60 & tmp18
    tmp68 = tl.load(in_ptr0 + (4 + x3), tmp67 & xmask, other=0.0)
    tmp69 = tl.sigmoid(tmp68)
    tmp70 = tl.full(tmp69.shape, float("-inf"), tmp69.dtype)
    tmp71 = tl.where(tmp67, tmp69, tmp70)
    tmp72 = triton_helpers.maximum(tmp71, tmp66)
    tmp73 = tmp60 & tmp28
    tmp74 = tl.load(in_ptr0 + (5 + x3), tmp73 & xmask, other=0.0)
    tmp75 = tl.sigmoid(tmp74)
    tmp76 = tl.full(tmp75.shape, float("-inf"), tmp75.dtype)
    tmp77 = tl.where(tmp73, tmp75, tmp76)
    tmp78 = triton_helpers.maximum(tmp77, tmp72)
    tmp79 = -1.0
    tmp80 = tmp12 * tmp79
    tmp81 = tl.full(tmp80.shape, float("-inf"), tmp80.dtype)
    tmp82 = tl.where(tmp10, tmp80, tmp81)
    tmp83 = tmp21 * tmp79
    tmp84 = tl.full(tmp83.shape, float("-inf"), tmp83.dtype)
    tmp85 = tl.where(tmp19, tmp83, tmp84)
    tmp86 = triton_helpers.maximum(tmp85, tmp82)
    tmp87 = tmp31 * tmp79
    tmp88 = tl.full(tmp87.shape, float("-inf"), tmp87.dtype)
    tmp89 = tl.where(tmp29, tmp87, tmp88)
    tmp90 = triton_helpers.maximum(tmp89, tmp86)
    tmp91 = tmp41 * tmp79
    tmp92 = tl.full(tmp91.shape, float("-inf"), tmp91.dtype)
    tmp93 = tl.where(tmp39, tmp91, tmp92)
    tmp94 = triton_helpers.maximum(tmp93, tmp90)
    tmp95 = tmp47 * tmp79
    tmp96 = tl.full(tmp95.shape, float("-inf"), tmp95.dtype)
    tmp97 = tl.where(tmp45, tmp95, tmp96)
    tmp98 = triton_helpers.maximum(tmp97, tmp94)
    tmp99 = tmp53 * tmp79
    tmp100 = tl.full(tmp99.shape, float("-inf"), tmp99.dtype)
    tmp101 = tl.where(tmp51, tmp99, tmp100)
    tmp102 = triton_helpers.maximum(tmp101, tmp98)
    tmp103 = tmp63 * tmp79
    tmp104 = tl.full(tmp103.shape, float("-inf"), tmp103.dtype)
    tmp105 = tl.where(tmp61, tmp103, tmp104)
    tmp106 = triton_helpers.maximum(tmp105, tmp102)
    tmp107 = tmp69 * tmp79
    tmp108 = tl.full(tmp107.shape, float("-inf"), tmp107.dtype)
    tmp109 = tl.where(tmp67, tmp107, tmp108)
    tmp110 = triton_helpers.maximum(tmp109, tmp106)
    tmp111 = tmp75 * tmp79
    tmp112 = tl.full(tmp111.shape, float("-inf"), tmp111.dtype)
    tmp113 = tl.where(tmp73, tmp111, tmp112)
    tmp114 = triton_helpers.maximum(tmp113, tmp110)
    tmp116 = tmp78 + tmp114
    tmp117 = tmp115 * tmp116
    tl.store(in_out_ptr0 + (x3), tmp117, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf2 = buf0; del buf0  # reuse
        # Topologically Sorted Source Nodes: [pos_sig, pos_sig_1, neg_sig, neg_sig_1, sum_sig, x], Original ATen: [aten.sigmoid, aten.max_pool2d_with_indices, aten.mul, aten.add]
        stream0 = get_raw_stream(0)
        triton_poi_fused_add_max_pool2d_with_indices_mul_sigmoid_0.run(buf2, arg0_1, 256, grid=grid(256), stream=stream0)
        del arg0_1
    return (buf2, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    arg0_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_1])
    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


class BILM(nn.Module):

    def __init__(self):
        super(BILM, self).__init__()
        self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)
        self.maxpool2 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)

    def forward(self, feat):
        pos_sig = torch.sigmoid(feat)
        neg_sig = -1 * pos_sig
        pos_sig = self.maxpool1(pos_sig)
        neg_sig = self.maxpool2(neg_sig)
        sum_sig = pos_sig + neg_sig
        x = feat * sum_sig
        return x


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


def get_init_inputs():
    return [[], {}]

import torch
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 torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_add_max_pool2d_with_indices_mul_sigmoid_0(in_out_ptr0,
    in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x3 = xindex
    tmp115 = tl.load(in_ptr0 + x3, xmask)
    tmp0 = -1 + x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tmp2 & tmp4
    tmp6 = -1 + x0
    tmp7 = tmp6 >= tmp1
    tmp8 = tmp6 < tmp3
    tmp9 = tmp7 & tmp8
    tmp10 = tmp5 & tmp9
    tmp11 = tl.load(in_ptr0 + (-5 + x3), tmp10 & xmask, other=0.0)
    tmp12 = tl.sigmoid(tmp11)
    tmp13 = tl.full(tmp12.shape, float('-inf'), tmp12.dtype)
    tmp14 = tl.where(tmp10, tmp12, tmp13)
    tmp15 = x0
    tmp16 = tmp15 >= tmp1
    tmp17 = tmp15 < tmp3
    tmp18 = tmp16 & tmp17
    tmp19 = tmp5 & tmp18
    tmp20 = tl.load(in_ptr0 + (-4 + x3), tmp19 & xmask, other=0.0)
    tmp21 = tl.sigmoid(tmp20)
    tmp22 = tl.full(tmp21.shape, float('-inf'), tmp21.dtype)
    tmp23 = tl.where(tmp19, tmp21, tmp22)
    tmp24 = triton_helpers.maximum(tmp23, tmp14)
    tmp25 = 1 + x0
    tmp26 = tmp25 >= tmp1
    tmp27 = tmp25 < tmp3
    tmp28 = tmp26 & tmp27
    tmp29 = tmp5 & tmp28
    tmp30 = tl.load(in_ptr0 + (-3 + x3), tmp29 & xmask, other=0.0)
    tmp31 = tl.sigmoid(tmp30)
    tmp32 = tl.full(tmp31.shape, float('-inf'), tmp31.dtype)
    tmp33 = tl.where(tmp29, tmp31, tmp32)
    tmp34 = triton_helpers.maximum(tmp33, tmp24)
    tmp35 = x1
    tmp36 = tmp35 >= tmp1
    tmp37 = tmp35 < tmp3
    tmp38 = tmp36 & tmp37
    tmp39 = tmp38 & tmp9
    tmp40 = tl.load(in_ptr0 + (-1 + x3), tmp39 & xmask, other=0.0)
    tmp41 = tl.sigmoid(tmp40)
    tmp42 = tl.full(tmp41.shape, float('-inf'), tmp41.dtype)
    tmp43 = tl.where(tmp39, tmp41, tmp42)
    tmp44 = triton_helpers.maximum(tmp43, tmp34)
    tmp45 = tmp38 & tmp18
    tmp46 = tl.load(in_ptr0 + x3, tmp45 & xmask, other=0.0)
    tmp47 = tl.sigmoid(tmp46)
    tmp48 = tl.full(tmp47.shape, float('-inf'), tmp47.dtype)
    tmp49 = tl.where(tmp45, tmp47, tmp48)
    tmp50 = triton_helpers.maximum(tmp49, tmp44)
    tmp51 = tmp38 & tmp28
    tmp52 = tl.load(in_ptr0 + (1 + x3), tmp51 & xmask, other=0.0)
    tmp53 = tl.sigmoid(tmp52)
    tmp54 = tl.full(tmp53.shape, float('-inf'), tmp53.dtype)
    tmp55 = tl.where(tmp51, tmp53, tmp54)
    tmp56 = triton_helpers.maximum(tmp55, tmp50)
    tmp57 = 1 + x1
    tmp58 = tmp57 >= tmp1
    tmp59 = tmp57 < tmp3
    tmp60 = tmp58 & tmp59
    tmp61 = tmp60 & tmp9
    tmp62 = tl.load(in_ptr0 + (3 + x3), tmp61 & xmask, other=0.0)
    tmp63 = tl.sigmoid(tmp62)
    tmp64 = tl.full(tmp63.shape, float('-inf'), tmp63.dtype)
    tmp65 = tl.where(tmp61, tmp63, tmp64)
    tmp66 = triton_helpers.maximum(tmp65, tmp56)
    tmp67 = tmp60 & tmp18
    tmp68 = tl.load(in_ptr0 + (4 + x3), tmp67 & xmask, other=0.0)
    tmp69 = tl.sigmoid(tmp68)
    tmp70 = tl.full(tmp69.shape, float('-inf'), tmp69.dtype)
    tmp71 = tl.where(tmp67, tmp69, tmp70)
    tmp72 = triton_helpers.maximum(tmp71, tmp66)
    tmp73 = tmp60 & tmp28
    tmp74 = tl.load(in_ptr0 + (5 + x3), tmp73 & xmask, other=0.0)
    tmp75 = tl.sigmoid(tmp74)
    tmp76 = tl.full(tmp75.shape, float('-inf'), tmp75.dtype)
    tmp77 = tl.where(tmp73, tmp75, tmp76)
    tmp78 = triton_helpers.maximum(tmp77, tmp72)
    tmp79 = -1.0
    tmp80 = tmp12 * tmp79
    tmp81 = tl.full(tmp80.shape, float('-inf'), tmp80.dtype)
    tmp82 = tl.where(tmp10, tmp80, tmp81)
    tmp83 = tmp21 * tmp79
    tmp84 = tl.full(tmp83.shape, float('-inf'), tmp83.dtype)
    tmp85 = tl.where(tmp19, tmp83, tmp84)
    tmp86 = triton_helpers.maximum(tmp85, tmp82)
    tmp87 = tmp31 * tmp79
    tmp88 = tl.full(tmp87.shape, float('-inf'), tmp87.dtype)
    tmp89 = tl.where(tmp29, tmp87, tmp88)
    tmp90 = triton_helpers.maximum(tmp89, tmp86)
    tmp91 = tmp41 * tmp79
    tmp92 = tl.full(tmp91.shape, float('-inf'), tmp91.dtype)
    tmp93 = tl.where(tmp39, tmp91, tmp92)
    tmp94 = triton_helpers.maximum(tmp93, tmp90)
    tmp95 = tmp47 * tmp79
    tmp96 = tl.full(tmp95.shape, float('-inf'), tmp95.dtype)
    tmp97 = tl.where(tmp45, tmp95, tmp96)
    tmp98 = triton_helpers.maximum(tmp97, tmp94)
    tmp99 = tmp53 * tmp79
    tmp100 = tl.full(tmp99.shape, float('-inf'), tmp99.dtype)
    tmp101 = tl.where(tmp51, tmp99, tmp100)
    tmp102 = triton_helpers.maximum(tmp101, tmp98)
    tmp103 = tmp63 * tmp79
    tmp104 = tl.full(tmp103.shape, float('-inf'), tmp103.dtype)
    tmp105 = tl.where(tmp61, tmp103, tmp104)
    tmp106 = triton_helpers.maximum(tmp105, tmp102)
    tmp107 = tmp69 * tmp79
    tmp108 = tl.full(tmp107.shape, float('-inf'), tmp107.dtype)
    tmp109 = tl.where(tmp67, tmp107, tmp108)
    tmp110 = triton_helpers.maximum(tmp109, tmp106)
    tmp111 = tmp75 * tmp79
    tmp112 = tl.full(tmp111.shape, float('-inf'), tmp111.dtype)
    tmp113 = tl.where(tmp73, tmp111, tmp112)
    tmp114 = triton_helpers.maximum(tmp113, tmp110)
    tmp116 = tmp78 + tmp114
    tmp117 = tmp115 * tmp116
    tl.store(in_out_ptr0 + x3, tmp117, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf2 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_add_max_pool2d_with_indices_mul_sigmoid_0[grid(256)](
            buf2, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1)
        del arg0_1
    return buf2,


class BILMNew(nn.Module):

    def __init__(self):
        super(BILMNew, self).__init__()
        self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)
        self.maxpool2 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)

    def forward(self, input_0):
        arg0_1 = input_0
        output = call([arg0_1])
        return output[0]
