# 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_0/inductor_cache/rp/crpgwmdyktvbz7ekbte4dpkir25jklz7lq2kagkfoomzfgmflycl.py
# Topologically Sorted Source Nodes: [avg_pool2d, edge, setitem, sub_1, abs_, mul, numerator, sum_2, mul_1, sub_2, numerator_fore, sum_4, sub_3, mul_2, numerator_back, sub_4, sum_6], Original ATen: [aten.avg_pool2d, aten.sub, aten.lift_fresh, aten.index_put, aten.abs, aten.mul, aten.sum, aten.rsub]
# Source node to ATen node mapping:
#   abs_ => abs_1
#   avg_pool2d => avg_pool2d
#   edge => sub
#   mul => mul
#   mul_1 => mul_1
#   mul_2 => mul_2
#   numerator => sum_1
#   numerator_back => sum_5
#   numerator_fore => sum_3
#   setitem => full_default, index_put
#   sub_1 => sub_1
#   sub_2 => sub_2
#   sub_3 => sub_3
#   sub_4 => sub_4
#   sum_2 => sum_2
#   sum_4 => sum_4
#   sum_6 => sum_6
# Graph fragment:
#   %avg_pool2d : [num_users=1] = call_function[target=torch.ops.aten.avg_pool2d.default](args = (%arg0_1, [5, 5], [1, 1], [2, 2]), kwargs = {})
#   %sub : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %avg_pool2d), kwargs = {})
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 1.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cpu, pin_memory: False})
#   %index_put : [num_users=2] = call_function[target=torch.ops.aten.index_put_.default](args = (%sub, [%ne], %full_default), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg1_1, %arg0_1), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%sub_1,), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index_put, %abs_1), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [2, 3]), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%index_put, [2, 3]), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%arg0_1, %arg1_1), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %mul_1), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sub_2, [2, 3]), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%arg0_1, [2, 3]), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_3, %arg1_1), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [2, 3]), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sub_4, [2, 3]), kwargs = {})
triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_0 = async_compile.triton('triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_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.persistent_reduction(
    size_hints=[16, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: '*fp32', 8: 'i32', 9: '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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 27, 'num_reduction': 6, '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}
)
@triton.jit
def triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = (rindex // 4)
    r1 = rindex % 4
    r3 = rindex
    x0 = xindex
    tmp118 = tl.load(in_ptr0 + (r3 + (16*x0)), xmask, other=0.0)
    tmp124 = tl.load(in_ptr1 + (r3 + (16*x0)), xmask, other=0.0)
    tmp0 = (-2) + r2
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1, 1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tmp2 & tmp4
    tmp6 = (-2) + r1
    tmp7 = tmp6 >= tmp1
    tmp8 = tmp6 < tmp3
    tmp9 = tmp7 & tmp8
    tmp10 = tmp5 & tmp9
    tmp11 = tl.load(in_ptr0 + ((-10) + r3 + (16*x0)), tmp10 & xmask, other=0.0)
    tmp12 = (-1) + r1
    tmp13 = tmp12 >= tmp1
    tmp14 = tmp12 < tmp3
    tmp15 = tmp13 & tmp14
    tmp16 = tmp5 & tmp15
    tmp17 = tl.load(in_ptr0 + ((-9) + r3 + (16*x0)), tmp16 & xmask, other=0.0)
    tmp18 = tmp17 + tmp11
    tmp19 = r1
    tmp20 = tmp19 >= tmp1
    tmp21 = tmp19 < tmp3
    tmp22 = tmp20 & tmp21
    tmp23 = tmp5 & tmp22
    tmp24 = tl.load(in_ptr0 + ((-8) + r3 + (16*x0)), tmp23 & xmask, other=0.0)
    tmp25 = tmp24 + tmp18
    tmp26 = 1 + r1
    tmp27 = tmp26 >= tmp1
    tmp28 = tmp26 < tmp3
    tmp29 = tmp27 & tmp28
    tmp30 = tmp5 & tmp29
    tmp31 = tl.load(in_ptr0 + ((-7) + r3 + (16*x0)), tmp30 & xmask, other=0.0)
    tmp32 = tmp31 + tmp25
    tmp33 = 2 + r1
    tmp34 = tmp33 >= tmp1
    tmp35 = tmp33 < tmp3
    tmp36 = tmp34 & tmp35
    tmp37 = tmp5 & tmp36
    tmp38 = tl.load(in_ptr0 + ((-6) + r3 + (16*x0)), tmp37 & xmask, other=0.0)
    tmp39 = tmp38 + tmp32
    tmp40 = (-1) + r2
    tmp41 = tmp40 >= tmp1
    tmp42 = tmp40 < tmp3
    tmp43 = tmp41 & tmp42
    tmp44 = tmp43 & tmp9
    tmp45 = tl.load(in_ptr0 + ((-6) + r3 + (16*x0)), tmp44 & xmask, other=0.0)
    tmp46 = tmp45 + tmp39
    tmp47 = tmp43 & tmp15
    tmp48 = tl.load(in_ptr0 + ((-5) + r3 + (16*x0)), tmp47 & xmask, other=0.0)
    tmp49 = tmp48 + tmp46
    tmp50 = tmp43 & tmp22
    tmp51 = tl.load(in_ptr0 + ((-4) + r3 + (16*x0)), tmp50 & xmask, other=0.0)
    tmp52 = tmp51 + tmp49
    tmp53 = tmp43 & tmp29
    tmp54 = tl.load(in_ptr0 + ((-3) + r3 + (16*x0)), tmp53 & xmask, other=0.0)
    tmp55 = tmp54 + tmp52
    tmp56 = tmp43 & tmp36
    tmp57 = tl.load(in_ptr0 + ((-2) + r3 + (16*x0)), tmp56 & xmask, other=0.0)
    tmp58 = tmp57 + tmp55
    tmp59 = r2
    tmp60 = tmp59 >= tmp1
    tmp61 = tmp59 < tmp3
    tmp62 = tmp60 & tmp61
    tmp63 = tmp62 & tmp9
    tmp64 = tl.load(in_ptr0 + ((-2) + r3 + (16*x0)), tmp63 & xmask, other=0.0)
    tmp65 = tmp64 + tmp58
    tmp66 = tmp62 & tmp15
    tmp67 = tl.load(in_ptr0 + ((-1) + r3 + (16*x0)), tmp66 & xmask, other=0.0)
    tmp68 = tmp67 + tmp65
    tmp69 = tmp62 & tmp22
    tmp70 = tl.load(in_ptr0 + (r3 + (16*x0)), tmp69 & xmask, other=0.0)
    tmp71 = tmp70 + tmp68
    tmp72 = tmp62 & tmp29
    tmp73 = tl.load(in_ptr0 + (1 + r3 + (16*x0)), tmp72 & xmask, other=0.0)
    tmp74 = tmp73 + tmp71
    tmp75 = tmp62 & tmp36
    tmp76 = tl.load(in_ptr0 + (2 + r3 + (16*x0)), tmp75 & xmask, other=0.0)
    tmp77 = tmp76 + tmp74
    tmp78 = 1 + r2
    tmp79 = tmp78 >= tmp1
    tmp80 = tmp78 < tmp3
    tmp81 = tmp79 & tmp80
    tmp82 = tmp81 & tmp9
    tmp83 = tl.load(in_ptr0 + (2 + r3 + (16*x0)), tmp82 & xmask, other=0.0)
    tmp84 = tmp83 + tmp77
    tmp85 = tmp81 & tmp15
    tmp86 = tl.load(in_ptr0 + (3 + r3 + (16*x0)), tmp85 & xmask, other=0.0)
    tmp87 = tmp86 + tmp84
    tmp88 = tmp81 & tmp22
    tmp89 = tl.load(in_ptr0 + (4 + r3 + (16*x0)), tmp88 & xmask, other=0.0)
    tmp90 = tmp89 + tmp87
    tmp91 = tmp81 & tmp29
    tmp92 = tl.load(in_ptr0 + (5 + r3 + (16*x0)), tmp91 & xmask, other=0.0)
    tmp93 = tmp92 + tmp90
    tmp94 = tmp81 & tmp36
    tmp95 = tl.load(in_ptr0 + (6 + r3 + (16*x0)), tmp94 & xmask, other=0.0)
    tmp96 = tmp95 + tmp93
    tmp97 = 2 + r2
    tmp98 = tmp97 >= tmp1
    tmp99 = tmp97 < tmp3
    tmp100 = tmp98 & tmp99
    tmp101 = tmp100 & tmp9
    tmp102 = tl.load(in_ptr0 + (6 + r3 + (16*x0)), tmp101 & xmask, other=0.0)
    tmp103 = tmp102 + tmp96
    tmp104 = tmp100 & tmp15
    tmp105 = tl.load(in_ptr0 + (7 + r3 + (16*x0)), tmp104 & xmask, other=0.0)
    tmp106 = tmp105 + tmp103
    tmp107 = tmp100 & tmp22
    tmp108 = tl.load(in_ptr0 + (8 + r3 + (16*x0)), tmp107 & xmask, other=0.0)
    tmp109 = tmp108 + tmp106
    tmp110 = tmp100 & tmp29
    tmp111 = tl.load(in_ptr0 + (9 + r3 + (16*x0)), tmp110 & xmask, other=0.0)
    tmp112 = tmp111 + tmp109
    tmp113 = tmp100 & tmp36
    tmp114 = tl.load(in_ptr0 + (10 + r3 + (16*x0)), tmp113 & xmask, other=0.0)
    tmp115 = tmp114 + tmp112
    tmp116 = 4 + ((-2)*r1) + ((-2)*r2) + (2*((6) * ((6) <= (3 + r1)) + (3 + r1) * ((3 + r1) < (6)))) + (2*((6) * ((6) <= (3 + r2)) + (3 + r2) * ((3 + r2) < (6)))) + (r1*r2) + (((6) * ((6) <= (3 + r1)) + (3 + r1) * ((3 + r1) < (6)))*((6) * ((6) <= (3 + r2)) + (3 + r2) * ((3 + r2) < (6)))) + ((-1)*r1*((6) * ((6) <= (3 + r2)) + (3 + r2) * ((3 + r2) < (6)))) + ((-1)*r2*((6) * ((6) <= (3 + r1)) + (3 + r1) * ((3 + r1) < (6))))
    tmp117 = tmp115 / tmp116
    tmp119 = tmp118 - tmp117
    tmp120 = 0.0
    tmp121 = tmp119 != tmp120
    tmp122 = 1.0
    tmp123 = tl.where(tmp121, tmp122, tmp119)
    tmp125 = tmp124 - tmp118
    tmp126 = tl_math.abs(tmp125)
    tmp127 = tmp123 * tmp126
    tmp128 = tl.broadcast_to(tmp127, [XBLOCK, RBLOCK])
    tmp130 = tl.where(xmask, tmp128, 0)
    tmp131 = tl.sum(tmp130, 1)[:, None]
    tmp132 = tmp118 * tmp124
    tmp133 = tmp118 - tmp132
    tmp134 = tl.broadcast_to(tmp133, [XBLOCK, RBLOCK])
    tmp136 = tl.where(xmask, tmp134, 0)
    tmp137 = tl.sum(tmp136, 1)[:, None]
    tmp138 = tmp122 - tmp118
    tmp139 = tmp138 * tmp124
    tmp140 = tl.broadcast_to(tmp139, [XBLOCK, RBLOCK])
    tmp142 = tl.where(xmask, tmp140, 0)
    tmp143 = tl.sum(tmp142, 1)[:, None]
    tmp144 = tl.broadcast_to(tmp118, [XBLOCK, RBLOCK])
    tmp146 = tl.where(xmask, tmp144, 0)
    tmp147 = tl.sum(tmp146, 1)[:, None]
    tmp148 = tl.broadcast_to(tmp138, [XBLOCK, RBLOCK])
    tmp150 = tl.where(xmask, tmp148, 0)
    tmp151 = tl.sum(tmp150, 1)[:, None]
    tmp152 = tl.broadcast_to(tmp123, [XBLOCK, RBLOCK])
    tmp154 = tl.where(xmask, tmp152, 0)
    tmp155 = tl.sum(tmp154, 1)[:, None]
    tl.store(out_ptr0 + (x0), tmp131, xmask)
    tl.store(out_ptr1 + (x0), tmp137, xmask)
    tl.store(out_ptr2 + (x0), tmp143, xmask)
    tl.store(out_ptr3 + (x0), tmp147, xmask)
    tl.store(out_ptr4 + (x0), tmp151, xmask)
    tl.store(out_ptr5 + (x0), tmp155, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_0/inductor_cache/nn/cnn52ycf3vxdayfprtsr4gt7ogw6rdtydchm63reo4sl3hjzcxzk.py
# Topologically Sorted Source Nodes: [denominator, edge_loss, denominator_fore, truediv_1, denominator_back, truediv_2, region_loss, add_4, mean], Original ATen: [aten.add, aten.div, aten.mean]
# Source node to ATen node mapping:
#   add_4 => add_4
#   denominator => add
#   denominator_back => add_2
#   denominator_fore => add_1
#   edge_loss => div
#   mean => mean
#   region_loss => add_3
#   truediv_1 => div_1
#   truediv_2 => div_2
# Graph fragment:
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_2, 1e-06), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_1, %add), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_4, 1e-06), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_3, %add_1), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_6, 1e-06), kwargs = {})
#   %div_2 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sum_5, %add_2), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div_1, %div_2), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %add_3), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%add_4,), kwargs = {})
triton_per_fused_add_div_mean_1 = async_compile.triton('triton_per_fused_add_div_mean_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.persistent_reduction(
    size_hints=[1, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: 'i32', 8: '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': {7: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 8), equal_to_1=(7,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_div_mean_1', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 6, 'num_reduction': 1, '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}
)
@triton.jit
def triton_per_fused_add_div_mean_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + (r0), None)
    tmp1 = tl.load(in_ptr1 + (r0), None)
    tmp5 = tl.load(in_ptr2 + (r0), None)
    tmp6 = tl.load(in_ptr3 + (r0), None)
    tmp9 = tl.load(in_ptr4 + (r0), None)
    tmp10 = tl.load(in_ptr5 + (r0), None)
    tmp2 = 1e-06
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 / tmp3
    tmp7 = tmp6 + tmp2
    tmp8 = tmp5 / tmp7
    tmp11 = tmp10 + tmp2
    tmp12 = tmp9 / tmp11
    tmp13 = tmp8 + tmp12
    tmp14 = tmp4 + tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.sum(tmp15, 1)[:, None]
    tmp18 = 16.0
    tmp19 = tmp17 / tmp18
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp19, None)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [avg_pool2d, edge, setitem, sub_1, abs_, mul, numerator, sum_2, mul_1, sub_2, numerator_fore, sum_4, sub_3, mul_2, numerator_back, sub_4, sum_6], Original ATen: [aten.avg_pool2d, aten.sub, aten.lift_fresh, aten.index_put, aten.abs, aten.mul, aten.sum, aten.rsub]
        stream0 = get_raw_stream(0)
        triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_0.run(arg0_1, arg1_1, buf2, buf4, buf6, buf5, buf7, buf3, 16, 16, grid=grid(16), stream=stream0)
        del arg0_1
        del arg1_1
        buf8 = empty_strided_cuda((), (), torch.float32)
        buf9 = buf8; del buf8  # reuse
        # Topologically Sorted Source Nodes: [denominator, edge_loss, denominator_fore, truediv_1, denominator_back, truediv_2, region_loss, add_4, mean], Original ATen: [aten.add, aten.div, aten.mean]
        triton_per_fused_add_div_mean_1.run(buf9, buf2, buf3, buf4, buf5, buf6, buf7, 1, 16, grid=grid(1), stream=stream0)
        del buf2
        del buf3
        del buf4
        del buf5
        del buf6
        del buf7
    return (buf9, )


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)
    arg1_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_1, arg1_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 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.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_0(
    in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4,
    out_ptr5, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex // 4
    r1 = rindex % 4
    r3 = rindex
    x0 = xindex
    tmp118 = tl.load(in_ptr0 + (r3 + 16 * x0), xmask, other=0.0)
    tmp124 = tl.load(in_ptr1 + (r3 + 16 * x0), xmask, other=0.0)
    tmp0 = -2 + r2
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1, 1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tmp2 & tmp4
    tmp6 = -2 + r1
    tmp7 = tmp6 >= tmp1
    tmp8 = tmp6 < tmp3
    tmp9 = tmp7 & tmp8
    tmp10 = tmp5 & tmp9
    tmp11 = tl.load(in_ptr0 + (-10 + r3 + 16 * x0), tmp10 & xmask, other=0.0)
    tmp12 = -1 + r1
    tmp13 = tmp12 >= tmp1
    tmp14 = tmp12 < tmp3
    tmp15 = tmp13 & tmp14
    tmp16 = tmp5 & tmp15
    tmp17 = tl.load(in_ptr0 + (-9 + r3 + 16 * x0), tmp16 & xmask, other=0.0)
    tmp18 = tmp17 + tmp11
    tmp19 = r1
    tmp20 = tmp19 >= tmp1
    tmp21 = tmp19 < tmp3
    tmp22 = tmp20 & tmp21
    tmp23 = tmp5 & tmp22
    tmp24 = tl.load(in_ptr0 + (-8 + r3 + 16 * x0), tmp23 & xmask, other=0.0)
    tmp25 = tmp24 + tmp18
    tmp26 = 1 + r1
    tmp27 = tmp26 >= tmp1
    tmp28 = tmp26 < tmp3
    tmp29 = tmp27 & tmp28
    tmp30 = tmp5 & tmp29
    tmp31 = tl.load(in_ptr0 + (-7 + r3 + 16 * x0), tmp30 & xmask, other=0.0)
    tmp32 = tmp31 + tmp25
    tmp33 = 2 + r1
    tmp34 = tmp33 >= tmp1
    tmp35 = tmp33 < tmp3
    tmp36 = tmp34 & tmp35
    tmp37 = tmp5 & tmp36
    tmp38 = tl.load(in_ptr0 + (-6 + r3 + 16 * x0), tmp37 & xmask, other=0.0)
    tmp39 = tmp38 + tmp32
    tmp40 = -1 + r2
    tmp41 = tmp40 >= tmp1
    tmp42 = tmp40 < tmp3
    tmp43 = tmp41 & tmp42
    tmp44 = tmp43 & tmp9
    tmp45 = tl.load(in_ptr0 + (-6 + r3 + 16 * x0), tmp44 & xmask, other=0.0)
    tmp46 = tmp45 + tmp39
    tmp47 = tmp43 & tmp15
    tmp48 = tl.load(in_ptr0 + (-5 + r3 + 16 * x0), tmp47 & xmask, other=0.0)
    tmp49 = tmp48 + tmp46
    tmp50 = tmp43 & tmp22
    tmp51 = tl.load(in_ptr0 + (-4 + r3 + 16 * x0), tmp50 & xmask, other=0.0)
    tmp52 = tmp51 + tmp49
    tmp53 = tmp43 & tmp29
    tmp54 = tl.load(in_ptr0 + (-3 + r3 + 16 * x0), tmp53 & xmask, other=0.0)
    tmp55 = tmp54 + tmp52
    tmp56 = tmp43 & tmp36
    tmp57 = tl.load(in_ptr0 + (-2 + r3 + 16 * x0), tmp56 & xmask, other=0.0)
    tmp58 = tmp57 + tmp55
    tmp59 = r2
    tmp60 = tmp59 >= tmp1
    tmp61 = tmp59 < tmp3
    tmp62 = tmp60 & tmp61
    tmp63 = tmp62 & tmp9
    tmp64 = tl.load(in_ptr0 + (-2 + r3 + 16 * x0), tmp63 & xmask, other=0.0)
    tmp65 = tmp64 + tmp58
    tmp66 = tmp62 & tmp15
    tmp67 = tl.load(in_ptr0 + (-1 + r3 + 16 * x0), tmp66 & xmask, other=0.0)
    tmp68 = tmp67 + tmp65
    tmp69 = tmp62 & tmp22
    tmp70 = tl.load(in_ptr0 + (r3 + 16 * x0), tmp69 & xmask, other=0.0)
    tmp71 = tmp70 + tmp68
    tmp72 = tmp62 & tmp29
    tmp73 = tl.load(in_ptr0 + (1 + r3 + 16 * x0), tmp72 & xmask, other=0.0)
    tmp74 = tmp73 + tmp71
    tmp75 = tmp62 & tmp36
    tmp76 = tl.load(in_ptr0 + (2 + r3 + 16 * x0), tmp75 & xmask, other=0.0)
    tmp77 = tmp76 + tmp74
    tmp78 = 1 + r2
    tmp79 = tmp78 >= tmp1
    tmp80 = tmp78 < tmp3
    tmp81 = tmp79 & tmp80
    tmp82 = tmp81 & tmp9
    tmp83 = tl.load(in_ptr0 + (2 + r3 + 16 * x0), tmp82 & xmask, other=0.0)
    tmp84 = tmp83 + tmp77
    tmp85 = tmp81 & tmp15
    tmp86 = tl.load(in_ptr0 + (3 + r3 + 16 * x0), tmp85 & xmask, other=0.0)
    tmp87 = tmp86 + tmp84
    tmp88 = tmp81 & tmp22
    tmp89 = tl.load(in_ptr0 + (4 + r3 + 16 * x0), tmp88 & xmask, other=0.0)
    tmp90 = tmp89 + tmp87
    tmp91 = tmp81 & tmp29
    tmp92 = tl.load(in_ptr0 + (5 + r3 + 16 * x0), tmp91 & xmask, other=0.0)
    tmp93 = tmp92 + tmp90
    tmp94 = tmp81 & tmp36
    tmp95 = tl.load(in_ptr0 + (6 + r3 + 16 * x0), tmp94 & xmask, other=0.0)
    tmp96 = tmp95 + tmp93
    tmp97 = 2 + r2
    tmp98 = tmp97 >= tmp1
    tmp99 = tmp97 < tmp3
    tmp100 = tmp98 & tmp99
    tmp101 = tmp100 & tmp9
    tmp102 = tl.load(in_ptr0 + (6 + r3 + 16 * x0), tmp101 & xmask, other=0.0)
    tmp103 = tmp102 + tmp96
    tmp104 = tmp100 & tmp15
    tmp105 = tl.load(in_ptr0 + (7 + r3 + 16 * x0), tmp104 & xmask, other=0.0)
    tmp106 = tmp105 + tmp103
    tmp107 = tmp100 & tmp22
    tmp108 = tl.load(in_ptr0 + (8 + r3 + 16 * x0), tmp107 & xmask, other=0.0)
    tmp109 = tmp108 + tmp106
    tmp110 = tmp100 & tmp29
    tmp111 = tl.load(in_ptr0 + (9 + r3 + 16 * x0), tmp110 & xmask, other=0.0)
    tmp112 = tmp111 + tmp109
    tmp113 = tmp100 & tmp36
    tmp114 = tl.load(in_ptr0 + (10 + r3 + 16 * x0), tmp113 & xmask, other=0.0)
    tmp115 = tmp114 + tmp112
    tmp116 = 4 + -2 * r1 + -2 * r2 + 2 * (6 * (6 <= 3 + r1) + (3 + r1) * (3 +
        r1 < 6)) + 2 * (6 * (6 <= 3 + r2) + (3 + r2) * (3 + r2 < 6)
        ) + r1 * r2 + (6 * (6 <= 3 + r1) + (3 + r1) * (3 + r1 < 6)) * (6 *
        (6 <= 3 + r2) + (3 + r2) * (3 + r2 < 6)) + -1 * r1 * (6 * (6 <= 3 +
        r2) + (3 + r2) * (3 + r2 < 6)) + -1 * r2 * (6 * (6 <= 3 + r1) + (3 +
        r1) * (3 + r1 < 6))
    tmp117 = tmp115 / tmp116
    tmp119 = tmp118 - tmp117
    tmp120 = 0.0
    tmp121 = tmp119 != tmp120
    tmp122 = 1.0
    tmp123 = tl.where(tmp121, tmp122, tmp119)
    tmp125 = tmp124 - tmp118
    tmp126 = tl_math.abs(tmp125)
    tmp127 = tmp123 * tmp126
    tmp128 = tl.broadcast_to(tmp127, [XBLOCK, RBLOCK])
    tmp130 = tl.where(xmask, tmp128, 0)
    tmp131 = tl.sum(tmp130, 1)[:, None]
    tmp132 = tmp118 * tmp124
    tmp133 = tmp118 - tmp132
    tmp134 = tl.broadcast_to(tmp133, [XBLOCK, RBLOCK])
    tmp136 = tl.where(xmask, tmp134, 0)
    tmp137 = tl.sum(tmp136, 1)[:, None]
    tmp138 = tmp122 - tmp118
    tmp139 = tmp138 * tmp124
    tmp140 = tl.broadcast_to(tmp139, [XBLOCK, RBLOCK])
    tmp142 = tl.where(xmask, tmp140, 0)
    tmp143 = tl.sum(tmp142, 1)[:, None]
    tmp144 = tl.broadcast_to(tmp118, [XBLOCK, RBLOCK])
    tmp146 = tl.where(xmask, tmp144, 0)
    tmp147 = tl.sum(tmp146, 1)[:, None]
    tmp148 = tl.broadcast_to(tmp138, [XBLOCK, RBLOCK])
    tmp150 = tl.where(xmask, tmp148, 0)
    tmp151 = tl.sum(tmp150, 1)[:, None]
    tmp152 = tl.broadcast_to(tmp123, [XBLOCK, RBLOCK])
    tmp154 = tl.where(xmask, tmp152, 0)
    tmp155 = tl.sum(tmp154, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp131, xmask)
    tl.store(out_ptr1 + x0, tmp137, xmask)
    tl.store(out_ptr2 + x0, tmp143, xmask)
    tl.store(out_ptr3 + x0, tmp147, xmask)
    tl.store(out_ptr4 + x0, tmp151, xmask)
    tl.store(out_ptr5 + x0, tmp155, xmask)


@triton.jit
def triton_per_fused_add_div_mean_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, in_ptr5, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp5 = tl.load(in_ptr2 + r0, None)
    tmp6 = tl.load(in_ptr3 + r0, None)
    tmp9 = tl.load(in_ptr4 + r0, None)
    tmp10 = tl.load(in_ptr5 + r0, None)
    tmp2 = 1e-06
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 / tmp3
    tmp7 = tmp6 + tmp2
    tmp8 = tmp5 / tmp7
    tmp11 = tmp10 + tmp2
    tmp12 = tmp9 / tmp11
    tmp13 = tmp8 + tmp12
    tmp14 = tmp4 + tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.sum(tmp15, 1)[:, None]
    tmp18 = 16.0
    tmp19 = tmp17 / tmp18
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp19, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_abs_avg_pool2d_index_put_lift_fresh_mul_rsub_sub_sum_0[
            grid(16)](arg0_1, arg1_1, buf2, buf4, buf6, buf5, buf7, buf3, 
            16, 16, XBLOCK=8, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        buf8 = empty_strided_cuda((), (), torch.float32)
        buf9 = buf8
        del buf8
        triton_per_fused_add_div_mean_1[grid(1)](buf9, buf2, buf3, buf4,
            buf5, buf6, buf7, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del buf2
        del buf3
        del buf4
        del buf5
        del buf6
        del buf7
    return buf9,


class HELNew(nn.Module):

    def __init__(self):
        super(HELNew, self).__init__()
        None
        self.eps = 1e-06

    def edge_loss(self, pred, target):
        edge = target - F.avg_pool2d(target, kernel_size=5, stride=1, padding=2
            )
        edge[edge != 0] = 1
        numerator = (edge * (pred - target).abs_()).sum([2, 3])
        denominator = edge.sum([2, 3]) + self.eps
        return numerator / denominator

    def region_loss(self, pred, target):
        numerator_fore = (target - target * pred).sum([2, 3])
        denominator_fore = target.sum([2, 3]) + self.eps
        numerator_back = ((1 - target) * pred).sum([2, 3])
        denominator_back = (1 - target).sum([2, 3]) + self.eps
        return (numerator_fore / denominator_fore + numerator_back /
            denominator_back)

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