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
import torch.nn as nn
import torch.nn.functional as F
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_linalg_vector_norm_mean_pow_view_0(in_ptr0, out_ptr0,
    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 + (64 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (68 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr0 + (72 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr0 + (76 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr0 + (65 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr0 + (69 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr0 + (73 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr0 + (77 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp28 = tl.load(in_ptr0 + (66 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp30 = tl.load(in_ptr0 + (70 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp33 = tl.load(in_ptr0 + (74 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp36 = tl.load(in_ptr0 + (78 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp42 = tl.load(in_ptr0 + (67 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp44 = tl.load(in_ptr0 + (71 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp47 = tl.load(in_ptr0 + (75 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp50 = tl.load(in_ptr0 + (79 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = 4.0
    tmp12 = tmp10 / tmp11
    tmp13 = tmp12 * tmp12
    tmp15 = tmp14 * tmp14
    tmp17 = tmp16 * tmp16
    tmp18 = tmp15 + tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp25 = tmp24 / tmp11
    tmp26 = tmp25 * tmp25
    tmp27 = tmp13 + tmp26
    tmp29 = tmp28 * tmp28
    tmp31 = tmp30 * tmp30
    tmp32 = tmp29 + tmp31
    tmp34 = tmp33 * tmp33
    tmp35 = tmp32 + tmp34
    tmp37 = tmp36 * tmp36
    tmp38 = tmp35 + tmp37
    tmp39 = tmp38 / tmp11
    tmp40 = tmp39 * tmp39
    tmp41 = tmp27 + tmp40
    tmp43 = tmp42 * tmp42
    tmp45 = tmp44 * tmp44
    tmp46 = tmp43 + tmp45
    tmp48 = tmp47 * tmp47
    tmp49 = tmp46 + tmp48
    tmp51 = tmp50 * tmp50
    tmp52 = tmp49 + tmp51
    tmp53 = tmp52 / tmp11
    tmp54 = tmp53 * tmp53
    tmp55 = tmp41 + tmp54
    tl.store(out_ptr0 + x0, tmp55, xmask)


@triton.jit
def triton_poi_fused_linalg_vector_norm_mean_pow_view_1(in_ptr0, out_ptr0,
    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 + (128 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (132 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr0 + (136 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr0 + (140 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr0 + (129 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr0 + (133 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr0 + (137 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr0 + (141 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp28 = tl.load(in_ptr0 + (130 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp30 = tl.load(in_ptr0 + (134 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp33 = tl.load(in_ptr0 + (138 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp36 = tl.load(in_ptr0 + (142 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp42 = tl.load(in_ptr0 + (131 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp44 = tl.load(in_ptr0 + (135 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp47 = tl.load(in_ptr0 + (139 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp50 = tl.load(in_ptr0 + (143 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = 4.0
    tmp12 = tmp10 / tmp11
    tmp13 = tmp12 * tmp12
    tmp15 = tmp14 * tmp14
    tmp17 = tmp16 * tmp16
    tmp18 = tmp15 + tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp25 = tmp24 / tmp11
    tmp26 = tmp25 * tmp25
    tmp27 = tmp13 + tmp26
    tmp29 = tmp28 * tmp28
    tmp31 = tmp30 * tmp30
    tmp32 = tmp29 + tmp31
    tmp34 = tmp33 * tmp33
    tmp35 = tmp32 + tmp34
    tmp37 = tmp36 * tmp36
    tmp38 = tmp35 + tmp37
    tmp39 = tmp38 / tmp11
    tmp40 = tmp39 * tmp39
    tmp41 = tmp27 + tmp40
    tmp43 = tmp42 * tmp42
    tmp45 = tmp44 * tmp44
    tmp46 = tmp43 + tmp45
    tmp48 = tmp47 * tmp47
    tmp49 = tmp46 + tmp48
    tmp51 = tmp50 * tmp50
    tmp52 = tmp49 + tmp51
    tmp53 = tmp52 / tmp11
    tmp54 = tmp53 * tmp53
    tmp55 = tmp41 + tmp54
    tl.store(out_ptr0 + x0, tmp55, xmask)


@triton.jit
def triton_poi_fused_linalg_vector_norm_mean_pow_view_2(in_ptr0, out_ptr0,
    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 + (192 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (196 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr0 + (200 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr0 + (204 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr0 + (193 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp16 = tl.load(in_ptr0 + (197 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp19 = tl.load(in_ptr0 + (201 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr0 + (205 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp28 = tl.load(in_ptr0 + (194 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp30 = tl.load(in_ptr0 + (198 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp33 = tl.load(in_ptr0 + (202 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp36 = tl.load(in_ptr0 + (206 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp42 = tl.load(in_ptr0 + (195 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp44 = tl.load(in_ptr0 + (199 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp47 = tl.load(in_ptr0 + (203 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp50 = tl.load(in_ptr0 + (207 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = 4.0
    tmp12 = tmp10 / tmp11
    tmp13 = tmp12 * tmp12
    tmp15 = tmp14 * tmp14
    tmp17 = tmp16 * tmp16
    tmp18 = tmp15 + tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp23 = tmp22 * tmp22
    tmp24 = tmp21 + tmp23
    tmp25 = tmp24 / tmp11
    tmp26 = tmp25 * tmp25
    tmp27 = tmp13 + tmp26
    tmp29 = tmp28 * tmp28
    tmp31 = tmp30 * tmp30
    tmp32 = tmp29 + tmp31
    tmp34 = tmp33 * tmp33
    tmp35 = tmp32 + tmp34
    tmp37 = tmp36 * tmp36
    tmp38 = tmp35 + tmp37
    tmp39 = tmp38 / tmp11
    tmp40 = tmp39 * tmp39
    tmp41 = tmp27 + tmp40
    tmp43 = tmp42 * tmp42
    tmp45 = tmp44 * tmp44
    tmp46 = tmp43 + tmp45
    tmp48 = tmp47 * tmp47
    tmp49 = tmp46 + tmp48
    tmp51 = tmp50 * tmp50
    tmp52 = tmp49 + tmp51
    tmp53 = tmp52 / tmp11
    tmp54 = tmp53 * tmp53
    tmp55 = tmp41 + tmp54
    tl.store(out_ptr0 + x0, tmp55, xmask)


@triton.jit
def triton_per_fused_add_div_mean_pow_sub_view_3(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 + (64 + r0 + 16 * r1), None)
    tmp2 = tl.load(in_ptr0 + (68 + r0 + 16 * r1), None)
    tmp5 = tl.load(in_ptr0 + (72 + r0 + 16 * r1), None)
    tmp8 = tl.load(in_ptr0 + (76 + r0 + 16 * r1), None)
    tmp13 = tl.load(in_ptr1 + r1, None, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr2 + (64 + r0 + 16 * r1), None)
    tmp20 = tl.load(in_ptr2 + (68 + r0 + 16 * r1), None)
    tmp23 = tl.load(in_ptr2 + (72 + r0 + 16 * r1), None)
    tmp26 = tl.load(in_ptr2 + (76 + r0 + 16 * r1), None)
    tmp30 = tl.load(in_ptr3 + r1, None, eviction_policy='evict_last')
    tmp39 = tl.load(in_ptr0 + (128 + r0 + 16 * r1), None)
    tmp41 = tl.load(in_ptr0 + (132 + r0 + 16 * r1), None)
    tmp44 = tl.load(in_ptr0 + (136 + r0 + 16 * r1), None)
    tmp47 = tl.load(in_ptr0 + (140 + r0 + 16 * r1), None)
    tmp51 = tl.load(in_ptr4 + r1, None, eviction_policy='evict_last')
    tmp55 = tl.load(in_ptr2 + (128 + r0 + 16 * r1), None)
    tmp57 = tl.load(in_ptr2 + (132 + r0 + 16 * r1), None)
    tmp60 = tl.load(in_ptr2 + (136 + r0 + 16 * r1), None)
    tmp63 = tl.load(in_ptr2 + (140 + r0 + 16 * r1), None)
    tmp67 = tl.load(in_ptr5 + r1, None, eviction_policy='evict_last')
    tmp76 = tl.load(in_ptr0 + (192 + r0 + 16 * r1), None)
    tmp78 = tl.load(in_ptr0 + (196 + r0 + 16 * r1), None)
    tmp81 = tl.load(in_ptr0 + (200 + r0 + 16 * r1), None)
    tmp84 = tl.load(in_ptr0 + (204 + r0 + 16 * r1), None)
    tmp88 = tl.load(in_ptr6 + r1, None, eviction_policy='evict_last')
    tmp92 = tl.load(in_ptr2 + (192 + r0 + 16 * r1), None)
    tmp94 = tl.load(in_ptr2 + (196 + r0 + 16 * r1), None)
    tmp97 = tl.load(in_ptr2 + (200 + r0 + 16 * r1), None)
    tmp100 = tl.load(in_ptr2 + (204 + r0 + 16 * r1), None)
    tmp104 = tl.load(in_ptr7 + r1, None, eviction_policy='evict_last')
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = 4.0
    tmp12 = tmp10 / tmp11
    tmp14 = libdevice.sqrt(tmp13)
    tmp15 = 1e-12
    tmp16 = triton_helpers.maximum(tmp14, tmp15)
    tmp17 = tmp12 / tmp16
    tmp19 = tmp18 * tmp18
    tmp21 = tmp20 * tmp20
    tmp22 = tmp19 + tmp21
    tmp24 = tmp23 * tmp23
    tmp25 = tmp22 + tmp24
    tmp27 = tmp26 * tmp26
    tmp28 = tmp25 + tmp27
    tmp29 = tmp28 / tmp11
    tmp31 = libdevice.sqrt(tmp30)
    tmp32 = triton_helpers.maximum(tmp31, tmp15)
    tmp33 = tmp29 / tmp32
    tmp34 = tmp17 - tmp33
    tmp35 = tmp34 * tmp34
    tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp38 = tl.sum(tmp36, 1)[:, None]
    tmp40 = tmp39 * tmp39
    tmp42 = tmp41 * tmp41
    tmp43 = tmp40 + tmp42
    tmp45 = tmp44 * tmp44
    tmp46 = tmp43 + tmp45
    tmp48 = tmp47 * tmp47
    tmp49 = tmp46 + tmp48
    tmp50 = tmp49 / tmp11
    tmp52 = libdevice.sqrt(tmp51)
    tmp53 = triton_helpers.maximum(tmp52, tmp15)
    tmp54 = tmp50 / tmp53
    tmp56 = tmp55 * tmp55
    tmp58 = tmp57 * tmp57
    tmp59 = tmp56 + tmp58
    tmp61 = tmp60 * tmp60
    tmp62 = tmp59 + tmp61
    tmp64 = tmp63 * tmp63
    tmp65 = tmp62 + tmp64
    tmp66 = tmp65 / tmp11
    tmp68 = libdevice.sqrt(tmp67)
    tmp69 = triton_helpers.maximum(tmp68, tmp15)
    tmp70 = tmp66 / tmp69
    tmp71 = tmp54 - tmp70
    tmp72 = tmp71 * tmp71
    tmp73 = tl.broadcast_to(tmp72, [XBLOCK, RBLOCK])
    tmp75 = tl.sum(tmp73, 1)[:, None]
    tmp77 = tmp76 * tmp76
    tmp79 = tmp78 * tmp78
    tmp80 = tmp77 + tmp79
    tmp82 = tmp81 * tmp81
    tmp83 = tmp80 + tmp82
    tmp85 = tmp84 * tmp84
    tmp86 = tmp83 + tmp85
    tmp87 = tmp86 / tmp11
    tmp89 = libdevice.sqrt(tmp88)
    tmp90 = triton_helpers.maximum(tmp89, tmp15)
    tmp91 = tmp87 / tmp90
    tmp93 = tmp92 * tmp92
    tmp95 = tmp94 * tmp94
    tmp96 = tmp93 + tmp95
    tmp98 = tmp97 * tmp97
    tmp99 = tmp96 + tmp98
    tmp101 = tmp100 * tmp100
    tmp102 = tmp99 + tmp101
    tmp103 = tmp102 / tmp11
    tmp105 = libdevice.sqrt(tmp104)
    tmp106 = triton_helpers.maximum(tmp105, tmp15)
    tmp107 = tmp103 / tmp106
    tmp108 = tmp91 - tmp107
    tmp109 = tmp108 * tmp108
    tmp110 = tl.broadcast_to(tmp109, [XBLOCK, RBLOCK])
    tmp112 = tl.sum(tmp110, 1)[:, None]
    tmp113 = 16.0
    tmp114 = tmp38 / tmp113
    tmp115 = 0.0
    tmp116 = tmp114 + tmp115
    tmp117 = tmp75 / tmp113
    tmp118 = tmp116 + tmp117
    tmp119 = tmp112 / tmp113
    tmp120 = tmp118 + tmp119
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp120, None)


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, 1), (1, 4), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_linalg_vector_norm_mean_pow_view_0[grid(4)](arg1_1,
            buf0, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused_linalg_vector_norm_mean_pow_view_0[grid(4)](arg0_1,
            buf1, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused_linalg_vector_norm_mean_pow_view_1[grid(4)](arg1_1,
            buf4, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf5 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused_linalg_vector_norm_mean_pow_view_1[grid(4)](arg0_1,
            buf5, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf8 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused_linalg_vector_norm_mean_pow_view_2[grid(4)](arg1_1,
            buf8, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused_linalg_vector_norm_mean_pow_view_2[grid(4)](arg0_1,
            buf9, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf11 = empty_strided_cuda((), (), torch.float32)
        buf12 = buf11
        del buf11
        triton_per_fused_add_div_mean_pow_sub_view_3[grid(1)](buf12, arg1_1,
            buf0, arg0_1, buf1, buf4, buf5, buf8, buf9, 1, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
        del buf0
        del buf1
        del buf4
        del buf5
        del buf8
        del buf9
    return buf12,


class ATLossNew(nn.Module):
    """
    Module for calculating AT Loss

    :param norm_type (int): Norm to be used in calculating loss
    """

    def __init__(self, norm_type=2):
        super(ATLossNew, self).__init__()
        self.p = norm_type

    def single_at_loss(self, activation):
        """
        Function for calculating single attention loss
        """
        return F.normalize(activation.pow(self.p).mean(1).view(activation.
            size(0), -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.077471