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.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_per_fused_abs_mean_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    rnumel = 192
    RBLOCK: tl.constexpr = 256
    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 % 12
    r1 = rindex // 12
    tmp0 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (r0 + 16 * r1), rmask, other=0.0)
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(rmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp7, None)


@triton.jit
def triton_per_fused_abs_mean_sub_1(in_ptr0, in_ptr1, out_ptr0, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 64
    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 + (12 + r0 + 16 * r1), None)
    tmp1 = tl.load(in_ptr1 + (12 + r0 + 16 * r1), None)
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.sum(tmp4, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None)


@triton.jit
def triton_poi_fused_stack_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16
    x0 = xindex % 16
    x2 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 3, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 1, tl.int64)
    tmp6 = tmp0 < tmp5
    tmp7 = tmp6 & tmp4
    tmp8 = tl.load(in_ptr0 + (16 + x0), tmp7 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp9 = tl.load(in_ptr0 + x0, tmp7 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp10 = tmp8 - tmp9
    tmp11 = tl.full(tmp10.shape, 0.0, tmp10.dtype)
    tmp12 = tl.where(tmp7, tmp10, tmp11)
    tmp13 = tmp0 >= tmp5
    tmp14 = tl.full([1], 2, tl.int64)
    tmp15 = tmp0 < tmp14
    tmp16 = tmp13 & tmp15
    tmp17 = tmp16 & tmp4
    tmp18 = tl.load(in_ptr0 + (32 + x0), tmp17 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp19 = tl.load(in_ptr0 + (16 + x0), tmp17 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp20 = tmp18 - tmp19
    tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype)
    tmp22 = tl.where(tmp17, tmp20, tmp21)
    tmp23 = tmp0 >= tmp14
    tmp24 = tmp23 & tmp4
    tmp25 = tl.load(in_ptr0 + (48 + x0), tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp26 = tl.load(in_ptr0 + (32 + x0), tmp24 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp27 = tmp25 - tmp26
    tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
    tmp29 = tl.where(tmp24, tmp27, tmp28)
    tmp30 = tl.where(tmp16, tmp22, tmp29)
    tmp31 = tl.where(tmp6, tmp12, tmp30)
    tmp32 = tl.full(tmp31.shape, 0.0, tmp31.dtype)
    tmp33 = tl.where(tmp4, tmp31, tmp32)
    tmp34 = tmp0 >= tmp3
    tmp35 = tl.full([1], 6, tl.int64)
    tmp36 = tmp0 < tmp35
    tmp37 = tmp34 & tmp36
    tmp38 = -3 + x1
    tmp40 = tmp38 < tmp5
    tmp41 = tmp40 & tmp37
    tmp42 = tl.load(in_ptr0 + (80 + x0), tmp41 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp43 = tl.load(in_ptr0 + (64 + x0), tmp41 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp44 = tmp42 - tmp43
    tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype)
    tmp46 = tl.where(tmp41, tmp44, tmp45)
    tmp47 = tmp38 >= tmp5
    tmp48 = tmp38 < tmp14
    tmp49 = tmp47 & tmp48
    tmp50 = tmp49 & tmp37
    tmp51 = tl.load(in_ptr0 + (96 + x0), tmp50 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp52 = tl.load(in_ptr0 + (80 + x0), tmp50 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp53 = tmp51 - tmp52
    tmp54 = tl.full(tmp53.shape, 0.0, tmp53.dtype)
    tmp55 = tl.where(tmp50, tmp53, tmp54)
    tmp56 = tmp38 >= tmp14
    tmp58 = tmp56 & tmp37
    tmp59 = tl.load(in_ptr0 + (112 + x0), tmp58 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp60 = tl.load(in_ptr0 + (96 + x0), tmp58 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp61 = tmp59 - tmp60
    tmp62 = tl.full(tmp61.shape, 0.0, tmp61.dtype)
    tmp63 = tl.where(tmp58, tmp61, tmp62)
    tmp64 = tl.where(tmp49, tmp55, tmp63)
    tmp65 = tl.where(tmp40, tmp46, tmp64)
    tmp66 = tl.full(tmp65.shape, 0.0, tmp65.dtype)
    tmp67 = tl.where(tmp37, tmp65, tmp66)
    tmp68 = tmp0 >= tmp35
    tmp69 = tl.full([1], 9, tl.int64)
    tmp70 = tmp0 < tmp69
    tmp71 = tmp68 & tmp70
    tmp72 = -6 + x1
    tmp74 = tmp72 < tmp5
    tmp75 = tmp74 & tmp71
    tmp76 = tl.load(in_ptr0 + (144 + x0), tmp75 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp77 = tl.load(in_ptr0 + (128 + x0), tmp75 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp78 = tmp76 - tmp77
    tmp79 = tl.full(tmp78.shape, 0.0, tmp78.dtype)
    tmp80 = tl.where(tmp75, tmp78, tmp79)
    tmp81 = tmp72 >= tmp5
    tmp82 = tmp72 < tmp14
    tmp83 = tmp81 & tmp82
    tmp84 = tmp83 & tmp71
    tmp85 = tl.load(in_ptr0 + (160 + x0), tmp84 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp86 = tl.load(in_ptr0 + (144 + x0), tmp84 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp87 = tmp85 - tmp86
    tmp88 = tl.full(tmp87.shape, 0.0, tmp87.dtype)
    tmp89 = tl.where(tmp84, tmp87, tmp88)
    tmp90 = tmp72 >= tmp14
    tmp92 = tmp90 & tmp71
    tmp93 = tl.load(in_ptr0 + (176 + x0), tmp92 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp94 = tl.load(in_ptr0 + (160 + x0), tmp92 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp95 = tmp93 - tmp94
    tmp96 = tl.full(tmp95.shape, 0.0, tmp95.dtype)
    tmp97 = tl.where(tmp92, tmp95, tmp96)
    tmp98 = tl.where(tmp83, tmp89, tmp97)
    tmp99 = tl.where(tmp74, tmp80, tmp98)
    tmp100 = tl.full(tmp99.shape, 0.0, tmp99.dtype)
    tmp101 = tl.where(tmp71, tmp99, tmp100)
    tmp102 = tmp0 >= tmp69
    tl.full([1], 12, tl.int64)
    tmp105 = -9 + x1
    tmp107 = tmp105 < tmp5
    tmp108 = tmp107 & tmp102
    tmp109 = tl.load(in_ptr0 + (208 + x0), tmp108 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp110 = tl.load(in_ptr0 + (192 + x0), tmp108 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp111 = tmp109 - tmp110
    tmp112 = tl.full(tmp111.shape, 0.0, tmp111.dtype)
    tmp113 = tl.where(tmp108, tmp111, tmp112)
    tmp114 = tmp105 >= tmp5
    tmp115 = tmp105 < tmp14
    tmp116 = tmp114 & tmp115
    tmp117 = tmp116 & tmp102
    tmp118 = tl.load(in_ptr0 + (224 + x0), tmp117 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp119 = tl.load(in_ptr0 + (208 + x0), tmp117 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp120 = tmp118 - tmp119
    tmp121 = tl.full(tmp120.shape, 0.0, tmp120.dtype)
    tmp122 = tl.where(tmp117, tmp120, tmp121)
    tmp123 = tmp105 >= tmp14
    tmp125 = tmp123 & tmp102
    tmp126 = tl.load(in_ptr0 + (240 + x0), tmp125 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp127 = tl.load(in_ptr0 + (224 + x0), tmp125 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp128 = tmp126 - tmp127
    tmp129 = tl.full(tmp128.shape, 0.0, tmp128.dtype)
    tmp130 = tl.where(tmp125, tmp128, tmp129)
    tmp131 = tl.where(tmp116, tmp122, tmp130)
    tmp132 = tl.where(tmp107, tmp113, tmp131)
    tmp133 = tl.full(tmp132.shape, 0.0, tmp132.dtype)
    tmp134 = tl.where(tmp102, tmp132, tmp133)
    tmp135 = tl.where(tmp71, tmp101, tmp134)
    tmp136 = tl.where(tmp37, tmp67, tmp135)
    tmp137 = tl.where(tmp4, tmp33, tmp136)
    tl.store(out_ptr0 + x2, tmp137, xmask)


@triton.jit
def triton_per_fused_abs_mean_sub_3(in_ptr0, in_ptr1, out_ptr0, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    rnumel = 144
    RBLOCK: tl.constexpr = 256
    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 % 12
    r1 = rindex // 12
    tmp0 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (r0 + 16 * r1), rmask, other=0.0)
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(rmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp7, None)


@triton.jit
def triton_per_fused_abs_add_exp_mean_mul_neg_sub_4(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    rnumel = 48
    RBLOCK: tl.constexpr = 64
    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 % 4
    r1 = rindex // 4
    tmp0 = tl.load(in_ptr0 + (12 + r0 + 16 * r1), rmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (12 + r0 + 16 * r1), rmask, other=0.0)
    tmp8 = tl.load(in_ptr2 + 0)
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, 1])
    tmp12 = tl.load(in_out_ptr0 + 0)
    tmp13 = tl.broadcast_to(tmp12, [XBLOCK, 1])
    tmp18 = tl.load(in_ptr3 + 0)
    tmp19 = tl.broadcast_to(tmp18, [XBLOCK, 1])
    tmp22 = tl.load(in_ptr4 + 0)
    tmp23 = tl.broadcast_to(tmp22, [XBLOCK, 1])
    tmp29 = tl.load(in_ptr5 + 0)
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK, 1])
    tmp33 = tl.load(in_ptr6 + 0)
    tmp34 = tl.broadcast_to(tmp33, [XBLOCK, 1])
    tmp39 = tl.load(in_ptr7 + 0)
    tmp40 = tl.broadcast_to(tmp39, [XBLOCK, 1])
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.where(rmask, tmp4, 0)
    tmp7 = tl.sum(tmp6, 1)[:, None]
    tmp10 = -tmp9
    tmp11 = tl_math.exp(tmp10)
    tmp14 = 192.0
    tmp15 = tmp13 / tmp14
    tmp16 = tmp11 * tmp15
    tmp17 = tmp16 + tmp9
    tmp20 = -tmp19
    tmp21 = tl_math.exp(tmp20)
    tmp24 = 64.0
    tmp25 = tmp23 / tmp24
    tmp26 = tmp21 * tmp25
    tmp27 = tmp17 + tmp26
    tmp28 = tmp27 + tmp19
    tmp31 = -tmp30
    tmp32 = tl_math.exp(tmp31)
    tmp35 = 144.0
    tmp36 = tmp34 / tmp35
    tmp37 = tmp32 * tmp36
    tmp38 = tmp37 + tmp30
    tmp41 = -tmp40
    tmp42 = tl_math.exp(tmp41)
    tmp43 = 48.0
    tmp44 = tmp7 / tmp43
    tmp45 = tmp42 * tmp44
    tmp46 = tmp38 + tmp45
    tmp47 = tmp46 + tmp40
    tmp48 = tmp28 + tmp47
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp48, None)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (1,), (1,))
    assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg3_1, (1,), (1,))
    assert_size_stride(arg4_1, (1,), (1,))
    assert_size_stride(arg5_1, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        get_raw_stream(0)
        triton_per_fused_abs_mean_sub_0[grid(1)](arg0_1, arg2_1, buf0, 1, 
            192, XBLOCK=1, num_warps=2, num_stages=1)
        buf1 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mean_sub_1[grid(1)](arg0_1, arg2_1, buf1, 1, 
            64, XBLOCK=1, num_warps=2, num_stages=1)
        buf2 = empty_strided_cuda((12, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_stack_2[grid(192)](arg0_1, buf2, 192, XBLOCK=128,
            num_warps=4, num_stages=1)
        del arg0_1
        buf3 = empty_strided_cuda((12, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_stack_2[grid(192)](arg2_1, buf3, 192, XBLOCK=128,
            num_warps=4, num_stages=1)
        del arg2_1
        buf4 = empty_strided_cuda((), (), torch.float32)
        triton_per_fused_abs_mean_sub_3[grid(1)](buf2, buf3, buf4, 1, 144,
            XBLOCK=1, num_warps=2, num_stages=1)
        buf6 = reinterpret_tensor(buf0, (1,), (1,), 0)
        del buf0
        triton_per_fused_abs_add_exp_mean_mul_neg_sub_4[grid(1)](buf6, buf2,
            buf3, arg1_1, arg3_1, buf1, arg4_1, buf4, arg5_1, 1, 48, XBLOCK
            =1, num_warps=2, num_stages=1)
        del arg1_1
        del arg3_1
        del arg4_1
        del arg5_1
        del buf1
        del buf2
        del buf3
        del buf4
    return buf6,


def calc_vos_simple(poses):
    vos = []
    for p in poses:
        pvos = [(p[i + 1].unsqueeze(0) - p[i].unsqueeze(0)) for i in range(
            len(p) - 1)]
        vos.append(torch.cat(pvos, dim=0))
    vos = torch.stack(vos, dim=0)
    return vos


class AtLocPlusCriterionNew(nn.Module):

    def __init__(self, t_loss_fn=nn.L1Loss(), q_loss_fn=nn.L1Loss(), sax=
        0.0, saq=0.0, srx=0.0, srq=0.0, learn_beta=False, learn_gamma=False):
        super(AtLocPlusCriterionNew, self).__init__()
        self.t_loss_fn = t_loss_fn
        self.q_loss_fn = q_loss_fn
        self.sax = nn.Parameter(torch.Tensor([sax]), requires_grad=learn_beta)
        self.saq = nn.Parameter(torch.Tensor([saq]), requires_grad=learn_beta)
        self.srx = nn.Parameter(torch.Tensor([srx]), requires_grad=learn_gamma)
        self.srq = nn.Parameter(torch.Tensor([srq]), requires_grad=learn_gamma)

    def forward(self, input_0, input_1):
        arg1_1 = self.sax
        arg3_1 = self.saq
        arg4_1 = self.srx
        arg5_1 = self.srq
        arg0_1 = input_0
        arg2_1 = input_1
        output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1])
        return output[0]


Measured latency_ms: 0.08573