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 libdevice
import torch.nn as nn
from itertools import product as product
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_mean_pow_sub_0(in_ptr0, out_ptr0, out_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp9 = tl.load(in_ptr0 + (4 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr0 + (20 + x0 + 64 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (36 + x0 + 64 * x1), xmask)
    tmp14 = tl.load(in_ptr0 + (52 + x0 + 64 * x1), xmask)
    tmp18 = tl.load(in_ptr0 + (8 + x0 + 64 * x1), xmask)
    tmp19 = tl.load(in_ptr0 + (24 + x0 + 64 * x1), xmask)
    tmp21 = tl.load(in_ptr0 + (40 + x0 + 64 * x1), xmask)
    tmp23 = tl.load(in_ptr0 + (56 + x0 + 64 * x1), xmask)
    tmp27 = tl.load(in_ptr0 + (12 + x0 + 64 * x1), xmask)
    tmp28 = tl.load(in_ptr0 + (28 + x0 + 64 * x1), xmask)
    tmp30 = tl.load(in_ptr0 + (44 + x0 + 64 * x1), xmask)
    tmp32 = tl.load(in_ptr0 + (60 + x0 + 64 * x1), xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tmp11 = tmp9 + tmp10
    tmp13 = tmp11 + tmp12
    tmp15 = tmp13 + tmp14
    tmp16 = tmp15 / tmp7
    tmp17 = tmp8 + tmp16
    tmp20 = tmp18 + tmp19
    tmp22 = tmp20 + tmp21
    tmp24 = tmp22 + tmp23
    tmp25 = tmp24 / tmp7
    tmp26 = tmp17 + tmp25
    tmp29 = tmp27 + tmp28
    tmp31 = tmp29 + tmp30
    tmp33 = tmp31 + tmp32
    tmp34 = tmp33 / tmp7
    tmp35 = tmp26 + tmp34
    tmp36 = tmp35 / tmp7
    tmp37 = tmp0 - tmp36
    tmp38 = tmp37 * tmp37
    tmp39 = tmp1 - tmp36
    tmp40 = tmp39 * tmp39
    tmp41 = tmp38 + tmp40
    tmp42 = tmp3 - tmp36
    tmp43 = tmp42 * tmp42
    tmp44 = tmp41 + tmp43
    tmp45 = tmp5 - tmp36
    tmp46 = tmp45 * tmp45
    tmp47 = tmp44 + tmp46
    tmp48 = tmp47 / tmp7
    tmp49 = tmp9 - tmp36
    tmp50 = tmp49 * tmp49
    tmp51 = tmp10 - tmp36
    tmp52 = tmp51 * tmp51
    tmp53 = tmp50 + tmp52
    tmp54 = tmp12 - tmp36
    tmp55 = tmp54 * tmp54
    tmp56 = tmp53 + tmp55
    tmp57 = tmp14 - tmp36
    tmp58 = tmp57 * tmp57
    tmp59 = tmp56 + tmp58
    tmp60 = tmp59 / tmp7
    tmp61 = tmp48 + tmp60
    tmp62 = tmp18 - tmp36
    tmp63 = tmp62 * tmp62
    tmp64 = tmp19 - tmp36
    tmp65 = tmp64 * tmp64
    tmp66 = tmp63 + tmp65
    tmp67 = tmp21 - tmp36
    tmp68 = tmp67 * tmp67
    tmp69 = tmp66 + tmp68
    tmp70 = tmp23 - tmp36
    tmp71 = tmp70 * tmp70
    tmp72 = tmp69 + tmp71
    tmp73 = tmp72 / tmp7
    tmp74 = tmp61 + tmp73
    tmp75 = tmp27 - tmp36
    tmp76 = tmp75 * tmp75
    tmp77 = tmp28 - tmp36
    tmp78 = tmp77 * tmp77
    tmp79 = tmp76 + tmp78
    tmp80 = tmp30 - tmp36
    tmp81 = tmp80 * tmp80
    tmp82 = tmp79 + tmp81
    tmp83 = tmp32 - tmp36
    tmp84 = tmp83 * tmp83
    tmp85 = tmp82 + tmp84
    tmp86 = tmp85 / tmp7
    tmp87 = tmp74 + tmp86
    tmp88 = tmp87 / tmp7
    tl.store(out_ptr0 + x2, tmp36, xmask)
    tl.store(out_ptr1 + x2, tmp88, xmask)


@triton.jit
def triton_poi_fused_add_div_mul_pow_sub_1(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x4 = xindex
    x0 = xindex % 4
    x3 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x4, xmask)
    tmp2 = tl.load(in_ptr2 + (x0 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp5 = tl.load(in_ptr3 + (x0 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp10 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tmp1 - tmp2
    tmp4 = tmp0 * tmp3
    tmp6 = 1e-08
    tmp7 = tmp5 + tmp6
    tmp8 = libdevice.sqrt(tmp7)
    tmp9 = tmp4 / tmp8
    tmp11 = tmp9 + tmp10
    tl.store(out_ptr0 + x4, tmp11, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (1, 4, 1), (4, 1, 1))
    assert_size_stride(primals_3, (1, 4, 1), (4, 1, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1, 1, 4), (4, 16, 16, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 1, 1, 4), (4, 16, 16, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mean_pow_sub_0[grid(16)](primals_1, buf0, buf1, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_add_div_mul_pow_sub_1[grid(256)](primals_2,
            primals_1, buf0, buf1, primals_3, buf2, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        del buf0
        del buf1
        del primals_2
        del primals_3
    return buf2, primals_1


class GlobalLayerNormNew(nn.Module):

    def __init__(self, channel_size):
        super(GlobalLayerNormNew, self).__init__()
        self.gamma = nn.Parameter(torch.Tensor(1, channel_size, 1))
        self.beta = nn.Parameter(torch.Tensor(1, channel_size, 1))
        self.reset_parameters()

    def reset_parameters(self):
        self.gamma.data.fill_(1)
        self.beta.data.zero_()

    def forward(self, input_0):
        primals_2 = self.gamma
        primals_3 = self.beta
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0]


Measured latency_ms: 0.031703