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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_avg_pool2d_clamp_mul_pow_reciprocal_0(in_out_ptr0,
    in_ptr0, in_ptr1, 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 + 16 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + 0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp6 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
        )
    tmp10 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp18 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp26 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp30 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp34 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp38 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp42 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp46 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp50 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp54 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp58 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp62 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
        'evict_last')
    tmp1 = 1e-06
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp5 = libdevice.pow(tmp2, tmp4)
    tmp7 = triton_helpers.maximum(tmp6, tmp1)
    tmp8 = libdevice.pow(tmp7, tmp4)
    tmp9 = tmp8 + tmp5
    tmp11 = triton_helpers.maximum(tmp10, tmp1)
    tmp12 = libdevice.pow(tmp11, tmp4)
    tmp13 = tmp12 + tmp9
    tmp15 = triton_helpers.maximum(tmp14, tmp1)
    tmp16 = libdevice.pow(tmp15, tmp4)
    tmp17 = tmp16 + tmp13
    tmp19 = triton_helpers.maximum(tmp18, tmp1)
    tmp20 = libdevice.pow(tmp19, tmp4)
    tmp21 = tmp20 + tmp17
    tmp23 = triton_helpers.maximum(tmp22, tmp1)
    tmp24 = libdevice.pow(tmp23, tmp4)
    tmp25 = tmp24 + tmp21
    tmp27 = triton_helpers.maximum(tmp26, tmp1)
    tmp28 = libdevice.pow(tmp27, tmp4)
    tmp29 = tmp28 + tmp25
    tmp31 = triton_helpers.maximum(tmp30, tmp1)
    tmp32 = libdevice.pow(tmp31, tmp4)
    tmp33 = tmp32 + tmp29
    tmp35 = triton_helpers.maximum(tmp34, tmp1)
    tmp36 = libdevice.pow(tmp35, tmp4)
    tmp37 = tmp36 + tmp33
    tmp39 = triton_helpers.maximum(tmp38, tmp1)
    tmp40 = libdevice.pow(tmp39, tmp4)
    tmp41 = tmp40 + tmp37
    tmp43 = triton_helpers.maximum(tmp42, tmp1)
    tmp44 = libdevice.pow(tmp43, tmp4)
    tmp45 = tmp44 + tmp41
    tmp47 = triton_helpers.maximum(tmp46, tmp1)
    tmp48 = libdevice.pow(tmp47, tmp4)
    tmp49 = tmp48 + tmp45
    tmp51 = triton_helpers.maximum(tmp50, tmp1)
    tmp52 = libdevice.pow(tmp51, tmp4)
    tmp53 = tmp52 + tmp49
    tmp55 = triton_helpers.maximum(tmp54, tmp1)
    tmp56 = libdevice.pow(tmp55, tmp4)
    tmp57 = tmp56 + tmp53
    tmp59 = triton_helpers.maximum(tmp58, tmp1)
    tmp60 = libdevice.pow(tmp59, tmp4)
    tmp61 = tmp60 + tmp57
    tmp63 = triton_helpers.maximum(tmp62, tmp1)
    tmp64 = libdevice.pow(tmp63, tmp4)
    tmp65 = tmp64 + tmp61
    tmp66 = 0.0625
    tmp67 = tmp65 * tmp66
    tmp68 = tl.full([1], 1, tl.int32)
    tmp69 = tmp68 / tmp4
    tmp70 = 1.0
    tmp71 = tmp69 * tmp70
    tmp72 = libdevice.pow(tmp67, tmp71)
    tl.store(in_out_ptr0 + x0, tmp72, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (1,), (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, 4, 1, 1), (4, 1, 16, 16), torch.float32)
        buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
        del buf0
        get_raw_stream(0)
        triton_poi_fused_avg_pool2d_clamp_mul_pow_reciprocal_0[grid(16)](buf1,
            arg1_1, arg0_1, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
    return buf1,


class GeMNew(nn.Module):

    def __init__(self, p=3, eps=1e-06, requires_grad=False):
        super(GeMNew, self).__init__()
        self.p = nn.Parameter(torch.ones(1) * p, requires_grad=requires_grad)
        self.eps = eps

    def gem(self, x, p=3, eps=1e-06):
        return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))
            ).pow(1.0 / p)

    def __repr__(self):
        return self.__class__.__name__ + '(' + 'p=' + '{:.4f}'.format(self.
            p.data.tolist()[0]) + ', ' + 'eps=' + str(self.eps) + ')'

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


Measured latency_ms: 0.015891