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
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_div_log_sigmoid_forward_mean_mul_neg_rsub_sub_sum_0(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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
    tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp44 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp47 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp49 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp67 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp70 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp72 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp90 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp1 = -tmp0
    tmp3 = 0.0
    tmp4 = triton_helpers.minimum(tmp3, tmp2)
    tmp5 = tl_math.abs(tmp2)
    tmp6 = -tmp5
    tmp7 = tl_math.exp(tmp6)
    tmp8 = libdevice.log1p(tmp7)
    tmp9 = tmp4 - tmp8
    tmp10 = tmp1 * tmp9
    tmp11 = -tmp2
    tmp12 = triton_helpers.minimum(tmp3, tmp11)
    tmp13 = tl_math.abs(tmp11)
    tmp14 = -tmp13
    tmp15 = tl_math.exp(tmp14)
    tmp16 = libdevice.log1p(tmp15)
    tmp17 = tmp12 - tmp16
    tmp18 = 1.0
    tmp19 = tmp18 - tmp0
    tmp20 = tmp17 * tmp19
    tmp21 = tmp10 - tmp20
    tmp23 = tmp21 * tmp22
    tmp25 = -tmp24
    tmp27 = triton_helpers.minimum(tmp3, tmp26)
    tmp28 = tl_math.abs(tmp26)
    tmp29 = -tmp28
    tmp30 = tl_math.exp(tmp29)
    tmp31 = libdevice.log1p(tmp30)
    tmp32 = tmp27 - tmp31
    tmp33 = tmp25 * tmp32
    tmp34 = -tmp26
    tmp35 = triton_helpers.minimum(tmp3, tmp34)
    tmp36 = tl_math.abs(tmp34)
    tmp37 = -tmp36
    tmp38 = tl_math.exp(tmp37)
    tmp39 = libdevice.log1p(tmp38)
    tmp40 = tmp35 - tmp39
    tmp41 = tmp18 - tmp24
    tmp42 = tmp40 * tmp41
    tmp43 = tmp33 - tmp42
    tmp45 = tmp43 * tmp44
    tmp46 = tmp23 + tmp45
    tmp48 = -tmp47
    tmp50 = triton_helpers.minimum(tmp3, tmp49)
    tmp51 = tl_math.abs(tmp49)
    tmp52 = -tmp51
    tmp53 = tl_math.exp(tmp52)
    tmp54 = libdevice.log1p(tmp53)
    tmp55 = tmp50 - tmp54
    tmp56 = tmp48 * tmp55
    tmp57 = -tmp49
    tmp58 = triton_helpers.minimum(tmp3, tmp57)
    tmp59 = tl_math.abs(tmp57)
    tmp60 = -tmp59
    tmp61 = tl_math.exp(tmp60)
    tmp62 = libdevice.log1p(tmp61)
    tmp63 = tmp58 - tmp62
    tmp64 = tmp18 - tmp47
    tmp65 = tmp63 * tmp64
    tmp66 = tmp56 - tmp65
    tmp68 = tmp66 * tmp67
    tmp69 = tmp46 + tmp68
    tmp71 = -tmp70
    tmp73 = triton_helpers.minimum(tmp3, tmp72)
    tmp74 = tl_math.abs(tmp72)
    tmp75 = -tmp74
    tmp76 = tl_math.exp(tmp75)
    tmp77 = libdevice.log1p(tmp76)
    tmp78 = tmp73 - tmp77
    tmp79 = tmp71 * tmp78
    tmp80 = -tmp72
    tmp81 = triton_helpers.minimum(tmp3, tmp80)
    tmp82 = tl_math.abs(tmp80)
    tmp83 = -tmp82
    tmp84 = tl_math.exp(tmp83)
    tmp85 = libdevice.log1p(tmp84)
    tmp86 = tmp81 - tmp85
    tmp87 = tmp18 - tmp70
    tmp88 = tmp86 * tmp87
    tmp89 = tmp79 - tmp88
    tmp91 = tmp89 * tmp90
    tmp92 = tmp69 + tmp91
    tmp93 = 0.25
    tmp94 = tmp92 * tmp93
    tmp95 = tl.broadcast_to(tmp94, [XBLOCK, RBLOCK])
    tmp97 = tl.sum(tmp95, 1)[:, None]
    tmp98 = 64.0
    tmp99 = tmp97 / tmp98
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp99, None)


def call(args):
    arg0_1, arg1_1, arg2_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))
    assert_size_stride(arg2_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_div_log_sigmoid_forward_mean_mul_neg_rsub_sub_sum_0[
            grid(1)](buf2, arg1_1, arg0_1, arg2_1, 1, 64, XBLOCK=1,
            num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del arg2_1
    return buf2,


class WeightedBCELossNew(torch.nn.Module):

    def __init__(self, neg_scale=-1, bce_sum=False):
        super(WeightedBCELossNew, self).__init__()
        self.log_sigmoid = torch.nn.LogSigmoid()
        self.neg_scale = neg_scale
        self.bce_sum = bce_sum

    def forward(self, input_0, input_1, input_2):
        arg0_1 = input_0
        arg1_1 = input_1
        arg2_1 = input_2
        output = call([arg0_1, arg1_1, arg2_1])
        return output[0]


Measured latency_ms: 0.016142