# AOT ID: ['15_inference']
from ctypes import c_void_p, c_long
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
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
alloc_from_pool = torch.ops.inductor._alloc_from_pool
reinterpret_tensor = torch.ops.inductor._reinterpret_tensor
async_compile = AsyncCompile()
# kernel path: /tmp/torchinductor_root/ez/cezduj4uzpjjqnjw6t2actaaxirsq2fzqbvpinmwh7nqnwdydabj.py
# Source Nodes: [abs_1, abs_2, le, le_1, local_mask, offset_x, offset_y, sub, sub_1], Original ATen: [aten.abs, aten.add, aten.bitwise_and, aten.le, aten.sub]
# abs_1 => abs_1
# abs_2 => abs_2
# le => le
# le_1 => le_1
# local_mask => bitwise_and
# offset_x => add_8
# offset_y => add_7
# sub => sub_10
# sub_1 => sub_11
triton_poi_fused_abs_add_bitwise_and_le_sub_0 = async_compile.triton('triton_', '''
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=[536870912],
filename=__file__,
triton_meta={'signature': {0: '*i1', 1: 'i32', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0,), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_abs_add_bitwise_and_le_sub_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 0, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(out_ptr0, ks0, ks1, xnumel, XBLOCK : tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % ks0
x1 = (xindex // ks0)
x2 = xindex
tmp0 = tl_math.abs(7 + ((-1)*(x0 // (14 + ks1))) + (x1 // ks1))
tmp1 = tl.full([1], 7, tl.int64)
tmp2 = tmp0 <= tmp1
tmp3 = tl_math.abs(7 + ((-1)*(x0 % (14 + ks1))) + (x1 % ks1))
tmp4 = tmp3 <= tmp1
tmp5 = tmp2 & tmp4
tl.store(out_ptr0 + (x2), tmp5, xmask)
''', device_str='cuda')
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
# kernel path: /tmp/torchinductor_root/7a/c7aivb6nuzjina3frpf52qjeuloxbnk7o2dow7w33nysppkburwr.py
# Source Nodes: [local_attn, mul_1, qk_1, qk_2], Original ATen: [aten._softmax, aten.add, aten.mul, aten.sub]
# local_attn => amax, exp, sub_1, sum_1
# mul_1 => mul_1
# qk_1 => add
# qk_2 => sub
triton_red_fused__softmax_add_mul_sub_1 = async_compile.triton('triton_', '''
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.reduction(
size_hints=[32768, 256],
reduction_hint=ReductionHint.DEFAULT,
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: 'i32', 7: 'i32', 8: 'i32', 9: 'i32', 10: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_red_fused__softmax_add_mul_sub_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 6, 'num_reduction': 2, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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}
)
@triton.jit
def triton_(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, ks0, ks1, ks2, ks3, xnumel, rnumel, XBLOCK : tl.constexpr, RBLOCK : tl.constexpr):
rnumel = 225
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
_tmp9 = tl.full([XBLOCK, RBLOCK], float("-inf"), tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (x0 + (ks0*ks1*r1)), rmask & xmask, eviction_policy='evict_last', other=0.0).to(tl.float32)
tmp1 = tl.load(in_ptr1 + (x0 + (ks2*ks3*r1)), rmask & xmask, eviction_policy='evict_last', other=0.0).to(tl.float32)
tmp4 = tl.load(in_ptr2 + (x0 + (ks2*ks3*r1)), rmask & xmask, eviction_policy='evict_last', other=0.0)
tmp2 = tmp0 + tmp1
tmp3 = tmp2.to(tl.float32)
tmp5 = 10000.0
tmp6 = tmp4 * tmp5
tmp7 = tmp3 - tmp6
tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK])
tmp10 = triton_helpers.maximum(_tmp9, tmp8)
_tmp9 = tl.where(rmask & xmask, tmp10, _tmp9)
tmp9 = triton_helpers.max2(_tmp9, 1)[:, None]
tl.store(out_ptr0 + (x0), tmp9, xmask)
_tmp22 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp11 = tl.load(in_ptr0 + (x0 + (ks0*ks1*r1)), rmask & xmask, eviction_policy='evict_first', other=0.0).to(tl.float32)
tmp12 = tl.load(in_ptr1 + (x0 + (ks2*ks3*r1)), rmask & xmask, eviction_policy='evict_first', other=0.0).to(tl.float32)
tmp15 = tl.load(in_ptr2 + (x0 + (ks2*ks3*r1)), rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp13 = tmp11 + tmp12
tmp14 = tmp13.to(tl.float32)
tmp16 = 10000.0
tmp17 = tmp15 * tmp16
tmp18 = tmp14 - tmp17
tmp19 = tmp18 - tmp9
tmp20 = tl_math.exp(tmp19)
tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK])
tmp23 = _tmp22 + tmp21
_tmp22 = tl.where(rmask & xmask, tmp23, _tmp22)
tmp22 = tl.sum(_tmp22, 1)[:, None]
tl.store(out_ptr1 + (x0), tmp22, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/zj/czju4nuz6bmdvnvdlr2h7l6ov3e3m3bonx3ombckdexpztpy6uyp.py
# Source Nodes: [agg_bias, local_attn, mul_1, qk_1, qk_2], Original ATen: [aten._softmax, aten._to_copy, aten.add, aten.mul, aten.sub]
# agg_bias => convert_element_type_2
# local_attn => div, exp, sub_1
# mul_1 => mul_1
# qk_1 => add
# qk_2 => sub
triton_poi_fused__softmax__to_copy_add_mul_sub_2 = async_compile.triton('triton_', '''
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=[4194304],
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp16', 7: 'i32', 8: 'i32', 9: 'i32', 10: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax__to_copy_add_mul_sub_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, ks0, ks1, ks2, xnumel, XBLOCK : tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % ks0
x1 = (xindex // ks0)
tmp0 = tl.load(in_ptr0 + (x2), xmask, eviction_policy='evict_last').to(tl.float32)
tmp1 = tl.load(in_ptr1 + (x0 + (ks1*ks2*x1)), xmask, eviction_policy='evict_last').to(tl.float32)
tmp4 = tl.load(in_ptr2 + (x0 + (ks1*ks2*x1)), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr3 + (x0), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr4 + (x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tmp2.to(tl.float32)
tmp5 = 10000.0
tmp6 = tmp4 * tmp5
tmp7 = tmp3 - tmp6
tmp9 = tmp7 - tmp8
tmp10 = tl_math.exp(tmp9)
tmp12 = tmp10 / tmp11
tmp13 = tmp12.to(tl.float32)
tl.store(out_ptr0 + (x2), tmp12, xmask)
tl.store(out_ptr1 + (x2), tmp13, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/sg/csgjgipgtga6lvpvfcnjqbjn6n4jkhvrbtvmukwal7l4n725njmt.py
# Source Nodes: [global_attn], Original ATen: [aten.zeros]
# global_attn => full
triton_poi_fused_zeros_3 = async_compile.triton('triton_', '''
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=[536870912],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0,), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_zeros_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 0, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(out_ptr0, xnumel, XBLOCK : tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = 0.0
tl.store(out_ptr0 + (x0), tmp0, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/ih/cih5ghbmux6szyi3feaqe3pypk4qvp6slxfpnd2plu62tvtk5foi.py
# Source Nodes: [reshape_4], Original ATen: [aten.clone]
# reshape_4 => clone_5
triton_poi_fused_clone_4 = async_compile.triton('triton_', '''
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=[32768, 256], tile_hint=TileHint.DEFAULT,
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32', 4: 'i32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clone_4', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, ks0, ks1, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
xnumel = 225
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + (ks0*ks1*x1)), xmask & ymask, eviction_policy='evict_last')
tl.store(out_ptr0 + (x1 + (225*y0)), tmp0, xmask & ymask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/zx/czxw3mnytupgnexvg3ys6eqs6g3aqh2ihgojoweydctmesftrxw5.py
# Source Nodes: [global_attn, setitem], Original ATen: [aten.index_put, aten.zeros]
# global_attn => full
# setitem => index_put
triton_poi_fused_index_put_zeros_5 = async_compile.triton('triton_', '''
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=[4194304],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32', 3: 'i32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_index_put_zeros_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, ks0, ks1, xnumel, XBLOCK : tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (xindex % (225*ks0*ks1)), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + (x0), tmp0, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/oc/cockoktgafrxu7hsaffdvdr2lmgwxqvxouejspgeahjtj2daze3g.py
# Source Nodes: [agg_value], Original ATen: [aten._to_copy]
# agg_value => convert_element_type_6
triton_poi_fused__to_copy_6 = async_compile.triton('triton_', '''
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=[536870912],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32', 3: 'i32', 4: 'i32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, ks0, ks1, ks2, xnumel, XBLOCK : tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % ks0
x1 = (xindex // ks0)
x2 = xindex
tmp0 = tl.load(in_ptr0 + (105 + x0 + (7*ks2) + (14*(x0 // ks2)) + (196*x1) + (14*ks1*x1) + (14*ks2*x1) + (ks1*ks2*x1)), xmask, eviction_policy='evict_last')
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x2), tmp1, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/cl/cclksls4v7ba7njcwisdzvyytkuogytnf3vrmvpdgsafo6y3x5le.py
# Source Nodes: [agg_bias], Original ATen: [aten._to_copy]
# agg_bias => convert_element_type_3
triton_poi_fused__to_copy_7 = async_compile.triton('triton_', '''
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=[65536],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_7', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 57600
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), xmask)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/nt/cnteoqw3bgqa7hk4uioapq67wzhtraarsdzln2qrli2gyfjipxry.py
# Source Nodes: [add_5], Original ATen: [aten.add]
# add_5 => add_9
triton_poi_fused_add_8 = async_compile.triton('triton_', '''
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=[8388608],
filename=__file__,
triton_meta={'signature': {0: '*fp16', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_8', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + (x0), xmask).to(tl.float32)
tmp1 = tl.load(in_ptr0 + (x0), xmask).to(tl.float32)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + (x0), tmp2, xmask)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/z6/cz6xyjuhhw7ltpd3r5was52efdrbhgij2q5o427a445lhgnppbsl.py
# Source Nodes: [output_1], Original ATen: [aten._to_copy]
# output_1 => convert_element_type_10
triton_poi_fused__to_copy_9 = async_compile.triton('triton_', '''
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=[65536],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_9', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
xnumel = 65536
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, None)
''', device_str='cuda')
# kernel path: /tmp/torchinductor_root/uv/cuvzghjjuq7bbuannslkwhorgmlskgj27naqrmgwguptxzoq2q54.py
# Source Nodes: [output_1], Original ATen: [aten._to_copy]
# output_1 => convert_element_type_9
triton_poi_fused__to_copy_10 = async_compile.triton('triton_', '''
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=[256],
filename=__file__,
triton_meta={'signature': {0: '*fp32', 1: '*fp16', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=89, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=1536, multi_processor_count=58), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__to_copy_10', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': '72c34bdb145549777ca2f0838f26abe42bb446cf528c78d229508b5a55e67a78', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': False, '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_(in_ptr0, 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
tmp0 = tl.load(in_ptr0 + (x0), xmask)
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + (x0), tmp1, xmask)
''', device_str='cuda')
async_compile.wait(globals())
del async_compile
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_1, arg9_1, arg10_1 = args
args.clear()
s0 = arg0_1
s1 = arg1_1
s2 = arg3_1
s3 = arg4_1
assert_size_stride(arg2_1, (1, 15, 15, s0, s1), (225*s0*s1, 15*s0*s1, s0*s1, s1, 1))
assert_size_stride(arg5_1, (1, 1, 225, s0*s1), (225*s0*s1, 225*s0*s1, s0*s1, 1))
assert_size_stride(arg6_1, (1, 1, 225, s0*s1), (225*s0*s1, 225*s0*s1, s0*s1, 1))
assert_size_stride(arg7_1, (1, 256, 225), (57600, 225, 1))
assert_size_stride(arg8_1, (1, 1, 256, s2*s3), (256*s2*s3, 256*s2*s3, s2*s3, 1))
assert_size_stride(arg9_1, (256, 256), (256, 1))
assert_size_stride(arg10_1, (256, ), (1, ))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
ps0 = 196 + (14*s2) + (14*s3) + (s2*s3)
buf0 = empty_strided_cuda((s2*s3, 196 + (14*s2) + (14*s3) + (s2*s3)), (196 + (14*s2) + (14*s3) + (s2*s3), 1), torch.bool)
# Source Nodes: [abs_1, abs_2, le, le_1, local_mask, offset_x, offset_y, sub, sub_1], Original ATen: [aten.abs, aten.add, aten.bitwise_and, aten.le, aten.sub]
triton_poi_fused_abs_add_bitwise_and_le_sub_0_xnumel = ((s2*s2)*(s3*s3)) + (14*s2*(s3*s3)) + (14*s3*(s2*s2)) + (196*s2*s3)
stream0 = get_raw_stream(0)
triton_poi_fused_abs_add_bitwise_and_le_sub_0.run(buf0, ps0, s3, triton_poi_fused_abs_add_bitwise_and_le_sub_0_xnumel, grid=grid(triton_poi_fused_abs_add_bitwise_and_le_sub_0_xnumel), stream=stream0)
buf1 = empty_strided_cuda((1, 1, 1, s2*s3), (s2*s3, s2*s3, s2*s3, 1), torch.float32)
buf2 = empty_strided_cuda((1, 1, 1, s2*s3), (s2*s3, s2*s3, s2*s3, 1), torch.float32)
# Source Nodes: [local_attn, mul_1, qk_1, qk_2], Original ATen: [aten._softmax, aten.add, aten.mul, aten.sub]
triton_red_fused__softmax_add_mul_sub_1_xnumel = s2*s3
triton_red_fused__softmax_add_mul_sub_1.run(arg2_1, arg5_1, arg6_1, buf1, buf2, s2, s3, s0, s1, triton_red_fused__softmax_add_mul_sub_1_xnumel, 225, grid=grid(triton_red_fused__softmax_add_mul_sub_1_xnumel), stream=stream0)
ps1 = s2*s3
buf3 = empty_strided_cuda((1, 1, 225, s2*s3), (225*s2*s3, 225*s2*s3, s2*s3, 1), torch.float32)
buf11 = empty_strided_cuda((1, 1, 225, s2*s3), (225*s2*s3, 1, s2*s3, 1), torch.float16)
# Source Nodes: [agg_bias, local_attn, mul_1, qk_1, qk_2], Original ATen: [aten._softmax, aten._to_copy, aten.add, aten.mul, aten.sub]
triton_poi_fused__softmax__to_copy_add_mul_sub_2_xnumel = 225*s2*s3
triton_poi_fused__softmax__to_copy_add_mul_sub_2.run(arg2_1, arg5_1, arg6_1, buf1, buf2, buf3, buf11, ps1, s0, s1, triton_poi_fused__softmax__to_copy_add_mul_sub_2_xnumel, grid=grid(triton_poi_fused__softmax__to_copy_add_mul_sub_2_xnumel), stream=stream0)
del arg2_1
del arg5_1
del arg6_1
del buf1
del buf2
buf4 = empty_strided_cuda((1, 1, s2*s3, 14 + s2, 14 + s3), (((s2*s2)*(s3*s3)) + (14*s2*(s3*s3)) + (14*s3*(s2*s2)) + (196*s2*s3), ((s2*s2)*(s3*s3)) + (14*s2*(s3*s3)) + (14*s3*(s2*s2)) + (196*s2*s3), 196 + (14*s2) + (14*s3) + (s2*s3), 14 + s3, 1), torch.float32)
# Source Nodes: [global_attn], Original ATen: [aten.zeros]
triton_poi_fused_zeros_3_xnumel = ((s2*s2)*(s3*s3)) + (14*s2*(s3*s3)) + (14*s3*(s2*s2)) + (196*s2*s3)
triton_poi_fused_zeros_3.run(buf4, triton_poi_fused_zeros_3_xnumel, grid=grid(triton_poi_fused_zeros_3_xnumel), stream=stream0)
buf5 = empty_strided_cuda((1, 1, s2*s3, 225), (225*s2*s3, 1, 225, 1), torch.float32)
# Source Nodes: [reshape_4], Original ATen: [aten.clone]
triton_poi_fused_clone_4_ynumel = s2*s3
triton_poi_fused_clone_4.run(buf3, buf5, s2, s3, triton_poi_fused_clone_4_ynumel, 225, grid=grid(triton_poi_fused_clone_4_ynumel, 225), stream=stream0)
buf6 = empty_strided_cuda((225*s0*s1, ), (1, ), torch.float32)
# Source Nodes: [global_attn, setitem], Original ATen: [aten.index_put, aten.zeros]
triton_poi_fused_index_put_zeros_5_xnumel = 225*s0*s1
triton_poi_fused_index_put_zeros_5.run(buf5, buf6, s2, s3, triton_poi_fused_index_put_zeros_5_xnumel, grid=grid(triton_poi_fused_index_put_zeros_5_xnumel), stream=stream0)
del buf5
aten.index_put_(buf4, [reinterpret_tensor(buf0, (1, 1, s2*s3, 14 + s2, 14 + s3), (0, 0, 196 + (14*s2) + (14*s3) + (s2*s3), 14 + s3, 1), 0)], buf6, False)
del buf6
buf9 = empty_strided_cuda((1, 1, s2*s3, s2*s3), ((s2*s2)*(s3*s3), 1, s2*s3, 1), torch.float16)
# Source Nodes: [agg_value], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_6_xnumel = (s2*s2)*(s3*s3)
triton_poi_fused__to_copy_6.run(buf4, buf9, ps1, s2, s3, triton_poi_fused__to_copy_6_xnumel, grid=grid(triton_poi_fused__to_copy_6_xnumel), stream=stream0)
del buf4
buf10 = empty_strided_cuda((1, s2*s3, 256), (256*s2*s3, 256, 1), torch.float16)
# Source Nodes: [agg_value], Original ATen: [aten.bmm]
extern_kernels.bmm(reinterpret_tensor(buf9, (1, s2*s3, s2*s3), (0, s2*s3, 1), 0), reinterpret_tensor(arg8_1, (1, s2*s3, 256), (0, 1, s2*s3), 0), out=buf10)
del arg8_1
del buf9
buf12 = empty_strided_cuda((1, 256, 225), (57600, 225, 1), torch.float16)
# Source Nodes: [agg_bias], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_7.run(arg7_1, buf12, 57600, grid=grid(57600), stream=stream0)
del arg7_1
buf13 = empty_strided_cuda((1, s0*s1, 256), (256*s0*s1, 256, 1), torch.float16)
# Source Nodes: [agg_bias], Original ATen: [aten.bmm]
extern_kernels.bmm(reinterpret_tensor(buf11, (1, s0*s1, 225), (0, 1, s2*s3), 0), reinterpret_tensor(buf12, (1, 225, 256), (0, 1, 225), 0), out=buf13)
del buf11
del buf12
buf14 = reinterpret_tensor(buf10, (1, 1, s2*s3, 256), (256*s2*s3, 1, 256, 1), 0); del buf10 # reuse
# Source Nodes: [add_5], Original ATen: [aten.add]
triton_poi_fused_add_8_xnumel = 256*s2*s3
triton_poi_fused_add_8.run(buf14, buf13, triton_poi_fused_add_8_xnumel, grid=grid(triton_poi_fused_add_8_xnumel), stream=stream0)
del buf13
buf15 = empty_strided_cuda((256, 256), (256, 1), torch.float16)
# Source Nodes: [output_1], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_9.run(arg9_1, buf15, 65536, grid=grid(65536), stream=stream0)
del arg9_1
buf16 = empty_strided_cuda((256, ), (1, ), torch.float16)
# Source Nodes: [output_1], Original ATen: [aten._to_copy]
triton_poi_fused__to_copy_10.run(arg10_1, buf16, 256, grid=grid(256), stream=stream0)
del arg10_1
buf17 = empty_strided_cuda((s2*s3, 256), (256, 1), torch.float16)
# Source Nodes: [output_1], Original ATen: [aten._to_copy, aten.addmm]
extern_kernels.addmm(buf16, reinterpret_tensor(buf14, (s2*s3, 256), (256, 1), 0), reinterpret_tensor(buf15, (256, 256), (1, 256), 0), alpha=1, beta=1, out=buf17)
del buf14
del buf15
del buf16
return (reinterpret_tensor(buf17, (s2*s3, 1, 256), (256, 256, 1), 0), buf3, reinterpret_tensor(buf0, (1, 1, s2*s3, 14 + s2, 14 + s3), (((s2*s2)*(s3*s3)) + (14*s2*(s3*s3)) + (14*s3*(s2*s2)) + (196*s2*s3), ((s2*s2)*(s3*s3)) + (14*s2*(s3*s3)) + (14*s3*(s2*s2)) + (196*s2*s3), 196 + (14*s2) + (14*s3) + (s2*s3), 14 + s3, 1), 0), )
def benchmark_compiled_module(times=10, repeat=10):
from torch._dynamo.testing import rand_strided
from torch._inductor.utils import print_performance
arg0_1 = 136
arg1_1 = 136
arg2_1 = rand_strided((1, 15, 15, 136, 136), (4161600, 277440, 18496, 136, 1), device='cuda:0', dtype=torch.float16)
arg3_1 = 136
arg4_1 = 136
arg5_1 = rand_strided((1, 1, 225, 18496), (4161600, 4161600, 18496, 1), device='cuda:0', dtype=torch.float16)
arg6_1 = rand_strided((1, 1, 225, 18496), (4161600, 4161600, 18496, 1), device='cuda:0', dtype=torch.float32)
arg7_1 = rand_strided((1, 256, 225), (57600, 225, 1), device='cuda:0', dtype=torch.float32)
arg8_1 = rand_strided((1, 1, 256, 18496), (4734976, 4734976, 18496, 1), device='cuda:0', dtype=torch.float16)
arg9_1 = rand_strided((256, 256), (256, 1), device='cuda:0', dtype=torch.float32)
arg10_1 = rand_strided((256, ), (1, ), device='cuda:0', dtype=torch.float32)
fn = lambda: call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_1, arg9_1, arg10_1])
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)