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
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(
    in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 8 % 8
    x0 = xindex % 8
    x2 = xindex // 64
    x4 = xindex
    tmp0 = x1
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.42857142857142855
    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)
    tmp11 = x0
    tmp12 = tmp11.to(tl.float32)
    tmp13 = tmp12 * tmp2
    tmp14 = triton_helpers.maximum(tmp13, tmp4)
    tmp15 = tmp14.to(tl.int32)
    tmp16 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp17 = tmp15 + tmp7
    tmp18 = triton_helpers.minimum(tmp17, tmp9)
    tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp20 = tmp19 - tmp16
    tmp21 = tmp15.to(tl.float32)
    tmp22 = tmp14 - tmp21
    tmp23 = triton_helpers.maximum(tmp22, tmp4)
    tmp24 = 1.0
    tmp25 = triton_helpers.minimum(tmp23, tmp24)
    tmp26 = tmp20 * tmp25
    tmp27 = tmp16 + tmp26
    tmp28 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp30 = tmp29 - tmp28
    tmp31 = tmp30 * tmp25
    tmp32 = tmp28 + tmp31
    tmp33 = tmp27 - tmp32
    tmp34 = tmp6.to(tl.float32)
    tmp35 = tmp5 - tmp34
    tmp36 = triton_helpers.maximum(tmp35, tmp4)
    tmp37 = triton_helpers.minimum(tmp36, tmp24)
    tmp38 = tmp33 * tmp37
    tmp39 = tmp32 + tmp38
    tl.store(in_out_ptr0 + x4, tmp39, xmask)


@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_1(
    in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 8 % 8
    x0 = xindex % 8
    x2 = xindex // 64 % 8
    x3 = xindex // 512
    x5 = xindex
    tmp0 = x1
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.42857142857142855
    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)
    tmp11 = x0
    tmp12 = tmp11.to(tl.float32)
    tmp13 = tmp12 * tmp2
    tmp14 = triton_helpers.maximum(tmp13, tmp4)
    tmp15 = tmp14.to(tl.int32)
    tmp16 = tmp15 + tmp7
    tmp17 = triton_helpers.minimum(tmp16, tmp9)
    tmp18 = x2
    tl.full([1], 0, tl.int64)
    tmp21 = tl.full([1], 4, tl.int64)
    tmp22 = tmp18 < tmp21
    tmp23 = tl.load(in_ptr0 + (tmp17 + 4 * tmp10 + 16 * x2 + 64 * x3),
        tmp22, eviction_policy='evict_last', other=0.0)
    tmp24 = tmp18 >= tmp21
    tl.full([1], 8, tl.int64)
    tmp27 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp10 + 64 * (-4 + x2) + 
        256 * x3), tmp24, eviction_policy='evict_last', other=0.0)
    tmp28 = tl.where(tmp22, tmp23, tmp27)
    tmp29 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2 + 64 * x3),
        tmp22, eviction_policy='evict_last', other=0.0)
    tmp30 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp10 + 64 * (-4 + x2) + 
        256 * x3), tmp24, eviction_policy='evict_last', other=0.0)
    tmp31 = tl.where(tmp22, tmp29, tmp30)
    tmp32 = tmp28 - tmp31
    tmp33 = tmp15.to(tl.float32)
    tmp34 = tmp14 - tmp33
    tmp35 = triton_helpers.maximum(tmp34, tmp4)
    tmp36 = 1.0
    tmp37 = triton_helpers.minimum(tmp35, tmp36)
    tmp38 = tmp32 * tmp37
    tmp39 = tmp31 + tmp38
    tmp40 = tl.load(in_ptr0 + (tmp17 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22,
        eviction_policy='evict_last', other=0.0)
    tmp41 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp6 + 64 * (-4 + x2) + 256 *
        x3), tmp24, eviction_policy='evict_last', other=0.0)
    tmp42 = tl.where(tmp22, tmp40, tmp41)
    tmp43 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22,
        eviction_policy='evict_last', other=0.0)
    tmp44 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp6 + 64 * (-4 + x2) + 256 *
        x3), tmp24, eviction_policy='evict_last', other=0.0)
    tmp45 = tl.where(tmp22, tmp43, tmp44)
    tmp46 = tmp42 - tmp45
    tmp47 = tmp46 * tmp37
    tmp48 = tmp45 + tmp47
    tl.store(in_out_ptr0 + x5, tmp39, None)
    tl.store(in_out_ptr1 + x5, tmp48, None)


@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_2(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr1, out_ptr2, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 3072
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 8 % 8
    x0 = xindex % 8
    x2 = xindex // 64 % 12
    x3 = xindex // 768
    x6 = xindex
    tmp0 = x1
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.42857142857142855
    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)
    tmp11 = x0
    tmp12 = tmp11.to(tl.float32)
    tmp13 = tmp12 * tmp2
    tmp14 = triton_helpers.maximum(tmp13, tmp4)
    tmp15 = tmp14.to(tl.int32)
    tmp16 = tmp15 + tmp7
    tmp17 = triton_helpers.minimum(tmp16, tmp9)
    tmp18 = x2
    tl.full([1], 0, tl.int64)
    tmp21 = tl.full([1], 4, tl.int64)
    tmp22 = tmp18 < tmp21
    tmp23 = tl.load(in_ptr0 + (tmp17 + 4 * tmp10 + 16 * x2 + 64 * x3), 
        tmp22 & xmask, eviction_policy='evict_last', other=0.0)
    tmp24 = tmp18 >= tmp21
    tl.full([1], 12, tl.int64)
    tmp27 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp10 + 64 * (-4 + x2) + 
        512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp28 = tl.load(in_ptr2 + (18 + tmp17 + 8 * tmp10 + 64 * (-4 + x2) + 
        512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp29 = tmp28 - tmp27
    tmp30 = tl.broadcast_to(2 + tmp10, [XBLOCK])
    tmp31 = tmp30.to(tl.float32)
    tmp32 = tmp31 * tmp2
    tmp33 = triton_helpers.maximum(tmp32, tmp4)
    tmp34 = tmp33.to(tl.int32)
    tmp35 = tmp34.to(tl.float32)
    tmp36 = tmp33 - tmp35
    tmp37 = triton_helpers.maximum(tmp36, tmp4)
    tmp38 = 1.0
    tmp39 = triton_helpers.minimum(tmp37, tmp38)
    tmp40 = tmp29 * tmp39
    tmp41 = tmp27 + tmp40
    tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype)
    tmp43 = tl.where(tmp24, tmp41, tmp42)
    tmp44 = tl.where(tmp22, tmp23, tmp43)
    tmp45 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2 + 64 * x3), 
        tmp22 & xmask, eviction_policy='evict_last', other=0.0)
    tmp46 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp10 + 64 * (-4 + x2) + 
        512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp47 = tl.load(in_ptr2 + (18 + tmp15 + 8 * tmp10 + 64 * (-4 + x2) + 
        512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp48 = tmp47 - tmp46
    tmp49 = tmp48 * tmp39
    tmp50 = tmp46 + tmp49
    tmp51 = tl.full(tmp50.shape, 0.0, tmp50.dtype)
    tmp52 = tl.where(tmp24, tmp50, tmp51)
    tmp53 = tl.where(tmp22, tmp45, tmp52)
    tmp54 = tl.load(in_ptr0 + (tmp17 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp55 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp6 + 64 * (-4 + x2) + 512 *
        x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp56 = tl.load(in_ptr2 + (18 + tmp17 + 8 * tmp6 + 64 * (-4 + x2) + 512 *
        x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp57 = tmp56 - tmp55
    tmp58 = tl.broadcast_to(2 + tmp6, [XBLOCK])
    tmp59 = tmp58.to(tl.float32)
    tmp60 = tmp59 * tmp2
    tmp61 = triton_helpers.maximum(tmp60, tmp4)
    tmp62 = tmp61.to(tl.int32)
    tmp63 = tmp62.to(tl.float32)
    tmp64 = tmp61 - tmp63
    tmp65 = triton_helpers.maximum(tmp64, tmp4)
    tmp66 = triton_helpers.minimum(tmp65, tmp38)
    tmp67 = tmp57 * tmp66
    tmp68 = tmp55 + tmp67
    tmp69 = tl.full(tmp68.shape, 0.0, tmp68.dtype)
    tmp70 = tl.where(tmp24, tmp68, tmp69)
    tmp71 = tl.where(tmp22, tmp54, tmp70)
    tmp72 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp73 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp6 + 64 * (-4 + x2) + 512 *
        x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp74 = tl.load(in_ptr2 + (18 + tmp15 + 8 * tmp6 + 64 * (-4 + x2) + 512 *
        x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0)
    tmp75 = tmp74 - tmp73
    tmp76 = tmp75 * tmp66
    tmp77 = tmp73 + tmp76
    tmp78 = tl.full(tmp77.shape, 0.0, tmp77.dtype)
    tmp79 = tl.where(tmp24, tmp77, tmp78)
    tmp80 = tl.where(tmp22, tmp72, tmp79)
    tmp81 = tmp44 - tmp53
    tmp82 = tmp15.to(tl.float32)
    tmp83 = tmp14 - tmp82
    tmp84 = triton_helpers.maximum(tmp83, tmp4)
    tmp85 = triton_helpers.minimum(tmp84, tmp38)
    tmp86 = tmp81 * tmp85
    tmp87 = tmp53 + tmp86
    tmp88 = tmp71 - tmp80
    tmp89 = tmp88 * tmp85
    tmp90 = tmp80 + tmp89
    tmp91 = tmp87 - tmp90
    tmp92 = tmp6.to(tl.float32)
    tmp93 = tmp5 - tmp92
    tmp94 = triton_helpers.maximum(tmp93, tmp4)
    tmp95 = triton_helpers.minimum(tmp94, tmp38)
    tmp96 = tmp91 * tmp95
    tl.store(out_ptr1 + x6, tmp71, xmask)
    tl.store(out_ptr2 + x6, tmp80, xmask)
    tl.store(in_out_ptr0 + x6, tmp96, xmask)


@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 16 % 16
    x3 = xindex // 256
    x4 = xindex % 16
    x0 = xindex % 4
    x1 = xindex // 4 % 4
    x6 = xindex
    tmp0 = x2
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x4 + 16 * x2 + 64 * x3), tmp4 & xmask, other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 16, tl.int64)
    tmp9 = tl.load(in_ptr1 + (18 + x0 + 8 * x1 + 64 * (-4 + x2) + 768 * x3),
        tmp6 & xmask, other=0.0)
    tmp10 = tl.load(in_ptr2 + (18 + x0 + 8 * x1 + 64 * (-4 + x2) + 768 * x3
        ), tmp6 & xmask, other=0.0)
    tmp11 = tmp10 - tmp9
    tmp12 = 2 + x0
    tmp13 = tmp12.to(tl.float32)
    tmp14 = 0.42857142857142855
    tmp15 = tmp13 * tmp14
    tmp16 = 0.0
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp18 = tmp17.to(tl.int32)
    tmp19 = tmp18.to(tl.float32)
    tmp20 = tmp17 - tmp19
    tmp21 = triton_helpers.maximum(tmp20, tmp16)
    tmp22 = 1.0
    tmp23 = triton_helpers.minimum(tmp21, tmp22)
    tmp24 = tmp11 * tmp23
    tmp25 = tmp9 + tmp24
    tmp26 = tl.load(in_ptr3 + (18 + x0 + 8 * x1 + 64 * (-4 + x2) + 768 * x3
        ), tmp6 & xmask, other=0.0)
    tmp27 = tmp25 + tmp26
    tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
    tmp29 = tl.where(tmp6, tmp27, tmp28)
    tmp30 = tl.where(tmp4, tmp5, tmp29)
    tl.store(out_ptr0 + x6, tmp30, xmask)


def call(args):
    arg0_1, arg1_1, arg2_1, arg3_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg3_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, 8, 8), (256, 64, 8, 1), torch.float32)
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
            (1024)](buf1, arg0_1, 1024, XBLOCK=128, num_warps=4, num_stages=1)
        del arg0_1
        buf2 = empty_strided_cuda((4, 8, 8, 8), (512, 64, 8, 1), torch.float32)
        buf3 = buf2
        del buf2
        buf4 = buf3
        del buf3
        buf5 = empty_strided_cuda((4, 8, 8, 8), (512, 64, 8, 1), torch.float32)
        buf6 = buf5
        del buf5
        triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_1[
            grid(2048)](buf4, buf6, arg1_1, buf1, 2048, XBLOCK=128,
            num_warps=4, num_stages=1)
        del arg1_1
        buf7 = empty_strided_cuda((4, 12, 8, 8), (768, 64, 8, 1), torch.float32
            )
        buf9 = empty_strided_cuda((4, 12, 8, 8), (768, 64, 8, 1), torch.float32
            )
        buf10 = empty_strided_cuda((4, 12, 8, 8), (768, 64, 8, 1), torch.
            float32)
        buf11 = buf7
        del buf7
        triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_2[
            grid(3072)](buf11, arg2_1, buf6, buf4, buf9, buf10, 3072,
            XBLOCK=128, num_warps=4, num_stages=1)
        del arg2_1
        del buf4
        del buf6
        buf12 = reinterpret_tensor(buf1, (4, 16, 4, 4), (256, 16, 4, 1), 0)
        del buf1
        triton_poi_fused_cat_3[grid(1024)](arg3_1, buf10, buf9, buf11,
            buf12, 1024, XBLOCK=256, num_warps=4, num_stages=1)
        del arg3_1
        del buf10
        del buf11
        del buf9
    return buf12,


class DeepSupervisionModuleNew(nn.Module):

    def __init__(self, up_sampling_factors=(2, 2, 2)):
        super(DeepSupervisionModuleNew, self).__init__()
        self.up = nn.UpsamplingBilinear2d(scale_factor=2)
        self.up_sampling_factors = up_sampling_factors

    def forward(self, input_0, input_1, input_2, input_3):
        arg0_1 = input_0
        arg1_1 = input_1
        arg2_1 = input_2
        arg3_1 = input_3
        output = call([arg0_1, arg1_1, arg2_1, arg3_1])
        return output[0]


Measured latency_ms: 0.015173