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.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_add_pow_sqrt_sub_sum_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
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask)
    tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
    tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
    tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp6 = tmp4 - tmp5
    tmp7 = tmp6 * tmp6
    tmp8 = tmp3 + tmp7
    tmp11 = tmp9 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tmp8 + tmp12
    tmp16 = tmp14 - tmp15
    tmp17 = tmp16 * tmp16
    tmp18 = tmp13 + tmp17
    tmp19 = 1e-08
    tmp20 = tmp18 + tmp19
    tmp21 = libdevice.sqrt(tmp20)
    tl.store(out_ptr0 + x2, tmp21, xmask)


@triton.jit
def triton_per_fused_div_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + r1, None, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tmp7 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp9 = tl.where(xmask, tmp7, 0)
    tmp10 = tl.sum(tmp9, 1)[:, None]
    tmp11 = tmp6 / tmp10
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp11, xmask)


def call(args):
    arg0_1, arg1_1, arg2_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))
    assert_size_stride(arg2_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), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_pow_sqrt_sub_sum_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_per_fused_div_sum_1[grid(4)](buf3, buf0, arg2_1, 4, 64,
            XBLOCK=1, num_warps=2, num_stages=1)
        del arg2_1
        del buf0
    return buf3,


class EpeLossWithMaskNew(nn.Module):

    def __init__(self, eps=1e-08, q=None):
        super(EpeLossWithMaskNew, self).__init__()
        self.eps = eps
        self.q = q

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


Measured latency_ms: 0.015434