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.triton_helpers import libdevice
from torch import nn
import torch.autograd
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_fill_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 48
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 3
    x2 = xindex // 12
    x1 = xindex // 3 % 4
    x4 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 2, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp3 = tl.full([1], 1, tl.int32)
    tmp4 = tmp0 == tmp3
    tmp5 = x2
    tmp6 = tmp5.to(tl.float32)
    tmp7 = 2.0
    tmp8 = tmp6 < tmp7
    tmp9 = 1.0
    tmp10 = tmp6 * tmp9
    tmp11 = -1.5
    tmp12 = tmp10 + tmp11
    tmp13 = 3 + -1 * x2
    tmp14 = tmp13.to(tl.float32)
    tmp15 = tmp14 * tmp9
    tmp16 = 1.5
    tmp17 = tmp16 - tmp15
    tmp18 = tl.where(tmp8, tmp12, tmp17)
    tmp19 = tl.full([1], 0, tl.int32)
    tmp20 = tmp0 == tmp19
    tmp21 = x1
    tmp22 = tmp21.to(tl.float32)
    tmp23 = tmp22 < tmp7
    tmp24 = tmp22 * tmp9
    tmp25 = tmp24 + tmp11
    tmp26 = 3 + -1 * x1
    tmp27 = tmp26.to(tl.float32)
    tmp28 = tmp27 * tmp9
    tmp29 = tmp16 - tmp28
    tmp30 = tl.where(tmp23, tmp25, tmp29)
    tmp31 = float('nan')
    tmp32 = tl.where(tmp20, tmp30, tmp31)
    tmp33 = tl.where(tmp4, tmp18, tmp32)
    tmp34 = tl.where(tmp2, tmp9, tmp33)
    tl.store(out_ptr0 + x4, tmp34, xmask)


@triton.jit
def triton_poi_fused_div_lift_fresh_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 6
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x2 = xindex
    tmp0 = x1 + 3 * x0
    tmp1 = tl.full([1], 3, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 2, tl.int64)
    tmp6 = tmp0 < tmp5
    tmp7 = -0.06975647062063217
    tmp8 = 0.0
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = 0.9975640773773193
    tmp11 = tl.where(tmp4, tmp10, tmp9)
    tmp12 = tl.full([1], 4, tl.int64)
    tmp13 = tmp0 < tmp12
    tmp14 = tl.full([1], 5, tl.int64)
    tmp15 = tmp0 < tmp14
    tmp16 = tl.where(tmp15, tmp10, tmp8)
    tmp17 = 0.06975647062063217
    tmp18 = tl.where(tmp13, tmp17, tmp16)
    tmp19 = tl.where(tmp2, tmp11, tmp18)
    tmp20 = x0
    tmp21 = tmp20 < tmp3
    tmp22 = 2.0
    tmp23 = tl.where(tmp21, tmp22, tmp22)
    tmp24 = tmp19 / tmp23
    tl.store(out_ptr0 + x2, tmp24, xmask)


@triton.jit
def triton_poi_fused_grid_sampler_2d_2(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x3 = xindex // 16
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = 2.0
    tmp2 = tmp0 * tmp1
    tmp3 = 1.5
    tmp4 = tmp2 + tmp3
    tmp5 = libdevice.nearbyint(tmp4)
    tmp6 = 0.0
    tmp7 = tmp5 >= tmp6
    tmp8 = 4.0
    tmp9 = tmp5 < tmp8
    tmp11 = tmp10 * tmp1
    tmp12 = tmp11 + tmp3
    tmp13 = libdevice.nearbyint(tmp12)
    tmp14 = tmp13 >= tmp6
    tmp15 = tmp13 < tmp8
    tmp16 = tmp14 & tmp15
    tmp17 = tmp9 & tmp16
    tmp18 = tmp7 & tmp17
    tmp19 = tmp13.to(tl.int64)
    tmp20 = tl.full([1], 0, tl.int64)
    tmp21 = tl.where(tmp18, tmp19, tmp20)
    tmp22 = tl.full([XBLOCK], 4, tl.int32)
    tmp23 = tmp21 + tmp22
    tmp24 = tmp21 < 0
    tmp25 = tl.where(tmp24, tmp23, tmp21)
    tl.device_assert((0 <= tmp25) & (tmp25 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp25 < 4')
    tmp27 = tmp5.to(tl.int64)
    tmp28 = tl.where(tmp18, tmp27, tmp20)
    tmp29 = tmp28 + tmp22
    tmp30 = tmp28 < 0
    tmp31 = tl.where(tmp30, tmp29, tmp28)
    tl.device_assert((0 <= tmp31) & (tmp31 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp31 < 4')
    tmp33 = tl.load(in_ptr1 + (tmp31 + 4 * tmp25 + 16 * x3), xmask,
        eviction_policy='evict_last')
    tmp34 = tl.full([1], 1, tl.int64)
    tmp35 = tl.where(tmp18, tmp34, tmp20)
    tmp36 = tmp35.to(tl.float32)
    tmp37 = tmp33 * tmp36
    tl.store(out_ptr0 + x4, tmp37, 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)
        buf2 = empty_strided_cuda((1, 4, 4, 3), (48, 12, 3, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_fill_0[grid(48)](buf2, 48, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf3 = empty_strided_cuda((1, 3, 2), (6, 2, 1), torch.float32)
        triton_poi_fused_div_lift_fresh_1[grid(6)](buf3, 6, XBLOCK=8,
            num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((1, 16, 2), (32, 2, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf2, (1, 16, 3), (48, 3, 1),
            0), buf3, out=buf4)
        del buf2
        del buf3
        buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_grid_sampler_2d_2[grid(256)](buf4, arg0_1, buf5, 
            256, XBLOCK=256, num_warps=4, num_stages=1)
        del arg0_1
        del buf4
    return buf5,


class RotateNew(nn.Module):

    def __init__(self, angle: 'float') ->None:
        super().__init__()
        self.angle = angle

    def extra_repr(self) ->str:
        return f'factor={self.angle}'

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


Measured latency_ms: 0.014123