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 libdevice, math as tl_math
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_red_fused_abs_div_index_linalg_vector_norm_sub_sum_0(in_out_ptr0,
    in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.
    constexpr):
    rnumel = 96
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rbase = tl.arange(0, RBLOCK)[None, :]
    _tmp65 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r1 = rindex // 4 % 6
        r0 = rindex % 4
        r2 = rindex // 24
        tmp0 = r1
        tmp1 = tl.full([1, 1], 3, tl.int64)
        tmp2 = tmp0 < tmp1
        tmp3 = tl.full([1, 1], 1, tl.int64)
        tmp4 = tmp0 < tmp3
        tmp5 = tl.full([1, 1], 2, tl.int64)
        tmp6 = tmp0 < tmp5
        tmp7 = tl.full([1, 1], 0, tl.int64)
        tmp8 = tl.where(tmp6, tmp7, tmp7)
        tmp9 = tl.where(tmp4, tmp7, tmp8)
        tmp10 = tl.full([1, 1], 4, tl.int64)
        tmp11 = tmp0 < tmp10
        tmp12 = tl.full([1, 1], 5, tl.int64)
        tmp13 = tmp0 < tmp12
        tmp14 = tl.where(tmp13, tmp3, tmp5)
        tmp15 = tl.where(tmp11, tmp3, tmp14)
        tmp16 = tl.where(tmp2, tmp9, tmp15)
        tmp17 = tl.load(in_ptr0 + (4 * r0 + 16 * tmp16 + 64 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp18 = tl.where(tmp6, tmp5, tmp1)
        tmp19 = tl.where(tmp4, tmp3, tmp18)
        tmp20 = tl.where(tmp13, tmp1, tmp1)
        tmp21 = tl.where(tmp11, tmp5, tmp20)
        tmp22 = tl.where(tmp2, tmp19, tmp21)
        tmp23 = tl.load(in_ptr0 + (4 * r0 + 16 * tmp22 + 64 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp24 = tmp17 - tmp23
        tmp25 = tmp24 * tmp24
        tmp26 = tl.load(in_ptr0 + (1 + 4 * r0 + 16 * tmp16 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp27 = tl.load(in_ptr0 + (1 + 4 * r0 + 16 * tmp22 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp28 = tmp26 - tmp27
        tmp29 = tmp28 * tmp28
        tmp30 = tmp25 + tmp29
        tmp31 = tl.load(in_ptr0 + (2 + 4 * r0 + 16 * tmp16 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp32 = tl.load(in_ptr0 + (2 + 4 * r0 + 16 * tmp22 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp33 = tmp31 - tmp32
        tmp34 = tmp33 * tmp33
        tmp35 = tmp30 + tmp34
        tmp36 = tl.load(in_ptr0 + (3 + 4 * r0 + 16 * tmp16 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp37 = tl.load(in_ptr0 + (3 + 4 * r0 + 16 * tmp22 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp38 = tmp36 - tmp37
        tmp39 = tmp38 * tmp38
        tmp40 = tmp35 + tmp39
        tmp41 = tl.load(in_ptr1 + (4 * r0 + 16 * tmp16 + 64 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp42 = tl.load(in_ptr1 + (4 * r0 + 16 * tmp22 + 64 * r2), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp43 = tmp41 - tmp42
        tmp44 = tmp43 * tmp43
        tmp45 = tl.load(in_ptr1 + (1 + 4 * r0 + 16 * tmp16 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp46 = tl.load(in_ptr1 + (1 + 4 * r0 + 16 * tmp22 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp47 = tmp45 - tmp46
        tmp48 = tmp47 * tmp47
        tmp49 = tmp44 + tmp48
        tmp50 = tl.load(in_ptr1 + (2 + 4 * r0 + 16 * tmp16 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp51 = tl.load(in_ptr1 + (2 + 4 * r0 + 16 * tmp22 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp52 = tmp50 - tmp51
        tmp53 = tmp52 * tmp52
        tmp54 = tmp49 + tmp53
        tmp55 = tl.load(in_ptr1 + (3 + 4 * r0 + 16 * tmp16 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp56 = tl.load(in_ptr1 + (3 + 4 * r0 + 16 * tmp22 + 64 * r2),
            rmask, eviction_policy='evict_last', other=0.0)
        tmp57 = tmp55 - tmp56
        tmp58 = tmp57 * tmp57
        tmp59 = tmp54 + tmp58
        tmp60 = libdevice.sqrt(tmp40)
        tmp61 = libdevice.sqrt(tmp59)
        tmp62 = tmp60 - tmp61
        tmp63 = tl_math.abs(tmp62)
        tmp64 = tl.broadcast_to(tmp63, [XBLOCK, RBLOCK])
        tmp66 = _tmp65 + tmp64
        _tmp65 = tl.where(rmask, tmp66, _tmp65)
    tmp65 = tl.sum(_tmp65, 1)[:, None]
    tmp67 = 0.25
    tmp68 = tmp65 * tmp67
    tmp69 = 0.16666666666666666
    tmp70 = tmp68 * tmp69
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp70, 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((), (), torch.float32)
        buf3 = buf2
        del buf2
        get_raw_stream(0)
        triton_red_fused_abs_div_index_linalg_vector_norm_sub_sum_0[grid(1)](
            buf3, arg0_1, arg1_1, 1, 96, XBLOCK=1, RBLOCK=64, num_warps=2,
            num_stages=1)
        del arg0_1
        del arg1_1
    return buf3,


class JointBoneLossNew(torch.nn.Module):

    def __init__(self, joint_num):
        super(JointBoneLossNew, self).__init__()
        id_i, id_j = [], []
        for i in range(joint_num):
            for j in range(i + 1, joint_num):
                id_i.append(i)
                id_j.append(j)
        self.id_i = id_i
        self.id_j = id_j

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


Measured latency_ms: 0.014122