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
from torch._inductor.runtime.triton_helpers import libdevice
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__unsafe_index_add_arange_clamp_floor_mul_rsub_sub_0(
    in_out_ptr1, 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
    x3 = xindex
    tmp0 = x1
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = tmp3 * tmp2
    tmp5 = tmp4 - tmp2
    tmp6 = libdevice.floor(tmp5)
    tmp7 = tmp6.to(tl.int32)
    tmp8 = tl.full([1], 1, tl.int64)
    tmp9 = tmp7 - tmp8
    tmp10 = tl.full([1], 0, tl.int64)
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp12 = tl.full([1], 3, tl.int64)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tmp14 = x0
    tmp15 = tmp14.to(tl.float32)
    tmp16 = tmp15 + tmp2
    tmp17 = tmp16 * tmp2
    tmp18 = tmp17 - tmp2
    tmp19 = libdevice.floor(tmp18)
    tmp20 = tmp19.to(tl.int32)
    tmp21 = tmp20 - tmp8
    tmp22 = triton_helpers.maximum(tmp21, tmp10)
    tmp23 = triton_helpers.minimum(tmp22, tmp12)
    tmp24 = tl.load(in_ptr0 + (tmp23 + 4 * tmp13 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp25 = tmp18 - tmp19
    tmp26 = 0.0
    tmp27 = triton_helpers.maximum(tmp25, tmp26)
    tmp28 = 1.0
    tmp29 = triton_helpers.minimum(tmp27, tmp28)
    tmp30 = tmp29 + tmp28
    tmp31 = -0.75
    tmp32 = tmp30 * tmp31
    tmp33 = -3.75
    tmp34 = tmp32 - tmp33
    tmp35 = tmp34 * tmp30
    tmp36 = -6.0
    tmp37 = tmp35 + tmp36
    tmp38 = tmp37 * tmp30
    tmp39 = -3.0
    tmp40 = tmp38 - tmp39
    tmp41 = tmp24 * tmp40
    tmp42 = triton_helpers.maximum(tmp20, tmp10)
    tmp43 = triton_helpers.minimum(tmp42, tmp12)
    tmp44 = tl.load(in_ptr0 + (tmp43 + 4 * tmp13 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp45 = 1.25
    tmp46 = tmp29 * tmp45
    tmp47 = 2.25
    tmp48 = tmp46 - tmp47
    tmp49 = tmp48 * tmp29
    tmp50 = tmp49 * tmp29
    tmp51 = tmp50 + tmp28
    tmp52 = tmp44 * tmp51
    tmp53 = tmp20 + tmp8
    tmp54 = triton_helpers.maximum(tmp53, tmp10)
    tmp55 = triton_helpers.minimum(tmp54, tmp12)
    tmp56 = tl.load(in_ptr0 + (tmp55 + 4 * tmp13 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp57 = tmp28 - tmp29
    tmp58 = tmp57 * tmp45
    tmp59 = tmp58 - tmp47
    tmp60 = tmp59 * tmp57
    tmp61 = tmp60 * tmp57
    tmp62 = tmp61 + tmp28
    tmp63 = tmp56 * tmp62
    tmp64 = tl.full([1], 2, tl.int64)
    tmp65 = tmp20 + tmp64
    tmp66 = triton_helpers.maximum(tmp65, tmp10)
    tmp67 = triton_helpers.minimum(tmp66, tmp12)
    tmp68 = tl.load(in_ptr0 + (tmp67 + 4 * tmp13 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp69 = 2.0
    tmp70 = tmp69 - tmp29
    tmp71 = tmp70 * tmp31
    tmp72 = tmp71 - tmp33
    tmp73 = tmp72 * tmp70
    tmp74 = tmp73 + tmp36
    tmp75 = tmp74 * tmp70
    tmp76 = tmp75 - tmp39
    tmp77 = tmp68 * tmp76
    tmp78 = tmp41 + tmp52
    tmp79 = tmp78 + tmp63
    tmp80 = tmp79 + tmp77
    tmp81 = tmp5 - tmp6
    tmp82 = triton_helpers.maximum(tmp81, tmp26)
    tmp83 = triton_helpers.minimum(tmp82, tmp28)
    tmp84 = tmp83 + tmp28
    tmp85 = tmp84 * tmp31
    tmp86 = tmp85 - tmp33
    tmp87 = tmp86 * tmp84
    tmp88 = tmp87 + tmp36
    tmp89 = tmp88 * tmp84
    tmp90 = tmp89 - tmp39
    tmp91 = tmp80 * tmp90
    tmp92 = triton_helpers.maximum(tmp7, tmp10)
    tmp93 = triton_helpers.minimum(tmp92, tmp12)
    tmp94 = tl.load(in_ptr0 + (tmp23 + 4 * tmp93 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp95 = tmp94 * tmp40
    tmp96 = tl.load(in_ptr0 + (tmp43 + 4 * tmp93 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp97 = tmp96 * tmp51
    tmp98 = tl.load(in_ptr0 + (tmp55 + 4 * tmp93 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp99 = tmp98 * tmp62
    tmp100 = tl.load(in_ptr0 + (tmp67 + 4 * tmp93 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp101 = tmp100 * tmp76
    tmp102 = tmp7 + tmp8
    tmp103 = triton_helpers.maximum(tmp102, tmp10)
    tmp104 = triton_helpers.minimum(tmp103, tmp12)
    tmp105 = tl.load(in_ptr0 + (tmp23 + 4 * tmp104 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp106 = tmp105 * tmp40
    tmp107 = tl.load(in_ptr0 + (tmp43 + 4 * tmp104 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp108 = tmp107 * tmp51
    tmp109 = tl.load(in_ptr0 + (tmp55 + 4 * tmp104 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp110 = tmp109 * tmp62
    tmp111 = tl.load(in_ptr0 + (tmp67 + 4 * tmp104 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp112 = tmp111 * tmp76
    tmp113 = tmp95 + tmp97
    tmp114 = tmp113 + tmp99
    tmp115 = tmp114 + tmp101
    tmp116 = tmp83 * tmp45
    tmp117 = tmp116 - tmp47
    tmp118 = tmp117 * tmp83
    tmp119 = tmp118 * tmp83
    tmp120 = tmp119 + tmp28
    tmp121 = tmp115 * tmp120
    tmp122 = tmp91 + tmp121
    tmp123 = tmp106 + tmp108
    tmp124 = tmp123 + tmp110
    tmp125 = tmp124 + tmp112
    tmp126 = tmp28 - tmp83
    tmp127 = tmp126 * tmp45
    tmp128 = tmp127 - tmp47
    tmp129 = tmp128 * tmp126
    tmp130 = tmp129 * tmp126
    tmp131 = tmp130 + tmp28
    tmp132 = tmp125 * tmp131
    tmp133 = tmp122 + tmp132
    tmp134 = tmp7 + tmp64
    tmp135 = triton_helpers.maximum(tmp134, tmp10)
    tmp136 = triton_helpers.minimum(tmp135, tmp12)
    tmp137 = tl.load(in_ptr0 + (tmp23 + 4 * tmp136 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp138 = tmp137 * tmp40
    tmp139 = tl.load(in_ptr0 + (tmp43 + 4 * tmp136 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp140 = tmp139 * tmp51
    tmp141 = tl.load(in_ptr0 + (tmp55 + 4 * tmp136 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp142 = tmp141 * tmp62
    tmp143 = tl.load(in_ptr0 + (tmp67 + 4 * tmp136 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp144 = tmp143 * tmp76
    tmp145 = tmp138 + tmp140
    tmp146 = tmp145 + tmp142
    tmp147 = tmp146 + tmp144
    tmp148 = tmp69 - tmp83
    tmp149 = tmp148 * tmp31
    tmp150 = tmp149 - tmp33
    tmp151 = tmp150 * tmp148
    tmp152 = tmp151 + tmp36
    tmp153 = tmp152 * tmp148
    tmp154 = tmp153 - tmp39
    tmp155 = tmp147 * tmp154
    tmp156 = tmp133 + tmp155
    tl.store(in_out_ptr1 + x3, tmp156, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf10 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32
            )
        buf13 = buf10
        del buf10
        buf19 = buf13
        del buf13
        get_raw_stream(0)
        triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_floor_mul_rsub_sub_0[
            grid(1024)](buf19, arg0_1, 1024, XBLOCK=128, num_warps=4,
            num_stages=1)
        del arg0_1
    return buf19,


class BicubicNew(nn.Module):

    def __init__(self, scale_factor=2):
        super().__init__()
        self.scale_factor = scale_factor

    def forward(self, input_0):
        arg0_1 = input_0
        output = call([arg0_1])
        return output[0]


Measured latency_ms: 0.013985