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
from typing import *
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_poi_fused_add_clamp_min_logsumexp_mul_rsub_softplus_sub_0(
    in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp10 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp17 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp46 = tl.load(in_ptr1 + x0, xmask)
    tmp53 = tl.load(in_ptr1 + (64 + x0), xmask)
    tmp60 = tl.load(in_ptr1 + (128 + x0), xmask)
    tmp67 = tl.load(in_ptr1 + (192 + x0), xmask)
    tmp1 = 5.0
    tmp2 = tmp1 - tmp0
    tmp3 = 0.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = -4.0
    tmp6 = tmp4 * tmp5
    tmp7 = -3.0
    tmp8 = tmp0 - tmp7
    tmp9 = tmp6 * tmp8
    tmp11 = tmp1 - tmp10
    tmp12 = triton_helpers.maximum(tmp11, tmp3)
    tmp13 = tmp12 * tmp5
    tmp14 = tmp10 - tmp7
    tmp15 = tmp13 * tmp14
    tmp16 = triton_helpers.maximum(tmp9, tmp15)
    tmp18 = tmp1 - tmp17
    tmp19 = triton_helpers.maximum(tmp18, tmp3)
    tmp20 = tmp19 * tmp5
    tmp21 = tmp17 - tmp7
    tmp22 = tmp20 * tmp21
    tmp23 = triton_helpers.maximum(tmp16, tmp22)
    tmp25 = tmp1 - tmp24
    tmp26 = triton_helpers.maximum(tmp25, tmp3)
    tmp27 = tmp26 * tmp5
    tmp28 = tmp24 - tmp7
    tmp29 = tmp27 * tmp28
    tmp30 = triton_helpers.maximum(tmp23, tmp29)
    tmp31 = tl_math.abs(tmp30)
    tmp32 = float('inf')
    tmp33 = tmp31 == tmp32
    tmp34 = tl.where(tmp33, tmp3, tmp30)
    tmp35 = tmp9 - tmp34
    tmp36 = tl_math.exp(tmp35)
    tmp37 = tmp15 - tmp34
    tmp38 = tl_math.exp(tmp37)
    tmp39 = tmp36 + tmp38
    tmp40 = tmp22 - tmp34
    tmp41 = tl_math.exp(tmp40)
    tmp42 = tmp39 + tmp41
    tmp43 = tmp29 - tmp34
    tmp44 = tl_math.exp(tmp43)
    tmp45 = tmp42 + tmp44
    tmp47 = 4.0
    tmp48 = tmp46 + tmp47
    tmp49 = triton_helpers.maximum(tmp48, tmp3)
    tmp50 = tmp49 * tmp47
    tmp51 = tmp46 - tmp47
    tmp52 = tmp50 * tmp51
    tmp54 = tmp53 + tmp47
    tmp55 = triton_helpers.maximum(tmp54, tmp3)
    tmp56 = tmp55 * tmp47
    tmp57 = tmp53 - tmp47
    tmp58 = tmp56 * tmp57
    tmp59 = triton_helpers.maximum(tmp52, tmp58)
    tmp61 = tmp60 + tmp47
    tmp62 = triton_helpers.maximum(tmp61, tmp3)
    tmp63 = tmp62 * tmp47
    tmp64 = tmp60 - tmp47
    tmp65 = tmp63 * tmp64
    tmp66 = triton_helpers.maximum(tmp59, tmp65)
    tmp68 = tmp67 + tmp47
    tmp69 = triton_helpers.maximum(tmp68, tmp3)
    tmp70 = tmp69 * tmp47
    tmp71 = tmp67 - tmp47
    tmp72 = tmp70 * tmp71
    tmp73 = triton_helpers.maximum(tmp66, tmp72)
    tmp74 = tl_math.abs(tmp73)
    tmp75 = tmp74 == tmp32
    tmp76 = tl.where(tmp75, tmp3, tmp73)
    tmp77 = tmp52 - tmp76
    tmp78 = tl_math.exp(tmp77)
    tmp79 = tmp58 - tmp76
    tmp80 = tl_math.exp(tmp79)
    tmp81 = tmp78 + tmp80
    tmp82 = tmp65 - tmp76
    tmp83 = tl_math.exp(tmp82)
    tmp84 = tmp81 + tmp83
    tmp85 = tmp72 - tmp76
    tmp86 = tl_math.exp(tmp85)
    tmp87 = tmp84 + tmp86
    tmp88 = tl_math.log(tmp45)
    tmp89 = tmp88 + tmp34
    tmp90 = tl_math.log(tmp87)
    tmp91 = tmp90 + tmp76
    tmp92 = tmp89 + tmp91
    tmp93 = 20.0
    tmp94 = tmp92 > tmp93
    tmp95 = tl_math.exp(tmp92)
    tmp96 = libdevice.log1p(tmp95)
    tmp97 = tl.where(tmp94, tmp92, tmp96)
    tl.store(in_out_ptr0 + x0, tmp97, xmask)


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((4, 4, 4), (16, 4, 1), torch.float32)
        buf5 = buf1
        del buf1
        get_raw_stream(0)
        triton_poi_fused_add_clamp_min_logsumexp_mul_rsub_softplus_sub_0[grid
            (64)](buf5, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        del arg0_1
        del arg1_1
    return buf5,


class CircleLossNew(nn.Module):

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

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