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.hub
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_sub_xlogy_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)
    tmp9 = tl.load(in_ptr1 + r0, None)
    tmp1 = libdevice.isnan(tmp0).to(tl.int1)
    tmp2 = 0.0
    tmp3 = tmp0 == tmp2
    tmp4 = tl_math.log(tmp0)
    tmp5 = tmp0 * tmp4
    tmp6 = tl.where(tmp3, tmp2, tmp5)
    tmp7 = float('nan')
    tmp8 = tl.where(tmp1, tmp7, tmp6)
    tmp10 = tl.sigmoid(tmp9)
    tmp11 = 1e-07
    tmp12 = triton_helpers.maximum(tmp10, tmp11)
    tmp13 = 1.0
    tmp14 = triton_helpers.minimum(tmp12, tmp13)
    tmp15 = tl_math.log(tmp14)
    tmp16 = tmp0 * tmp15
    tmp17 = tmp8 - tmp16
    tmp18 = tl.broadcast_to(tmp17, [RBLOCK])
    tmp20 = triton_helpers.promote_to_tensor(tl.sum(tmp18, 0))
    tmp21 = libdevice.isnan(tmp10).to(tl.int1)
    tmp22 = tmp10 == tmp2
    tmp23 = tl_math.log(tmp10)
    tmp24 = tmp10 * tmp23
    tmp25 = tl.where(tmp22, tmp2, tmp24)
    tmp26 = tl.where(tmp21, tmp7, tmp25)
    tmp27 = 0.0001
    tmp28 = triton_helpers.maximum(tmp0, tmp27)
    tmp29 = triton_helpers.minimum(tmp28, tmp13)
    tmp30 = tl_math.log(tmp29)
    tmp31 = tmp10 * tmp30
    tmp32 = tmp26 - tmp31
    tmp33 = tl.broadcast_to(tmp32, [RBLOCK])
    tmp35 = triton_helpers.promote_to_tensor(tl.sum(tmp33, 0))
    tmp36 = 256.0
    tmp37 = tmp20 / tmp36
    tmp38 = 0.1
    tmp39 = tmp37 * tmp38
    tmp40 = tmp35 / tmp36
    tmp41 = tmp40 * tmp38
    tmp42 = tmp39 + tmp41
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp42, 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)
        buf2 = buf0
        del buf0
        get_raw_stream(0)
        triton_per_fused_add_clamp_log_mean_mul_sub_xlogy_0[grid(1)](buf2,
            arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf2,


class SymmetricBCELossNew(nn.Module):

    def __init__(self, alpha=0.1, beta=0.1):
        super().__init__()
        self.alpha = alpha
        self.beta = beta

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