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
import torch.optim
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_per_fused_add_mean_pow_sqrt_sub_sum_0(in_out_ptr0, in_ptr0,
    in_ptr1, 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
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr0 + (64 + r0), None)
    tmp3 = tl.load(in_ptr0 + (128 + r0), None)
    tmp5 = tl.load(in_ptr0 + (192 + r0), None)
    tmp9 = tl.load(in_ptr1 + r0, None)
    tmp10 = tl.load(in_ptr1 + (64 + r0), None)
    tmp12 = tl.load(in_ptr1 + (128 + r0), None)
    tmp14 = tl.load(in_ptr1 + (192 + r0), None)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tmp11 = tmp9 + tmp10
    tmp13 = tmp11 + tmp12
    tmp15 = tmp13 + tmp14
    tmp16 = tmp15 / tmp7
    tmp17 = tmp8 - tmp16
    tmp18 = tmp17 * tmp17
    tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK])
    tmp21 = tl.sum(tmp19, 1)[:, None]
    tmp22 = tmp0 * tmp0
    tmp23 = tmp1 * tmp1
    tmp24 = tmp22 + tmp23
    tmp25 = tmp3 * tmp3
    tmp26 = tmp24 + tmp25
    tmp27 = tmp5 * tmp5
    tmp28 = tmp26 + tmp27
    tmp29 = tmp28 / tmp7
    tmp30 = tmp9 * tmp9
    tmp31 = tmp10 * tmp10
    tmp32 = tmp30 + tmp31
    tmp33 = tmp12 * tmp12
    tmp34 = tmp32 + tmp33
    tmp35 = tmp14 * tmp14
    tmp36 = tmp34 + tmp35
    tmp37 = tmp36 / tmp7
    tmp38 = tmp29 - tmp37
    tmp39 = tmp38 * tmp38
    tmp40 = tl.broadcast_to(tmp39, [XBLOCK, RBLOCK])
    tmp42 = tl.sum(tmp40, 1)[:, None]
    tmp43 = tmp22 * tmp0
    tmp44 = tmp23 * tmp1
    tmp45 = tmp43 + tmp44
    tmp46 = tmp25 * tmp3
    tmp47 = tmp45 + tmp46
    tmp48 = tmp27 * tmp5
    tmp49 = tmp47 + tmp48
    tmp50 = tmp49 / tmp7
    tmp51 = tmp30 * tmp9
    tmp52 = tmp31 * tmp10
    tmp53 = tmp51 + tmp52
    tmp54 = tmp33 * tmp12
    tmp55 = tmp53 + tmp54
    tmp56 = tmp35 * tmp14
    tmp57 = tmp55 + tmp56
    tmp58 = tmp57 / tmp7
    tmp59 = tmp50 - tmp58
    tmp60 = tmp22 * tmp22
    tmp61 = tmp23 * tmp23
    tmp62 = tmp60 + tmp61
    tmp63 = tmp25 * tmp25
    tmp64 = tmp62 + tmp63
    tmp65 = tmp27 * tmp27
    tmp66 = tmp64 + tmp65
    tmp67 = tmp66 / tmp7
    tmp68 = tmp30 * tmp30
    tmp69 = tmp31 * tmp31
    tmp70 = tmp68 + tmp69
    tmp71 = tmp33 * tmp33
    tmp72 = tmp70 + tmp71
    tmp73 = tmp35 * tmp35
    tmp74 = tmp72 + tmp73
    tmp75 = tmp74 / tmp7
    tmp76 = tmp67 - tmp75
    tmp77 = tmp59 * tmp59
    tmp78 = tl.broadcast_to(tmp77, [XBLOCK, RBLOCK])
    tmp80 = tl.sum(tmp78, 1)[:, None]
    tmp81 = tmp76 * tmp76
    tmp82 = tl.broadcast_to(tmp81, [XBLOCK, RBLOCK])
    tmp84 = tl.sum(tmp82, 1)[:, None]
    tmp85 = 1e-08
    tmp86 = tmp21 + tmp85
    tmp87 = libdevice.sqrt(tmp86)
    tmp88 = 0.0
    tmp89 = tmp87 + tmp88
    tmp90 = tmp42 + tmp85
    tmp91 = libdevice.sqrt(tmp90)
    tmp92 = tmp89 + tmp91
    tmp93 = tmp80 + tmp85
    tmp94 = libdevice.sqrt(tmp93)
    tmp95 = tmp92 + tmp94
    tmp96 = tmp84 + tmp85
    tmp97 = libdevice.sqrt(tmp96)
    tmp98 = tmp95 + tmp97
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp98, 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((), (), torch.float32)
        buf6 = buf0
        del buf0
        get_raw_stream(0)
        triton_per_fused_add_mean_pow_sqrt_sub_sum_0[grid(1)](buf6, arg0_1,
            arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf6,


class KMomentLossNew(nn.Module):

    def __init__(self, k: 'int'=4):
        """
        k moment distance, where `k` represents the highest order of moment.
        """
        super(KMomentLossNew, self).__init__()
        self.eps = 1e-08
        self.k = k

    def euclidean_dist(self, d1: 'torch.Tensor', d2: 'torch.Tensor'
        ) ->torch.Tensor:
        return (((d1 - d2) ** 2).sum() + self.eps).sqrt()

    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.027077