# 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/hx/chxkpcmpfbzijvb7oqsj6zrwdt4rwy644sy7sax45arm74rbooa5.py
# Topologically Sorted Source Nodes: [input_soft, input_soft_1, input_soft_2, input_soft_3], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   input_soft => amax, exp, sub
#   input_soft_1 => amax_1, exp_1, sub_2
#   input_soft_2 => amax_2, exp_2, sub_4
#   input_soft_3 => amax_3, exp_3, sub_6
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%arg0_1, [1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
#   %amax_1 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%arg0_1, [1], True), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %amax_1), kwargs = {})
#   %exp_1 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_2,), kwargs = {})
#   %amax_2 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%arg0_1, [1], True), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %amax_2), kwargs = {})
#   %exp_2 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_4,), kwargs = {})
#   %amax_3 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%arg0_1, [1], True), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%arg0_1, %amax_3), kwargs = {})
#   %exp_3 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_6,), kwargs = {})
triton_poi_fused__softmax_0 = async_compile.triton('triton_poi_fused__softmax_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: '*fp32', 3: '*fp32', 4: '*fp32', 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': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, '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__softmax_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = (xindex // 64)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + (x3), tmp9, xmask)
    tl.store(out_ptr1 + (x3), tmp9, xmask)
    tl.store(out_ptr2 + (x3), tmp9, xmask)
    tl.store(out_ptr3 + (x3), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/v4/cv4nyn2kde7dd2c53ddahw4vtxyldln6pqt62jrliqindkf3sj5m.py
# Topologically Sorted Source Nodes: [input_soft], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   input_soft => div, sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_1 = async_compile.triton('triton_poi_fused__softmax_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=[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__softmax_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, '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__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = (xindex // 64)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + (64*x2)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x3), tmp8, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/6d/c6dex3at3ouwuawkwijil5jjfdt2oqf3h3g6z7qlev6kgj3uxheq.py
# Topologically Sorted Source Nodes: [mul, intersection, mul_1, add_1, add, cardinality, add_2, add_3, dice_score, sub, bg, mul_8, mul_2, intersection_1, mul_3, add_5, add_4, cardinality_1, add_6, add_7, dice_score_1, sub_1, fg, mul_9, add_16, mul_4, intersection_2, mul_5, add_9, add_8, cardinality_2, add_10, add_11, dice_score_2, sub_2, tg, mul_10, add_17, mul_6, intersection_3, mul_7, add_13, add_12, cardinality_3, add_14, add_15, dice_score_3, sub_3, gp, mul_11, add_18], Original ATen: [aten.mul, aten.sum, aten.add, aten.div, aten.rsub, aten.mean]
# Source node to ATen node mapping:
#   add => add
#   add_1 => add_1
#   add_10 => add_10
#   add_11 => add_11
#   add_12 => add_12
#   add_13 => add_13
#   add_14 => add_14
#   add_15 => add_15
#   add_16 => add_16
#   add_17 => add_17
#   add_18 => add_18
#   add_2 => add_2
#   add_3 => add_3
#   add_4 => add_4
#   add_5 => add_5
#   add_6 => add_6
#   add_7 => add_7
#   add_8 => add_8
#   add_9 => add_9
#   bg => mean
#   cardinality => sum_3
#   cardinality_1 => sum_6
#   cardinality_2 => sum_9
#   cardinality_3 => sum_12
#   dice_score => div_1
#   dice_score_1 => div_3
#   dice_score_2 => div_5
#   dice_score_3 => div_7
#   fg => mean_1
#   gp => mean_3
#   intersection => sum_2
#   intersection_1 => sum_5
#   intersection_2 => sum_8
#   intersection_3 => sum_11
#   mul => mul
#   mul_1 => mul_1
#   mul_10 => mul_10
#   mul_11 => mul_11
#   mul_2 => mul_2
#   mul_3 => mul_3
#   mul_4 => mul_4
#   mul_5 => mul_5
#   mul_6 => mul_6
#   mul_7 => mul_7
#   mul_8 => mul_8
#   mul_9 => mul_9
#   sub => sub_1
#   sub_1 => sub_3
#   sub_2 => sub_5
#   sub_3 => sub_7
#   tg => mean_2
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div, %arg1_1), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [0]), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_2, 2.0), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_1, 1), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %arg1_1), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%add, [0]), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_3, 1), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_2, 1e-06), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_1, %add_3), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_1,), kwargs = {})
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean, 0.2), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div_2, %arg1_1), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [1]), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_5, 2.0), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_3, 1), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div_2, %arg1_1), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%add_4, [1]), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_6, 1), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_6, 1e-06), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_5, %add_7), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_3), kwargs = {})
#   %mean_1 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_3,), kwargs = {})
#   %mul_9 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean_1, 1.1), kwargs = {})
#   %add_16 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_8, %mul_9), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div_4, %arg1_1), kwargs = {})
#   %sum_8 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_4, [2]), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_8, 2.0), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_5, 1), kwargs = {})
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div_4, %arg1_1), kwargs = {})
#   %sum_9 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%add_8, [2]), kwargs = {})
#   %add_10 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_9, 1), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_10, 1e-06), kwargs = {})
#   %div_5 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_9, %add_11), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_5), kwargs = {})
#   %mean_2 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_5,), kwargs = {})
#   %mul_10 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean_2, 3), kwargs = {})
#   %add_17 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_16, %mul_10), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%div_6, %arg1_1), kwargs = {})
#   %sum_11 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_6, [3]), kwargs = {})
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_11, 2.0), kwargs = {})
#   %add_13 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_7, 1), kwargs = {})
#   %add_12 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div_6, %arg1_1), kwargs = {})
#   %sum_12 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%add_12, [3]), kwargs = {})
#   %add_14 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_12, 1), kwargs = {})
#   %add_15 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_14, 1e-06), kwargs = {})
#   %div_7 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_13, %add_15), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %div_7), kwargs = {})
#   %mean_3 : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%sub_7,), kwargs = {})
#   %mul_11 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mean_3, 3), kwargs = {})
#   %add_18 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_17, %mul_11), kwargs = {})
triton_per_fused_add_div_mean_mul_rsub_sum_2 = async_compile.triton('triton_per_fused_add_div_mean_mul_rsub_sum_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.persistent_reduction(
    size_hints=[1, 64],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32', 7: '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': {6: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 7), equal_to_1=(6,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_div_mean_mul_rsub_sum_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 32, 'num_reduction': 4, '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_mul_rsub_sum_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 64
    RBLOCK: tl.constexpr = 64
    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
    r1 = rindex % 16
    r2 = (rindex // 16)
    r3 = rindex % 4
    r4 = (rindex // 4)
    tmp0 = tl.load(in_ptr0 + (r0), None)
    tmp1 = tl.load(in_ptr1 + (r0), None)
    tmp3 = tl.load(in_ptr0 + (64 + r0), None)
    tmp4 = tl.load(in_ptr1 + (64 + r0), None)
    tmp7 = tl.load(in_ptr0 + (128 + r0), None)
    tmp8 = tl.load(in_ptr1 + (128 + r0), None)
    tmp11 = tl.load(in_ptr0 + (192 + r0), None)
    tmp12 = tl.load(in_ptr1 + (192 + r0), None)
    tmp34 = tl.load(in_ptr2 + (r1 + (64*r2)), None)
    tmp35 = tl.load(in_ptr1 + (r1 + (64*r2)), None)
    tmp37 = tl.load(in_ptr2 + (16 + r1 + (64*r2)), None)
    tmp38 = tl.load(in_ptr1 + (16 + r1 + (64*r2)), None)
    tmp41 = tl.load(in_ptr2 + (32 + r1 + (64*r2)), None)
    tmp42 = tl.load(in_ptr1 + (32 + r1 + (64*r2)), None)
    tmp45 = tl.load(in_ptr2 + (48 + r1 + (64*r2)), None)
    tmp46 = tl.load(in_ptr1 + (48 + r1 + (64*r2)), None)
    tmp65 = tl.load(in_ptr3 + (r3 + (16*r4)), None)
    tmp66 = tl.load(in_ptr1 + (r3 + (16*r4)), None)
    tmp68 = tl.load(in_ptr3 + (4 + r3 + (16*r4)), None)
    tmp69 = tl.load(in_ptr1 + (4 + r3 + (16*r4)), None)
    tmp72 = tl.load(in_ptr3 + (8 + r3 + (16*r4)), None)
    tmp73 = tl.load(in_ptr1 + (8 + r3 + (16*r4)), None)
    tmp76 = tl.load(in_ptr3 + (12 + r3 + (16*r4)), None)
    tmp77 = tl.load(in_ptr1 + (12 + r3 + (16*r4)), None)
    tmp96 = tl.load(in_ptr4 + (4*r0), None, eviction_policy='evict_last')
    tmp97 = tl.load(in_ptr1 + (4*r0), None, eviction_policy='evict_last')
    tmp99 = tl.load(in_ptr4 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp100 = tl.load(in_ptr1 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp103 = tl.load(in_ptr4 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp104 = tl.load(in_ptr1 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp107 = tl.load(in_ptr4 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp108 = tl.load(in_ptr1 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tmp15 = 2.0
    tmp16 = tmp14 * tmp15
    tmp17 = 1.0
    tmp18 = tmp16 + tmp17
    tmp19 = tmp0 + tmp1
    tmp20 = tmp3 + tmp4
    tmp21 = tmp19 + tmp20
    tmp22 = tmp7 + tmp8
    tmp23 = tmp21 + tmp22
    tmp24 = tmp11 + tmp12
    tmp25 = tmp23 + tmp24
    tmp26 = tmp25 + tmp17
    tmp27 = 1e-06
    tmp28 = tmp26 + tmp27
    tmp29 = tmp18 / tmp28
    tmp30 = tmp17 - tmp29
    tmp31 = tl.broadcast_to(tmp30, [XBLOCK, RBLOCK])
    tmp33 = tl.sum(tmp31, 1)[:, None]
    tmp36 = tmp34 * tmp35
    tmp39 = tmp37 * tmp38
    tmp40 = tmp36 + tmp39
    tmp43 = tmp41 * tmp42
    tmp44 = tmp40 + tmp43
    tmp47 = tmp45 * tmp46
    tmp48 = tmp44 + tmp47
    tmp49 = tmp48 * tmp15
    tmp50 = tmp49 + tmp17
    tmp51 = tmp34 + tmp35
    tmp52 = tmp37 + tmp38
    tmp53 = tmp51 + tmp52
    tmp54 = tmp41 + tmp42
    tmp55 = tmp53 + tmp54
    tmp56 = tmp45 + tmp46
    tmp57 = tmp55 + tmp56
    tmp58 = tmp57 + tmp17
    tmp59 = tmp58 + tmp27
    tmp60 = tmp50 / tmp59
    tmp61 = tmp17 - tmp60
    tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK])
    tmp64 = tl.sum(tmp62, 1)[:, None]
    tmp67 = tmp65 * tmp66
    tmp70 = tmp68 * tmp69
    tmp71 = tmp67 + tmp70
    tmp74 = tmp72 * tmp73
    tmp75 = tmp71 + tmp74
    tmp78 = tmp76 * tmp77
    tmp79 = tmp75 + tmp78
    tmp80 = tmp79 * tmp15
    tmp81 = tmp80 + tmp17
    tmp82 = tmp65 + tmp66
    tmp83 = tmp68 + tmp69
    tmp84 = tmp82 + tmp83
    tmp85 = tmp72 + tmp73
    tmp86 = tmp84 + tmp85
    tmp87 = tmp76 + tmp77
    tmp88 = tmp86 + tmp87
    tmp89 = tmp88 + tmp17
    tmp90 = tmp89 + tmp27
    tmp91 = tmp81 / tmp90
    tmp92 = tmp17 - tmp91
    tmp93 = tl.broadcast_to(tmp92, [XBLOCK, RBLOCK])
    tmp95 = tl.sum(tmp93, 1)[:, None]
    tmp98 = tmp96 * tmp97
    tmp101 = tmp99 * tmp100
    tmp102 = tmp98 + tmp101
    tmp105 = tmp103 * tmp104
    tmp106 = tmp102 + tmp105
    tmp109 = tmp107 * tmp108
    tmp110 = tmp106 + tmp109
    tmp111 = tmp110 * tmp15
    tmp112 = tmp111 + tmp17
    tmp113 = tmp96 + tmp97
    tmp114 = tmp99 + tmp100
    tmp115 = tmp113 + tmp114
    tmp116 = tmp103 + tmp104
    tmp117 = tmp115 + tmp116
    tmp118 = tmp107 + tmp108
    tmp119 = tmp117 + tmp118
    tmp120 = tmp119 + tmp17
    tmp121 = tmp120 + tmp27
    tmp122 = tmp112 / tmp121
    tmp123 = tmp17 - tmp122
    tmp124 = tl.broadcast_to(tmp123, [XBLOCK, RBLOCK])
    tmp126 = tl.sum(tmp124, 1)[:, None]
    tmp127 = 64.0
    tmp128 = tmp33 / tmp127
    tmp129 = 0.2
    tmp130 = tmp128 * tmp129
    tmp131 = tmp64 / tmp127
    tmp132 = 1.1
    tmp133 = tmp131 * tmp132
    tmp134 = tmp130 + tmp133
    tmp135 = tmp95 / tmp127
    tmp136 = 3.0
    tmp137 = tmp135 * tmp136
    tmp138 = tmp134 + tmp137
    tmp139 = tmp126 / tmp127
    tmp140 = tmp139 * tmp136
    tmp141 = tmp138 + tmp140
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp141, 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)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [input_soft, input_soft_1, input_soft_2, input_soft_3], Original ATen: [aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_0.run(arg0_1, buf0, buf4, buf8, buf12, 256, grid=grid(256), stream=stream0)
        del arg0_1
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [input_soft], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf0, buf1, 256, grid=grid(256), stream=stream0)
        buf13 = buf0; del buf0  # reuse
        # Topologically Sorted Source Nodes: [input_soft_3], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf12, buf13, 256, grid=grid(256), stream=stream0)
        buf5 = buf12; del buf12  # reuse
        # Topologically Sorted Source Nodes: [input_soft_1], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf4, buf5, 256, grid=grid(256), stream=stream0)
        buf9 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [input_soft_2], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf8, buf9, 256, grid=grid(256), stream=stream0)
        del buf8
        buf11 = empty_strided_cuda((), (), torch.float32)
        buf16 = buf11; del buf11  # reuse
        # Topologically Sorted Source Nodes: [mul, intersection, mul_1, add_1, add, cardinality, add_2, add_3, dice_score, sub, bg, mul_8, mul_2, intersection_1, mul_3, add_5, add_4, cardinality_1, add_6, add_7, dice_score_1, sub_1, fg, mul_9, add_16, mul_4, intersection_2, mul_5, add_9, add_8, cardinality_2, add_10, add_11, dice_score_2, sub_2, tg, mul_10, add_17, mul_6, intersection_3, mul_7, add_13, add_12, cardinality_3, add_14, add_15, dice_score_3, sub_3, gp, mul_11, add_18], Original ATen: [aten.mul, aten.sum, aten.add, aten.div, aten.rsub, aten.mean]
        triton_per_fused_add_div_mean_mul_rsub_sum_2.run(buf16, buf1, arg1_1, buf5, buf9, buf13, 1, 64, grid=grid(1), stream=stream0)
        del arg1_1
        del buf1
        del buf13
        del buf5
        del buf9
    return (buf16, )


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


class DiceLoss(nn.Module):

    def __init__(self, dims=(1, 2, 3)) ->None:
        super(DiceLoss, self).__init__()
        self.eps: 'float' = 1e-06
        self.dims = dims

    def forward(self, input: 'torch.Tensor', target: 'torch.Tensor',
        weights=None) ->torch.Tensor:
        if not torch.is_tensor(input):
            raise TypeError('Input type is not a torch.Tensor. Got {}'.
                format(type(input)))
        if not len(input.shape) == 4:
            raise ValueError('Invalid input shape, we expect BxNxHxW. Got: {}'
                .format(input.shape))
        if not input.shape[-2:] == target.shape[-2:]:
            raise ValueError(
                'input and target shapes must be the same. Got: {}'.format(
                input.shape))
        if not input.device == target.device:
            raise ValueError(
                'input and target must be in the same device. Got: {}'.
                format(input.device))
        smooth = 1
        input_soft = F.softmax(input, dim=1)
        intersection = torch.sum(input_soft * target, self.dims)
        cardinality = torch.sum(input_soft + target, self.dims)
        dice_score = (2.0 * intersection + smooth) / (cardinality + smooth +
            self.eps)
        return torch.mean(1.0 - dice_score)


class MDiceLoss(nn.Module):

    def __init__(self) ->None:
        super(MDiceLoss, self).__init__()
        self.dice_loss_bg = DiceLoss(dims=0)
        self.dice_loss_fg = DiceLoss(dims=1)
        self.dice_loss_th = DiceLoss(dims=2)
        self.dice_loss_gp = DiceLoss(dims=3)

    def forward(self, input: 'torch.Tensor', target: 'torch.Tensor', w=None
        ) ->torch.Tensor:
        bg = self.dice_loss_bg(input, target, w)
        fg = self.dice_loss_fg(input, target, w)
        tg = self.dice_loss_th(input, target, w)
        gp = self.dice_loss_gp(input, target, w)
        return bg * 0.2 + fg * 1.1 + tg * 3 + gp * 3


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 import triton_helpers
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_poi_fused__softmax_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2,
    out_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x3, tmp9, xmask)
    tl.store(out_ptr1 + x3, tmp9, xmask)
    tl.store(out_ptr2 + x3, tmp9, xmask)
    tl.store(out_ptr3 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x3, tmp8, xmask)


@triton.jit
def triton_per_fused_add_div_mean_mul_rsub_sum_2(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 64
    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
    r1 = rindex % 16
    r2 = rindex // 16
    r3 = rindex % 4
    r4 = rindex // 4
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp3 = tl.load(in_ptr0 + (64 + r0), None)
    tmp4 = tl.load(in_ptr1 + (64 + r0), None)
    tmp7 = tl.load(in_ptr0 + (128 + r0), None)
    tmp8 = tl.load(in_ptr1 + (128 + r0), None)
    tmp11 = tl.load(in_ptr0 + (192 + r0), None)
    tmp12 = tl.load(in_ptr1 + (192 + r0), None)
    tmp34 = tl.load(in_ptr2 + (r1 + 64 * r2), None)
    tmp35 = tl.load(in_ptr1 + (r1 + 64 * r2), None)
    tmp37 = tl.load(in_ptr2 + (16 + r1 + 64 * r2), None)
    tmp38 = tl.load(in_ptr1 + (16 + r1 + 64 * r2), None)
    tmp41 = tl.load(in_ptr2 + (32 + r1 + 64 * r2), None)
    tmp42 = tl.load(in_ptr1 + (32 + r1 + 64 * r2), None)
    tmp45 = tl.load(in_ptr2 + (48 + r1 + 64 * r2), None)
    tmp46 = tl.load(in_ptr1 + (48 + r1 + 64 * r2), None)
    tmp65 = tl.load(in_ptr3 + (r3 + 16 * r4), None)
    tmp66 = tl.load(in_ptr1 + (r3 + 16 * r4), None)
    tmp68 = tl.load(in_ptr3 + (4 + r3 + 16 * r4), None)
    tmp69 = tl.load(in_ptr1 + (4 + r3 + 16 * r4), None)
    tmp72 = tl.load(in_ptr3 + (8 + r3 + 16 * r4), None)
    tmp73 = tl.load(in_ptr1 + (8 + r3 + 16 * r4), None)
    tmp76 = tl.load(in_ptr3 + (12 + r3 + 16 * r4), None)
    tmp77 = tl.load(in_ptr1 + (12 + r3 + 16 * r4), None)
    tmp96 = tl.load(in_ptr4 + 4 * r0, None, eviction_policy='evict_last')
    tmp97 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
    tmp99 = tl.load(in_ptr4 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp100 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp103 = tl.load(in_ptr4 + (2 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp104 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp107 = tl.load(in_ptr4 + (3 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp108 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tmp15 = 2.0
    tmp16 = tmp14 * tmp15
    tmp17 = 1.0
    tmp18 = tmp16 + tmp17
    tmp19 = tmp0 + tmp1
    tmp20 = tmp3 + tmp4
    tmp21 = tmp19 + tmp20
    tmp22 = tmp7 + tmp8
    tmp23 = tmp21 + tmp22
    tmp24 = tmp11 + tmp12
    tmp25 = tmp23 + tmp24
    tmp26 = tmp25 + tmp17
    tmp27 = 1e-06
    tmp28 = tmp26 + tmp27
    tmp29 = tmp18 / tmp28
    tmp30 = tmp17 - tmp29
    tmp31 = tl.broadcast_to(tmp30, [XBLOCK, RBLOCK])
    tmp33 = tl.sum(tmp31, 1)[:, None]
    tmp36 = tmp34 * tmp35
    tmp39 = tmp37 * tmp38
    tmp40 = tmp36 + tmp39
    tmp43 = tmp41 * tmp42
    tmp44 = tmp40 + tmp43
    tmp47 = tmp45 * tmp46
    tmp48 = tmp44 + tmp47
    tmp49 = tmp48 * tmp15
    tmp50 = tmp49 + tmp17
    tmp51 = tmp34 + tmp35
    tmp52 = tmp37 + tmp38
    tmp53 = tmp51 + tmp52
    tmp54 = tmp41 + tmp42
    tmp55 = tmp53 + tmp54
    tmp56 = tmp45 + tmp46
    tmp57 = tmp55 + tmp56
    tmp58 = tmp57 + tmp17
    tmp59 = tmp58 + tmp27
    tmp60 = tmp50 / tmp59
    tmp61 = tmp17 - tmp60
    tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK])
    tmp64 = tl.sum(tmp62, 1)[:, None]
    tmp67 = tmp65 * tmp66
    tmp70 = tmp68 * tmp69
    tmp71 = tmp67 + tmp70
    tmp74 = tmp72 * tmp73
    tmp75 = tmp71 + tmp74
    tmp78 = tmp76 * tmp77
    tmp79 = tmp75 + tmp78
    tmp80 = tmp79 * tmp15
    tmp81 = tmp80 + tmp17
    tmp82 = tmp65 + tmp66
    tmp83 = tmp68 + tmp69
    tmp84 = tmp82 + tmp83
    tmp85 = tmp72 + tmp73
    tmp86 = tmp84 + tmp85
    tmp87 = tmp76 + tmp77
    tmp88 = tmp86 + tmp87
    tmp89 = tmp88 + tmp17
    tmp90 = tmp89 + tmp27
    tmp91 = tmp81 / tmp90
    tmp92 = tmp17 - tmp91
    tmp93 = tl.broadcast_to(tmp92, [XBLOCK, RBLOCK])
    tmp95 = tl.sum(tmp93, 1)[:, None]
    tmp98 = tmp96 * tmp97
    tmp101 = tmp99 * tmp100
    tmp102 = tmp98 + tmp101
    tmp105 = tmp103 * tmp104
    tmp106 = tmp102 + tmp105
    tmp109 = tmp107 * tmp108
    tmp110 = tmp106 + tmp109
    tmp111 = tmp110 * tmp15
    tmp112 = tmp111 + tmp17
    tmp113 = tmp96 + tmp97
    tmp114 = tmp99 + tmp100
    tmp115 = tmp113 + tmp114
    tmp116 = tmp103 + tmp104
    tmp117 = tmp115 + tmp116
    tmp118 = tmp107 + tmp108
    tmp119 = tmp117 + tmp118
    tmp120 = tmp119 + tmp17
    tmp121 = tmp120 + tmp27
    tmp122 = tmp112 / tmp121
    tmp123 = tmp17 - tmp122
    tmp124 = tl.broadcast_to(tmp123, [XBLOCK, RBLOCK])
    tmp126 = tl.sum(tmp124, 1)[:, None]
    tmp127 = 64.0
    tmp128 = tmp33 / tmp127
    tmp129 = 0.2
    tmp130 = tmp128 * tmp129
    tmp131 = tmp64 / tmp127
    tmp132 = 1.1
    tmp133 = tmp131 * tmp132
    tmp134 = tmp130 + tmp133
    tmp135 = tmp95 / tmp127
    tmp136 = 3.0
    tmp137 = tmp135 * tmp136
    tmp138 = tmp134 + tmp137
    tmp139 = tmp126 / tmp127
    tmp140 = tmp139 * tmp136
    tmp141 = tmp138 + tmp140
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp141, 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)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(256)](arg0_1, buf0, buf4, buf8,
            buf12, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del arg0_1
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_1[grid(256)](buf0, buf1, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf13 = buf0
        del buf0
        triton_poi_fused__softmax_1[grid(256)](buf12, buf13, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf5 = buf12
        del buf12
        triton_poi_fused__softmax_1[grid(256)](buf4, buf5, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf9 = buf4
        del buf4
        triton_poi_fused__softmax_1[grid(256)](buf8, buf9, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf8
        buf11 = empty_strided_cuda((), (), torch.float32)
        buf16 = buf11
        del buf11
        triton_per_fused_add_div_mean_mul_rsub_sum_2[grid(1)](buf16, buf1,
            arg1_1, buf5, buf9, buf13, 1, 64, XBLOCK=1, num_warps=2,
            num_stages=1)
        del arg1_1
        del buf1
        del buf13
        del buf5
        del buf9
    return buf16,


class DiceLoss(nn.Module):

    def __init__(self, dims=(1, 2, 3)) ->None:
        super(DiceLoss, self).__init__()
        self.eps: 'float' = 1e-06
        self.dims = dims

    def forward(self, input: 'torch.Tensor', target: 'torch.Tensor',
        weights=None) ->torch.Tensor:
        if not torch.is_tensor(input):
            raise TypeError('Input type is not a torch.Tensor. Got {}'.
                format(type(input)))
        if not len(input.shape) == 4:
            raise ValueError('Invalid input shape, we expect BxNxHxW. Got: {}'
                .format(input.shape))
        if not input.shape[-2:] == target.shape[-2:]:
            raise ValueError(
                'input and target shapes must be the same. Got: {}'.format(
                input.shape))
        if not input.device == target.device:
            raise ValueError(
                'input and target must be in the same device. Got: {}'.
                format(input.device))
        smooth = 1
        input_soft = F.softmax(input, dim=1)
        intersection = torch.sum(input_soft * target, self.dims)
        cardinality = torch.sum(input_soft + target, self.dims)
        dice_score = (2.0 * intersection + smooth) / (cardinality + smooth +
            self.eps)
        return torch.mean(1.0 - dice_score)


class MDiceLossNew(nn.Module):

    def __init__(self) ->None:
        super(MDiceLossNew, self).__init__()
        self.dice_loss_bg = DiceLoss(dims=0)
        self.dice_loss_fg = DiceLoss(dims=1)
        self.dice_loss_th = DiceLoss(dims=2)
        self.dice_loss_gp = DiceLoss(dims=3)

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