# 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/g3/cg3mfadxgphtenefky47kftf2p2dv334tfphh2toa2vuyiazyvln.py
# Topologically Sorted Source Nodes: [getitem], Original ATen: [aten.index]
# Source node to ATen node mapping:
#   getitem => index
# Graph fragment:
#   %index : [num_users=2] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_1, [None, None, None, %lift_fresh_copy]), kwargs = {})
triton_poi_fused_index_0 = async_compile.triton('triton_poi_fused_index_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=[2], 
    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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_index_0', 'mutated_arg_names': [], '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_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)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/2d/c2dpfkbop3alquzx4ydewgj6ypbtbtij4kb62w4cxlumzdfyb3hp.py
# Topologically Sorted Source Nodes: [grid_sample], Original ATen: [aten.grid_sampler_2d]
# Source node to ATen node mapping:
#   grid_sample => abs_1, abs_2, add, add_1, add_2, add_3, add_4, add_5, add_6, add_7, add_8, bitwise_and, bitwise_and_1, clamp_max, clamp_max_1, clamp_min, clamp_min_1, convert_element_type, convert_element_type_1, convert_element_type_2, convert_element_type_3, convert_element_type_4, convert_element_type_7, div, div_1, eq, eq_1, floor, floor_1, floor_2, floor_3, fmod, fmod_1, full_default, full_default_2, ge, ge_1, ge_2, ge_5, index_1, index_2, index_3, index_4, logical_and, logical_and_1, logical_and_10, logical_and_11, logical_and_2, logical_and_4, logical_and_5, logical_and_6, logical_and_7, logical_and_8, lt, lt_1, lt_2, lt_5, mul, mul_1, mul_2, mul_3, mul_4, mul_5, mul_6, mul_7, mul_8, mul_9, sub, sub_1, sub_2, sub_3, sub_4, sub_5, sub_6, sub_9, where, where_1, where_10, where_11, where_12, where_13, where_2, where_3, where_4, where_5, where_6, where_7, where_9
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select, 1.5), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, 1.5), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add, 0.0), kwargs = {})
#   %abs_1 : [num_users=2] = call_function[target=torch.ops.aten.abs.default](args = (%sub,), kwargs = {})
#   %fmod : [num_users=2] = call_function[target=torch.ops.aten.fmod.Scalar](args = (%abs_1, 3.0), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%abs_1, 3.0), kwargs = {})
#   %floor : [num_users=1] = call_function[target=torch.ops.aten.floor.default](args = (%div,), kwargs = {})
#   %convert_element_type : [num_users=1] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%floor, torch.int8), kwargs = {})
#   %bitwise_and : [num_users=1] = call_function[target=torch.ops.aten.bitwise_and.Scalar](args = (%convert_element_type, 1), kwargs = {})
#   %eq : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%bitwise_and, 0), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%fmod, 0.0), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (3.0, %fmod), kwargs = {})
#   %where : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%eq, %add_1, %sub_1), kwargs = {})
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%where, 0), kwargs = {})
#   %clamp_max : [num_users=3] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min, 3), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%select_1, 1.5), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_1, 1.5), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_2, 0.0), kwargs = {})
#   %abs_2 : [num_users=2] = call_function[target=torch.ops.aten.abs.default](args = (%sub_2,), kwargs = {})
#   %fmod_1 : [num_users=2] = call_function[target=torch.ops.aten.fmod.Scalar](args = (%abs_2, 3.0), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%abs_2, 3.0), kwargs = {})
#   %floor_1 : [num_users=1] = call_function[target=torch.ops.aten.floor.default](args = (%div_1,), kwargs = {})
#   %convert_element_type_1 : [num_users=1] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%floor_1, torch.int8), kwargs = {})
#   %bitwise_and_1 : [num_users=1] = call_function[target=torch.ops.aten.bitwise_and.Scalar](args = (%convert_element_type_1, 1), kwargs = {})
#   %eq_1 : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%bitwise_and_1, 0), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%fmod_1, 0.0), kwargs = {})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (3.0, %fmod_1), kwargs = {})
#   %where_1 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%eq_1, %add_3, %sub_3), kwargs = {})
#   %clamp_min_1 : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%where_1, 0), kwargs = {})
#   %clamp_max_1 : [num_users=3] = call_function[target=torch.ops.aten.clamp_max.default](args = (%clamp_min_1, 3), kwargs = {})
#   %floor_2 : [num_users=5] = call_function[target=torch.ops.aten.floor.default](args = (%clamp_max,), kwargs = {})
#   %floor_3 : [num_users=5] = call_function[target=torch.ops.aten.floor.default](args = (%clamp_max_1,), kwargs = {})
#   %add_4 : [num_users=4] = call_function[target=torch.ops.aten.add.Tensor](args = (%floor_2, 1), kwargs = {})
#   %add_5 : [num_users=4] = call_function[target=torch.ops.aten.add.Tensor](args = (%floor_3, 1), kwargs = {})
#   %sub_4 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_4, %clamp_max), kwargs = {})
#   %sub_5 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_5, %clamp_max_1), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_4, %sub_5), kwargs = {})
#   %sub_6 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%clamp_max, %floor_2), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_6, %sub_5), kwargs = {})
#   %sub_9 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%clamp_max_1, %floor_3), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_4, %sub_9), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_6, %sub_9), kwargs = {})
#   %ge : [num_users=2] = call_function[target=torch.ops.aten.ge.Scalar](args = (%floor_2, 0), kwargs = {})
#   %lt : [num_users=2] = call_function[target=torch.ops.aten.lt.Scalar](args = (%floor_2, 4), kwargs = {})
#   %ge_1 : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%floor_3, 0), kwargs = {})
#   %lt_1 : [num_users=1] = call_function[target=torch.ops.aten.lt.Scalar](args = (%floor_3, 4), kwargs = {})
#   %logical_and : [num_users=2] = call_function[target=torch.ops.aten.logical_and.default](args = (%ge_1, %lt_1), kwargs = {})
#   %logical_and_1 : [num_users=1] = call_function[target=torch.ops.aten.logical_and.default](args = (%lt, %logical_and), kwargs = {})
#   %logical_and_2 : [num_users=3] = call_function[target=torch.ops.aten.logical_and.default](args = (%ge, %logical_and_1), kwargs = {})
#   %convert_element_type_2 : [num_users=2] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%floor_2, torch.int64), kwargs = {})
#   %convert_element_type_3 : [num_users=2] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%floor_3, torch.int64), kwargs = {})
#   %full_default : [num_users=8] = call_function[target=torch.ops.aten.full.default](args = ([], 0), kwargs = {dtype: torch.int64, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where_2 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_2, %convert_element_type_2, %full_default), kwargs = {})
#   %where_3 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_2, %convert_element_type_3, %full_default), kwargs = {})
#   %full_default_2 : [num_users=4] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where_4 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_2, %mul_2, %full_default_2), kwargs = {})
#   %index_1 : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_2, [%view_2, %view_3, %where_3, %where_2]), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index_1, %where_4), kwargs = {})
#   %ge_2 : [num_users=2] = call_function[target=torch.ops.aten.ge.Scalar](args = (%add_4, 0), kwargs = {})
#   %lt_2 : [num_users=2] = call_function[target=torch.ops.aten.lt.Scalar](args = (%add_4, 4), kwargs = {})
#   %logical_and_4 : [num_users=1] = call_function[target=torch.ops.aten.logical_and.default](args = (%lt_2, %logical_and), kwargs = {})
#   %logical_and_5 : [num_users=3] = call_function[target=torch.ops.aten.logical_and.default](args = (%ge_2, %logical_and_4), kwargs = {})
#   %convert_element_type_4 : [num_users=2] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%add_4, torch.int64), kwargs = {})
#   %where_5 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_5, %convert_element_type_4, %full_default), kwargs = {})
#   %where_6 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_5, %convert_element_type_3, %full_default), kwargs = {})
#   %where_7 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_5, %mul_3, %full_default_2), kwargs = {})
#   %index_2 : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_2, [%view_2, %view_3, %where_6, %where_5]), kwargs = {})
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index_2, %where_7), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_6, %mul_7), kwargs = {})
#   %ge_5 : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%add_5, 0), kwargs = {})
#   %lt_5 : [num_users=1] = call_function[target=torch.ops.aten.lt.Scalar](args = (%add_5, 4), kwargs = {})
#   %logical_and_6 : [num_users=2] = call_function[target=torch.ops.aten.logical_and.default](args = (%ge_5, %lt_5), kwargs = {})
#   %logical_and_7 : [num_users=1] = call_function[target=torch.ops.aten.logical_and.default](args = (%lt, %logical_and_6), kwargs = {})
#   %logical_and_8 : [num_users=3] = call_function[target=torch.ops.aten.logical_and.default](args = (%ge, %logical_and_7), kwargs = {})
#   %convert_element_type_7 : [num_users=2] = call_function[target=torch.ops.prims.convert_element_type.default](args = (%add_5, torch.int64), kwargs = {})
#   %where_9 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_8, %convert_element_type_7, %full_default), kwargs = {})
#   %where_10 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_8, %mul_4, %full_default_2), kwargs = {})
#   %index_3 : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_2, [%view_2, %view_3, %where_9, %where_8]), kwargs = {})
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index_3, %where_10), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_6, %mul_8), kwargs = {})
#   %logical_and_10 : [num_users=1] = call_function[target=torch.ops.aten.logical_and.default](args = (%lt_2, %logical_and_6), kwargs = {})
#   %logical_and_11 : [num_users=3] = call_function[target=torch.ops.aten.logical_and.default](args = (%ge_2, %logical_and_10), kwargs = {})
#   %where_11 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_11, %convert_element_type_4, %full_default), kwargs = {})
#   %where_12 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_11, %convert_element_type_7, %full_default), kwargs = {})
#   %where_13 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%logical_and_11, %mul_5, %full_default_2), kwargs = {})
#   %index_4 : [num_users=1] = call_function[target=torch.ops.aten.index.Tensor](args = (%primals_2, [%view_2, %view_3, %where_12, %where_11]), kwargs = {})
#   %mul_9 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%index_4, %where_13), kwargs = {})
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_7, %mul_9), kwargs = {})
triton_poi_fused_grid_sampler_2d_1 = async_compile.triton('triton_poi_fused_grid_sampler_2d_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=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '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_grid_sampler_2d_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_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)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

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)
        # Topologically Sorted Source Nodes: [getitem], Original ATen: [aten.index]
        stream0 = get_raw_stream(0)
        triton_poi_fused_index_0.run(primals_1, buf0, 2, grid=grid(2), stream=stream0)
        del primals_1
        buf2 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
        buf12 = buf2; del buf2  # reuse
        buf21 = buf12; del buf12  # reuse
        # Topologically Sorted Source Nodes: [grid_sample], Original ATen: [aten.grid_sampler_2d]
        triton_poi_fused_grid_sampler_2d_1.run(buf21, buf0, primals_2, 4, grid=grid(4), stream=stream0)
    return (reinterpret_tensor(buf21, (1, 4), (1, 1), 0), primals_2, buf0, )


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((1, 1, 1, 3), (3, 3, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((1, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2])
    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
import torch.nn as nn
import torch.nn.functional as F


class FeatureVolume(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, x):
        N = x.shape[0]
        if len(x.shape) == 3:
            sample_coords = x.reshape(1, N, x.shape[1], 3)
            sampley = F.grid_sample(self.fmx, sample_coords[..., [0, 2]],
                align_corners=True, padding_mode=self.padding_mode)[0, :, :, :
                ].transpose(0, 1)
        else:
            sample_coords = x.reshape(1, N, 1, 3)
            sampley = F.grid_sample(self.fmx, sample_coords[..., [0, 2]],
                align_corners=True, padding_mode=self.padding_mode)[0, :, :, 0
                ].transpose(0, 1)
        return sampley


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


def get_init_inputs():
    return [[], {'fdim': 4, 'fsize': 4}]

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]
