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
import torch.nn as nn
import torch.nn.init
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_constant_pad_nd_0(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 = -1 + 2 * x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 5, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tmp2 & tmp4
    tmp6 = -1 + 2 * x0
    tmp7 = tmp6 >= tmp1
    tmp8 = tmp6 < tmp3
    tmp9 = tmp7 & tmp8
    tmp10 = tmp5 & tmp9
    tmp11 = -2 + 2 * x1
    tmp12 = tmp11 >= tmp1
    tmp13 = -2 + 2 * x0
    tmp14 = tmp13 >= tmp1
    tmp15 = tmp12 & tmp14
    tmp16 = tmp15 & tmp10
    tmp17 = tl.load(in_ptr0 + (-10 + 2 * x0 + 8 * x1 + 16 * x2), tmp16 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
    tmp19 = tl.where(tmp10, tmp17, tmp18)
    tmp20 = 2 * x0
    tmp21 = tmp20 >= tmp1
    tmp22 = tmp20 < tmp3
    tmp23 = tmp21 & tmp22
    tmp24 = tmp5 & tmp23
    tmp25 = tmp12 & tmp7
    tmp26 = tmp25 & tmp24
    tmp27 = tl.load(in_ptr0 + (-9 + 2 * x0 + 8 * x1 + 16 * x2), tmp26 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
    tmp29 = tl.where(tmp24, tmp27, tmp28)
    tmp30 = tmp29 + tmp19
    tmp31 = 1 + 2 * x0
    tmp32 = tmp31 >= tmp1
    tmp33 = tmp31 < tmp3
    tmp34 = tmp32 & tmp33
    tmp35 = tmp5 & tmp34
    tmp36 = tmp12 & tmp21
    tmp37 = tmp36 & tmp35
    tmp38 = tl.load(in_ptr0 + (-8 + 2 * x0 + 8 * x1 + 16 * x2), tmp37 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype)
    tmp40 = tl.where(tmp35, tmp38, tmp39)
    tmp41 = tmp40 + tmp30
    tmp42 = 2 * x1
    tmp43 = tmp42 >= tmp1
    tmp44 = tmp42 < tmp3
    tmp45 = tmp43 & tmp44
    tmp46 = tmp45 & tmp9
    tmp47 = tmp2 & tmp14
    tmp48 = tmp47 & tmp46
    tmp49 = tl.load(in_ptr0 + (-6 + 2 * x0 + 8 * x1 + 16 * x2), tmp48 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype)
    tmp51 = tl.where(tmp46, tmp49, tmp50)
    tmp52 = tmp51 + tmp41
    tmp53 = tmp45 & tmp23
    tmp54 = tmp2 & tmp7
    tmp55 = tmp54 & tmp53
    tmp56 = tl.load(in_ptr0 + (-5 + 2 * x0 + 8 * x1 + 16 * x2), tmp55 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype)
    tmp58 = tl.where(tmp53, tmp56, tmp57)
    tmp59 = tmp58 + tmp52
    tmp60 = tmp45 & tmp34
    tmp61 = tmp2 & tmp21
    tmp62 = tmp61 & tmp60
    tmp63 = tl.load(in_ptr0 + (-4 + 2 * x0 + 8 * x1 + 16 * x2), tmp62 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp64 = tl.full(tmp63.shape, 0.0, tmp63.dtype)
    tmp65 = tl.where(tmp60, tmp63, tmp64)
    tmp66 = tmp65 + tmp59
    tmp67 = 1 + 2 * x1
    tmp68 = tmp67 >= tmp1
    tmp69 = tmp67 < tmp3
    tmp70 = tmp68 & tmp69
    tmp71 = tmp70 & tmp9
    tmp72 = tmp43 & tmp14
    tmp73 = tmp72 & tmp71
    tmp74 = tl.load(in_ptr0 + (-2 + 2 * x0 + 8 * x1 + 16 * x2), tmp73 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype)
    tmp76 = tl.where(tmp71, tmp74, tmp75)
    tmp77 = tmp76 + tmp66
    tmp78 = tmp70 & tmp23
    tmp79 = tmp43 & tmp7
    tmp80 = tmp79 & tmp78
    tmp81 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x1 + 16 * x2), tmp80 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype)
    tmp83 = tl.where(tmp78, tmp81, tmp82)
    tmp84 = tmp83 + tmp77
    tmp85 = tmp70 & tmp34
    tmp86 = tmp43 & tmp21
    tmp87 = tmp86 & tmp85
    tmp88 = tl.load(in_ptr0 + (2 * x0 + 8 * x1 + 16 * x2), tmp87 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp89 = tl.full(tmp88.shape, 0.0, tmp88.dtype)
    tmp90 = tl.where(tmp85, tmp88, tmp89)
    tmp91 = tmp90 + tmp84
    tmp92 = (0 * (0 >= -1 + 2 * x0) + (-1 + 2 * x0) * (-1 + 2 * x0 > 0)) * (
        0 * (0 >= -1 + 2 * x1) + (-1 + 2 * x1) * (-1 + 2 * x1 > 0)) + (5 *
        (5 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 5)) * (5 * (5 <= 2 +
        2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 5)) + -1 * (0 * (0 >= -1 + 2 *
        x0) + (-1 + 2 * x0) * (-1 + 2 * x0 > 0)) * (5 * (5 <= 2 + 2 * x1) +
        (2 + 2 * x1) * (2 + 2 * x1 < 5)) + -1 * (0 * (0 >= -1 + 2 * x1) + (
        -1 + 2 * x1) * (-1 + 2 * x1 > 0)) * (5 * (5 <= 2 + 2 * x0) + (2 + 2 *
        x0) * (2 + 2 * x0 < 5))
    tmp93 = tmp91 / tmp92
    tl.store(out_ptr0 + x4, tmp93, 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((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_avg_pool2d_constant_pad_nd_0[grid(144)](arg0_1,
            buf0, 144, XBLOCK=128, num_warps=4, num_stages=1)
        del arg0_1
    return reinterpret_tensor(buf0, (4, 4, 2, 2), (36, 9, 3, 1), 4),


class AvgPoolPadNew(nn.Module):

    def __init__(self, stride=2, padding=1):
        super(AvgPoolPadNew, self).__init__()
        self.pad = nn.ZeroPad2d((1, 0, 1, 0))
        self.pool = nn.AvgPool2d(3, stride=stride, padding=padding,
            count_include_pad=False)

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


Measured latency_ms: 0.014855