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, math as tl_math
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_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 2
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 1, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.full([1], 0, tl.int64)
    tmp4 = tl.full([1], 2, tl.int64)
    tmp5 = tl.where(tmp2, tmp3, tmp4)
    tmp6 = tl.load(in_ptr0 + tmp5, xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x0, tmp6, xmask)


@triton.jit
def triton_poi_fused_grid_sampler_2d_1(in_out_ptr0, in_ptr0, in_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 1)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp30 = tl.load(in_ptr0 + 0)
    tmp31 = tl.broadcast_to(tmp30, [XBLOCK])
    tmp2 = 1.5
    tmp3 = tmp1 * tmp2
    tmp4 = tmp3 + tmp2
    tmp5 = 0.0
    tmp6 = tmp4 - tmp5
    tmp7 = tl_math.abs(tmp6)
    tmp8 = 0.3333333333333333
    tmp9 = tmp7 * tmp8
    tmp10 = libdevice.floor(tmp9)
    tmp11 = tmp10.to(tl.int8)
    tmp12 = tl.full([1], 1, tl.int8)
    tmp13 = tmp11 & tmp12
    tmp14 = tl.full([1], 0, tl.int8)
    tmp15 = tmp13 == tmp14
    tmp16 = 3.0
    tmp17 = libdevice.fmod(tmp7, tmp16)
    tmp18 = tmp17 + tmp5
    tmp19 = tmp16 - tmp17
    tmp20 = tl.where(tmp15, tmp18, tmp19)
    tmp21 = triton_helpers.maximum(tmp20, tmp5)
    tmp22 = triton_helpers.minimum(tmp21, tmp16)
    tmp23 = libdevice.floor(tmp22)
    tmp24 = 1.0
    tmp25 = tmp23 + tmp24
    tmp26 = tmp25 >= tmp5
    tmp27 = 4.0
    tmp28 = tmp25 < tmp27
    tmp29 = tmp26 & tmp28
    tmp32 = tmp31 * tmp2
    tmp33 = tmp32 + tmp2
    tmp34 = tmp33 - tmp5
    tmp35 = tl_math.abs(tmp34)
    tmp36 = tmp35 * tmp8
    tmp37 = libdevice.floor(tmp36)
    tmp38 = tmp37.to(tl.int8)
    tmp39 = tmp38 & tmp12
    tmp40 = tmp39 == tmp14
    tmp41 = libdevice.fmod(tmp35, tmp16)
    tmp42 = tmp41 + tmp5
    tmp43 = tmp16 - tmp41
    tmp44 = tl.where(tmp40, tmp42, tmp43)
    tmp45 = triton_helpers.maximum(tmp44, tmp5)
    tmp46 = triton_helpers.minimum(tmp45, tmp16)
    tmp47 = libdevice.floor(tmp46)
    tmp48 = tmp47 >= tmp5
    tmp49 = tmp47 < tmp27
    tmp50 = tmp49 & tmp29
    tmp51 = tmp48 & tmp50
    tmp52 = tmp47 + tmp24
    tmp53 = tmp52 < tmp27
    tmp54 = tmp53 & tmp29
    tmp55 = tmp23 >= tmp5
    tmp56 = tmp23 < tmp27
    tmp57 = tmp55 & tmp56
    tmp58 = tmp53 & tmp57
    tmp59 = tmp49 & tmp57
    tmp60 = tmp52 - tmp46
    tmp61 = tmp22 - tmp23
    tmp62 = tmp60 * tmp61
    tmp63 = tmp46 - tmp47
    tmp64 = tmp25 - tmp22
    tmp65 = tmp63 * tmp64
    tmp66 = tmp52 >= tmp5
    tmp67 = tmp66 & tmp58
    tmp68 = tl.where(tmp67, tmp65, tmp5)
    tmp69 = tmp63 * tmp61
    tmp70 = tmp66 & tmp54
    tmp71 = tl.where(tmp70, tmp69, tmp5)
    tmp72 = tmp60 * tmp64
    tmp73 = tmp52.to(tl.int64)
    tmp74 = tl.full([1], 0, tl.int64)
    tmp75 = tl.where(tmp67, tmp73, tmp74)
    tmp76 = tmp23.to(tl.int64)
    tmp77 = tl.where(tmp67, tmp76, tmp74)
    tmp78 = tl.where(tmp70, tmp73, tmp74)
    tmp79 = tmp25.to(tl.int64)
    tmp80 = tl.where(tmp70, tmp79, tmp74)
    tmp81 = tl.where(tmp51, tmp79, tmp74)
    tmp82 = tmp48 & tmp59
    tmp83 = tmp47.to(tl.int64)
    tmp84 = tl.where(tmp82, tmp83, tmp74)
    tmp85 = tl.where(tmp82, tmp76, tmp74)
    tmp86 = tl.full([XBLOCK], 4, tl.int32)
    tmp87 = tmp85 + tmp86
    tmp88 = tmp85 < 0
    tmp89 = tl.where(tmp88, tmp87, tmp85)
    tl.device_assert((0 <= tmp89) & (tmp89 < 4),
        'index out of bounds: 0 <= tmp89 < 4')
    tmp91 = tmp84 + tmp86
    tmp92 = tmp84 < 0
    tmp93 = tl.where(tmp92, tmp91, tmp84)
    tl.device_assert((0 <= tmp93) & (tmp93 < 4),
        'index out of bounds: 0 <= tmp93 < 4')
    tmp95 = tl.load(in_ptr1 + (tmp93 + 4 * tmp89 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp96 = tl.where(tmp82, tmp72, tmp5)
    tmp97 = tmp95 * tmp96
    tmp98 = tmp81 + tmp86
    tmp99 = tmp81 < 0
    tmp100 = tl.where(tmp99, tmp98, tmp81)
    tl.device_assert((0 <= tmp100) & (tmp100 < 4),
        'index out of bounds: 0 <= tmp100 < 4')
    tmp102 = tl.where(tmp51, tmp83, tmp74)
    tmp103 = tmp102 + tmp86
    tmp104 = tmp102 < 0
    tmp105 = tl.where(tmp104, tmp103, tmp102)
    tl.device_assert((0 <= tmp105) & (tmp105 < 4),
        'index out of bounds: 0 <= tmp105 < 4')
    tmp107 = tl.load(in_ptr1 + (tmp105 + 4 * tmp100 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp108 = tmp77 + tmp86
    tmp109 = tmp77 < 0
    tmp110 = tl.where(tmp109, tmp108, tmp77)
    tl.device_assert((0 <= tmp110) & (tmp110 < 4),
        'index out of bounds: 0 <= tmp110 < 4')
    tmp112 = tmp75 + tmp86
    tmp113 = tmp75 < 0
    tmp114 = tl.where(tmp113, tmp112, tmp75)
    tl.device_assert((0 <= tmp114) & (tmp114 < 4),
        'index out of bounds: 0 <= tmp114 < 4')
    tmp116 = tl.load(in_ptr1 + (tmp114 + 4 * tmp110 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp117 = tmp116 * tmp68
    tmp118 = tmp97 + tmp117
    tmp119 = tl.where(tmp51, tmp62, tmp5)
    tmp120 = tmp107 * tmp119
    tmp121 = tmp118 + tmp120
    tmp122 = tmp80 + tmp86
    tmp123 = tmp80 < 0
    tmp124 = tl.where(tmp123, tmp122, tmp80)
    tl.device_assert((0 <= tmp124) & (tmp124 < 4),
        'index out of bounds: 0 <= tmp124 < 4')
    tmp126 = tmp78 + tmp86
    tmp127 = tmp78 < 0
    tmp128 = tl.where(tmp127, tmp126, tmp78)
    tl.device_assert((0 <= tmp128) & (tmp128 < 4),
        'index out of bounds: 0 <= tmp128 < 4')
    tmp130 = tl.load(in_ptr1 + (tmp128 + 4 * tmp124 + 16 * x0), xmask,
        eviction_policy='evict_last')
    tmp131 = tmp130 * tmp71
    tmp132 = tmp121 + tmp131
    tl.store(in_out_ptr0 + x0, tmp132, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (1, 1, 1, 3), (3, 3, 3, 1))
    assert_size_stride(primals_2, (1, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 1, 1, 2), (2, 2, 2, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_index_0[grid(2)](primals_1, buf0, 2, XBLOCK=2,
            num_warps=1, num_stages=1)
        del primals_1
        buf2 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
        buf12 = buf2
        del buf2
        buf21 = buf12
        del buf12
        triton_poi_fused_grid_sampler_2d_1[grid(4)](buf21, buf0, primals_2,
            4, XBLOCK=4, num_warps=1, num_stages=1)
    return reinterpret_tensor(buf21, (1, 4), (1, 1), 0), primals_2, buf0


class FeatureVolumeNew(nn.Module):

    def __init__(self, fdim, fsize):
        super().__init__()
        self.fsize = fsize
        self.fdim = fdim
        var = 0.01
        self.fmx = nn.Parameter(torch.randn(1, fdim, fsize, fsize) * var)
        self.sparse = None
        self.padding_mode = 'reflection'

    def forward(self, input_0):
        primals_2 = self.fmx
        primals_1 = input_0
        output = call([primals_1, primals_2])
        return output[0]


Measured latency_ms: 0.028133