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
import torch.nn as nn
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__adaptive_avg_pool2d_0(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 6 % 6
    x0 = xindex % 6
    x2 = xindex // 36
    x4 = xindex
    tmp0 = 2 * x1 // 3
    tmp1 = (9 + 4 * x1) // 6
    tmp2 = tmp0 < tmp1
    tmp3 = 2 * x0 // 3
    tmp4 = (9 + 4 * x0) // 6
    tmp5 = tmp3 < tmp4
    tmp6 = tmp2 & tmp5
    tmp7 = tl.load(in_ptr0 + (4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 // 3), 
        tmp6 & xmask, eviction_policy='evict_last', other=0.0)
    tmp8 = 1 + 2 * x0 // 3
    tmp9 = tmp8 < tmp4
    tmp10 = tmp2 & tmp9
    tmp11 = tl.load(in_ptr0 + (1 + 4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 // 
        3), tmp10 & xmask, eviction_policy='evict_last', other=0.0)
    tmp12 = tmp11 + tmp7
    tmp13 = 1 + 2 * x1 // 3
    tmp14 = tmp13 < tmp1
    tmp15 = tmp14 & tmp5
    tmp16 = tl.load(in_ptr0 + (4 + 4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 // 
        3), tmp15 & xmask, eviction_policy='evict_last', other=0.0)
    tmp17 = tmp16 + tmp12
    tmp18 = tmp14 & tmp9
    tmp19 = tl.load(in_ptr0 + (5 + 4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 // 
        3), tmp18 & xmask, eviction_policy='evict_last', other=0.0)
    tmp20 = tmp19 + tmp17
    tmp21 = 1.0
    tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
    tmp23 = tl.where(tmp6, tmp21, tmp22)
    tmp24 = tl.where(tmp10, tmp21, tmp22)
    tmp25 = tmp24 + tmp23
    tmp26 = tl.where(tmp15, tmp21, tmp22)
    tmp27 = tmp26 + tmp25
    tmp28 = tl.where(tmp18, tmp21, tmp22)
    tmp29 = tmp28 + tmp27
    tmp30 = tmp20 / tmp29
    tl.store(out_ptr0 + x4, tmp30, xmask)


@triton.jit
def triton_poi_fused__adaptive_avg_pool2d_1(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 144
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 3 % 3
    x0 = xindex % 3
    x2 = xindex // 9
    x4 = xindex
    tmp0 = 4 * x1 // 3
    tmp1 = 2 + 4 * x1 // 3
    tmp2 = tmp0 < tmp1
    tmp3 = 4 * x0 // 3
    tmp4 = 2 + 4 * x0 // 3
    tmp5 = tmp3 < tmp4
    tmp6 = tmp2 & tmp5
    tmp7 = tl.load(in_ptr0 + (4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 // 3), 
        tmp6 & xmask, other=0.0)
    tmp8 = 1 + 4 * x0 // 3
    tmp9 = tmp8 < tmp4
    tmp10 = tmp2 & tmp9
    tmp11 = tl.load(in_ptr0 + (1 + 4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 // 
        3), tmp10 & xmask, other=0.0)
    tmp12 = tmp11 + tmp7
    tmp13 = 1 + 4 * x1 // 3
    tmp14 = tmp13 < tmp1
    tmp15 = tmp14 & tmp5
    tmp16 = tl.load(in_ptr0 + (4 + 4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 // 
        3), tmp15 & xmask, other=0.0)
    tmp17 = tmp16 + tmp12
    tmp18 = tmp14 & tmp9
    tmp19 = tl.load(in_ptr0 + (5 + 4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 // 
        3), tmp18 & xmask, other=0.0)
    tmp20 = tmp19 + tmp17
    tmp21 = 1.0
    tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
    tmp23 = tl.where(tmp6, tmp21, tmp22)
    tmp24 = tl.where(tmp10, tmp21, tmp22)
    tmp25 = tmp24 + tmp23
    tmp26 = tl.where(tmp15, tmp21, tmp22)
    tmp27 = tmp26 + tmp25
    tmp28 = tl.where(tmp18, tmp21, tmp22)
    tmp29 = tmp28 + tmp27
    tmp30 = tmp20 / tmp29
    tl.store(out_ptr0 + x4, tmp30, xmask)


@triton.jit
def triton_per_fused__adaptive_avg_pool2d__to_copy__unsafe_index_add_arange_clamp_mean_mul_sub_2(
    in_out_ptr4, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.
    constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    r3 = rindex // 4
    r2 = rindex % 4
    tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tmp5 = r3
    tmp6 = tmp5.to(tl.float32)
    tmp7 = 0.3333333333333333
    tmp8 = tmp6 * tmp7
    tmp9 = 0.0
    tmp10 = triton_helpers.maximum(tmp8, tmp9)
    tmp11 = tmp10.to(tl.int32)
    tmp12 = tl.full([1, 1], 1, tl.int64)
    tmp13 = tmp11 + tmp12
    tmp14 = triton_helpers.minimum(tmp13, tmp12)
    tmp15 = r2
    tmp16 = tmp15.to(tl.float32)
    tmp17 = tmp16 * tmp7
    tmp18 = triton_helpers.maximum(tmp17, tmp9)
    tmp19 = tmp18.to(tl.int32)
    tmp20 = tmp19 + tmp12
    tmp21 = triton_helpers.minimum(tmp20, tmp12)
    tmp22 = tl.load(in_ptr0 + (2 * tmp21 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (1 + 2 * tmp21 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp24 = tmp23 + tmp22
    tmp25 = tl.load(in_ptr0 + (4 + 2 * tmp21 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp26 = tmp25 + tmp24
    tmp27 = tl.load(in_ptr0 + (5 + 2 * tmp21 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp28 = tmp27 + tmp26
    tmp29 = 0.25
    tmp30 = tmp28 * tmp29
    tmp31 = tl.load(in_ptr0 + (2 * tmp19 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp32 = tl.load(in_ptr0 + (1 + 2 * tmp19 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp33 = tmp32 + tmp31
    tmp34 = tl.load(in_ptr0 + (4 + 2 * tmp19 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp35 = tmp34 + tmp33
    tmp36 = tl.load(in_ptr0 + (5 + 2 * tmp19 + 8 * tmp14 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp37 = tmp36 + tmp35
    tmp38 = tmp37 * tmp29
    tmp39 = tmp30 - tmp38
    tmp40 = tl.load(in_ptr0 + (2 * tmp21 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp41 = tl.load(in_ptr0 + (1 + 2 * tmp21 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp42 = tmp41 + tmp40
    tmp43 = tl.load(in_ptr0 + (4 + 2 * tmp21 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp44 = tmp43 + tmp42
    tmp45 = tl.load(in_ptr0 + (5 + 2 * tmp21 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp46 = tmp45 + tmp44
    tmp47 = tmp46 * tmp29
    tmp48 = tl.load(in_ptr0 + (2 * tmp19 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp49 = tl.load(in_ptr0 + (1 + 2 * tmp19 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp50 = tmp49 + tmp48
    tmp51 = tl.load(in_ptr0 + (4 + 2 * tmp19 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp52 = tmp51 + tmp50
    tmp53 = tl.load(in_ptr0 + (5 + 2 * tmp19 + 8 * tmp11 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp54 = tmp53 + tmp52
    tmp55 = tmp54 * tmp29
    tmp56 = tmp47 - tmp55
    tmp57 = tmp19.to(tl.float32)
    tmp58 = tmp18 - tmp57
    tmp59 = triton_helpers.maximum(tmp58, tmp9)
    tmp60 = 1.0
    tmp61 = triton_helpers.minimum(tmp59, tmp60)
    tmp62 = tmp39 * tmp61
    tmp63 = tmp38 + tmp62
    tmp64 = tmp56 * tmp61
    tmp65 = tmp55 + tmp64
    tmp66 = 16.0
    tmp67 = tmp4 / tmp66
    tmp68 = tmp67 - tmp67
    tmp69 = tmp68 * tmp9
    tmp70 = tmp67 + tmp69
    tmp71 = tmp70 - tmp70
    tmp72 = tmp71 * tmp9
    tmp73 = tmp70 + tmp72
    tmp74 = tmp0 + tmp73
    tmp75 = tmp63 - tmp65
    tmp76 = tmp11.to(tl.float32)
    tmp77 = tmp10 - tmp76
    tmp78 = triton_helpers.maximum(tmp77, tmp9)
    tmp79 = triton_helpers.minimum(tmp78, tmp60)
    tmp80 = tmp75 * tmp79
    tmp81 = tmp65 + tmp80
    tmp82 = tmp74 + tmp81
    tmp83 = 0.6666666666666666
    tmp84 = tmp6 * tmp83
    tmp85 = triton_helpers.maximum(tmp84, tmp9)
    tmp86 = tmp85.to(tl.int32)
    tmp87 = tmp86 + tmp12
    tmp88 = tl.full([1, 1], 2, tl.int64)
    tmp89 = triton_helpers.minimum(tmp87, tmp88)
    tmp90 = tmp16 * tmp83
    tmp91 = triton_helpers.maximum(tmp90, tmp9)
    tmp92 = tmp91.to(tl.int32)
    tmp93 = tl.load(in_ptr1 + (tmp92 + 3 * tmp89 + 9 * x0), xmask,
        eviction_policy='evict_last')
    tmp94 = tmp92 + tmp12
    tmp95 = triton_helpers.minimum(tmp94, tmp88)
    tmp96 = tl.load(in_ptr1 + (tmp95 + 3 * tmp89 + 9 * x0), xmask,
        eviction_policy='evict_last')
    tmp97 = tmp96 - tmp93
    tmp98 = tmp92.to(tl.float32)
    tmp99 = tmp91 - tmp98
    tmp100 = triton_helpers.maximum(tmp99, tmp9)
    tmp101 = triton_helpers.minimum(tmp100, tmp60)
    tmp102 = tmp97 * tmp101
    tmp103 = tmp93 + tmp102
    tmp104 = tl.load(in_ptr1 + (tmp92 + 3 * tmp86 + 9 * x0), xmask,
        eviction_policy='evict_last')
    tmp105 = tl.load(in_ptr1 + (tmp95 + 3 * tmp86 + 9 * x0), xmask,
        eviction_policy='evict_last')
    tmp106 = tmp105 - tmp104
    tmp107 = tmp106 * tmp101
    tmp108 = tmp104 + tmp107
    tmp109 = tmp103 - tmp108
    tmp110 = tmp86.to(tl.float32)
    tmp111 = tmp85 - tmp110
    tmp112 = triton_helpers.maximum(tmp111, tmp9)
    tmp113 = triton_helpers.minimum(tmp112, tmp60)
    tmp114 = tmp109 * tmp113
    tmp115 = tmp108 + tmp114
    tmp116 = 1.6666666666666667
    tmp117 = tmp6 * tmp116
    tmp118 = triton_helpers.maximum(tmp117, tmp9)
    tmp119 = tmp118.to(tl.int32)
    tmp120 = tmp119 + tmp12
    tmp121 = tl.full([1, 1], 5, tl.int64)
    tmp122 = triton_helpers.minimum(tmp120, tmp121)
    tmp123 = tmp16 * tmp116
    tmp124 = triton_helpers.maximum(tmp123, tmp9)
    tmp125 = tmp124.to(tl.int32)
    tmp126 = tl.load(in_ptr2 + (tmp125 + 6 * tmp122 + 36 * x0), xmask,
        eviction_policy='evict_last')
    tmp127 = tmp125 + tmp12
    tmp128 = triton_helpers.minimum(tmp127, tmp121)
    tmp129 = tl.load(in_ptr2 + (tmp128 + 6 * tmp122 + 36 * x0), xmask,
        eviction_policy='evict_last')
    tmp130 = tmp129 - tmp126
    tmp131 = tmp125.to(tl.float32)
    tmp132 = tmp124 - tmp131
    tmp133 = triton_helpers.maximum(tmp132, tmp9)
    tmp134 = triton_helpers.minimum(tmp133, tmp60)
    tmp135 = tmp130 * tmp134
    tmp136 = tmp126 + tmp135
    tmp137 = tl.load(in_ptr2 + (tmp125 + 6 * tmp119 + 36 * x0), xmask,
        eviction_policy='evict_last')
    tmp138 = tl.load(in_ptr2 + (tmp128 + 6 * tmp119 + 36 * x0), xmask,
        eviction_policy='evict_last')
    tmp139 = tmp138 - tmp137
    tmp140 = tmp139 * tmp134
    tmp141 = tmp137 + tmp140
    tmp142 = tmp136 - tmp141
    tmp143 = tmp119.to(tl.float32)
    tmp144 = tmp118 - tmp143
    tmp145 = triton_helpers.maximum(tmp144, tmp9)
    tmp146 = triton_helpers.minimum(tmp145, tmp60)
    tmp147 = tmp142 * tmp146
    tmp148 = tmp141 + tmp147
    tmp149 = tmp82 + tmp115
    tmp150 = tmp149 + tmp148
    tl.store(in_out_ptr4 + (r1 + 16 * x0), tmp150, 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)
        buf10 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32
            )
        get_raw_stream(0)
        triton_poi_fused__adaptive_avg_pool2d_0[grid(576)](arg0_1, buf10, 
            576, XBLOCK=256, num_warps=4, num_stages=1)
        buf7 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
        triton_poi_fused__adaptive_avg_pool2d_1[grid(144)](arg0_1, buf7, 
            144, XBLOCK=256, num_warps=4, num_stages=1)
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf12 = buf11
        del buf11
        buf13 = buf12
        del buf12
        triton_per_fused__adaptive_avg_pool2d__to_copy__unsafe_index_add_arange_clamp_mean_mul_sub_2[
            grid(16)](buf13, arg0_1, buf7, buf10, 16, 16, XBLOCK=1,
            num_warps=2, num_stages=1)
        del arg0_1
        del buf10
        del buf7
    return buf13,


class PyramidPoolingModuleNew(nn.Module):

    def __init__(self, pyramids=[1, 2, 3, 6]):
        super(PyramidPoolingModuleNew, self).__init__()
        self.pyramids = pyramids

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


Measured latency_ms: 0.039736