import torch
from torch._inductor.select_algorithm import extern_kernels
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
from torch.nn import init
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_clamp_sub_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 1.0
    tmp3 = tmp1 * tmp2
    tmp4 = 0.0
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp6 = tmp5.to(tl.int32)
    tmp7 = tmp6.to(tl.float32)
    tmp8 = tmp5 - tmp7
    tmp9 = triton_helpers.maximum(tmp8, tmp4)
    tmp10 = triton_helpers.minimum(tmp9, tmp2)
    tl.store(out_ptr0 + x0, tmp10, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused__to_copy_2(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 1.0
    tmp3 = tmp1 * tmp2
    tmp4 = 0.0
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp6 = tmp5.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp6, xmask)


@triton.jit
def triton_poi_fused_add_clamp_3(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 1.0
    tmp3 = tmp1 * tmp2
    tmp4 = 0.0
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp6 = tmp5.to(tl.int32)
    tmp7 = tl.full([1], 1, tl.int64)
    tmp8 = tmp6 + tmp7
    tmp9 = tl.full([1], 3, tl.int64)
    tmp10 = triton_helpers.minimum(tmp8, tmp9)
    tl.store(out_ptr0 + x0, tmp10, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_add_convolution_mul_sub_4(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7,
    out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    x2 = xindex // 4 % 4
    x1 = xindex % 4
    x3 = xindex // 16
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp4 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr6 + x2, xmask, eviction_policy='evict_last')
    tmp37 = tl.load(in_ptr7 + x2, xmask, eviction_policy='evict_last')
    tmp3 = tmp0 + tmp2
    tmp5 = tl.full([XBLOCK], 4, tl.int32)
    tmp6 = tmp4 + tmp5
    tmp7 = tmp4 < 0
    tmp8 = tl.where(tmp7, tmp6, tmp4)
    tmp10 = tmp9 + tmp5
    tmp11 = tmp9 < 0
    tmp12 = tl.where(tmp11, tmp10, tmp9)
    tmp13 = tl.load(in_ptr3 + (tmp12 + 4 * tmp8 + 16 * x3), xmask,
        eviction_policy='evict_last')
    tmp14 = tmp13 + tmp2
    tmp16 = tmp15 + tmp5
    tmp17 = tmp15 < 0
    tmp18 = tl.where(tmp17, tmp16, tmp15)
    tmp19 = tl.load(in_ptr3 + (tmp18 + 4 * tmp8 + 16 * x3), xmask,
        eviction_policy='evict_last')
    tmp20 = tmp19 + tmp2
    tmp21 = tmp20 - tmp14
    tmp23 = tmp21 * tmp22
    tmp24 = tmp14 + tmp23
    tmp26 = tmp25 + tmp5
    tmp27 = tmp25 < 0
    tmp28 = tl.where(tmp27, tmp26, tmp25)
    tmp29 = tl.load(in_ptr3 + (tmp12 + 4 * tmp28 + 16 * x3), xmask,
        eviction_policy='evict_last')
    tmp30 = tmp29 + tmp2
    tmp31 = tl.load(in_ptr3 + (tmp18 + 4 * tmp28 + 16 * x3), xmask,
        eviction_policy='evict_last')
    tmp32 = tmp31 + tmp2
    tmp33 = tmp32 - tmp30
    tmp34 = tmp33 * tmp22
    tmp35 = tmp30 + tmp34
    tmp36 = tmp35 - tmp24
    tmp38 = tmp36 * tmp37
    tmp39 = tmp24 + tmp38
    tl.store(in_out_ptr0 + x0, tmp3, xmask)
    tl.store(out_ptr2 + x0, tmp39, xmask)
    tl.store(out_ptr3 + x0, tmp39, xmask)
    tl.store(out_ptr4 + x0, tmp39, xmask)
    tl.store(out_ptr5 + x0, tmp39, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (1, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_3, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 
            1), padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 1, 4, 4), (16, 16, 4, 1))
        buf10 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_clamp_sub_0[grid(4)](buf10, 4, XBLOCK=4, num_warps
            =1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_max_pool2d_with_indices_1[grid(256)](primals_1,
            buf2, 256, XBLOCK=128, num_warps=4, num_stages=1)
        buf3 = extern_kernels.convolution(buf2, primals_2, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 1, 4, 4), (16, 16, 4, 1))
        buf4 = empty_strided_cuda((4, 1), (1, 1), torch.int64)
        triton_poi_fused__to_copy_2[grid(4)](buf4, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf5 = empty_strided_cuda((4, 1), (1, 1), torch.int64)
        triton_poi_fused_add_clamp_3[grid(4)](buf5, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf6 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused__to_copy_2[grid(4)](buf6, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf7 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused_add_clamp_3[grid(4)](buf7, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf8 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused_clamp_sub_0[grid(4)](buf8, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf1 = buf0
        del buf0
        buf12 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf13 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf14 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf15 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        triton_poi_fused__unsafe_index_add_convolution_mul_sub_4[grid(64)](buf1
            , primals_3, buf4, buf6, buf3, buf7, buf8, buf5, buf10, buf12,
            buf13, buf14, buf15, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del buf3
        del primals_3
    return (buf1, buf12, buf13, buf14, buf15, primals_1, primals_2, buf2,
        buf4, buf5, buf6, buf7, buf8, buf10)


class BaseblockNew(nn.Module):

    def __init__(self, in_channels):
        super(BaseblockNew, self).__init__()
        self.p_size = [1, 1, 1, 1]
        self.pool1 = nn.MaxPool2d(kernel_size=self.p_size[0], stride=self.
            p_size[0])
        self.pool2 = nn.MaxPool2d(kernel_size=self.p_size[1], stride=self.
            p_size[1])
        self.pool3 = nn.MaxPool2d(kernel_size=self.p_size[2], stride=self.
            p_size[2])
        self.pool4 = nn.MaxPool2d(kernel_size=self.p_size[3], stride=self.
            p_size[3])
        self.conv = nn.Conv2d(in_channels=in_channels, out_channels=1,
            dilation=2, kernel_size=3, padding=2)
        self.relu = nn.ReLU()
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_uniform_(m.weight.data)
                if m.bias is not None:
                    m.bias.data.zero_()
            elif isinstance(m, nn.BatchNorm2d):
                init.normal_(m.weight.data, 1.0, 0.02)
                init.constant_(m.bias.data, 0.0)

    def forward(self, input_0):
        primals_2 = self.conv.weight
        primals_3 = self.conv.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0], output[1], output[2], output[3], output[4]


Measured latency_ms: 0.127217