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 math as tl_math
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_per_fused_add_log_mean_mul_neg_pow_rsub_0(in_ptr0, in_ptr1,
    out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    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 + (x0 + 16 * r1), xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * r1), xmask, other=0.0)
    tmp2 = 1.0
    tmp3 = tmp2 - tmp1
    tmp4 = tmp2 - tmp0
    tmp5 = 1e-06
    tmp6 = tmp4 + tmp5
    tmp7 = tl_math.log(tmp6)
    tmp8 = tmp3 * tmp7
    tmp9 = tmp2 * tmp8
    tmp10 = -tmp9
    tmp11 = tmp0 + tmp5
    tmp12 = tl_math.log(tmp11)
    tmp13 = tmp1 * tmp12
    tmp14 = tmp2 * tmp13
    tmp15 = -tmp14
    tmp16 = tmp10 + tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp20, xmask)


@triton.jit
def triton_poi_fused_abs_add_div_mul_rsub_sub_sum_1(in_ptr0, in_ptr1,
    out_ptr0, out_ptr1, 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)
    tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp4 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
    tmp7 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp8 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
    tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp12 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tmp15 = 1e-06
    tmp16 = tmp14 + tmp15
    tmp17 = tl_math.abs(tmp0)
    tmp18 = tl_math.abs(tmp1)
    tmp19 = tmp17 + tmp18
    tmp20 = tl_math.abs(tmp3)
    tmp21 = tl_math.abs(tmp4)
    tmp22 = tmp20 + tmp21
    tmp23 = tmp19 + tmp22
    tmp24 = tl_math.abs(tmp7)
    tmp25 = tl_math.abs(tmp8)
    tmp26 = tmp24 + tmp25
    tmp27 = tmp23 + tmp26
    tmp28 = tl_math.abs(tmp11)
    tmp29 = tl_math.abs(tmp12)
    tmp30 = tmp28 + tmp29
    tmp31 = tmp27 + tmp30
    tmp32 = tmp31 + tmp15
    tmp33 = tmp16 / tmp32
    tmp34 = 1.0
    tmp35 = tmp34 - tmp0
    tmp36 = tmp34 - tmp1
    tmp37 = tmp35 * tmp36
    tmp38 = tmp34 - tmp3
    tmp39 = tmp34 - tmp4
    tmp40 = tmp38 * tmp39
    tmp41 = tmp37 + tmp40
    tmp42 = tmp34 - tmp7
    tmp43 = tmp34 - tmp8
    tmp44 = tmp42 * tmp43
    tmp45 = tmp41 + tmp44
    tmp46 = tmp34 - tmp11
    tmp47 = tmp34 - tmp12
    tmp48 = tmp46 * tmp47
    tmp49 = tmp45 + tmp48
    tmp50 = tmp49 + tmp15
    tmp51 = 2.0
    tmp52 = tmp51 - tmp17
    tmp53 = tmp52 - tmp18
    tmp54 = tmp51 - tmp20
    tmp55 = tmp54 - tmp21
    tmp56 = tmp53 + tmp55
    tmp57 = tmp51 - tmp24
    tmp58 = tmp57 - tmp25
    tmp59 = tmp56 + tmp58
    tmp60 = tmp51 - tmp28
    tmp61 = tmp60 - tmp29
    tmp62 = tmp59 + tmp61
    tmp63 = tmp62 + tmp15
    tmp64 = tmp50 / tmp63
    tl.store(out_ptr0 + x2, tmp33, xmask)
    tl.store(out_ptr1 + x2, tmp64, xmask)


@triton.jit
def triton_per_fused_add_log_mean_mul_neg_pow_rsub_sub_sum_2(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    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
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp6 = tl.load(in_ptr1 + r0, None)
    tmp9 = tl.load(in_ptr2 + r0, None)
    tmp11 = tl.load(in_ptr1 + (16 + r0), None)
    tmp13 = tl.load(in_ptr2 + (16 + r0), None)
    tmp16 = tl.load(in_ptr1 + (32 + r0), None)
    tmp18 = tl.load(in_ptr2 + (32 + r0), None)
    tmp21 = tl.load(in_ptr1 + (48 + r0), None)
    tmp23 = tl.load(in_ptr2 + (48 + r0), None)
    tmp1 = 16.0
    tmp2 = tmp0 / tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.sum(tmp3, 1)[:, None]
    tmp7 = 1.5
    tmp8 = tmp7 - tmp6
    tmp10 = tmp8 - tmp9
    tmp12 = tmp7 - tmp11
    tmp14 = tmp12 - tmp13
    tmp15 = tmp10 + tmp14
    tmp17 = tmp7 - tmp16
    tmp19 = tmp17 - tmp18
    tmp20 = tmp15 + tmp19
    tmp22 = tmp7 - tmp21
    tmp24 = tmp22 - tmp23
    tmp25 = tmp20 + tmp24
    tmp26 = 4.0
    tmp27 = tmp25 / tmp26
    tmp28 = tl.broadcast_to(tmp27, [XBLOCK, RBLOCK])
    tmp30 = tl.sum(tmp28, 1)[:, None]
    tmp31 = 1.0
    tmp32 = tmp30 * tmp31
    tmp33 = tmp5 + tmp32
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp33, 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((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_log_mean_mul_neg_pow_rsub_0[grid(16)](arg0_1,
            arg1_1, buf0, 16, 16, XBLOCK=1, num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_abs_add_div_mul_rsub_sub_sum_1[grid(64)](arg0_1,
            arg1_1, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        buf1 = empty_strided_cuda((), (), torch.float32)
        buf5 = buf1
        del buf1
        triton_per_fused_add_log_mean_mul_neg_pow_rsub_sub_sum_2[grid(1)](buf5,
            buf0, buf2, buf3, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del buf0
        del buf2
        del buf3
    return buf5,


class EstimationLossNew(nn.Module):

    def __init__(self):
        super(EstimationLossNew, self).__init__()
        self.gamma = 0
        self.alpha = 0

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