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
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__to_copy_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 18
    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 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = tmp3 * tmp2
    tmp5 = tmp4 - tmp2
    tmp6 = 0.0
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp7.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp8, xmask)


@triton.jit
def triton_poi_fused_add_clamp_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 18
    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 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = tmp3 * tmp2
    tmp5 = tmp4 - tmp2
    tmp6 = 0.0
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp7.to(tl.int32)
    tmp9 = tl.full([1], 1, tl.int64)
    tmp10 = tmp8 + tmp9
    tmp11 = tl.full([1], 8, tl.int64)
    tmp12 = triton_helpers.minimum(tmp10, tmp11)
    tl.store(out_ptr0 + x0, tmp12, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2(out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 18
    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 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = tmp3 * tmp2
    tmp5 = tmp4 - tmp2
    tmp6 = 0.0
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp7.to(tl.int32)
    tmp9 = tmp8.to(tl.float32)
    tmp10 = tmp7 - tmp9
    tmp11 = triton_helpers.maximum(tmp10, tmp6)
    tmp12 = 1.0
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tl.store(out_ptr0 + x0, tmp13, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_add_convolution_mul_sub_3(in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, out_ptr2,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 5184
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 18 % 18
    x0 = xindex % 18
    x6 = xindex // 324
    x2 = xindex // 324 % 4
    xindex // 1296
    xindex % 1296
    x7 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last')
    tmp34 = tl.load(in_ptr7 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 9, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tmp6 = tmp5 + tmp1
    tmp7 = tmp5 < 0
    tmp8 = tl.where(tmp7, tmp6, tmp5)
    tmp9 = tl.load(in_ptr2 + (tmp8 + 9 * tmp4 + 81 * x6), xmask,
        eviction_policy='evict_last')
    tmp11 = tmp9 + tmp10
    tmp13 = tmp12 + tmp1
    tmp14 = tmp12 < 0
    tmp15 = tl.where(tmp14, tmp13, tmp12)
    tmp16 = tl.load(in_ptr2 + (tmp15 + 9 * tmp4 + 81 * x6), xmask,
        eviction_policy='evict_last')
    tmp17 = tmp16 + tmp10
    tmp18 = tmp17 - tmp11
    tmp20 = tmp18 * tmp19
    tmp21 = tmp11 + tmp20
    tmp23 = tmp22 + tmp1
    tmp24 = tmp22 < 0
    tmp25 = tl.where(tmp24, tmp23, tmp22)
    tmp26 = tl.load(in_ptr2 + (tmp8 + 9 * tmp25 + 81 * x6), xmask,
        eviction_policy='evict_last')
    tmp27 = tmp26 + tmp10
    tmp28 = tl.load(in_ptr2 + (tmp15 + 9 * tmp25 + 81 * x6), xmask,
        eviction_policy='evict_last')
    tmp29 = tmp28 + tmp10
    tmp30 = tmp29 - tmp27
    tmp31 = tmp30 * tmp19
    tmp32 = tmp27 + tmp31
    tmp33 = tmp32 - tmp21
    tmp35 = tmp33 * tmp34
    tmp36 = tmp21 + tmp35
    tl.store(out_ptr2 + x7, tmp36, 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, (4,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(4, 4), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 9, 9), (324, 81, 9, 1))
        buf1 = empty_strided_cuda((18, 1), (1, 1), torch.int64)
        get_raw_stream(0)
        triton_poi_fused__to_copy_0[grid(18)](buf1, 18, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((18, 1), (1, 1), torch.int64)
        triton_poi_fused_add_clamp_1[grid(18)](buf2, 18, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((18,), (1,), torch.int64)
        triton_poi_fused__to_copy_0[grid(18)](buf3, 18, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((18,), (1,), torch.int64)
        triton_poi_fused_add_clamp_1[grid(18)](buf4, 18, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf5 = empty_strided_cuda((18,), (1,), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(18)](buf5,
            18, XBLOCK=32, num_warps=1, num_stages=1)
        buf7 = empty_strided_cuda((18, 1), (1, 1), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(18)](buf7,
            18, XBLOCK=32, num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((4, 4, 18, 18), (1296, 324, 18, 1), torch
            .float32)
        triton_poi_fused__unsafe_index_add_convolution_mul_sub_3[grid(5184)](
            buf1, buf3, buf0, primals_2, buf4, buf5, buf2, buf7, buf9, 5184,
            XBLOCK=256, num_warps=4, num_stages=1)
        del buf0
        del primals_2
    return buf9, primals_1, primals_3, buf1, buf2, buf3, buf4, buf5, buf7


class UpsamplingBlockNew(nn.Module):

    def __init__(self, input_nc, output_nc, kernel, stride, pad):
        """
        Single block of upsampling operation

        Input:
        - int input_nc    : Input number of channels
        - int output_nc   : Output number of channels
        - int kernel      : Kernel size
        - int stride	  : Stride length
        - int pad         : Padd_moduleing
        """
        super(UpsamplingBlockNew, self).__init__()
        conv = nn.Conv2d
        biup = nn.Upsample
        block = nn.Sequential()
        block.add_module('conv_1', conv(input_nc, output_nc, kernel, stride,
            pad))
        block.add_module('upsample_2', biup(scale_factor=2, mode='bilinear'))
        self.biup_block = block

    def forward(self, input_0):
        primals_1 = self.biup_block.conv_1.weight
        primals_2 = self.biup_block.conv_1.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0]


Measured latency_ms: 0.019142