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
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_per_fused_add_clamp_min_mean_mul_neg_sub_0(in_ptr0, in_ptr1,
    out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 16
    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)
    r1 = rindex // 4
    r2 = rindex
    tmp0 = tl.load(in_ptr0 + r1, None, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + r2, None)
    tmp2 = tmp0 - tmp1
    tmp3 = -1.0
    tmp4 = tmp3 * tmp2
    tmp5 = 0.0
    tmp6 = tmp4 + tmp5
    tmp7 = triton_helpers.maximum(tmp6, tmp5)
    tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK])
    tmp10 = tl.sum(tmp8, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp10, None)


@triton.jit
def triton_per_fused_add_clamp_min_mean_mul_neg_sub_1(in_ptr0, out_ptr0,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    rnumel = 12
    RBLOCK: tl.constexpr = 16
    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, :]
    rmask = rindex < rnumel
    r0 = rindex % 3
    r1 = rindex // 3
    tmp0 = tl.load(in_ptr0 + (r0 + 4 * r1), rmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + (1 + r0 + 4 * r1), rmask, other=0.0)
    tmp2 = tmp0 - tmp1
    tmp3 = -1.0
    tmp4 = tmp3 * tmp2
    tmp5 = 0.01
    tmp6 = tmp4 + tmp5
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.where(rmask, tmp9, 0)
    tmp12 = tl.sum(tmp11, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp12, None)


@triton.jit
def triton_per_fused_add_clamp_min_mean_mul_neg_sub_2(in_ptr0, out_ptr0,
    xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 8
    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 % 2
    r1 = rindex // 2
    tmp0 = tl.load(in_ptr0 + (r0 + 4 * r1), None)
    tmp1 = tl.load(in_ptr0 + (2 + r0 + 4 * r1), None)
    tmp2 = tmp0 - tmp1
    tmp3 = -1.0
    tmp4 = tmp3 * tmp2
    tmp5 = 0.02
    tmp6 = tmp4 + tmp5
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.sum(tmp9, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp11, None)


@triton.jit
def triton_per_fused_add_clamp_min_mean_mul_neg_sub_3(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    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')
    tmp1 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp12 = tl.load(in_out_ptr0 + 0)
    tmp13 = tl.broadcast_to(tmp12, [XBLOCK, 1])
    tmp16 = tl.load(in_ptr1 + 0)
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, 1])
    tmp21 = tl.load(in_ptr2 + 0)
    tmp22 = tl.broadcast_to(tmp21, [XBLOCK, 1])
    tmp2 = tmp0 - tmp1
    tmp3 = -1.0
    tmp4 = tmp3 * tmp2
    tmp5 = 0.03
    tmp6 = tmp4 + tmp5
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.sum(tmp9, 1)[:, None]
    tmp14 = 16.0
    tmp15 = tmp13 / tmp14
    tmp18 = 12.0
    tmp19 = tmp17 / tmp18
    tmp20 = tmp15 + tmp19
    tmp23 = 8.0
    tmp24 = tmp22 / tmp23
    tmp25 = tmp20 + tmp24
    tmp26 = 4.0
    tmp27 = tmp11 / tmp26
    tmp28 = tmp25 + tmp27
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp28, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4), (4, 1))
    assert_size_stride(arg1_1, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_clamp_min_mean_mul_neg_sub_0[grid(1)](arg1_1,
            arg0_1, buf0, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del arg1_1
        buf1 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_add_clamp_min_mean_mul_neg_sub_1[grid(1)](arg0_1,
            buf1, 1, 12, XBLOCK=1, num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_add_clamp_min_mean_mul_neg_sub_2[grid(1)](arg0_1,
            buf2, 1, 8, XBLOCK=1, num_warps=2, num_stages=1)
        buf4 = buf0
        del buf0
        triton_per_fused_add_clamp_min_mean_mul_neg_sub_3[grid(1)](buf4,
            arg0_1, buf1, buf2, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
        del arg0_1
        del buf1
        del buf2
    return buf4,


class RankingLossNew(nn.Module):

    def __init__(self, margin_lambda: 'float'=0.01) ->None:
        super(RankingLossNew, self).__init__()
        self.margin_lambda = margin_lambda

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