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
import torch.fft
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_add_mean_pow_sqrt_sub_0(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    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 + (64 + x0), xmask)
    tmp3 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp5 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp25 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp27 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp29 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp47 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp48 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp50 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp52 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp70 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp71 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp73 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp75 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tmp9 = tmp0 - tmp8
    tmp10 = tmp9 * tmp9
    tmp11 = tmp1 - tmp8
    tmp12 = tmp11 * tmp11
    tmp13 = tmp10 + tmp12
    tmp14 = tmp3 - tmp8
    tmp15 = tmp14 * tmp14
    tmp16 = tmp13 + tmp15
    tmp17 = tmp5 - tmp8
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp20 = tmp19 / tmp7
    tmp21 = 1e-08
    tmp22 = tmp20 + tmp21
    tmp23 = libdevice.sqrt(tmp22)
    tmp26 = tmp24 + tmp25
    tmp28 = tmp26 + tmp27
    tmp30 = tmp28 + tmp29
    tmp31 = tmp30 / tmp7
    tmp32 = tmp24 - tmp31
    tmp33 = tmp32 * tmp32
    tmp34 = tmp25 - tmp31
    tmp35 = tmp34 * tmp34
    tmp36 = tmp33 + tmp35
    tmp37 = tmp27 - tmp31
    tmp38 = tmp37 * tmp37
    tmp39 = tmp36 + tmp38
    tmp40 = tmp29 - tmp31
    tmp41 = tmp40 * tmp40
    tmp42 = tmp39 + tmp41
    tmp43 = tmp42 / tmp7
    tmp44 = tmp43 + tmp21
    tmp45 = libdevice.sqrt(tmp44)
    tmp46 = tmp23 + tmp45
    tmp49 = tmp47 + tmp48
    tmp51 = tmp49 + tmp50
    tmp53 = tmp51 + tmp52
    tmp54 = tmp53 / tmp7
    tmp55 = tmp47 - tmp54
    tmp56 = tmp55 * tmp55
    tmp57 = tmp48 - tmp54
    tmp58 = tmp57 * tmp57
    tmp59 = tmp56 + tmp58
    tmp60 = tmp50 - tmp54
    tmp61 = tmp60 * tmp60
    tmp62 = tmp59 + tmp61
    tmp63 = tmp52 - tmp54
    tmp64 = tmp63 * tmp63
    tmp65 = tmp62 + tmp64
    tmp66 = tmp65 / tmp7
    tmp67 = tmp66 + tmp21
    tmp68 = libdevice.sqrt(tmp67)
    tmp69 = tmp46 + tmp68
    tmp72 = tmp70 + tmp71
    tmp74 = tmp72 + tmp73
    tmp76 = tmp74 + tmp75
    tmp77 = tmp76 / tmp7
    tmp78 = tmp70 - tmp77
    tmp79 = tmp78 * tmp78
    tmp80 = tmp71 - tmp77
    tmp81 = tmp80 * tmp80
    tmp82 = tmp79 + tmp81
    tmp83 = tmp73 - tmp77
    tmp84 = tmp83 * tmp83
    tmp85 = tmp82 + tmp84
    tmp86 = tmp75 - tmp77
    tmp87 = tmp86 * tmp86
    tmp88 = tmp85 + tmp87
    tmp89 = tmp88 / tmp7
    tmp90 = tmp89 + tmp21
    tmp91 = libdevice.sqrt(tmp90)
    tmp92 = tmp69 + tmp91
    tmp93 = tmp92 / tmp7
    tl.store(out_ptr0 + x0, tmp93, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 320
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 5
    x0 = xindex % 16
    x2 = xindex // 80
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 5, tl.int64)
    tmp9 = tl.load(in_ptr1 + x0, tmp6 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x3, tmp10, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_add_mean_pow_sqrt_sub_0[grid(16)](arg0_1, buf0, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 5, 4, 4), (80, 16, 4, 1), torch.float32)
        triton_poi_fused_cat_1[grid(320)](arg0_1, buf0, buf1, 320, XBLOCK=
            128, num_warps=4, num_stages=1)
        del arg0_1
        del buf0
    return buf1,


class MiniBatchAverageLayerNew(nn.Module):
    """Minibatch stat concatenation layer. Implementation is from https://github.com/shanexn/pytorch-pggan."""

    def __init__(self, offset=1e-08):
        super().__init__()
        self.offset = offset

    def forward(self, input_0):
        arg0_1 = input_0
        output = call([arg0_1])
        return output[0]


Measured latency_ms: 0.026796