# AOT ID: ['0_forward']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_4/inductor_cache/nb/cnbca5sshbm5zgfgicbddaejzk5thqksd5raak3rakwfnspwfrig.py
# Topologically Sorted Source Nodes: [upsample1], Original ATen: [aten.arange, aten._to_copy, aten.add, aten.mul, aten.sub, aten.clamp, aten._unsafe_index]
# Source node to ATen node mapping:
#   upsample1 => _unsafe_index, _unsafe_index_1, _unsafe_index_2, _unsafe_index_3, _unsafe_index_4, _unsafe_index_5, _unsafe_index_6, _unsafe_index_7, add, add_10, add_11, add_12, add_6, add_7, add_8, add_9, clamp_max_3, clamp_max_4, clamp_max_5, clamp_min, clamp_min_3, clamp_min_4, clamp_min_5, convert_element_type, convert_element_type_1, convert_element_type_3, convert_element_type_5, iota, mul, mul_3, mul_4, mul_5, mul_6, mul_7, mul_8, mul_9, sub, sub_10, sub_11, sub_12, sub_3, sub_4, sub_5, sub_6, sub_7, sub_8, sub_9
# Graph fragment:
#   %iota : [num_users=1] = call_function[target=torch.ops.prims.iota.default](args = (8,), kwargs = {start: 0, step: 1, dtype: torch.int64, device: cuda:0, requires_grad: False})
#   %convert_element_type : [num_users=1] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%iota, torch.float32), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%convert_element_type, 0.5), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, 0.5), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mul, 0.5), kwargs = {})
#   %clamp_min : [num_users=4] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub, 0.0), kwargs = {})
#   %convert_element_type_1 : [num_users=6] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%view, torch.int64), kwargs = {})
#   %convert_element_type_3 : [num_users=6] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%view_1, torch.int64), kwargs = {})
#   %convert_element_type_5 : [num_users=6] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%clamp_min, torch.int64), kwargs = {})
#   %_unsafe_index : [num_users=2] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %convert_element_type_1, %convert_element_type_3, %convert_element_type_5]), kwargs = {})
#   %_unsafe_index_1 : [num_users=1] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %convert_element_type_1, %convert_element_type_3, %clamp_max_2]), kwargs = {})
#   %_unsafe_index_2 : [num_users=2] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %convert_element_type_1, %clamp_max_1, %convert_element_type_5]), kwargs = {})
#   %_unsafe_index_3 : [num_users=1] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %convert_element_type_1, %clamp_max_1, %clamp_max_2]), kwargs = {})
#   %_unsafe_index_4 : [num_users=2] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %clamp_max, %convert_element_type_3, %convert_element_type_5]), kwargs = {})
#   %_unsafe_index_5 : [num_users=1] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %clamp_max, %convert_element_type_3, %clamp_max_2]), kwargs = {})
#   %_unsafe_index_6 : [num_users=2] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %clamp_max, %clamp_max_1, %convert_element_type_5]), kwargs = {})
#   %_unsafe_index_7 : [num_users=1] = call_function[target=torch.ops.aten._unsafe_index.Tensor](args = (%primals_1, [None, None, %clamp_max, %clamp_max_1, %clamp_max_2]), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%clamp_min, %convert_element_type_5), kwargs = {})
#   %clamp_min_3 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub_3, 0.0), kwargs = {})
#   %clamp_max_3 : [num_users=4] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_3, 1.0), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%_unsafe_index_1, %_unsafe_index), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_4, %clamp_max_3), kwargs = {})
#   %add_6 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%_unsafe_index, %mul_3), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%_unsafe_index_3, %_unsafe_index_2), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_5, %clamp_max_3), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%_unsafe_index_2, %mul_4), kwargs = {})
#   %sub_6 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%_unsafe_index_5, %_unsafe_index_4), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_6, %clamp_max_3), kwargs = {})
#   %add_8 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%_unsafe_index_4, %mul_5), kwargs = {})
#   %sub_7 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%_unsafe_index_7, %_unsafe_index_6), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_7, %clamp_max_3), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%_unsafe_index_6, %mul_6), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view_1, %convert_element_type_3), kwargs = {})
#   %clamp_min_4 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub_8, 0.0), kwargs = {})
#   %clamp_max_4 : [num_users=2] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_4, 1.0), kwargs = {})
#   %sub_9 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_7, %add_6), kwargs = {})
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_9, %clamp_max_4), kwargs = {})
#   %add_10 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_6, %mul_7), kwargs = {})
#   %sub_10 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_9, %add_8), kwargs = {})
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_10, %clamp_max_4), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_8, %mul_8), kwargs = {})
#   %sub_11 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view, %convert_element_type_1), kwargs = {})
#   %clamp_min_5 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub_11, 0.0), kwargs = {})
#   %clamp_max_5 : [num_users=1] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_5, 1.0), kwargs = {})
#   %sub_12 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_11, %add_10), kwargs = {})
#   %mul_9 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_12, %clamp_max_5), kwargs = {})
#   %add_12 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_10, %mul_9), kwargs = {})
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0 = async_compile.triton('triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[8192], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0', 'mutated_arg_names': ['in_out_ptr1'], 'no_x_dim': False, 'num_load': 0, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(in_out_ptr1, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 8192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = tl.full([XBLOCK], True, tl.int1)
    x2 = (xindex // 64) % 8
    x1 = (xindex // 8) % 8
    x0 = xindex % 8
    x3 = (xindex // 512)
    x5 = xindex
    tmp0 = x2
    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 = x1
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp10 + tmp2
    tmp12 = tmp11 * tmp2
    tmp13 = tmp12 - tmp2
    tmp14 = triton_helpers.maximum(tmp13, tmp6)
    tmp15 = tmp14.to(tl.int32)
    tmp16 = x0
    tmp17 = tmp16.to(tl.float32)
    tmp18 = tmp17 + tmp2
    tmp19 = tmp18 * tmp2
    tmp20 = tmp19 - tmp2
    tmp21 = triton_helpers.maximum(tmp20, tmp6)
    tmp22 = tmp21.to(tl.int32)
    tmp23 = tl.full([1], 1, tl.int64)
    tmp24 = tmp22 + tmp23
    tmp25 = tl.full([1], 3, tl.int64)
    tmp26 = triton_helpers.minimum(tmp24, tmp25)
    tmp27 = tl.load(in_ptr0 + (tmp26 + (4*tmp15) + (16*tmp8) + (64*x3)), None, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr0 + (tmp22 + (4*tmp15) + (16*tmp8) + (64*x3)), None, eviction_policy='evict_last')
    tmp29 = tmp27 - tmp28
    tmp30 = tmp22.to(tl.float32)
    tmp31 = tmp21 - tmp30
    tmp32 = triton_helpers.maximum(tmp31, tmp6)
    tmp33 = 1.0
    tmp34 = triton_helpers.minimum(tmp32, tmp33)
    tmp35 = tmp29 * tmp34
    tmp36 = tmp8 + tmp23
    tmp37 = triton_helpers.minimum(tmp36, tmp25)
    tmp38 = tmp15 + tmp23
    tmp39 = triton_helpers.minimum(tmp38, tmp25)
    tmp40 = tl.load(in_ptr0 + (tmp26 + (4*tmp39) + (16*tmp37) + (64*x3)), None, eviction_policy='evict_last')
    tmp41 = tl.load(in_ptr0 + (tmp26 + (4*tmp39) + (16*tmp8) + (64*x3)), None, eviction_policy='evict_last')
    tmp42 = tl.load(in_ptr0 + (tmp22 + (4*tmp39) + (16*tmp8) + (64*x3)), None, eviction_policy='evict_last')
    tmp43 = tmp41 - tmp42
    tmp44 = tmp43 * tmp34
    tmp45 = tmp42 + tmp44
    tmp46 = tl.load(in_ptr0 + (tmp26 + (4*tmp15) + (16*tmp37) + (64*x3)), None, eviction_policy='evict_last')
    tmp47 = tl.load(in_ptr0 + (tmp22 + (4*tmp15) + (16*tmp37) + (64*x3)), None, eviction_policy='evict_last')
    tmp48 = tmp46 - tmp47
    tmp49 = tmp48 * tmp34
    tmp50 = tmp47 + tmp49
    tmp51 = tl.load(in_ptr0 + (tmp22 + (4*tmp39) + (16*tmp37) + (64*x3)), None, eviction_policy='evict_last')
    tmp52 = tmp40 - tmp51
    tmp53 = tmp52 * tmp34
    tmp54 = tmp51 + tmp53
    tmp55 = tmp28 + tmp35
    tmp56 = tmp45 - tmp55
    tmp57 = tmp15.to(tl.float32)
    tmp58 = tmp14 - tmp57
    tmp59 = triton_helpers.maximum(tmp58, tmp6)
    tmp60 = triton_helpers.minimum(tmp59, tmp33)
    tmp61 = tmp56 * tmp60
    tmp62 = tmp54 - tmp50
    tmp63 = tmp62 * tmp60
    tmp64 = tmp50 + tmp63
    tmp65 = tmp55 + tmp61
    tmp66 = tmp64 - tmp65
    tmp67 = tmp8.to(tl.float32)
    tmp68 = tmp7 - tmp67
    tmp69 = triton_helpers.maximum(tmp68, tmp6)
    tmp70 = triton_helpers.minimum(tmp69, tmp33)
    tmp71 = tmp66 * tmp70
    tmp72 = tmp65 + tmp71
    tl.store(in_out_ptr1 + (x5), tmp72, None)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/pr/cpr5ipr4tio67qyjwchplqvfau3ehryxnhuzkplrchppzclithjy.py
# Topologically Sorted Source Nodes: [upsample_1], Original ATen: [aten.convolution]
# Source node to ATen node mapping:
#   upsample_1 => convolution
# Graph fragment:
#   %convolution : [num_users=1] = call_function[target=torch.ops.aten.convolution.default](args = (%add_12, %primals_2, %primals_3, [1, 1, 1], [0, 0, 0], [1, 1, 1], False, [0, 0, 0], 1), kwargs = {})
triton_poi_fused_convolution_1 = async_compile.triton('triton_poi_fused_convolution_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[8192], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_convolution_1', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 8192
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = (xindex // 512) % 4
    tmp0 = tl.load(in_out_ptr0 + (x3), None)
    tmp1 = tl.load(in_ptr0 + (x1), None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + (x3), tmp2, None)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 1, 1, 1), (4, 1, 1, 1, 1))
    assert_size_stride(primals_3, (4, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf4 = empty_strided_cuda((4, 4, 8, 8, 8), (2048, 512, 64, 8, 1), torch.float32)
        buf5 = buf4; del buf4  # reuse
        buf9 = buf5; del buf5  # reuse
        buf10 = buf9; del buf9  # reuse
        # Topologically Sorted Source Nodes: [upsample1], Original ATen: [aten.arange, aten._to_copy, aten.add, aten.mul, aten.sub, aten.clamp, aten._unsafe_index]
        stream0 = get_raw_stream(0)
        triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0.run(buf10, primals_1, 8192, grid=grid(8192), stream=stream0)
        del primals_1
        # Topologically Sorted Source Nodes: [upsample_1], Original ATen: [aten.convolution]
        buf11 = extern_kernels.convolution(buf10, primals_2, 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(buf11, (4, 4, 8, 8, 8), (2048, 512, 64, 8, 1))
        buf12 = buf11; del buf11  # reuse
        # Topologically Sorted Source Nodes: [upsample_1], Original ATen: [aten.convolution]
        triton_poi_fused_convolution_1.run(buf12, primals_3, 8192, grid=grid(8192), stream=stream0)
        del primals_3
    return (buf12, primals_2, buf10, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4, 1, 1, 1), (4, 1, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import torch
from torch import nn
import torch.nn.functional as F


def conv3d(in_channels, out_channels, kernel_size, bias, padding=1, stride=1):
    return nn.Conv3d(in_channels, out_channels, kernel_size, padding=
        padding, bias=bias, stride=stride)


class UpBlock(nn.Module):
    """
        A module down sample the feature map
        Args:
            in_channels (int): number of input channels
            out_channels (int): number of output channels
            kernel_size (int): size of the convolving kernel
            order (string): determines the order of layers, e.g.
                'cr' -> conv + ReLU
                'crg' -> conv + ReLU + groupnorm
            num_groups (int): number of groups for the GroupNorm
        """

    def __init__(self, input_channels, output_channels):
        super(UpBlock, self).__init__()
        self.input_channels = input_channels
        self.output_channels = output_channels
        self.conv1 = conv3d(input_channels, output_channels, kernel_size=1,
            bias=True, padding=0)

    def forward(self, x):
        _, _c, w, h, d = x.size()
        upsample1 = F.upsample(x, [2 * w, 2 * h, 2 * d], mode='trilinear')
        upsample = self.conv1(upsample1)
        return upsample


def get_inputs():
    return [torch.rand([4, 4, 4, 4, 4])]


def get_init_inputs():
    return [[], {'input_channels': 4, 'output_channels': 4}]

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__unsafe_index_add_arange_clamp_mul_sub_0(
    in_out_ptr1, in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex // 64 % 8
    x1 = xindex // 8 % 8
    x0 = xindex % 8
    x3 = xindex // 512
    x5 = xindex
    tmp0 = x2
    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 = x1
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp10 + tmp2
    tmp12 = tmp11 * tmp2
    tmp13 = tmp12 - tmp2
    tmp14 = triton_helpers.maximum(tmp13, tmp6)
    tmp15 = tmp14.to(tl.int32)
    tmp16 = x0
    tmp17 = tmp16.to(tl.float32)
    tmp18 = tmp17 + tmp2
    tmp19 = tmp18 * tmp2
    tmp20 = tmp19 - tmp2
    tmp21 = triton_helpers.maximum(tmp20, tmp6)
    tmp22 = tmp21.to(tl.int32)
    tmp23 = tl.full([1], 1, tl.int64)
    tmp24 = tmp22 + tmp23
    tmp25 = tl.full([1], 3, tl.int64)
    tmp26 = triton_helpers.minimum(tmp24, tmp25)
    tmp27 = tl.load(in_ptr0 + (tmp26 + 4 * tmp15 + 16 * tmp8 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr0 + (tmp22 + 4 * tmp15 + 16 * tmp8 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp29 = tmp27 - tmp28
    tmp30 = tmp22.to(tl.float32)
    tmp31 = tmp21 - tmp30
    tmp32 = triton_helpers.maximum(tmp31, tmp6)
    tmp33 = 1.0
    tmp34 = triton_helpers.minimum(tmp32, tmp33)
    tmp35 = tmp29 * tmp34
    tmp36 = tmp8 + tmp23
    tmp37 = triton_helpers.minimum(tmp36, tmp25)
    tmp38 = tmp15 + tmp23
    tmp39 = triton_helpers.minimum(tmp38, tmp25)
    tmp40 = tl.load(in_ptr0 + (tmp26 + 4 * tmp39 + 16 * tmp37 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp41 = tl.load(in_ptr0 + (tmp26 + 4 * tmp39 + 16 * tmp8 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp42 = tl.load(in_ptr0 + (tmp22 + 4 * tmp39 + 16 * tmp8 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp43 = tmp41 - tmp42
    tmp44 = tmp43 * tmp34
    tmp45 = tmp42 + tmp44
    tmp46 = tl.load(in_ptr0 + (tmp26 + 4 * tmp15 + 16 * tmp37 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp47 = tl.load(in_ptr0 + (tmp22 + 4 * tmp15 + 16 * tmp37 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp48 = tmp46 - tmp47
    tmp49 = tmp48 * tmp34
    tmp50 = tmp47 + tmp49
    tmp51 = tl.load(in_ptr0 + (tmp22 + 4 * tmp39 + 16 * tmp37 + 64 * x3),
        None, eviction_policy='evict_last')
    tmp52 = tmp40 - tmp51
    tmp53 = tmp52 * tmp34
    tmp54 = tmp51 + tmp53
    tmp55 = tmp28 + tmp35
    tmp56 = tmp45 - tmp55
    tmp57 = tmp15.to(tl.float32)
    tmp58 = tmp14 - tmp57
    tmp59 = triton_helpers.maximum(tmp58, tmp6)
    tmp60 = triton_helpers.minimum(tmp59, tmp33)
    tmp61 = tmp56 * tmp60
    tmp62 = tmp54 - tmp50
    tmp63 = tmp62 * tmp60
    tmp64 = tmp50 + tmp63
    tmp65 = tmp55 + tmp61
    tmp66 = tmp64 - tmp65
    tmp67 = tmp8.to(tl.float32)
    tmp68 = tmp7 - tmp67
    tmp69 = triton_helpers.maximum(tmp68, tmp6)
    tmp70 = triton_helpers.minimum(tmp69, tmp33)
    tmp71 = tmp66 * tmp70
    tmp72 = tmp65 + tmp71
    tl.store(in_out_ptr1 + x5, tmp72, None)


@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 512 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, None)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 1, 1, 1), (4, 1, 1, 1, 1))
    assert_size_stride(primals_3, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf4 = empty_strided_cuda((4, 4, 8, 8, 8), (2048, 512, 64, 8, 1),
            torch.float32)
        buf5 = buf4
        del buf4
        buf9 = buf5
        del buf5
        buf10 = buf9
        del buf9
        get_raw_stream(0)
        triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
            (8192)](buf10, primals_1, 8192, XBLOCK=128, num_warps=4,
            num_stages=1)
        del primals_1
        buf11 = extern_kernels.convolution(buf10, primals_2, 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(buf11, (4, 4, 8, 8, 8), (2048, 512, 64, 8, 1))
        buf12 = buf11
        del buf11
        triton_poi_fused_convolution_1[grid(8192)](buf12, primals_3, 8192,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_3
    return buf12, primals_2, buf10


def conv3d(in_channels, out_channels, kernel_size, bias, padding=1, stride=1):
    return nn.Conv3d(in_channels, out_channels, kernel_size, padding=
        padding, bias=bias, stride=stride)


class UpBlockNew(nn.Module):
    """
        A module down sample the feature map
        Args:
            in_channels (int): number of input channels
            out_channels (int): number of output channels
            kernel_size (int): size of the convolving kernel
            order (string): determines the order of layers, e.g.
                'cr' -> conv + ReLU
                'crg' -> conv + ReLU + groupnorm
            num_groups (int): number of groups for the GroupNorm
        """

    def __init__(self, input_channels, output_channels):
        super(UpBlockNew, self).__init__()
        self.input_channels = input_channels
        self.output_channels = output_channels
        self.conv1 = conv3d(input_channels, output_channels, kernel_size=1,
            bias=True, padding=0)

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