# 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/3r/c3rrqmsoj3kmkiuqjj3upn322synzbjnaz56rqhue6nu2otdg4ap.py
# Topologically Sorted Source Nodes: [sub_1, add_1, log_1, sub_2, mul_2, sum_7], Original ATen: [aten.rsub, aten.add, aten.log, aten.mul, aten.sum]
# Source node to ATen node mapping:
#   add_1 => add_1
#   log_1 => log_1
#   mul_2 => mul_2
#   sub_1 => sub_1
#   sub_2 => sub_2
#   sum_7 => sum_7
# Graph fragment:
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg1_1), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub_1, 1e-16), kwargs = {})
#   %log_1 : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%add_1,), kwargs = {})
#   %sub_2 : [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 = (%log_1, %sub_2), kwargs = {})
#   %sum_7 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [3]), kwargs = {})
triton_poi_fused_add_log_mul_rsub_sum_0 = async_compile.triton('triton_poi_fused_add_log_mul_rsub_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.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_log_mul_rsub_sum_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 8, '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_log_mul_rsub_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (4*x0), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + (4*x0), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr1 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr0 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp21 = tl.load(in_ptr1 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr0 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr1 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp3 = 1e-16
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.log(tmp4)
    tmp7 = tmp1 - tmp6
    tmp8 = tmp5 * tmp7
    tmp10 = tmp1 - tmp9
    tmp11 = tmp10 + tmp3
    tmp12 = tl_math.log(tmp11)
    tmp14 = tmp1 - tmp13
    tmp15 = tmp12 * tmp14
    tmp16 = tmp8 + tmp15
    tmp18 = tmp1 - tmp17
    tmp19 = tmp18 + tmp3
    tmp20 = tl_math.log(tmp19)
    tmp22 = tmp1 - tmp21
    tmp23 = tmp20 * tmp22
    tmp24 = tmp16 + tmp23
    tmp26 = tmp1 - tmp25
    tmp27 = tmp26 + tmp3
    tmp28 = tl_math.log(tmp27)
    tmp30 = tmp1 - tmp29
    tmp31 = tmp28 * tmp30
    tmp32 = tmp24 + tmp31
    tl.store(out_ptr0 + (x0), tmp32, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/m2/cm2uxxu4dk3huzeksw4rq43sezkn4eowfif2xjgujjbn22vrsiwb.py
# Topologically Sorted Source Nodes: [add, log, mul, sum_5, sum_6, mul_1, sum_1, N_fg, L_fg, sum_8, mul_3, sub, sum_3, N_bg, L_bg, L, mean], Original ATen: [aten.add, aten.log, aten.mul, aten.sum, aten.div, aten.rsub, aten.mean]
# Source node to ATen node mapping:
#   L => add_2
#   L_bg => div_1
#   L_fg => div
#   N_bg => sum_4
#   N_fg => sum_2
#   add => add
#   log => log
#   mean => mean
#   mul => mul
#   mul_1 => mul_1
#   mul_3 => mul_3
#   sub => sub
#   sum_1 => sum_1
#   sum_3 => sum_3
#   sum_5 => sum_5
#   sum_6 => sum_6
#   sum_8 => sum_8
# Graph fragment:
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%arg1_1, 1e-16), kwargs = {})
#   %log : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%add,), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%log, %arg0_1), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [3]), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_5, [2]), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_6, -1), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%arg0_1, [3]), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_1, [2]), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul_1, %sum_2), kwargs = {})
#   %sum_8 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_7, [2]), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_8, -1), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1, %arg0_1), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sub, [3]), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_3, [2]), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul_3, %sum_4), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %div_1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%add_2,), kwargs = {})
triton_per_fused_add_div_log_mean_mul_rsub_sum_1 = async_compile.triton('triton_per_fused_add_div_log_mean_mul_rsub_sum_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.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: 'i32', 5: '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': {4: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 5), equal_to_1=(4,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_div_log_mean_mul_rsub_sum_1', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 36, '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_log_mean_mul_rsub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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 + (16*r0), None, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (16*r0), None, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (1 + (16*r0)), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (1 + (16*r0)), None, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (2 + (16*r0)), None, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (2 + (16*r0)), None, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (3 + (16*r0)), None, eviction_policy='evict_last')
    tmp21 = tl.load(in_ptr1 + (3 + (16*r0)), None, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr0 + (4 + (16*r0)), None, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr1 + (4 + (16*r0)), None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr0 + (5 + (16*r0)), None, eviction_policy='evict_last')
    tmp32 = tl.load(in_ptr1 + (5 + (16*r0)), None, eviction_policy='evict_last')
    tmp35 = tl.load(in_ptr0 + (6 + (16*r0)), None, eviction_policy='evict_last')
    tmp38 = tl.load(in_ptr1 + (6 + (16*r0)), None, eviction_policy='evict_last')
    tmp41 = tl.load(in_ptr0 + (7 + (16*r0)), None, eviction_policy='evict_last')
    tmp44 = tl.load(in_ptr1 + (7 + (16*r0)), None, eviction_policy='evict_last')
    tmp48 = tl.load(in_ptr0 + (8 + (16*r0)), None, eviction_policy='evict_last')
    tmp51 = tl.load(in_ptr1 + (8 + (16*r0)), None, eviction_policy='evict_last')
    tmp53 = tl.load(in_ptr0 + (9 + (16*r0)), None, eviction_policy='evict_last')
    tmp56 = tl.load(in_ptr1 + (9 + (16*r0)), None, eviction_policy='evict_last')
    tmp59 = tl.load(in_ptr0 + (10 + (16*r0)), None, eviction_policy='evict_last')
    tmp62 = tl.load(in_ptr1 + (10 + (16*r0)), None, eviction_policy='evict_last')
    tmp65 = tl.load(in_ptr0 + (11 + (16*r0)), None, eviction_policy='evict_last')
    tmp68 = tl.load(in_ptr1 + (11 + (16*r0)), None, eviction_policy='evict_last')
    tmp72 = tl.load(in_ptr0 + (12 + (16*r0)), None, eviction_policy='evict_last')
    tmp75 = tl.load(in_ptr1 + (12 + (16*r0)), None, eviction_policy='evict_last')
    tmp77 = tl.load(in_ptr0 + (13 + (16*r0)), None, eviction_policy='evict_last')
    tmp80 = tl.load(in_ptr1 + (13 + (16*r0)), None, eviction_policy='evict_last')
    tmp83 = tl.load(in_ptr0 + (14 + (16*r0)), None, eviction_policy='evict_last')
    tmp86 = tl.load(in_ptr1 + (14 + (16*r0)), None, eviction_policy='evict_last')
    tmp89 = tl.load(in_ptr0 + (15 + (16*r0)), None, eviction_policy='evict_last')
    tmp92 = tl.load(in_ptr1 + (15 + (16*r0)), None, eviction_policy='evict_last')
    tmp146 = tl.load(in_ptr2 + (4*r0), None, eviction_policy='evict_last')
    tmp147 = tl.load(in_ptr2 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp149 = tl.load(in_ptr2 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp151 = tl.load(in_ptr2 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp1 = 1e-16
    tmp2 = tmp0 + tmp1
    tmp3 = tl_math.log(tmp2)
    tmp5 = tmp3 * tmp4
    tmp7 = tmp6 + tmp1
    tmp8 = tl_math.log(tmp7)
    tmp10 = tmp8 * tmp9
    tmp11 = tmp5 + tmp10
    tmp13 = tmp12 + tmp1
    tmp14 = tl_math.log(tmp13)
    tmp16 = tmp14 * tmp15
    tmp17 = tmp11 + tmp16
    tmp19 = tmp18 + tmp1
    tmp20 = tl_math.log(tmp19)
    tmp22 = tmp20 * tmp21
    tmp23 = tmp17 + tmp22
    tmp25 = tmp24 + tmp1
    tmp26 = tl_math.log(tmp25)
    tmp28 = tmp26 * tmp27
    tmp30 = tmp29 + tmp1
    tmp31 = tl_math.log(tmp30)
    tmp33 = tmp31 * tmp32
    tmp34 = tmp28 + tmp33
    tmp36 = tmp35 + tmp1
    tmp37 = tl_math.log(tmp36)
    tmp39 = tmp37 * tmp38
    tmp40 = tmp34 + tmp39
    tmp42 = tmp41 + tmp1
    tmp43 = tl_math.log(tmp42)
    tmp45 = tmp43 * tmp44
    tmp46 = tmp40 + tmp45
    tmp47 = tmp23 + tmp46
    tmp49 = tmp48 + tmp1
    tmp50 = tl_math.log(tmp49)
    tmp52 = tmp50 * tmp51
    tmp54 = tmp53 + tmp1
    tmp55 = tl_math.log(tmp54)
    tmp57 = tmp55 * tmp56
    tmp58 = tmp52 + tmp57
    tmp60 = tmp59 + tmp1
    tmp61 = tl_math.log(tmp60)
    tmp63 = tmp61 * tmp62
    tmp64 = tmp58 + tmp63
    tmp66 = tmp65 + tmp1
    tmp67 = tl_math.log(tmp66)
    tmp69 = tmp67 * tmp68
    tmp70 = tmp64 + tmp69
    tmp71 = tmp47 + tmp70
    tmp73 = tmp72 + tmp1
    tmp74 = tl_math.log(tmp73)
    tmp76 = tmp74 * tmp75
    tmp78 = tmp77 + tmp1
    tmp79 = tl_math.log(tmp78)
    tmp81 = tmp79 * tmp80
    tmp82 = tmp76 + tmp81
    tmp84 = tmp83 + tmp1
    tmp85 = tl_math.log(tmp84)
    tmp87 = tmp85 * tmp86
    tmp88 = tmp82 + tmp87
    tmp90 = tmp89 + tmp1
    tmp91 = tl_math.log(tmp90)
    tmp93 = tmp91 * tmp92
    tmp94 = tmp88 + tmp93
    tmp95 = tmp71 + tmp94
    tmp96 = tmp4 + tmp9
    tmp97 = tmp96 + tmp15
    tmp98 = tmp97 + tmp21
    tmp99 = tmp27 + tmp32
    tmp100 = tmp99 + tmp38
    tmp101 = tmp100 + tmp44
    tmp102 = tmp98 + tmp101
    tmp103 = tmp51 + tmp56
    tmp104 = tmp103 + tmp62
    tmp105 = tmp104 + tmp68
    tmp106 = tmp102 + tmp105
    tmp107 = tmp75 + tmp80
    tmp108 = tmp107 + tmp86
    tmp109 = tmp108 + tmp92
    tmp110 = tmp106 + tmp109
    tmp111 = 1.0
    tmp112 = tmp111 - tmp4
    tmp113 = tmp111 - tmp9
    tmp114 = tmp112 + tmp113
    tmp115 = tmp111 - tmp15
    tmp116 = tmp114 + tmp115
    tmp117 = tmp111 - tmp21
    tmp118 = tmp116 + tmp117
    tmp119 = tmp111 - tmp27
    tmp120 = tmp111 - tmp32
    tmp121 = tmp119 + tmp120
    tmp122 = tmp111 - tmp38
    tmp123 = tmp121 + tmp122
    tmp124 = tmp111 - tmp44
    tmp125 = tmp123 + tmp124
    tmp126 = tmp118 + tmp125
    tmp127 = tmp111 - tmp51
    tmp128 = tmp111 - tmp56
    tmp129 = tmp127 + tmp128
    tmp130 = tmp111 - tmp62
    tmp131 = tmp129 + tmp130
    tmp132 = tmp111 - tmp68
    tmp133 = tmp131 + tmp132
    tmp134 = tmp126 + tmp133
    tmp135 = tmp111 - tmp75
    tmp136 = tmp111 - tmp80
    tmp137 = tmp135 + tmp136
    tmp138 = tmp111 - tmp86
    tmp139 = tmp137 + tmp138
    tmp140 = tmp111 - tmp92
    tmp141 = tmp139 + tmp140
    tmp142 = tmp134 + tmp141
    tmp143 = -1.0
    tmp144 = tmp95 * tmp143
    tmp145 = tmp144 / tmp110
    tmp148 = tmp146 + tmp147
    tmp150 = tmp148 + tmp149
    tmp152 = tmp150 + tmp151
    tmp153 = tmp152 * tmp143
    tmp154 = tmp153 / tmp142
    tmp155 = tmp145 + tmp154
    tmp156 = tl.broadcast_to(tmp155, [XBLOCK, RBLOCK])
    tmp158 = tl.sum(tmp156, 1)[:, None]
    tmp159 = 16.0
    tmp160 = tmp158 / tmp159
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp160, 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), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [sub_1, add_1, log_1, sub_2, mul_2, sum_7], Original ATen: [aten.rsub, aten.add, aten.log, aten.mul, aten.sum]
        stream0 = get_raw_stream(0)
        triton_poi_fused_add_log_mul_rsub_sum_0.run(arg1_1, arg0_1, buf2, 64, grid=grid(64), stream=stream0)
        buf4 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [add, log, mul, sum_5, sum_6, mul_1, sum_1, N_fg, L_fg, sum_8, mul_3, sub, sum_3, N_bg, L_bg, L, mean], Original ATen: [aten.add, aten.log, aten.mul, aten.sum, aten.div, aten.rsub, aten.mean]
        triton_per_fused_add_div_log_mean_mul_rsub_sum_1.run(buf5, arg1_1, arg0_1, buf2, 1, 16, grid=grid(1), stream=stream0)
        del arg0_1
        del arg1_1
        del buf2
    return (buf5, )


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 torch.nn as nn


class WCE_loss(nn.Module):

    def __init__(self):
        super(WCE_loss, self).__init__()

    def sum_ij(self, x):
        return torch.sum(torch.sum(x, dim=3), dim=2)

    def forward(self, pred, gt):
        N_fg = self.sum_ij(gt)
        N_bg = self.sum_ij(1 - gt)
        L_fg = -1 * self.sum_ij(torch.log(pred + 1e-16) * gt) / N_fg
        L_bg = -1 * self.sum_ij(torch.log(1 - pred + 1e-16) * (1 - gt)) / N_bg
        L = L_fg + L_bg
        return torch.mean(L)


def get_inputs():
    return [torch.rand([4, 4, 4, 4]), 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.triton_helpers import math as tl_math
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_log_mul_rsub_sum_0(in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp21 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp29 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp3 = 1e-16
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.log(tmp4)
    tmp7 = tmp1 - tmp6
    tmp8 = tmp5 * tmp7
    tmp10 = tmp1 - tmp9
    tmp11 = tmp10 + tmp3
    tmp12 = tl_math.log(tmp11)
    tmp14 = tmp1 - tmp13
    tmp15 = tmp12 * tmp14
    tmp16 = tmp8 + tmp15
    tmp18 = tmp1 - tmp17
    tmp19 = tmp18 + tmp3
    tmp20 = tl_math.log(tmp19)
    tmp22 = tmp1 - tmp21
    tmp23 = tmp20 * tmp22
    tmp24 = tmp16 + tmp23
    tmp26 = tmp1 - tmp25
    tmp27 = tmp26 + tmp3
    tmp28 = tl_math.log(tmp27)
    tmp30 = tmp1 - tmp29
    tmp31 = tmp28 * tmp30
    tmp32 = tmp24 + tmp31
    tl.store(out_ptr0 + x0, tmp32, xmask)


@triton.jit
def triton_per_fused_add_div_log_mean_mul_rsub_sum_1(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, 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 + 16 * r0, None, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + 16 * r0, None, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (1 + 16 * r0), None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (1 + 16 * r0), None, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (2 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (2 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp18 = tl.load(in_ptr0 + (3 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp21 = tl.load(in_ptr1 + (3 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp24 = tl.load(in_ptr0 + (4 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp27 = tl.load(in_ptr1 + (4 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp29 = tl.load(in_ptr0 + (5 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp32 = tl.load(in_ptr1 + (5 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp35 = tl.load(in_ptr0 + (6 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp38 = tl.load(in_ptr1 + (6 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp41 = tl.load(in_ptr0 + (7 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp44 = tl.load(in_ptr1 + (7 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp48 = tl.load(in_ptr0 + (8 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp51 = tl.load(in_ptr1 + (8 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp53 = tl.load(in_ptr0 + (9 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp56 = tl.load(in_ptr1 + (9 + 16 * r0), None, eviction_policy='evict_last'
        )
    tmp59 = tl.load(in_ptr0 + (10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp62 = tl.load(in_ptr1 + (10 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp65 = tl.load(in_ptr0 + (11 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp68 = tl.load(in_ptr1 + (11 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp72 = tl.load(in_ptr0 + (12 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp75 = tl.load(in_ptr1 + (12 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp77 = tl.load(in_ptr0 + (13 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp80 = tl.load(in_ptr1 + (13 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp83 = tl.load(in_ptr0 + (14 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp86 = tl.load(in_ptr1 + (14 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp89 = tl.load(in_ptr0 + (15 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp92 = tl.load(in_ptr1 + (15 + 16 * r0), None, eviction_policy=
        'evict_last')
    tmp146 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last')
    tmp147 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp149 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp151 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp1 = 1e-16
    tmp2 = tmp0 + tmp1
    tmp3 = tl_math.log(tmp2)
    tmp5 = tmp3 * tmp4
    tmp7 = tmp6 + tmp1
    tmp8 = tl_math.log(tmp7)
    tmp10 = tmp8 * tmp9
    tmp11 = tmp5 + tmp10
    tmp13 = tmp12 + tmp1
    tmp14 = tl_math.log(tmp13)
    tmp16 = tmp14 * tmp15
    tmp17 = tmp11 + tmp16
    tmp19 = tmp18 + tmp1
    tmp20 = tl_math.log(tmp19)
    tmp22 = tmp20 * tmp21
    tmp23 = tmp17 + tmp22
    tmp25 = tmp24 + tmp1
    tmp26 = tl_math.log(tmp25)
    tmp28 = tmp26 * tmp27
    tmp30 = tmp29 + tmp1
    tmp31 = tl_math.log(tmp30)
    tmp33 = tmp31 * tmp32
    tmp34 = tmp28 + tmp33
    tmp36 = tmp35 + tmp1
    tmp37 = tl_math.log(tmp36)
    tmp39 = tmp37 * tmp38
    tmp40 = tmp34 + tmp39
    tmp42 = tmp41 + tmp1
    tmp43 = tl_math.log(tmp42)
    tmp45 = tmp43 * tmp44
    tmp46 = tmp40 + tmp45
    tmp47 = tmp23 + tmp46
    tmp49 = tmp48 + tmp1
    tmp50 = tl_math.log(tmp49)
    tmp52 = tmp50 * tmp51
    tmp54 = tmp53 + tmp1
    tmp55 = tl_math.log(tmp54)
    tmp57 = tmp55 * tmp56
    tmp58 = tmp52 + tmp57
    tmp60 = tmp59 + tmp1
    tmp61 = tl_math.log(tmp60)
    tmp63 = tmp61 * tmp62
    tmp64 = tmp58 + tmp63
    tmp66 = tmp65 + tmp1
    tmp67 = tl_math.log(tmp66)
    tmp69 = tmp67 * tmp68
    tmp70 = tmp64 + tmp69
    tmp71 = tmp47 + tmp70
    tmp73 = tmp72 + tmp1
    tmp74 = tl_math.log(tmp73)
    tmp76 = tmp74 * tmp75
    tmp78 = tmp77 + tmp1
    tmp79 = tl_math.log(tmp78)
    tmp81 = tmp79 * tmp80
    tmp82 = tmp76 + tmp81
    tmp84 = tmp83 + tmp1
    tmp85 = tl_math.log(tmp84)
    tmp87 = tmp85 * tmp86
    tmp88 = tmp82 + tmp87
    tmp90 = tmp89 + tmp1
    tmp91 = tl_math.log(tmp90)
    tmp93 = tmp91 * tmp92
    tmp94 = tmp88 + tmp93
    tmp95 = tmp71 + tmp94
    tmp96 = tmp4 + tmp9
    tmp97 = tmp96 + tmp15
    tmp98 = tmp97 + tmp21
    tmp99 = tmp27 + tmp32
    tmp100 = tmp99 + tmp38
    tmp101 = tmp100 + tmp44
    tmp102 = tmp98 + tmp101
    tmp103 = tmp51 + tmp56
    tmp104 = tmp103 + tmp62
    tmp105 = tmp104 + tmp68
    tmp106 = tmp102 + tmp105
    tmp107 = tmp75 + tmp80
    tmp108 = tmp107 + tmp86
    tmp109 = tmp108 + tmp92
    tmp110 = tmp106 + tmp109
    tmp111 = 1.0
    tmp112 = tmp111 - tmp4
    tmp113 = tmp111 - tmp9
    tmp114 = tmp112 + tmp113
    tmp115 = tmp111 - tmp15
    tmp116 = tmp114 + tmp115
    tmp117 = tmp111 - tmp21
    tmp118 = tmp116 + tmp117
    tmp119 = tmp111 - tmp27
    tmp120 = tmp111 - tmp32
    tmp121 = tmp119 + tmp120
    tmp122 = tmp111 - tmp38
    tmp123 = tmp121 + tmp122
    tmp124 = tmp111 - tmp44
    tmp125 = tmp123 + tmp124
    tmp126 = tmp118 + tmp125
    tmp127 = tmp111 - tmp51
    tmp128 = tmp111 - tmp56
    tmp129 = tmp127 + tmp128
    tmp130 = tmp111 - tmp62
    tmp131 = tmp129 + tmp130
    tmp132 = tmp111 - tmp68
    tmp133 = tmp131 + tmp132
    tmp134 = tmp126 + tmp133
    tmp135 = tmp111 - tmp75
    tmp136 = tmp111 - tmp80
    tmp137 = tmp135 + tmp136
    tmp138 = tmp111 - tmp86
    tmp139 = tmp137 + tmp138
    tmp140 = tmp111 - tmp92
    tmp141 = tmp139 + tmp140
    tmp142 = tmp134 + tmp141
    tmp143 = -1.0
    tmp144 = tmp95 * tmp143
    tmp145 = tmp144 / tmp110
    tmp148 = tmp146 + tmp147
    tmp150 = tmp148 + tmp149
    tmp152 = tmp150 + tmp151
    tmp153 = tmp152 * tmp143
    tmp154 = tmp153 / tmp142
    tmp155 = tmp145 + tmp154
    tmp156 = tl.broadcast_to(tmp155, [XBLOCK, RBLOCK])
    tmp158 = tl.sum(tmp156, 1)[:, None]
    tmp159 = 16.0
    tmp160 = tmp158 / tmp159
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp160, 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), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_log_mul_rsub_sum_0[grid(64)](arg1_1, arg0_1,
            buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf4
        del buf4
        triton_per_fused_add_div_log_mean_mul_rsub_sum_1[grid(1)](buf5,
            arg1_1, arg0_1, buf2, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del buf2
    return buf5,


class WCE_lossNew(nn.Module):

    def __init__(self):
        super(WCE_lossNew, self).__init__()

    def sum_ij(self, x):
        return torch.sum(torch.sum(x, dim=3), dim=2)

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