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_add_clamp_exp_log_log_sigmoid_forward_mean_mul_neg_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)
    tmp2 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
    tmp29 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
    tmp31 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
    tmp56 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
    tmp58 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
    tmp83 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
    tmp85 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
    tmp1 = -tmp0
    tmp3 = 2.0
    tmp4 = tmp2 * tmp3
    tmp5 = 1.0
    tmp6 = tmp4 - tmp5
    tmp7 = tmp1 * tmp6
    tmp8 = 0.0
    tmp9 = triton_helpers.minimum(tmp8, tmp7)
    tmp10 = tl_math.abs(tmp7)
    tmp11 = -tmp10
    tmp12 = tl_math.exp(tmp11)
    tmp13 = libdevice.log1p(tmp12)
    tmp14 = tmp9 - tmp13
    tmp15 = tmp14 * tmp3
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp0 * tmp2
    tmp18 = tmp0 - tmp17
    tmp19 = triton_helpers.maximum(tmp1, tmp8)
    tmp20 = tmp18 + tmp19
    tmp21 = -tmp19
    tmp22 = tl_math.exp(tmp21)
    tmp23 = tmp1 - tmp19
    tmp24 = tl_math.exp(tmp23)
    tmp25 = tmp22 + tmp24
    tmp26 = tl_math.log(tmp25)
    tmp27 = tmp20 + tmp26
    tmp28 = tmp16 * tmp27
    tmp30 = -tmp29
    tmp32 = tmp31 * tmp3
    tmp33 = tmp32 - tmp5
    tmp34 = tmp30 * tmp33
    tmp35 = triton_helpers.minimum(tmp8, tmp34)
    tmp36 = tl_math.abs(tmp34)
    tmp37 = -tmp36
    tmp38 = tl_math.exp(tmp37)
    tmp39 = libdevice.log1p(tmp38)
    tmp40 = tmp35 - tmp39
    tmp41 = tmp40 * tmp3
    tmp42 = tl_math.exp(tmp41)
    tmp43 = tmp29 * tmp31
    tmp44 = tmp29 - tmp43
    tmp45 = triton_helpers.maximum(tmp30, tmp8)
    tmp46 = tmp44 + tmp45
    tmp47 = -tmp45
    tmp48 = tl_math.exp(tmp47)
    tmp49 = tmp30 - tmp45
    tmp50 = tl_math.exp(tmp49)
    tmp51 = tmp48 + tmp50
    tmp52 = tl_math.log(tmp51)
    tmp53 = tmp46 + tmp52
    tmp54 = tmp42 * tmp53
    tmp55 = tmp28 + tmp54
    tmp57 = -tmp56
    tmp59 = tmp58 * tmp3
    tmp60 = tmp59 - tmp5
    tmp61 = tmp57 * tmp60
    tmp62 = triton_helpers.minimum(tmp8, tmp61)
    tmp63 = tl_math.abs(tmp61)
    tmp64 = -tmp63
    tmp65 = tl_math.exp(tmp64)
    tmp66 = libdevice.log1p(tmp65)
    tmp67 = tmp62 - tmp66
    tmp68 = tmp67 * tmp3
    tmp69 = tl_math.exp(tmp68)
    tmp70 = tmp56 * tmp58
    tmp71 = tmp56 - tmp70
    tmp72 = triton_helpers.maximum(tmp57, tmp8)
    tmp73 = tmp71 + tmp72
    tmp74 = -tmp72
    tmp75 = tl_math.exp(tmp74)
    tmp76 = tmp57 - tmp72
    tmp77 = tl_math.exp(tmp76)
    tmp78 = tmp75 + tmp77
    tmp79 = tl_math.log(tmp78)
    tmp80 = tmp73 + tmp79
    tmp81 = tmp69 * tmp80
    tmp82 = tmp55 + tmp81
    tmp84 = -tmp83
    tmp86 = tmp85 * tmp3
    tmp87 = tmp86 - tmp5
    tmp88 = tmp84 * tmp87
    tmp89 = triton_helpers.minimum(tmp8, tmp88)
    tmp90 = tl_math.abs(tmp88)
    tmp91 = -tmp90
    tmp92 = tl_math.exp(tmp91)
    tmp93 = libdevice.log1p(tmp92)
    tmp94 = tmp89 - tmp93
    tmp95 = tmp94 * tmp3
    tmp96 = tl_math.exp(tmp95)
    tmp97 = tmp83 * tmp85
    tmp98 = tmp83 - tmp97
    tmp99 = triton_helpers.maximum(tmp84, tmp8)
    tmp100 = tmp98 + tmp99
    tmp101 = -tmp99
    tmp102 = tl_math.exp(tmp101)
    tmp103 = tmp84 - tmp99
    tmp104 = tl_math.exp(tmp103)
    tmp105 = tmp102 + tmp104
    tmp106 = tl_math.log(tmp105)
    tmp107 = tmp100 + tmp106
    tmp108 = tmp96 * tmp107
    tmp109 = tmp82 + tmp108
    tmp110 = tl.broadcast_to(tmp109, [XBLOCK, RBLOCK])
    tmp112 = tl.sum(tmp110, 1)[:, None]
    tmp113 = 64.0
    tmp114 = tmp112 / tmp113
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp114, 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_exp_log_log_sigmoid_forward_mean_mul_neg_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 FocalLossNew(torch.nn.Module):

    def __init__(self, gamma=2):
        super().__init__()
        self.gamma = gamma

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