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
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_clamp_min_div_linalg_vector_norm_mul_0(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr1 + x3, xmask)
    tmp17 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr1 + (4 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr1 + (8 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr1 + (12 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-08
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = tmp0 / tmp14
    tmp18 = tmp17 * tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp26 = tmp25 * tmp25
    tmp27 = tmp24 + tmp26
    tmp28 = libdevice.sqrt(tmp27)
    tmp29 = triton_helpers.maximum(tmp28, tmp13)
    tmp30 = tmp16 / tmp29
    tmp31 = tmp15 * tmp30
    tl.store(out_ptr0 + x3, tmp31, xmask)


@triton.jit
def triton_per_fused_div_exp_sum_1(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 % 4
    r1 = rindex // 4
    tmp0 = tl.load(in_ptr0 + (r0 + 16 * r1), None)
    tmp1 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), None)
    tmp3 = tl.load(in_ptr0 + (8 + r0 + 16 * r1), None)
    tmp5 = tl.load(in_ptr0 + (12 + r0 + 16 * r1), None)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 0.25
    tmp8 = tmp6 * tmp7
    tmp9 = tl_math.exp(tmp8)
    tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
    tmp12 = tl.sum(tmp10, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp12, None)


@triton.jit
def triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_2(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + (64 + x3), xmask)
    tmp1 = tl.load(in_ptr0 + (64 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (68 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (72 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (76 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr1 + (64 + x3), xmask)
    tmp17 = tl.load(in_ptr1 + (64 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr1 + (68 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr1 + (72 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr1 + (76 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-08
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = tmp0 / tmp14
    tmp18 = tmp17 * tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp26 = tmp25 * tmp25
    tmp27 = tmp24 + tmp26
    tmp28 = libdevice.sqrt(tmp27)
    tmp29 = triton_helpers.maximum(tmp28, tmp13)
    tmp30 = tmp16 / tmp29
    tmp31 = tmp15 * tmp30
    tl.store(out_ptr0 + x3, tmp31, xmask)


@triton.jit
def triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_3(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + (128 + x3), xmask)
    tmp1 = tl.load(in_ptr0 + (128 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (132 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (136 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (140 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr1 + (128 + x3), xmask)
    tmp17 = tl.load(in_ptr1 + (128 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr1 + (132 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr1 + (136 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr1 + (140 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-08
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = tmp0 / tmp14
    tmp18 = tmp17 * tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp26 = tmp25 * tmp25
    tmp27 = tmp24 + tmp26
    tmp28 = libdevice.sqrt(tmp27)
    tmp29 = triton_helpers.maximum(tmp28, tmp13)
    tmp30 = tmp16 / tmp29
    tmp31 = tmp15 * tmp30
    tl.store(out_ptr0 + x3, tmp31, xmask)


@triton.jit
def triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_4(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + (192 + x3), xmask)
    tmp1 = tl.load(in_ptr0 + (192 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr0 + (196 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (200 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr0 + (204 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr1 + (192 + x3), xmask)
    tmp17 = tl.load(in_ptr1 + (192 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr1 + (196 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr1 + (200 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp25 = tl.load(in_ptr1 + (204 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = 1e-08
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp15 = tmp0 / tmp14
    tmp18 = tmp17 * tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp26 = tmp25 * tmp25
    tmp27 = tmp24 + tmp26
    tmp28 = libdevice.sqrt(tmp27)
    tmp29 = triton_helpers.maximum(tmp28, tmp13)
    tmp30 = tmp16 / tmp29
    tmp31 = tmp15 * tmp30
    tl.store(out_ptr0 + x3, tmp31, xmask)


@triton.jit
def triton_poi_fused_add_div_log_neg_5(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + (4 + x0), xmask)
    tmp3 = tl.load(in_ptr0 + (8 + x0), xmask)
    tmp5 = tl.load(in_ptr0 + (12 + x0), xmask)
    tmp10 = tl.load(in_ptr1 + 0)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp17 = tl.load(in_ptr2 + x0, xmask)
    tmp18 = tl.load(in_ptr2 + (4 + x0), xmask)
    tmp20 = tl.load(in_ptr2 + (8 + x0), xmask)
    tmp22 = tl.load(in_ptr2 + (12 + x0), xmask)
    tmp26 = tl.load(in_ptr3 + 0)
    tmp27 = tl.broadcast_to(tmp26, [XBLOCK])
    tmp32 = tl.load(in_ptr4 + x0, xmask)
    tmp33 = tl.load(in_ptr4 + (4 + x0), xmask)
    tmp35 = tl.load(in_ptr4 + (8 + x0), xmask)
    tmp37 = tl.load(in_ptr4 + (12 + x0), xmask)
    tmp41 = tl.load(in_ptr5 + 0)
    tmp42 = tl.broadcast_to(tmp41, [XBLOCK])
    tmp47 = tl.load(in_ptr6 + x0, xmask)
    tmp48 = tl.load(in_ptr6 + (4 + x0), xmask)
    tmp50 = tl.load(in_ptr6 + (8 + x0), xmask)
    tmp52 = tl.load(in_ptr6 + (12 + x0), xmask)
    tmp56 = tl.load(in_ptr7 + 0)
    tmp57 = tl.broadcast_to(tmp56, [XBLOCK])
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 0.25
    tmp8 = tmp6 * tmp7
    tmp9 = tl_math.exp(tmp8)
    tmp12 = tmp9 / tmp11
    tmp13 = tl_math.log(tmp12)
    tmp14 = -tmp13
    tmp15 = 0.0
    tmp16 = tmp14 + tmp15
    tmp19 = tmp17 + tmp18
    tmp21 = tmp19 + tmp20
    tmp23 = tmp21 + tmp22
    tmp24 = tmp23 * tmp7
    tmp25 = tl_math.exp(tmp24)
    tmp28 = tmp25 / tmp27
    tmp29 = tl_math.log(tmp28)
    tmp30 = -tmp29
    tmp31 = tmp16 + tmp30
    tmp34 = tmp32 + tmp33
    tmp36 = tmp34 + tmp35
    tmp38 = tmp36 + tmp37
    tmp39 = tmp38 * tmp7
    tmp40 = tl_math.exp(tmp39)
    tmp43 = tmp40 / tmp42
    tmp44 = tl_math.log(tmp43)
    tmp45 = -tmp44
    tmp46 = tmp31 + tmp45
    tmp49 = tmp47 + tmp48
    tmp51 = tmp49 + tmp50
    tmp53 = tmp51 + tmp52
    tmp54 = tmp53 * tmp7
    tmp55 = tl_math.exp(tmp54)
    tmp58 = tmp55 / tmp57
    tmp59 = tl_math.log(tmp58)
    tmp60 = -tmp59
    tmp61 = tmp46 + tmp60
    tmp62 = tmp61 * tmp7
    tl.store(in_out_ptr0 + x0, tmp62, 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)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_0[grid(64)](
            arg0_1, arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_div_exp_sum_1[grid(1)](buf0, buf1, 1, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_2[grid(64)](
            arg0_1, arg1_1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_div_exp_sum_1[grid(1)](buf2, buf3, 1, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_3[grid(64)](
            arg0_1, arg1_1, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_div_exp_sum_1[grid(1)](buf5, buf6, 1, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_4[grid(64)](
            arg0_1, arg1_1, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        buf8 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_div_exp_sum_1[grid(1)](buf7, buf8, 1, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf4 = empty_strided_cuda((4,), (1,), torch.float32)
        buf9 = buf4
        del buf4
        buf10 = buf9
        del buf9
        triton_poi_fused_add_div_log_neg_5[grid(4)](buf10, buf0, buf1, buf2,
            buf3, buf5, buf6, buf7, buf8, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        del buf0
        del buf1
        del buf2
        del buf3
        del buf5
        del buf6
        del buf7
        del buf8
    return buf10,


class InfoNCE_loss_vectorizedNew(nn.Module):
    """
        SimCLR loss: https://github.com/google-research/simclr // https://github.com/sthalles/SimCLR
    """

    def __init__(self, temperature):
        super(InfoNCE_loss_vectorizedNew, self).__init__()
        self.temperature = temperature
        self.cos = nn.CosineSimilarity(dim=1)

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