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
from torch import 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_div_mse_loss_mul_pow_sum_0(in_out_ptr0, in_ptr0,
    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)
    r2 = rindex
    r1 = rindex // 4
    tmp0 = tl.load(in_ptr0 + r2, None)
    tmp3 = tl.load(in_ptr0 + 4 * r1, None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1 + 4 * r1), None, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (2 + 4 * r1), None, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (3 + 4 * r1), None, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (64 + r2), None)
    tmp20 = tl.load(in_ptr0 + (64 + 4 * r1), None, eviction_policy='evict_last'
        )
    tmp22 = tl.load(in_ptr0 + (65 + 4 * r1), None, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr0 + (66 + 4 * r1), None, eviction_policy='evict_last'
        )
    tmp28 = tl.load(in_ptr0 + (67 + 4 * r1), None, eviction_policy='evict_last'
        )
    tmp39 = tl.load(in_ptr0 + (128 + r2), None)
    tmp41 = tl.load(in_ptr0 + (128 + 4 * r1), None, eviction_policy=
        'evict_last')
    tmp43 = tl.load(in_ptr0 + (129 + 4 * r1), None, eviction_policy=
        'evict_last')
    tmp46 = tl.load(in_ptr0 + (130 + 4 * r1), None, eviction_policy=
        'evict_last')
    tmp49 = tl.load(in_ptr0 + (131 + 4 * r1), None, eviction_policy=
        'evict_last')
    tmp1 = 1.0
    tmp2 = tmp0 * tmp1
    tmp4 = tmp3 * tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp12 = tmp11 * tmp11
    tmp13 = tmp10 + tmp12
    tmp14 = libdevice.sqrt(tmp13)
    tmp15 = 1e-12
    tmp16 = tmp14 + tmp15
    tmp17 = tmp2 / tmp16
    tmp19 = tmp18 * tmp1
    tmp21 = tmp20 * tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp26 = tmp25 * tmp25
    tmp27 = tmp24 + tmp26
    tmp29 = tmp28 * tmp28
    tmp30 = tmp27 + tmp29
    tmp31 = libdevice.sqrt(tmp30)
    tmp32 = tmp31 + tmp15
    tmp33 = tmp19 / tmp32
    tmp34 = tmp17 - tmp33
    tmp35 = tmp34 * tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp40 = tmp39 * tmp1
    tmp42 = tmp41 * tmp41
    tmp44 = tmp43 * tmp43
    tmp45 = tmp42 + tmp44
    tmp47 = tmp46 * tmp46
    tmp48 = tmp45 + tmp47
    tmp50 = tmp49 * tmp49
    tmp51 = tmp48 + tmp50
    tmp52 = libdevice.sqrt(tmp51)
    tmp53 = tmp52 + tmp15
    tmp54 = tmp40 / tmp53
    tmp55 = tmp17 - tmp54
    tmp56 = tmp55 * tmp55
    tmp57 = tl.broadcast_to(tmp56, [XBLOCK, RBLOCK])
    tmp59 = tl.sum(tmp57, 1)[:, None]
    tmp60 = 64.0
    tmp61 = tmp38 / tmp60
    tmp62 = tmp61 * tmp1
    tmp63 = tmp59 / tmp60
    tmp64 = tl.full([1, 1], 1, tl.int32)
    tmp65 = tmp64 / tmp63
    tmp66 = tmp62 * tmp65
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp66, None)


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


def normalize(x, axis=-1):
    """Normalizing to unit length along the specified dimension.
    Args:
      x: pytorch Variable
    Returns:
      x: pytorch Variable, same shape as input
    """
    x = 1.0 * x / (torch.norm(x, 2, axis, keepdim=True).expand_as(x) + 1e-12)
    return x


class triplet_my_lossNew(nn.Module):

    def __init__(self, margin=1.0, use_gpu=True):
        super(triplet_my_lossNew, self).__init__()
        self.use_gpu = use_gpu
        self.margin = margin
        self.mse = nn.MSELoss()

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


Measured latency_ms: 0.014041