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


class MaxPoolNew(nn.Module):

    def __init__(self, in_channels, reduction, save_device=torch.device('cpu')
        ):
        super(MaxPoolNew, self).__init__()
        self.save_device = save_device
        self.reduction = reduction
        if self.reduction:
            stride = 2
        else:
            stride = 1
        self.stride = stride
        self.Max_Pool = nn.MaxPool2d(3, stride=stride, return_indices=True)
        self.pool_indices = None

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


Measured latency_ms: 0.015695