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, math as tl_math
import torch.nn as nn
import torch.utils.data
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_any_atan2_div_isnan_mean_mul_pow_sin_sqrt_sub_0(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp2 = tl.load(in_ptr1 + r0, None)
    tmp6 = tl.load(in_ptr2 + r0, None)
    tmp8 = tl.load(in_ptr3 + r0, None)
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp5 = libdevice.sqrt(tmp4)
    tmp7 = tmp6 * tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = libdevice.sqrt(tmp10)
    tmp12 = tmp5 - tmp11
    tmp13 = tmp12 * tmp12
    tmp14 = 2.0
    tmp15 = tmp11 * tmp14
    tmp16 = libdevice.atan2(tmp2, tmp0)
    tmp17 = libdevice.atan2(tmp8, tmp6)
    tmp18 = tmp16 - tmp17
    tmp19 = 0.5
    tmp20 = tmp18 * tmp19
    tmp21 = tl_math.sin(tmp20)
    tmp22 = tmp15 * tmp21
    tmp23 = tmp22 * tmp22
    tmp24 = 4.0
    tmp25 = tmp23 * tmp24
    tmp26 = tmp13 + tmp25
    tmp27 = tl.broadcast_to(tmp26, [RBLOCK])
    tmp29 = triton_helpers.promote_to_tensor(tl.sum(tmp27, 0))
    tmp30 = 256.0
    tmp31 = tmp29 / tmp30
    tmp32 = libdevice.isnan(tmp31).to(tl.int1)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp31, None)
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp32, None)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_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))
    assert_size_stride(arg3_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)
        buf1 = buf0
        del buf0
        buf2 = empty_strided_cuda((), (), torch.bool)
        get_raw_stream(0)
        triton_per_fused_add_any_atan2_div_isnan_mean_mul_pow_sin_sqrt_sub_0[
            grid(1)](buf1, arg2_1, arg3_1, arg0_1, arg1_1, buf2, 1, 256,
            num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del arg2_1
        del arg3_1
    return buf1, buf2


class WPMLossNew(nn.Module):

    def __init__(self, weight):
        super(WPMLossNew, self).__init__()
        self.weight = weight

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


Measured latency_ms: 0.018326