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
from torch import optim as optim
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_clamp_div_eq_log_mean_mul_neg_ones_like_pow_rsub_sub_sum_where_zeros_like_0(
    in_out_ptr0, in_ptr0, in_ptr1, 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)
    tmp3 = tl.load(in_ptr1 + r0, None)
    tmp1 = 1.0
    tmp2 = tmp0 == tmp1
    tmp4 = 1e-07
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp6 = tl.where(tmp2, tmp5, tmp1)
    tmp7 = tmp1 - tmp6
    tmp8 = 1.1
    tmp9 = libdevice.pow(tmp7, tmp8)
    tmp10 = 0.48
    tmp11 = tmp9 * tmp10
    tmp12 = tl_math.log(tmp6)
    tmp13 = tmp11 * tmp12
    tmp14 = tl.broadcast_to(tmp13, [RBLOCK])
    tmp16 = triton_helpers.promote_to_tensor(tl.sum(tmp14, 0))
    tmp17 = 0.0
    tmp18 = tmp0 == tmp17
    tmp19 = tl.where(tmp18, tmp5, tmp17)
    tmp20 = libdevice.pow(tmp19, tmp8)
    tmp21 = 0.52
    tmp22 = tmp20 * tmp21
    tmp23 = tmp1 - tmp19
    tmp24 = tl_math.log(tmp23)
    tmp25 = tmp22 * tmp24
    tmp26 = tl.broadcast_to(tmp25, [RBLOCK])
    tmp28 = triton_helpers.promote_to_tensor(tl.sum(tmp26, 0))
    tmp29 = tmp0 * tmp3
    tmp30 = tl.broadcast_to(tmp29, [RBLOCK])
    tmp32 = triton_helpers.promote_to_tensor(tl.sum(tmp30, 0))
    tmp33 = tmp0 * tmp0
    tmp34 = tl.broadcast_to(tmp33, [RBLOCK])
    tmp36 = triton_helpers.promote_to_tensor(tl.sum(tmp34, 0))
    tmp37 = tmp3 * tmp3
    tmp38 = tl.broadcast_to(tmp37, [RBLOCK])
    tmp40 = triton_helpers.promote_to_tensor(tl.sum(tmp38, 0))
    tmp41 = 256.0
    tmp42 = tmp16 / tmp41
    tmp43 = -tmp42
    tmp44 = tmp28 / tmp41
    tmp45 = tmp43 - tmp44
    tmp46 = 2.0
    tmp47 = tmp32 * tmp46
    tmp48 = tmp47 + tmp1
    tmp49 = tmp36 + tmp40
    tmp50 = tmp49 + tmp1
    tmp51 = tmp48 / tmp50
    tmp52 = tl_math.log(tmp51)
    tmp53 = tmp45 - tmp52
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp53, 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)
        buf5 = buf0
        del buf0
        get_raw_stream(0)
        triton_per_fused_add_clamp_div_eq_log_mean_mul_neg_ones_like_pow_rsub_sub_sum_where_zeros_like_0[
            grid(1)](buf5, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf5,


class EMLLossNew(nn.Module):

    def __init__(self):
        super(EMLLossNew, self).__init__()

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