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, math as tl_math
from torch.nn.modules.loss import _Loss
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_exp_log_mean_mul_pow_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 % 16
    r1 = rindex // 16
    tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
    tmp4 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
    tmp13 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
    tmp17 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
    tmp25 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
    tmp29 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
    tmp37 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
    tmp41 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
    tmp1 = tl_math.exp(tmp0)
    tmp2 = libdevice.sqrt(tmp1)
    tmp3 = tmp2 * tmp2
    tmp5 = tmp4 * tmp4
    tmp6 = tmp3 + tmp5
    tmp7 = 1.0
    tmp8 = tmp6 - tmp7
    tmp9 = tl_math.log(tmp3)
    tmp10 = tmp8 - tmp9
    tmp11 = 0.5
    tmp12 = tmp10 * tmp11
    tmp14 = tl_math.exp(tmp13)
    tmp15 = libdevice.sqrt(tmp14)
    tmp16 = tmp15 * tmp15
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp20 = tmp19 - tmp7
    tmp21 = tl_math.log(tmp16)
    tmp22 = tmp20 - tmp21
    tmp23 = tmp22 * tmp11
    tmp24 = tmp12 + tmp23
    tmp26 = tl_math.exp(tmp25)
    tmp27 = libdevice.sqrt(tmp26)
    tmp28 = tmp27 * tmp27
    tmp30 = tmp29 * tmp29
    tmp31 = tmp28 + tmp30
    tmp32 = tmp31 - tmp7
    tmp33 = tl_math.log(tmp28)
    tmp34 = tmp32 - tmp33
    tmp35 = tmp34 * tmp11
    tmp36 = tmp24 + tmp35
    tmp38 = tl_math.exp(tmp37)
    tmp39 = libdevice.sqrt(tmp38)
    tmp40 = tmp39 * tmp39
    tmp42 = tmp41 * tmp41
    tmp43 = tmp40 + tmp42
    tmp44 = tmp43 - tmp7
    tmp45 = tl_math.log(tmp40)
    tmp46 = tmp44 - tmp45
    tmp47 = tmp46 * tmp11
    tmp48 = tmp36 + tmp47
    tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK])
    tmp51 = tl.sum(tmp49, 1)[:, None]
    tmp52 = 64.0
    tmp53 = tmp51 / tmp52
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 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)
        buf1 = empty_strided_cuda((), (), torch.float32)
        buf2 = buf1
        del buf1
        get_raw_stream(0)
        triton_per_fused_add_div_exp_log_mean_mul_pow_sub_sum_0[grid(1)](buf2,
            arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf2,


class NormalKLLossNew(_Loss):

    def __init__(self, reduction='mean'):
        super(NormalKLLossNew, self).__init__()
        assert reduction in ['none', 'sum', 'mean']
        self.reduction = reduction

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