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_constant_pad_nd_max_pool2d_with_indices_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, float('-inf'), 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, float('-inf'), tmp27.dtype)
    tmp29 = tl.where(tmp24, tmp27, tmp28)
    tmp30 = triton_helpers.maximum(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, float('-inf'), tmp38.dtype)
    tmp40 = tl.where(tmp35, tmp38, tmp39)
    tmp41 = triton_helpers.maximum(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, float('-inf'), tmp49.dtype)
    tmp51 = tl.where(tmp46, tmp49, tmp50)
    tmp52 = triton_helpers.maximum(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, float('-inf'), tmp56.dtype)
    tmp58 = tl.where(tmp53, tmp56, tmp57)
    tmp59 = triton_helpers.maximum(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, float('-inf'), tmp63.dtype)
    tmp65 = tl.where(tmp60, tmp63, tmp64)
    tmp66 = triton_helpers.maximum(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, float('-inf'), tmp74.dtype)
    tmp76 = tl.where(tmp71, tmp74, tmp75)
    tmp77 = triton_helpers.maximum(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, float('-inf'), tmp81.dtype)
    tmp83 = tl.where(tmp78, tmp81, tmp82)
    tmp84 = triton_helpers.maximum(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, float('-inf'), tmp88.dtype)
    tmp90 = tl.where(tmp85, tmp88, tmp89)
    tmp91 = triton_helpers.maximum(tmp90, tmp84)
    tl.store(out_ptr0 + x4, tmp91, xmask)


@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2 % 2
    x2 = xindex // 4
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + x0 + 3 * x1 + 9 * x2), xmask)
    tl.store(out_ptr0 + x3, tmp0, 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_constant_pad_nd_max_pool2d_with_indices_0[grid(144)](
            arg0_1, buf0, 144, XBLOCK=256, num_warps=4, num_stages=1)
        del arg0_1
        buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        triton_poi_fused_clone_1[grid(64)](buf0, buf1, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del buf0
    return buf1,


class MaxPoolPadNew(nn.Module):

    def __init__(self):
        super(MaxPoolPadNew, self).__init__()
        self.pad = nn.ZeroPad2d((1, 0, 1, 0))
        self.pool = nn.MaxPool2d(3, stride=2, padding=1)

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


Measured latency_ms: 0.036045