# 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_1/inductor_cache/uf/cuf2n554zsgrrdxmi7emtplbgjplti2rucbziwhh3mlinlefs6nd.py
# Topologically Sorted Source Nodes: [d2_matrix], Original ATen: [aten.stack]
# Source node to ATen node mapping:
#   d2_matrix => cat
# Graph fragment:
#   %cat : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%sqrt, %sqrt_1, %sqrt_2, %sqrt_3],), kwargs = {})
triton_poi_fused_stack_0 = async_compile.triton('triton_poi_fused_stack_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=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_stack_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 32, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_stack_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
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4*x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + (4*x0), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp7 = tmp5 - tmp6
    tmp8 = tmp7 * tmp7
    tmp9 = tl.load(in_ptr0 + (1 + (4*x1)), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp10 = tl.load(in_ptr1 + (1 + (4*x0)), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp11 = tmp9 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tmp8 + tmp12
    tmp14 = tl.load(in_ptr0 + (2 + (4*x1)), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp15 = tl.load(in_ptr1 + (2 + (4*x0)), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp16 = tmp14 - tmp15
    tmp17 = tmp16 * tmp16
    tmp18 = tmp13 + tmp17
    tmp19 = tl.load(in_ptr0 + (3 + (4*x1)), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp20 = tl.load(in_ptr1 + (3 + (4*x0)), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp21 = tmp19 - tmp20
    tmp22 = tmp21 * tmp21
    tmp23 = tmp18 + tmp22
    tmp24 = libdevice.sqrt(tmp23)
    tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
    tmp26 = tl.where(tmp4, tmp24, tmp25)
    tmp27 = tmp0 >= tmp3
    tmp28 = tl.full([1], 8, tl.int64)
    tmp29 = tmp0 < tmp28
    tmp30 = tmp27 & tmp29
    tmp31 = tl.load(in_ptr0 + (16 + (4*((-4) + x1))), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp32 = tl.load(in_ptr1 + (16 + (4*x0)), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp33 = tmp31 - tmp32
    tmp34 = tmp33 * tmp33
    tmp35 = tl.load(in_ptr0 + (17 + (4*((-4) + x1))), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp36 = tl.load(in_ptr1 + (17 + (4*x0)), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp37 = tmp35 - tmp36
    tmp38 = tmp37 * tmp37
    tmp39 = tmp34 + tmp38
    tmp40 = tl.load(in_ptr0 + (18 + (4*((-4) + x1))), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp41 = tl.load(in_ptr1 + (18 + (4*x0)), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp42 = tmp40 - tmp41
    tmp43 = tmp42 * tmp42
    tmp44 = tmp39 + tmp43
    tmp45 = tl.load(in_ptr0 + (19 + (4*((-4) + x1))), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp46 = tl.load(in_ptr1 + (19 + (4*x0)), tmp30 & xmask, eviction_policy='evict_last', other=0.0)
    tmp47 = tmp45 - tmp46
    tmp48 = tmp47 * tmp47
    tmp49 = tmp44 + tmp48
    tmp50 = libdevice.sqrt(tmp49)
    tmp51 = tl.full(tmp50.shape, 0.0, tmp50.dtype)
    tmp52 = tl.where(tmp30, tmp50, tmp51)
    tmp53 = tmp0 >= tmp28
    tmp54 = tl.full([1], 12, tl.int64)
    tmp55 = tmp0 < tmp54
    tmp56 = tmp53 & tmp55
    tmp57 = tl.load(in_ptr0 + (32 + (4*((-8) + x1))), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp58 = tl.load(in_ptr1 + (32 + (4*x0)), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp59 = tmp57 - tmp58
    tmp60 = tmp59 * tmp59
    tmp61 = tl.load(in_ptr0 + (33 + (4*((-8) + x1))), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp62 = tl.load(in_ptr1 + (33 + (4*x0)), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp63 = tmp61 - tmp62
    tmp64 = tmp63 * tmp63
    tmp65 = tmp60 + tmp64
    tmp66 = tl.load(in_ptr0 + (34 + (4*((-8) + x1))), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp67 = tl.load(in_ptr1 + (34 + (4*x0)), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp68 = tmp66 - tmp67
    tmp69 = tmp68 * tmp68
    tmp70 = tmp65 + tmp69
    tmp71 = tl.load(in_ptr0 + (35 + (4*((-8) + x1))), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp72 = tl.load(in_ptr1 + (35 + (4*x0)), tmp56 & xmask, eviction_policy='evict_last', other=0.0)
    tmp73 = tmp71 - tmp72
    tmp74 = tmp73 * tmp73
    tmp75 = tmp70 + tmp74
    tmp76 = libdevice.sqrt(tmp75)
    tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype)
    tmp78 = tl.where(tmp56, tmp76, tmp77)
    tmp79 = tmp0 >= tmp54
    tmp80 = tl.full([1], 16, tl.int64)
    tmp81 = tmp0 < tmp80
    tmp82 = tl.load(in_ptr0 + (48 + (4*((-12) + x1))), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp83 = tl.load(in_ptr1 + (48 + (4*x0)), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp84 = tmp82 - tmp83
    tmp85 = tmp84 * tmp84
    tmp86 = tl.load(in_ptr0 + (49 + (4*((-12) + x1))), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp87 = tl.load(in_ptr1 + (49 + (4*x0)), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp88 = tmp86 - tmp87
    tmp89 = tmp88 * tmp88
    tmp90 = tmp85 + tmp89
    tmp91 = tl.load(in_ptr0 + (50 + (4*((-12) + x1))), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp92 = tl.load(in_ptr1 + (50 + (4*x0)), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp93 = tmp91 - tmp92
    tmp94 = tmp93 * tmp93
    tmp95 = tmp90 + tmp94
    tmp96 = tl.load(in_ptr0 + (51 + (4*((-12) + x1))), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp97 = tl.load(in_ptr1 + (51 + (4*x0)), tmp79 & xmask, eviction_policy='evict_last', other=0.0)
    tmp98 = tmp96 - tmp97
    tmp99 = tmp98 * tmp98
    tmp100 = tmp95 + tmp99
    tmp101 = libdevice.sqrt(tmp100)
    tmp102 = tl.full(tmp101.shape, 0.0, tmp101.dtype)
    tmp103 = tl.where(tmp79, tmp101, tmp102)
    tmp104 = tl.where(tmp56, tmp78, tmp103)
    tmp105 = tl.where(tmp30, tmp52, tmp104)
    tmp106 = tl.where(tmp4, tmp26, tmp105)
    tl.store(out_ptr0 + (x2), tmp106, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/el/celctfu4wbdfgiomns6zpsypz5fnhalcl57xq3mfaseeoxdoxxjb.py
# Topologically Sorted Source Nodes: [min_1, min_2, term_1, term_2, res, mul], Original ATen: [aten.min, aten.mean, aten.add, aten.mul]
# Source node to ATen node mapping:
#   min_1 => min_1
#   min_2 => min_2
#   mul => mul
#   res => add
#   term_1 => mean
#   term_2 => mean_1
# Graph fragment:
#   %min_1 : [num_users=1] = call_function[target=torch.ops.aten.min.dim](args = (%view, 2), kwargs = {})
#   %min_2 : [num_users=1] = call_function[target=torch.ops.aten.min.dim](args = (%view, 1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%getitem, [-1]), kwargs = {})
#   %mean_1 : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%getitem_2, [-1]), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mean, %mean_1), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, 1.0), kwargs = {})
triton_poi_fused_add_mean_min_mul_1 = async_compile.triton('triton_poi_fused_add_mean_min_mul_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=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_mean_min_mul_1', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 16, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_mean_min_mul_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (16*x0), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (4 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (5 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (6 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (7 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (8 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr0 + (9 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (10 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr0 + (11 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (12 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr0 + (13 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr0 + (14 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr0 + (15 + (16*x0)), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.minimum(tmp0, tmp1)
    tmp4 = triton_helpers.minimum(tmp2, tmp3)
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp9 = triton_helpers.minimum(tmp7, tmp8)
    tmp11 = triton_helpers.minimum(tmp9, tmp10)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tmp14 = tmp6 + tmp13
    tmp17 = triton_helpers.minimum(tmp15, tmp16)
    tmp19 = triton_helpers.minimum(tmp17, tmp18)
    tmp21 = triton_helpers.minimum(tmp19, tmp20)
    tmp22 = tmp14 + tmp21
    tmp25 = triton_helpers.minimum(tmp23, tmp24)
    tmp27 = triton_helpers.minimum(tmp25, tmp26)
    tmp29 = triton_helpers.minimum(tmp27, tmp28)
    tmp30 = tmp22 + tmp29
    tmp31 = 4.0
    tmp32 = tmp30 / tmp31
    tmp33 = triton_helpers.minimum(tmp0, tmp7)
    tmp34 = triton_helpers.minimum(tmp33, tmp15)
    tmp35 = triton_helpers.minimum(tmp34, tmp23)
    tmp36 = triton_helpers.minimum(tmp1, tmp8)
    tmp37 = triton_helpers.minimum(tmp36, tmp16)
    tmp38 = triton_helpers.minimum(tmp37, tmp24)
    tmp39 = tmp35 + tmp38
    tmp40 = triton_helpers.minimum(tmp3, tmp10)
    tmp41 = triton_helpers.minimum(tmp40, tmp18)
    tmp42 = triton_helpers.minimum(tmp41, tmp26)
    tmp43 = tmp39 + tmp42
    tmp44 = triton_helpers.minimum(tmp5, tmp12)
    tmp45 = triton_helpers.minimum(tmp44, tmp20)
    tmp46 = triton_helpers.minimum(tmp45, tmp28)
    tmp47 = tmp43 + tmp46
    tmp48 = tmp47 / tmp31
    tmp49 = tmp32 + tmp48
    tmp50 = 1.0
    tmp51 = tmp49 * tmp50
    tl.store(in_out_ptr0 + (x0), tmp51, xmask)
''', 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), (16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [d2_matrix], Original ATen: [aten.stack]
        stream0 = get_raw_stream(0)
        triton_poi_fused_stack_0.run(arg0_1, arg1_1, buf0, 64, grid=grid(64), stream=stream0)
        del arg0_1
        del arg1_1
        buf1 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf3 = buf1; del buf1  # reuse
        # Topologically Sorted Source Nodes: [min_1, min_2, term_1, term_2, res, mul], Original ATen: [aten.min, aten.mean, aten.add, aten.mul]
        triton_poi_fused_add_mean_min_mul_1.run(buf3, buf0, 4, grid=grid(4), stream=stream0)
        del buf0
    return (buf3, )


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), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    arg1_1 = rand_strided((4, 4, 4), (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 HausdorffLoss(nn.Module):

    def __init__(self, loss_weight=1.0):
        super(HausdorffLoss, self).__init__()
        self.weight = loss_weight

    def forward(self, set1, set2):
        """
        Compute the Averaged Hausdorff Distance function
        between two unordered sets of points (the function is symmetric).
        Batches are not supported, so squeeze your inputs first!
        :param set1: Tensor where each row is an N-dimensional point.
        :param set2: Tensor where each row is an N-dimensional point.
        :return: The Averaged Hausdorff Distance between set1 and set2.
        """
        assert set1.ndimension() == 3, 'got %s' % set1.ndimension()
        assert set2.ndimension() == 3, 'got %s' % set2.ndimension()
        if set1.shape[0] > 0:
            assert set1.size()[1] == set2.size()[1
                ], 'The points in both sets must have the same number of dimensions, got %s and %s.' % (
                set1.size()[1], set2.size()[1])
            """ the second implement to avoid the CUDA out of the memory
                 need the size to be  set1: (N, 40, 2), set2:(N, 40, 2)"""
            d2_matrix = torch.stack([self.cdist(item1, item2) for item1,
                item2 in zip(set1, set2)], dim=0)
            term_1 = torch.mean(torch.min(d2_matrix, 2)[0], -1)
            term_2 = torch.mean(torch.min(d2_matrix, 1)[0], -1)
            res = term_1 + term_2
        else:
            res = set1.sum() * 0
        return res * self.weight

    def cdist(self, x, y):
        """
        Compute distance between each pair of the two collections of inputs.
        :param x: Nxd Tensor
        :param y: Mxd Tensor
        :res: NxM matrix where dist[i,j] is the norm between x[i,:] and y[j,:],
              i.e. dist[i,j] = ||x[i,:]-y[j,:]||

        """
        differences = x.unsqueeze(1) - y.unsqueeze(0)
        distances = torch.sum(differences ** 2, -1).sqrt()
        return distances


def get_inputs():
    return [torch.rand([4, 4, 4]), torch.rand([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 libdevice
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_stack_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
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + 4 * x1, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + 4 * x0, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tmp5 - tmp6
    tmp8 = tmp7 * tmp7
    tmp9 = tl.load(in_ptr0 + (1 + 4 * x1), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = tmp9 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tmp8 + tmp12
    tmp14 = tl.load(in_ptr0 + (2 + 4 * x1), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tl.load(in_ptr1 + (2 + 4 * x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tmp14 - tmp15
    tmp17 = tmp16 * tmp16
    tmp18 = tmp13 + tmp17
    tmp19 = tl.load(in_ptr0 + (3 + 4 * x1), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp20 = tl.load(in_ptr1 + (3 + 4 * x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp21 = tmp19 - tmp20
    tmp22 = tmp21 * tmp21
    tmp23 = tmp18 + tmp22
    tmp24 = libdevice.sqrt(tmp23)
    tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
    tmp26 = tl.where(tmp4, tmp24, tmp25)
    tmp27 = tmp0 >= tmp3
    tmp28 = tl.full([1], 8, tl.int64)
    tmp29 = tmp0 < tmp28
    tmp30 = tmp27 & tmp29
    tmp31 = tl.load(in_ptr0 + (16 + 4 * (-4 + x1)), tmp30 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp32 = tl.load(in_ptr1 + (16 + 4 * x0), tmp30 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp33 = tmp31 - tmp32
    tmp34 = tmp33 * tmp33
    tmp35 = tl.load(in_ptr0 + (17 + 4 * (-4 + x1)), tmp30 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp36 = tl.load(in_ptr1 + (17 + 4 * x0), tmp30 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp37 = tmp35 - tmp36
    tmp38 = tmp37 * tmp37
    tmp39 = tmp34 + tmp38
    tmp40 = tl.load(in_ptr0 + (18 + 4 * (-4 + x1)), tmp30 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp41 = tl.load(in_ptr1 + (18 + 4 * x0), tmp30 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp42 = tmp40 - tmp41
    tmp43 = tmp42 * tmp42
    tmp44 = tmp39 + tmp43
    tmp45 = tl.load(in_ptr0 + (19 + 4 * (-4 + x1)), tmp30 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp46 = tl.load(in_ptr1 + (19 + 4 * x0), tmp30 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp47 = tmp45 - tmp46
    tmp48 = tmp47 * tmp47
    tmp49 = tmp44 + tmp48
    tmp50 = libdevice.sqrt(tmp49)
    tmp51 = tl.full(tmp50.shape, 0.0, tmp50.dtype)
    tmp52 = tl.where(tmp30, tmp50, tmp51)
    tmp53 = tmp0 >= tmp28
    tmp54 = tl.full([1], 12, tl.int64)
    tmp55 = tmp0 < tmp54
    tmp56 = tmp53 & tmp55
    tmp57 = tl.load(in_ptr0 + (32 + 4 * (-8 + x1)), tmp56 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp58 = tl.load(in_ptr1 + (32 + 4 * x0), tmp56 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp59 = tmp57 - tmp58
    tmp60 = tmp59 * tmp59
    tmp61 = tl.load(in_ptr0 + (33 + 4 * (-8 + x1)), tmp56 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp62 = tl.load(in_ptr1 + (33 + 4 * x0), tmp56 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp63 = tmp61 - tmp62
    tmp64 = tmp63 * tmp63
    tmp65 = tmp60 + tmp64
    tmp66 = tl.load(in_ptr0 + (34 + 4 * (-8 + x1)), tmp56 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp67 = tl.load(in_ptr1 + (34 + 4 * x0), tmp56 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp68 = tmp66 - tmp67
    tmp69 = tmp68 * tmp68
    tmp70 = tmp65 + tmp69
    tmp71 = tl.load(in_ptr0 + (35 + 4 * (-8 + x1)), tmp56 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp72 = tl.load(in_ptr1 + (35 + 4 * x0), tmp56 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp73 = tmp71 - tmp72
    tmp74 = tmp73 * tmp73
    tmp75 = tmp70 + tmp74
    tmp76 = libdevice.sqrt(tmp75)
    tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype)
    tmp78 = tl.where(tmp56, tmp76, tmp77)
    tmp79 = tmp0 >= tmp54
    tl.full([1], 16, tl.int64)
    tmp82 = tl.load(in_ptr0 + (48 + 4 * (-12 + x1)), tmp79 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp83 = tl.load(in_ptr1 + (48 + 4 * x0), tmp79 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp84 = tmp82 - tmp83
    tmp85 = tmp84 * tmp84
    tmp86 = tl.load(in_ptr0 + (49 + 4 * (-12 + x1)), tmp79 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp87 = tl.load(in_ptr1 + (49 + 4 * x0), tmp79 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp88 = tmp86 - tmp87
    tmp89 = tmp88 * tmp88
    tmp90 = tmp85 + tmp89
    tmp91 = tl.load(in_ptr0 + (50 + 4 * (-12 + x1)), tmp79 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp92 = tl.load(in_ptr1 + (50 + 4 * x0), tmp79 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp93 = tmp91 - tmp92
    tmp94 = tmp93 * tmp93
    tmp95 = tmp90 + tmp94
    tmp96 = tl.load(in_ptr0 + (51 + 4 * (-12 + x1)), tmp79 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp97 = tl.load(in_ptr1 + (51 + 4 * x0), tmp79 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp98 = tmp96 - tmp97
    tmp99 = tmp98 * tmp98
    tmp100 = tmp95 + tmp99
    tmp101 = libdevice.sqrt(tmp100)
    tmp102 = tl.full(tmp101.shape, 0.0, tmp101.dtype)
    tmp103 = tl.where(tmp79, tmp101, tmp102)
    tmp104 = tl.where(tmp56, tmp78, tmp103)
    tmp105 = tl.where(tmp30, tmp52, tmp104)
    tmp106 = tl.where(tmp4, tmp26, tmp105)
    tl.store(out_ptr0 + x2, tmp106, xmask)


@triton.jit
def triton_poi_fused_add_mean_min_mul_1(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp8 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp10 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp18 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp20 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp24 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp26 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp28 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = triton_helpers.minimum(tmp0, tmp1)
    tmp4 = triton_helpers.minimum(tmp2, tmp3)
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp9 = triton_helpers.minimum(tmp7, tmp8)
    tmp11 = triton_helpers.minimum(tmp9, tmp10)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tmp14 = tmp6 + tmp13
    tmp17 = triton_helpers.minimum(tmp15, tmp16)
    tmp19 = triton_helpers.minimum(tmp17, tmp18)
    tmp21 = triton_helpers.minimum(tmp19, tmp20)
    tmp22 = tmp14 + tmp21
    tmp25 = triton_helpers.minimum(tmp23, tmp24)
    tmp27 = triton_helpers.minimum(tmp25, tmp26)
    tmp29 = triton_helpers.minimum(tmp27, tmp28)
    tmp30 = tmp22 + tmp29
    tmp31 = 4.0
    tmp32 = tmp30 / tmp31
    tmp33 = triton_helpers.minimum(tmp0, tmp7)
    tmp34 = triton_helpers.minimum(tmp33, tmp15)
    tmp35 = triton_helpers.minimum(tmp34, tmp23)
    tmp36 = triton_helpers.minimum(tmp1, tmp8)
    tmp37 = triton_helpers.minimum(tmp36, tmp16)
    tmp38 = triton_helpers.minimum(tmp37, tmp24)
    tmp39 = tmp35 + tmp38
    tmp40 = triton_helpers.minimum(tmp3, tmp10)
    tmp41 = triton_helpers.minimum(tmp40, tmp18)
    tmp42 = triton_helpers.minimum(tmp41, tmp26)
    tmp43 = tmp39 + tmp42
    tmp44 = triton_helpers.minimum(tmp5, tmp12)
    tmp45 = triton_helpers.minimum(tmp44, tmp20)
    tmp46 = triton_helpers.minimum(tmp45, tmp28)
    tmp47 = tmp43 + tmp46
    tmp48 = tmp47 / tmp31
    tmp49 = tmp32 + tmp48
    tmp50 = 1.0
    tmp51 = tmp49 * tmp50
    tl.store(in_out_ptr0 + x0, tmp51, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_stack_0[grid(64)](arg0_1, arg1_1, buf0, 64, XBLOCK
            =64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        buf1 = empty_strided_cuda((4,), (1,), torch.float32)
        buf3 = buf1
        del buf1
        triton_poi_fused_add_mean_min_mul_1[grid(4)](buf3, buf0, 4, XBLOCK=
            4, num_warps=1, num_stages=1)
        del buf0
    return buf3,


class HausdorffLossNew(nn.Module):

    def __init__(self, loss_weight=1.0):
        super(HausdorffLossNew, self).__init__()
        self.weight = loss_weight

    def cdist(self, x, y):
        """
        Compute distance between each pair of the two collections of inputs.
        :param x: Nxd Tensor
        :param y: Mxd Tensor
        :res: NxM matrix where dist[i,j] is the norm between x[i,:] and y[j,:],
              i.e. dist[i,j] = ||x[i,:]-y[j,:]||

        """
        differences = x.unsqueeze(1) - y.unsqueeze(0)
        distances = torch.sum(differences ** 2, -1).sqrt()
        return distances

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