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 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_clamp_log_mean_mul_neg_rsub_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)
    tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
    tmp13 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
    tmp14 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
    tmp25 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
    tmp26 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
    tmp37 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
    tmp38 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
    tmp2 = 1e-10
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp4 = tl_math.log(tmp3)
    tmp5 = tmp0 * tmp4
    tmp6 = 1.0
    tmp7 = tmp6 - tmp0
    tmp8 = tmp6 - tmp1
    tmp9 = triton_helpers.maximum(tmp8, tmp2)
    tmp10 = tl_math.log(tmp9)
    tmp11 = tmp7 * tmp10
    tmp12 = tmp5 + tmp11
    tmp15 = triton_helpers.maximum(tmp14, tmp2)
    tmp16 = tl_math.log(tmp15)
    tmp17 = tmp13 * tmp16
    tmp18 = tmp6 - tmp13
    tmp19 = tmp6 - tmp14
    tmp20 = triton_helpers.maximum(tmp19, tmp2)
    tmp21 = tl_math.log(tmp20)
    tmp22 = tmp18 * tmp21
    tmp23 = tmp17 + tmp22
    tmp24 = tmp12 + tmp23
    tmp27 = triton_helpers.maximum(tmp26, tmp2)
    tmp28 = tl_math.log(tmp27)
    tmp29 = tmp25 * tmp28
    tmp30 = tmp6 - tmp25
    tmp31 = tmp6 - tmp26
    tmp32 = triton_helpers.maximum(tmp31, tmp2)
    tmp33 = tl_math.log(tmp32)
    tmp34 = tmp30 * tmp33
    tmp35 = tmp29 + tmp34
    tmp36 = tmp24 + tmp35
    tmp39 = triton_helpers.maximum(tmp38, tmp2)
    tmp40 = tl_math.log(tmp39)
    tmp41 = tmp37 * tmp40
    tmp42 = tmp6 - tmp37
    tmp43 = tmp6 - tmp38
    tmp44 = triton_helpers.maximum(tmp43, tmp2)
    tmp45 = tl_math.log(tmp44)
    tmp46 = tmp42 * tmp45
    tmp47 = tmp41 + tmp46
    tmp48 = tmp36 + tmp47
    tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK])
    tmp51 = tl.sum(tmp49, 1)[:, None]
    tmp52 = 64.0
    tmp53 = tmp51 / tmp52
    tmp54 = -tmp53
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp54, 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_clamp_log_mean_mul_neg_rsub_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 BCELossNew(nn.Module):

    def __init__(self):
        super(self.__class__, 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.015211