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
from torch import 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 = 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 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 1.0
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp9, xmask)


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


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


@triton.jit
def triton_poi_fused__unsafe_index_add_convolution_mul_sub_3(in_out_ptr1,
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7,
    in_ptr8, in_ptr9, in_ptr10, xnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 16 % 4
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x6 = xindex // 64
    x3 = xindex // 64 % 4
    x8 = xindex
    tmp0 = tl.load(in_ptr0 + x2, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr4 + x3, xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last')
    tmp22 = tl.load(in_ptr6 + x0, xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr7 + x0, xmask, eviction_policy='evict_last')
    tmp38 = tl.load(in_ptr8 + x1, xmask, eviction_policy='evict_last')
    tmp40 = tl.load(in_ptr9 + x2, xmask, eviction_policy='evict_last')
    tmp63 = tl.load(in_ptr10 + x2, xmask, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 4, 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)
    tmp10 = tmp9 + tmp1
    tmp11 = tmp9 < 0
    tmp12 = tl.where(tmp11, tmp10, tmp9)
    tmp13 = tl.load(in_ptr3 + (tmp12 + 4 * tmp8 + 16 * tmp4 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp15 = tmp13 + tmp14
    tmp17 = tmp16 + tmp1
    tmp18 = tmp16 < 0
    tmp19 = tl.where(tmp18, tmp17, tmp16)
    tmp20 = tl.load(in_ptr3 + (tmp12 + 4 * tmp19 + 16 * tmp4 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp21 = tmp20 + tmp14
    tmp23 = tmp22 + tmp1
    tmp24 = tmp22 < 0
    tmp25 = tl.where(tmp24, tmp23, tmp22)
    tmp26 = tl.load(in_ptr3 + (tmp25 + 4 * tmp19 + 16 * tmp4 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp27 = tmp26 + tmp14
    tmp28 = tmp27 - tmp21
    tmp30 = tmp28 * tmp29
    tmp31 = tmp21 + tmp30
    tmp32 = tl.load(in_ptr3 + (tmp25 + 4 * tmp8 + 16 * tmp4 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp33 = tmp32 + tmp14
    tmp34 = tmp33 - tmp15
    tmp35 = tmp34 * tmp29
    tmp36 = tmp15 + tmp35
    tmp37 = tmp36 - tmp31
    tmp39 = tmp37 * tmp38
    tmp41 = tmp40 + tmp1
    tmp42 = tmp40 < 0
    tmp43 = tl.where(tmp42, tmp41, tmp40)
    tmp44 = tl.load(in_ptr3 + (tmp12 + 4 * tmp8 + 16 * tmp43 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp45 = tmp44 + tmp14
    tmp46 = tl.load(in_ptr3 + (tmp12 + 4 * tmp19 + 16 * tmp43 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp47 = tmp46 + tmp14
    tmp48 = tl.load(in_ptr3 + (tmp25 + 4 * tmp19 + 16 * tmp43 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp49 = tmp48 + tmp14
    tmp50 = tmp49 - tmp47
    tmp51 = tmp50 * tmp29
    tmp52 = tmp47 + tmp51
    tmp53 = tl.load(in_ptr3 + (tmp25 + 4 * tmp8 + 16 * tmp43 + 64 * x6),
        xmask, eviction_policy='evict_last')
    tmp54 = tmp53 + tmp14
    tmp55 = tmp54 - tmp45
    tmp56 = tmp55 * tmp29
    tmp57 = tmp45 + tmp56
    tmp58 = tmp57 - tmp52
    tmp59 = tmp58 * tmp38
    tmp60 = tmp31 + tmp39
    tmp61 = tmp52 + tmp59
    tmp62 = tmp61 - tmp60
    tmp64 = tmp62 * tmp63
    tmp65 = tmp60 + tmp64
    tl.store(in_out_ptr1 + x8, tmp65, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 1, 1, 1), (4, 1, 1, 1, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4, 4), (256, 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, 1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
        buf1 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.int64)
        get_raw_stream(0)
        triton_poi_fused__to_copy_0[grid(4)](buf1, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf2 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.int64)
        triton_poi_fused_add_clamp_1[grid(4)](buf2, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf3 = empty_strided_cuda((4, 1), (1, 1), torch.int64)
        triton_poi_fused__to_copy_0[grid(4)](buf3, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf4 = empty_strided_cuda((4, 1), (1, 1), torch.int64)
        triton_poi_fused_add_clamp_1[grid(4)](buf4, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf5 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused__to_copy_0[grid(4)](buf5, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf6 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused_add_clamp_1[grid(4)](buf6, 4, XBLOCK=4, num_warps=
            1, num_stages=1)
        buf11 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(4)](buf11,
            4, XBLOCK=4, num_warps=1, num_stages=1)
        buf14 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(4)](buf14,
            4, XBLOCK=4, num_warps=1, num_stages=1)
        buf17 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(4)](buf17,
            4, XBLOCK=4, num_warps=1, num_stages=1)
        buf8 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
            torch.float32)
        buf15 = buf8
        del buf8
        buf18 = buf15
        del buf15
        triton_poi_fused__unsafe_index_add_convolution_mul_sub_3[grid(1024)](
            buf18, buf1, buf4, buf5, buf0, primals_2, buf3, buf6, buf11,
            buf14, buf2, buf17, 1024, XBLOCK=128, num_warps=4, num_stages=1)
        del buf0
        del primals_2
    return (buf18, primals_1, primals_3, buf1, buf2, buf3, buf4, buf5, buf6,
        buf11, buf14, buf17)


class UpSamplerNew(nn.Module):
    """Up Sample module
    
    Decrease the channels size and increase the spatial size of tensor
    
    Extends:
        nn.Module
    """

    def __init__(self, inChannels, outChannels, spatial_size):
        """
        Arguments:
            inChannels {int} -- Number of in channels
            outChannels {int} -- Number of out channels
            spatial_size {tuple} -- Spatial size to get
        """
        super(UpSamplerNew, self).__init__()
        self.spatial_size = spatial_size
        self.conv = nn.Conv3d(inChannels, outChannels, 1)

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


Measured latency_ms: 0.014934