# AOT ID: ['0_forward']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_8/inductor_cache/uk/cukg7ikh2js3f5lgwuhamf4rclidekibnzzkn54t6vyfir6hcsao.py
# Topologically Sorted Source Nodes: [u, i, j, mul, x_ui, mul_1, x_uj, x_uij, log_sigmoid, log_prob, norm, pow_1, sum_4, norm_1, pow_2, sum_5, add, norm_2, pow_3, sum_6, add_1, regularization, neg, add_2], Original ATen: [aten.index, aten.mul, aten.sum, aten.sub, aten.log_sigmoid_forward, aten.linalg_vector_norm, aten.pow, aten.add, aten.neg]
# Source node to ATen node mapping:
#   add => add
#   add_1 => add_1
#   add_2 => add_2
#   i => index_1
#   j => index_2
#   log_prob => sum_3
#   log_sigmoid => abs_1, exp, full_default, log1p, minimum, neg, sub_1
#   mul => mul
#   mul_1 => mul_1
#   neg => neg_1
#   norm => pow_1, pow_2, sum_4
#   norm_1 => pow_4, pow_5, sum_6
#   norm_2 => pow_7, pow_8, sum_8
#   pow_1 => pow_3
#   pow_2 => pow_6
#   pow_3 => pow_9
#   regularization => mul_2
#   sum_4 => sum_5
#   sum_5 => sum_7
#   sum_6 => sum_9
#   u => index
#   x_ui => sum_1
#   x_uij => sub
#   x_uj => sum_2
# Graph fragment:
#   %index : [num_users=3] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_1, [%primals_2]), kwargs = {})
#   %index_1 : [num_users=2] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_3, [%primals_4]), kwargs = {})
#   %index_2 : [num_users=2] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_3, [%primals_5]), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index, %index_1), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [1]), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index, %index_2), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_1, [1]), kwargs = {})
#   %sub : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sum_1, %sum_2), kwargs = {})
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %minimum : [num_users=1] = call_function[target=torch.ops.aten.minimum.default](args = (%full_default, %sub), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%sub,), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%abs_1,), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%neg,), kwargs = {})
#   %log1p : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp,), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%minimum, %log1p), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%sub_1,), kwargs = {})
#   %pow_1 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%index, 2), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%pow_1, [1]), kwargs = {})
#   %pow_2 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sum_4, 0.5), kwargs = {})
#   %pow_3 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%pow_2, 2), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%pow_3,), kwargs = {})
#   %pow_4 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%index_1, 2), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%pow_4, [1]), kwargs = {})
#   %pow_5 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sum_6, 0.5), kwargs = {})
#   %pow_6 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%pow_5, 2), kwargs = {})
#   %sum_7 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%pow_6,), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_5, %sum_7), kwargs = {})
#   %pow_7 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%index_2, 2), kwargs = {})
#   %sum_8 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%pow_7, [1]), kwargs = {})
#   %pow_8 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sum_8, 0.5), kwargs = {})
#   %pow_9 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%pow_8, 2), kwargs = {})
#   %sum_9 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%pow_9,), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add, %sum_9), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_1, 4), kwargs = {})
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%sum_3,), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%neg_1, %mul_2), kwargs = {})
triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0 = async_compile.triton('triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[1, 4],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i64', 2: '*fp32', 3: '*i64', 4: '*fp32', 5: '*i64', 6: 'i32', 7: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {6: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=(6,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 4, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 4
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + (r0), None)
    tmp7 = tl.load(in_ptr2 + (r0), None)
    tmp26 = tl.load(in_ptr4 + (r0), None)
    tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4), "index out of bounds: 0 <= tmp4 < 4")
    tmp6 = tl.load(in_ptr1 + (4*tmp4), None, eviction_policy='evict_last')
    tmp8 = tmp7 + tmp1
    tmp9 = tmp7 < 0
    tmp10 = tl.where(tmp9, tmp8, tmp7)
    tl.device_assert((0 <= tmp10) & (tmp10 < 4), "index out of bounds: 0 <= tmp10 < 4")
    tmp12 = tl.load(in_ptr3 + (4*tmp10), None, eviction_policy='evict_last')
    tmp13 = tmp6 * tmp12
    tmp14 = tl.load(in_ptr1 + (1 + (4*tmp4)), None, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr3 + (1 + (4*tmp10)), None, eviction_policy='evict_last')
    tmp16 = tmp14 * tmp15
    tmp17 = tmp13 + tmp16
    tmp18 = tl.load(in_ptr1 + (2 + (4*tmp4)), None, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr3 + (2 + (4*tmp10)), None, eviction_policy='evict_last')
    tmp20 = tmp18 * tmp19
    tmp21 = tmp17 + tmp20
    tmp22 = tl.load(in_ptr1 + (3 + (4*tmp4)), None, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr3 + (3 + (4*tmp10)), None, eviction_policy='evict_last')
    tmp24 = tmp22 * tmp23
    tmp25 = tmp21 + tmp24
    tmp27 = tmp26 + tmp1
    tmp28 = tmp26 < 0
    tmp29 = tl.where(tmp28, tmp27, tmp26)
    tl.device_assert((0 <= tmp29) & (tmp29 < 4), "index out of bounds: 0 <= tmp29 < 4")
    tmp31 = tl.load(in_ptr3 + (4*tmp29), None, eviction_policy='evict_last')
    tmp32 = tmp6 * tmp31
    tmp33 = tl.load(in_ptr3 + (1 + (4*tmp29)), None, eviction_policy='evict_last')
    tmp34 = tmp14 * tmp33
    tmp35 = tmp32 + tmp34
    tmp36 = tl.load(in_ptr3 + (2 + (4*tmp29)), None, eviction_policy='evict_last')
    tmp37 = tmp18 * tmp36
    tmp38 = tmp35 + tmp37
    tmp39 = tl.load(in_ptr3 + (3 + (4*tmp29)), None, eviction_policy='evict_last')
    tmp40 = tmp22 * tmp39
    tmp41 = tmp38 + tmp40
    tmp42 = tmp6 * tmp6
    tmp43 = tmp14 * tmp14
    tmp44 = tmp42 + tmp43
    tmp45 = tmp18 * tmp18
    tmp46 = tmp44 + tmp45
    tmp47 = tmp22 * tmp22
    tmp48 = tmp46 + tmp47
    tmp49 = libdevice.sqrt(tmp48)
    tmp50 = tmp49 * tmp49
    tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK])
    tmp53 = tl.sum(tmp51, 1)[:, None]
    tmp54 = tmp12 * tmp12
    tmp55 = tmp15 * tmp15
    tmp56 = tmp54 + tmp55
    tmp57 = tmp19 * tmp19
    tmp58 = tmp56 + tmp57
    tmp59 = tmp23 * tmp23
    tmp60 = tmp58 + tmp59
    tmp61 = libdevice.sqrt(tmp60)
    tmp62 = tmp61 * tmp61
    tmp63 = tl.broadcast_to(tmp62, [XBLOCK, RBLOCK])
    tmp65 = tl.sum(tmp63, 1)[:, None]
    tmp66 = tmp31 * tmp31
    tmp67 = tmp33 * tmp33
    tmp68 = tmp66 + tmp67
    tmp69 = tmp36 * tmp36
    tmp70 = tmp68 + tmp69
    tmp71 = tmp39 * tmp39
    tmp72 = tmp70 + tmp71
    tmp73 = libdevice.sqrt(tmp72)
    tmp74 = tmp73 * tmp73
    tmp75 = tl.broadcast_to(tmp74, [XBLOCK, RBLOCK])
    tmp77 = tl.sum(tmp75, 1)[:, None]
    tmp78 = tmp25 - tmp41
    tmp79 = 0.0
    tmp80 = triton_helpers.minimum(tmp79, tmp78)
    tmp81 = tl_math.abs(tmp78)
    tmp82 = -tmp81
    tmp83 = tl_math.exp(tmp82)
    tmp84 = libdevice.log1p(tmp83)
    tmp85 = tmp80 - tmp84
    tmp86 = tl.broadcast_to(tmp85, [XBLOCK, RBLOCK])
    tmp88 = tl.sum(tmp86, 1)[:, None]
    tmp89 = -tmp88
    tmp90 = tmp53 + tmp65
    tmp91 = tmp90 + tmp77
    tmp92 = 4.0
    tmp93 = tmp91 * tmp92
    tmp94 = tmp89 + tmp93
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp94, None)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4, ), (1, ))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, ), (1, ))
    assert_size_stride(primals_5, (4, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf2 = empty_strided_cuda((), (), torch.float32)
        buf6 = buf2; del buf2  # reuse
        # Topologically Sorted Source Nodes: [u, i, j, mul, x_ui, mul_1, x_uj, x_uij, log_sigmoid, log_prob, norm, pow_1, sum_4, norm_1, pow_2, sum_5, add, norm_2, pow_3, sum_6, add_1, regularization, neg, add_2], Original ATen: [aten.index, aten.mul, aten.sum, aten.sub, aten.log_sigmoid_forward, aten.linalg_vector_norm, aten.pow, aten.add, aten.neg]
        stream0 = get_raw_stream(0)
        triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0.run(buf6, primals_2, primals_1, primals_4, primals_3, primals_5, 1, 4, grid=grid(1), stream=stream0)
    return (buf6, primals_1, primals_2, primals_3, primals_4, primals_5, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.int64)
    primals_3 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.int64)
    primals_5 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.int64)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import torch
import torch.nn as nn
import torch.nn.functional as F


class BPR(nn.Module):

    def __init__(self, user_size, item_size, dim, weight_decay):
        super().__init__()
        self.W = nn.Parameter(torch.empty(user_size, dim))
        self.H = nn.Parameter(torch.empty(item_size, dim))
        nn.init.xavier_normal_(self.W.data)
        nn.init.xavier_normal_(self.H.data)
        self.weight_decay = weight_decay

    def forward(self, u, i, j):
        """Return loss value.
        
        Args:
            u(torch.LongTensor): tensor stored user indexes. [batch_size,]
            i(torch.LongTensor): tensor stored item indexes which is prefered by user. [batch_size,]
            j(torch.LongTensor): tensor stored item indexes which is not prefered by user. [batch_size,]
        
        Returns:
            torch.FloatTensor
        """
        u = self.W[u, :]
        i = self.H[i, :]
        j = self.H[j, :]
        x_ui = torch.mul(u, i).sum(dim=1)
        x_uj = torch.mul(u, j).sum(dim=1)
        x_uij = x_ui - x_uj
        log_prob = F.logsigmoid(x_uij).sum()
        regularization = self.weight_decay * (u.norm(dim=1).pow(2).sum() +
            i.norm(dim=1).pow(2).sum() + j.norm(dim=1).pow(2).sum())
        return -log_prob + regularization

    def recommend(self, u):
        """Return recommended item list given users.

        Args:
            u(torch.LongTensor): tensor stored user indexes. [batch_size,]

        Returns:
            pred(torch.LongTensor): recommended item list sorted by preference. [batch_size, item_size]
        """
        u = self.W[u, :]
        x_ui = torch.mm(u, self.H.t())
        pred = torch.argsort(x_ui, dim=1)
        return pred


def get_inputs():
    return [torch.ones([4], dtype=torch.int64), torch.ones([4], dtype=torch
        .int64), torch.ones([4], dtype=torch.int64)]


def get_init_inputs():
    return [[], {'user_size': 4, 'item_size': 4, 'dim': 4, 'weight_decay': 4}]

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_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 + r0, None)
    tmp7 = tl.load(in_ptr2 + r0, None)
    tmp26 = tl.load(in_ptr4 + r0, None)
    tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tl.device_assert((0 <= tmp4) & (tmp4 < 4),
        'index out of bounds: 0 <= tmp4 < 4')
    tmp6 = tl.load(in_ptr1 + 4 * tmp4, None, eviction_policy='evict_last')
    tmp8 = tmp7 + tmp1
    tmp9 = tmp7 < 0
    tmp10 = tl.where(tmp9, tmp8, tmp7)
    tl.device_assert((0 <= tmp10) & (tmp10 < 4),
        'index out of bounds: 0 <= tmp10 < 4')
    tmp12 = tl.load(in_ptr3 + 4 * tmp10, None, eviction_policy='evict_last')
    tmp13 = tmp6 * tmp12
    tmp14 = tl.load(in_ptr1 + (1 + 4 * tmp4), None, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr3 + (1 + 4 * tmp10), None, eviction_policy=
        'evict_last')
    tmp16 = tmp14 * tmp15
    tmp17 = tmp13 + tmp16
    tmp18 = tl.load(in_ptr1 + (2 + 4 * tmp4), None, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr3 + (2 + 4 * tmp10), None, eviction_policy=
        'evict_last')
    tmp20 = tmp18 * tmp19
    tmp21 = tmp17 + tmp20
    tmp22 = tl.load(in_ptr1 + (3 + 4 * tmp4), None, eviction_policy=
        'evict_last')
    tmp23 = tl.load(in_ptr3 + (3 + 4 * tmp10), None, eviction_policy=
        'evict_last')
    tmp24 = tmp22 * tmp23
    tmp25 = tmp21 + tmp24
    tmp27 = tmp26 + tmp1
    tmp28 = tmp26 < 0
    tmp29 = tl.where(tmp28, tmp27, tmp26)
    tl.device_assert((0 <= tmp29) & (tmp29 < 4),
        'index out of bounds: 0 <= tmp29 < 4')
    tmp31 = tl.load(in_ptr3 + 4 * tmp29, None, eviction_policy='evict_last')
    tmp32 = tmp6 * tmp31
    tmp33 = tl.load(in_ptr3 + (1 + 4 * tmp29), None, eviction_policy=
        'evict_last')
    tmp34 = tmp14 * tmp33
    tmp35 = tmp32 + tmp34
    tmp36 = tl.load(in_ptr3 + (2 + 4 * tmp29), None, eviction_policy=
        'evict_last')
    tmp37 = tmp18 * tmp36
    tmp38 = tmp35 + tmp37
    tmp39 = tl.load(in_ptr3 + (3 + 4 * tmp29), None, eviction_policy=
        'evict_last')
    tmp40 = tmp22 * tmp39
    tmp41 = tmp38 + tmp40
    tmp42 = tmp6 * tmp6
    tmp43 = tmp14 * tmp14
    tmp44 = tmp42 + tmp43
    tmp45 = tmp18 * tmp18
    tmp46 = tmp44 + tmp45
    tmp47 = tmp22 * tmp22
    tmp48 = tmp46 + tmp47
    tmp49 = libdevice.sqrt(tmp48)
    tmp50 = tmp49 * tmp49
    tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK])
    tmp53 = tl.sum(tmp51, 1)[:, None]
    tmp54 = tmp12 * tmp12
    tmp55 = tmp15 * tmp15
    tmp56 = tmp54 + tmp55
    tmp57 = tmp19 * tmp19
    tmp58 = tmp56 + tmp57
    tmp59 = tmp23 * tmp23
    tmp60 = tmp58 + tmp59
    tmp61 = libdevice.sqrt(tmp60)
    tmp62 = tmp61 * tmp61
    tmp63 = tl.broadcast_to(tmp62, [XBLOCK, RBLOCK])
    tmp65 = tl.sum(tmp63, 1)[:, None]
    tmp66 = tmp31 * tmp31
    tmp67 = tmp33 * tmp33
    tmp68 = tmp66 + tmp67
    tmp69 = tmp36 * tmp36
    tmp70 = tmp68 + tmp69
    tmp71 = tmp39 * tmp39
    tmp72 = tmp70 + tmp71
    tmp73 = libdevice.sqrt(tmp72)
    tmp74 = tmp73 * tmp73
    tmp75 = tl.broadcast_to(tmp74, [XBLOCK, RBLOCK])
    tmp77 = tl.sum(tmp75, 1)[:, None]
    tmp78 = tmp25 - tmp41
    tmp79 = 0.0
    tmp80 = triton_helpers.minimum(tmp79, tmp78)
    tmp81 = tl_math.abs(tmp78)
    tmp82 = -tmp81
    tmp83 = tl_math.exp(tmp82)
    tmp84 = libdevice.log1p(tmp83)
    tmp85 = tmp80 - tmp84
    tmp86 = tl.broadcast_to(tmp85, [XBLOCK, RBLOCK])
    tmp88 = tl.sum(tmp86, 1)[:, None]
    tmp89 = -tmp88
    tmp90 = tmp53 + tmp65
    tmp91 = tmp90 + tmp77
    tmp92 = 4.0
    tmp93 = tmp91 * tmp92
    tmp94 = tmp89 + tmp93
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp94, None)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf2 = empty_strided_cuda((), (), torch.float32)
        buf6 = buf2
        del buf2
        get_raw_stream(0)
        triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0[
            grid(1)](buf6, primals_2, primals_1, primals_4, primals_3,
            primals_5, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
    return buf6, primals_1, primals_2, primals_3, primals_4, primals_5


class BPRNew(nn.Module):

    def __init__(self, user_size, item_size, dim, weight_decay):
        super().__init__()
        self.W = nn.Parameter(torch.empty(user_size, dim))
        self.H = nn.Parameter(torch.empty(item_size, dim))
        nn.init.xavier_normal_(self.W.data)
        nn.init.xavier_normal_(self.H.data)
        self.weight_decay = weight_decay

    def recommend(self, u):
        """Return recommended item list given users.

        Args:
            u(torch.LongTensor): tensor stored user indexes. [batch_size,]

        Returns:
            pred(torch.LongTensor): recommended item list sorted by preference. [batch_size, item_size]
        """
        u = self.W[u, :]
        x_ui = torch.mm(u, self.H.t())
        pred = torch.argsort(x_ui, dim=1)
        return pred

    def forward(self, input_0, input_1, input_2):
        primals_1 = self.W
        primals_3 = self.H
        primals_2 = input_0
        primals_4 = input_1
        primals_5 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]
