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_div_dot_exp_minimum_mul_reciprocal_sub_sum_0(in_ptr0,
    in_ptr1, out_ptr4, out_ptr5, out_ptr6, out_ptr7, 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 + (12 + r0), None)
    tmp1 = tl.load(in_ptr1 + (12 + r0), None)
    tmp3 = tl.load(in_ptr1 + 3)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp5 = tl.load(in_ptr1 + 7)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tmp8 = tl.load(in_ptr1 + 11)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.load(in_ptr1 + 15)
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
    tmp29 = tl.load(in_ptr0 + (8 + r0), None)
    tmp30 = tl.load(in_ptr1 + (8 + r0), None)
    tmp32 = tl.load(in_ptr1 + 2)
    tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK])
    tmp34 = tl.load(in_ptr1 + 6)
    tmp35 = tl.broadcast_to(tmp34, [XBLOCK, RBLOCK])
    tmp37 = tl.load(in_ptr1 + 10)
    tmp38 = tl.broadcast_to(tmp37, [XBLOCK, RBLOCK])
    tmp40 = tl.load(in_ptr1 + 14)
    tmp41 = tl.broadcast_to(tmp40, [XBLOCK, RBLOCK])
    tmp54 = tl.load(in_ptr0 + (4 + r0), None)
    tmp55 = tl.load(in_ptr1 + (4 + r0), None)
    tmp57 = tl.load(in_ptr1 + 1)
    tmp58 = tl.broadcast_to(tmp57, [XBLOCK, RBLOCK])
    tmp59 = tl.load(in_ptr1 + 5)
    tmp60 = tl.broadcast_to(tmp59, [XBLOCK, RBLOCK])
    tmp62 = tl.load(in_ptr1 + 9)
    tmp63 = tl.broadcast_to(tmp62, [XBLOCK, RBLOCK])
    tmp65 = tl.load(in_ptr1 + 13)
    tmp66 = tl.broadcast_to(tmp65, [XBLOCK, RBLOCK])
    tmp79 = tl.load(in_ptr0 + r0, None)
    tmp80 = tl.load(in_ptr1 + r0, None)
    tmp82 = tl.load(in_ptr1 + 0)
    tmp83 = tl.broadcast_to(tmp82, [XBLOCK, RBLOCK])
    tmp84 = tl.load(in_ptr1 + 4)
    tmp85 = tl.broadcast_to(tmp84, [XBLOCK, RBLOCK])
    tmp87 = tl.load(in_ptr1 + 8)
    tmp88 = tl.broadcast_to(tmp87, [XBLOCK, RBLOCK])
    tmp90 = tl.load(in_ptr1 + 12)
    tmp91 = tl.broadcast_to(tmp90, [XBLOCK, RBLOCK])
    tmp104 = tl.load(in_ptr0 + 0)
    tmp105 = tl.broadcast_to(tmp104, [XBLOCK, RBLOCK])
    tmp106 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
    tmp108 = tl.load(in_ptr0 + 1)
    tmp109 = tl.broadcast_to(tmp108, [XBLOCK, RBLOCK])
    tmp110 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp113 = tl.load(in_ptr0 + 2)
    tmp114 = tl.broadcast_to(tmp113, [XBLOCK, RBLOCK])
    tmp115 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp118 = tl.load(in_ptr0 + 3)
    tmp119 = tl.broadcast_to(tmp118, [XBLOCK, RBLOCK])
    tmp120 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last'
        )
    tmp124 = tl.load(in_ptr0 + 4)
    tmp125 = tl.broadcast_to(tmp124, [XBLOCK, RBLOCK])
    tmp127 = tl.load(in_ptr0 + 5)
    tmp128 = tl.broadcast_to(tmp127, [XBLOCK, RBLOCK])
    tmp131 = tl.load(in_ptr0 + 6)
    tmp132 = tl.broadcast_to(tmp131, [XBLOCK, RBLOCK])
    tmp135 = tl.load(in_ptr0 + 7)
    tmp136 = tl.broadcast_to(tmp135, [XBLOCK, RBLOCK])
    tmp140 = tl.load(in_ptr0 + 8)
    tmp141 = tl.broadcast_to(tmp140, [XBLOCK, RBLOCK])
    tmp143 = tl.load(in_ptr0 + 9)
    tmp144 = tl.broadcast_to(tmp143, [XBLOCK, RBLOCK])
    tmp147 = tl.load(in_ptr0 + 10)
    tmp148 = tl.broadcast_to(tmp147, [XBLOCK, RBLOCK])
    tmp151 = tl.load(in_ptr0 + 11)
    tmp152 = tl.broadcast_to(tmp151, [XBLOCK, RBLOCK])
    tmp156 = tl.load(in_ptr0 + 12)
    tmp157 = tl.broadcast_to(tmp156, [XBLOCK, RBLOCK])
    tmp159 = tl.load(in_ptr0 + 13)
    tmp160 = tl.broadcast_to(tmp159, [XBLOCK, RBLOCK])
    tmp163 = tl.load(in_ptr0 + 14)
    tmp164 = tl.broadcast_to(tmp163, [XBLOCK, RBLOCK])
    tmp167 = tl.load(in_ptr0 + 15)
    tmp168 = tl.broadcast_to(tmp167, [XBLOCK, RBLOCK])
    tmp2 = triton_helpers.minimum(tmp0, tmp1)
    tmp7 = triton_helpers.maximum(tmp4, tmp6)
    tmp10 = triton_helpers.maximum(tmp7, tmp9)
    tmp13 = triton_helpers.maximum(tmp10, tmp12)
    tmp14 = 0.55
    tmp15 = tmp13 * tmp14
    tmp16 = tmp1 - tmp15
    tmp17 = -100.0
    tmp18 = tmp16 * tmp17
    tmp19 = tl_math.exp(tmp18)
    tmp20 = 1.0
    tmp21 = tmp19 + tmp20
    tmp22 = tl.full([1, 1], 1, tl.int32)
    tmp23 = tmp22 / tmp21
    tmp24 = tmp23 * tmp20
    tmp25 = tmp2 * tmp24
    tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
    tmp28 = tl.sum(tmp26, 1)[:, None]
    tmp31 = triton_helpers.minimum(tmp29, tmp30)
    tmp36 = triton_helpers.maximum(tmp33, tmp35)
    tmp39 = triton_helpers.maximum(tmp36, tmp38)
    tmp42 = triton_helpers.maximum(tmp39, tmp41)
    tmp43 = tmp42 * tmp14
    tmp44 = tmp30 - tmp43
    tmp45 = tmp44 * tmp17
    tmp46 = tl_math.exp(tmp45)
    tmp47 = tmp46 + tmp20
    tmp48 = tmp22 / tmp47
    tmp49 = tmp48 * tmp20
    tmp50 = tmp31 * tmp49
    tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK])
    tmp53 = tl.sum(tmp51, 1)[:, None]
    tmp56 = triton_helpers.minimum(tmp54, tmp55)
    tmp61 = triton_helpers.maximum(tmp58, tmp60)
    tmp64 = triton_helpers.maximum(tmp61, tmp63)
    tmp67 = triton_helpers.maximum(tmp64, tmp66)
    tmp68 = tmp67 * tmp14
    tmp69 = tmp55 - tmp68
    tmp70 = tmp69 * tmp17
    tmp71 = tl_math.exp(tmp70)
    tmp72 = tmp71 + tmp20
    tmp73 = tmp22 / tmp72
    tmp74 = tmp73 * tmp20
    tmp75 = tmp56 * tmp74
    tmp76 = tl.broadcast_to(tmp75, [XBLOCK, RBLOCK])
    tmp78 = tl.sum(tmp76, 1)[:, None]
    tmp81 = triton_helpers.minimum(tmp79, tmp80)
    tmp86 = triton_helpers.maximum(tmp83, tmp85)
    tmp89 = triton_helpers.maximum(tmp86, tmp88)
    tmp92 = triton_helpers.maximum(tmp89, tmp91)
    tmp93 = tmp92 * tmp14
    tmp94 = tmp80 - tmp93
    tmp95 = tmp94 * tmp17
    tmp96 = tl_math.exp(tmp95)
    tmp97 = tmp96 + tmp20
    tmp98 = tmp22 / tmp97
    tmp99 = tmp98 * tmp20
    tmp100 = tmp81 * tmp99
    tmp101 = tl.broadcast_to(tmp100, [XBLOCK, RBLOCK])
    tmp103 = tl.sum(tmp101, 1)[:, None]
    tmp107 = tmp105 + tmp106
    tmp111 = tmp109 + tmp110
    tmp112 = tmp107 + tmp111
    tmp116 = tmp114 + tmp115
    tmp117 = tmp112 + tmp116
    tmp121 = tmp119 + tmp120
    tmp122 = tmp117 + tmp121
    tmp123 = tmp103 / tmp122
    tmp126 = tmp125 + tmp106
    tmp129 = tmp128 + tmp110
    tmp130 = tmp126 + tmp129
    tmp133 = tmp132 + tmp115
    tmp134 = tmp130 + tmp133
    tmp137 = tmp136 + tmp120
    tmp138 = tmp134 + tmp137
    tmp139 = tmp78 / tmp138
    tmp142 = tmp141 + tmp106
    tmp145 = tmp144 + tmp110
    tmp146 = tmp142 + tmp145
    tmp149 = tmp148 + tmp115
    tmp150 = tmp146 + tmp149
    tmp153 = tmp152 + tmp120
    tmp154 = tmp150 + tmp153
    tmp155 = tmp53 / tmp154
    tmp158 = tmp157 + tmp106
    tmp161 = tmp160 + tmp110
    tmp162 = tmp158 + tmp161
    tmp165 = tmp164 + tmp115
    tmp166 = tmp162 + tmp165
    tmp169 = tmp168 + tmp120
    tmp170 = tmp166 + tmp169
    tmp171 = tmp28 / tmp170
    tl.store(out_ptr4 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp123, None)
    tl.store(out_ptr5 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp139, None)
    tl.store(out_ptr6 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp155, None)
    tl.store(out_ptr7 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp171, None)


@triton.jit
def triton_poi_fused_stack_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = 2.0
    tmp7 = tmp5 * tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tmp11 = tl.full([1], 8, tl.int64)
    tmp12 = tmp0 < tmp11
    tmp13 = tmp10 & tmp12
    tmp14 = tl.load(in_ptr1 + (-4 + x0), tmp13 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tmp14 * tmp6
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp13, tmp15, tmp16)
    tmp18 = tmp0 >= tmp11
    tmp19 = tl.full([1], 12, tl.int64)
    tmp20 = tmp0 < tmp19
    tmp21 = tmp18 & tmp20
    tmp22 = tl.load(in_ptr2 + (-8 + x0), tmp21 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp23 = tmp22 * tmp6
    tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
    tmp25 = tl.where(tmp21, tmp23, tmp24)
    tmp26 = tmp0 >= tmp19
    tl.full([1], 16, tl.int64)
    tmp29 = tl.load(in_ptr3 + (-12 + x0), tmp26 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp30 = tmp29 * tmp6
    tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype)
    tmp32 = tl.where(tmp26, tmp30, tmp31)
    tmp33 = tl.where(tmp21, tmp25, tmp32)
    tmp34 = tl.where(tmp13, tmp17, tmp33)
    tmp35 = tl.where(tmp4, tmp9, tmp34)
    tl.store(out_ptr0 + x0, tmp35, xmask)


@triton.jit
def triton_per_fused_index_put_lift_fresh_mean_2(in_out_ptr0, in_ptr0,
    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)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = libdevice.isnan(tmp0).to(tl.int1)
    tmp2 = 0.0
    tmp3 = tl.where(tmp1, tmp2, tmp0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.sum(tmp4, 1)[:, None]
    tmp7 = 16.0
    tmp8 = tmp6 / tmp7
    tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp3, None)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, 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, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf1 = empty_strided_cuda((4,), (1,), torch.float32)
        buf3 = empty_strided_cuda((4,), (1,), torch.float32)
        buf5 = empty_strided_cuda((4,), (1,), torch.float32)
        buf7 = empty_strided_cuda((4,), (1,), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_div_dot_exp_minimum_mul_reciprocal_sub_sum_0[grid
            (1)](arg0_1, arg1_1, buf1, buf3, buf5, buf7, 1, 4, XBLOCK=1,
            num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        buf8 = empty_strided_cuda((16,), (1,), torch.float32)
        triton_poi_fused_stack_1[grid(16)](buf1, buf3, buf5, buf7, buf8, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        del buf1
        del buf3
        del buf5
        del buf7
        buf11 = empty_strided_cuda((), (), torch.float32)
        buf12 = buf11
        del buf11
        triton_per_fused_index_put_lift_fresh_mean_2[grid(1)](buf12, buf8,
            buf8, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del buf8
    return buf12,


class MaskLossNew(nn.Module):

    def __init__(self, size_average=None, reduce=None, reduction='mean'):
        super(MaskLossNew, self).__init__()
        self.reduction = reduction

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