# AOT ID: ['0_inference']
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/ks/cksqjkxhqokfmhaiyddd2sqanuybw23urbi4cptxkpiflxiuo3ta.py
# Topologically Sorted Source Nodes: [sub, add, abs_1, tvcomp1, sum_2], Original ATen: [aten.sub, aten.add, aten.abs, aten.sum]
# Source node to ATen node mapping:
#   abs_1 => abs_1
#   add => add
#   sub => sub
#   sum_2 => sum_2
#   tvcomp1 => sum_1
# Graph fragment:
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%slice_3, %slice_6), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub, 1e-06), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%add,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%abs_1, [0]), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_1, [0]), kwargs = {})
triton_poi_fused_abs_add_sub_sum_0 = async_compile.triton('triton_poi_fused_abs_add_sub_sum_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=[16], 
    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_abs_add_sub_sum_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 32, '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_abs_add_sub_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 12
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + x0), xmask)
    tmp1 = tl.load(in_ptr0 + (x0), xmask)
    tmp6 = tl.load(in_ptr0 + (68 + x0), xmask)
    tmp7 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp12 = tl.load(in_ptr0 + (132 + x0), xmask)
    tmp13 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp18 = tl.load(in_ptr0 + (196 + x0), xmask)
    tmp19 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (20 + x0), xmask)
    tmp25 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp29 = tl.load(in_ptr0 + (84 + x0), xmask)
    tmp30 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp35 = tl.load(in_ptr0 + (148 + x0), xmask)
    tmp36 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp41 = tl.load(in_ptr0 + (212 + x0), xmask)
    tmp42 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp48 = tl.load(in_ptr0 + (36 + x0), xmask)
    tmp49 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp53 = tl.load(in_ptr0 + (100 + x0), xmask)
    tmp54 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp59 = tl.load(in_ptr0 + (164 + x0), xmask)
    tmp60 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp65 = tl.load(in_ptr0 + (228 + x0), xmask)
    tmp66 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp72 = tl.load(in_ptr0 + (52 + x0), xmask)
    tmp73 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp77 = tl.load(in_ptr0 + (116 + x0), xmask)
    tmp78 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp83 = tl.load(in_ptr0 + (180 + x0), xmask)
    tmp84 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp89 = tl.load(in_ptr0 + (244 + x0), xmask)
    tmp90 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp2 = tmp0 - tmp1
    tmp3 = 1e-06
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.abs(tmp4)
    tmp8 = tmp6 - tmp7
    tmp9 = tmp8 + tmp3
    tmp10 = tl_math.abs(tmp9)
    tmp11 = tmp5 + tmp10
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 + tmp3
    tmp16 = tl_math.abs(tmp15)
    tmp17 = tmp11 + tmp16
    tmp20 = tmp18 - tmp19
    tmp21 = tmp20 + tmp3
    tmp22 = tl_math.abs(tmp21)
    tmp23 = tmp17 + tmp22
    tmp26 = tmp24 - tmp25
    tmp27 = tmp26 + tmp3
    tmp28 = tl_math.abs(tmp27)
    tmp31 = tmp29 - tmp30
    tmp32 = tmp31 + tmp3
    tmp33 = tl_math.abs(tmp32)
    tmp34 = tmp28 + tmp33
    tmp37 = tmp35 - tmp36
    tmp38 = tmp37 + tmp3
    tmp39 = tl_math.abs(tmp38)
    tmp40 = tmp34 + tmp39
    tmp43 = tmp41 - tmp42
    tmp44 = tmp43 + tmp3
    tmp45 = tl_math.abs(tmp44)
    tmp46 = tmp40 + tmp45
    tmp47 = tmp23 + tmp46
    tmp50 = tmp48 - tmp49
    tmp51 = tmp50 + tmp3
    tmp52 = tl_math.abs(tmp51)
    tmp55 = tmp53 - tmp54
    tmp56 = tmp55 + tmp3
    tmp57 = tl_math.abs(tmp56)
    tmp58 = tmp52 + tmp57
    tmp61 = tmp59 - tmp60
    tmp62 = tmp61 + tmp3
    tmp63 = tl_math.abs(tmp62)
    tmp64 = tmp58 + tmp63
    tmp67 = tmp65 - tmp66
    tmp68 = tmp67 + tmp3
    tmp69 = tl_math.abs(tmp68)
    tmp70 = tmp64 + tmp69
    tmp71 = tmp47 + tmp70
    tmp74 = tmp72 - tmp73
    tmp75 = tmp74 + tmp3
    tmp76 = tl_math.abs(tmp75)
    tmp79 = tmp77 - tmp78
    tmp80 = tmp79 + tmp3
    tmp81 = tl_math.abs(tmp80)
    tmp82 = tmp76 + tmp81
    tmp85 = tmp83 - tmp84
    tmp86 = tmp85 + tmp3
    tmp87 = tl_math.abs(tmp86)
    tmp88 = tmp82 + tmp87
    tmp91 = tmp89 - tmp90
    tmp92 = tmp91 + tmp3
    tmp93 = tl_math.abs(tmp92)
    tmp94 = tmp88 + tmp93
    tmp95 = tmp71 + tmp94
    tl.store(out_ptr0 + (x0), tmp95, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/ay/caynatcta4tbj4q6qgpflhmpdrc4z6whkhp6d7rujsdjvddpo3nz.py
# Topologically Sorted Source Nodes: [sub_1, add_1, abs_2, tvcomp2, sum_5], Original ATen: [aten.sub, aten.add, aten.abs, aten.sum]
# Source node to ATen node mapping:
#   abs_2 => abs_2
#   add_1 => add_1
#   sub_1 => sub_1
#   sum_5 => sum_5
#   tvcomp2 => sum_4
# Graph fragment:
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%slice_8, %slice_11), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sub_1, 1e-06), kwargs = {})
#   %abs_2 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%add_1,), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%abs_2, [0]), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_4, [0]), kwargs = {})
triton_poi_fused_abs_add_sub_sum_1 = async_compile.triton('triton_poi_fused_abs_add_sub_sum_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=[16], 
    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, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_abs_add_sub_sum_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 16, '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_abs_add_sub_sum_1(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp1 = tl.load(in_ptr0 + (x0), xmask)
    tmp6 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp7 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp12 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp13 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp18 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp19 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp28 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp33 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp38 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp44 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp48 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp53 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp58 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp2 = tmp0 - tmp1
    tmp3 = 1e-06
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.abs(tmp4)
    tmp8 = tmp6 - tmp7
    tmp9 = tmp8 + tmp3
    tmp10 = tl_math.abs(tmp9)
    tmp11 = tmp5 + tmp10
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 + tmp3
    tmp16 = tl_math.abs(tmp15)
    tmp17 = tmp11 + tmp16
    tmp20 = tmp18 - tmp19
    tmp21 = tmp20 + tmp3
    tmp22 = tl_math.abs(tmp21)
    tmp23 = tmp17 + tmp22
    tmp25 = tmp24 - tmp0
    tmp26 = tmp25 + tmp3
    tmp27 = tl_math.abs(tmp26)
    tmp29 = tmp28 - tmp6
    tmp30 = tmp29 + tmp3
    tmp31 = tl_math.abs(tmp30)
    tmp32 = tmp27 + tmp31
    tmp34 = tmp33 - tmp12
    tmp35 = tmp34 + tmp3
    tmp36 = tl_math.abs(tmp35)
    tmp37 = tmp32 + tmp36
    tmp39 = tmp38 - tmp18
    tmp40 = tmp39 + tmp3
    tmp41 = tl_math.abs(tmp40)
    tmp42 = tmp37 + tmp41
    tmp43 = tmp23 + tmp42
    tmp45 = tmp44 - tmp24
    tmp46 = tmp45 + tmp3
    tmp47 = tl_math.abs(tmp46)
    tmp49 = tmp48 - tmp28
    tmp50 = tmp49 + tmp3
    tmp51 = tl_math.abs(tmp50)
    tmp52 = tmp47 + tmp51
    tmp54 = tmp53 - tmp33
    tmp55 = tmp54 + tmp3
    tmp56 = tl_math.abs(tmp55)
    tmp57 = tmp52 + tmp56
    tmp59 = tmp58 - tmp38
    tmp60 = tmp59 + tmp3
    tmp61 = tl_math.abs(tmp60)
    tmp62 = tmp57 + tmp61
    tmp63 = tmp43 + tmp62
    tl.store(out_ptr0 + (x0), tmp63, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/k4/ck4zkprup45v2vixnlnioxl3kg5o7dho7xa52oqtx3vplfkyrfxp.py
# Topologically Sorted Source Nodes: [tvcomp1_1, tvcomp2_1, tv, truediv], Original ATen: [aten.sum, aten.add, aten.div]
# Source node to ATen node mapping:
#   truediv => div
#   tv => add_2
#   tvcomp1_1 => sum_3
#   tvcomp2_1 => sum_6
# Graph fragment:
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_2, [0]), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sum_5, [0]), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_3, %sum_6), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%add_2, 256), kwargs = {})
triton_poi_fused_add_div_sum_2 = async_compile.triton('triton_poi_fused_add_div_sum_2', '''
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_add_div_sum_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 7, '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_add_div_sum_2(in_ptr0, in_ptr1, out_ptr0, 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 + (x0), xmask)
    tmp1 = tl.load(in_ptr0 + (4 + x0), xmask)
    tmp3 = tl.load(in_ptr0 + (8 + x0), xmask)
    tmp5 = tl.load(in_ptr1 + (x0), xmask)
    tmp6 = tl.load(in_ptr1 + (4 + x0), xmask)
    tmp8 = tl.load(in_ptr1 + (8 + x0), xmask)
    tmp10 = tl.load(in_ptr1 + (12 + x0), xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp7 = tmp5 + tmp6
    tmp9 = tmp7 + tmp8
    tmp11 = tmp9 + tmp10
    tmp12 = tmp4 + tmp11
    tmp13 = 0.00390625
    tmp14 = tmp12 * tmp13
    tl.store(out_ptr0 + (x0), tmp14, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

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)
        buf0 = empty_strided_cuda((3, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [sub, add, abs_1, tvcomp1, sum_2], Original ATen: [aten.sub, aten.add, aten.abs, aten.sum]
        stream0 = get_raw_stream(0)
        triton_poi_fused_abs_add_sub_sum_0.run(arg0_1, buf0, 12, grid=grid(12), stream=stream0)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [sub_1, add_1, abs_2, tvcomp2, sum_5], Original ATen: [aten.sub, aten.add, aten.abs, aten.sum]
        triton_poi_fused_abs_add_sub_sum_1.run(arg0_1, buf1, 16, grid=grid(16), stream=stream0)
        del arg0_1
        buf2 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [tvcomp1_1, tvcomp2_1, tv, truediv], Original ATen: [aten.sum, aten.add, aten.div]
        triton_poi_fused_add_div_sum_2.run(buf0, buf1, buf2, 4, grid=grid(4), stream=stream0)
        del buf0
        del buf1
    return (buf2, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    arg0_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_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)

import torch
import torch.nn as nn


class TotalVariation(nn.Module):
    """TotalVariation: calculates the total variation of a patch.

    Module providing the functionality necessary to calculate the total vatiation (TV) of an adversarial patch.

    """

    def __init__(self):
        super(TotalVariation, self).__init__()

    def forward(self, adv_patch):
        tvcomp1 = torch.sum(torch.abs(adv_patch[:, :, 1:] - adv_patch[:, :,
            :-1] + 1e-06), 0)
        tvcomp1 = torch.sum(torch.sum(tvcomp1, 0), 0)
        tvcomp2 = torch.sum(torch.abs(adv_patch[:, 1:, :] - adv_patch[:, :-
            1, :] + 1e-06), 0)
        tvcomp2 = torch.sum(torch.sum(tvcomp2, 0), 0)
        tv = tvcomp1 + tvcomp2
        return tv / torch.numel(adv_patch)


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


def get_init_inputs():
    return [[], {}]

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.triton_helpers import 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


@triton.jit
def triton_poi_fused_abs_add_sub_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 12
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + x0), xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask)
    tmp6 = tl.load(in_ptr0 + (68 + x0), xmask)
    tmp7 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp12 = tl.load(in_ptr0 + (132 + x0), xmask)
    tmp13 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp18 = tl.load(in_ptr0 + (196 + x0), xmask)
    tmp19 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (20 + x0), xmask)
    tmp25 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp29 = tl.load(in_ptr0 + (84 + x0), xmask)
    tmp30 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp35 = tl.load(in_ptr0 + (148 + x0), xmask)
    tmp36 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp41 = tl.load(in_ptr0 + (212 + x0), xmask)
    tmp42 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp48 = tl.load(in_ptr0 + (36 + x0), xmask)
    tmp49 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp53 = tl.load(in_ptr0 + (100 + x0), xmask)
    tmp54 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp59 = tl.load(in_ptr0 + (164 + x0), xmask)
    tmp60 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp65 = tl.load(in_ptr0 + (228 + x0), xmask)
    tmp66 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp72 = tl.load(in_ptr0 + (52 + x0), xmask)
    tmp73 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp77 = tl.load(in_ptr0 + (116 + x0), xmask)
    tmp78 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp83 = tl.load(in_ptr0 + (180 + x0), xmask)
    tmp84 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp89 = tl.load(in_ptr0 + (244 + x0), xmask)
    tmp90 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp2 = tmp0 - tmp1
    tmp3 = 1e-06
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.abs(tmp4)
    tmp8 = tmp6 - tmp7
    tmp9 = tmp8 + tmp3
    tmp10 = tl_math.abs(tmp9)
    tmp11 = tmp5 + tmp10
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 + tmp3
    tmp16 = tl_math.abs(tmp15)
    tmp17 = tmp11 + tmp16
    tmp20 = tmp18 - tmp19
    tmp21 = tmp20 + tmp3
    tmp22 = tl_math.abs(tmp21)
    tmp23 = tmp17 + tmp22
    tmp26 = tmp24 - tmp25
    tmp27 = tmp26 + tmp3
    tmp28 = tl_math.abs(tmp27)
    tmp31 = tmp29 - tmp30
    tmp32 = tmp31 + tmp3
    tmp33 = tl_math.abs(tmp32)
    tmp34 = tmp28 + tmp33
    tmp37 = tmp35 - tmp36
    tmp38 = tmp37 + tmp3
    tmp39 = tl_math.abs(tmp38)
    tmp40 = tmp34 + tmp39
    tmp43 = tmp41 - tmp42
    tmp44 = tmp43 + tmp3
    tmp45 = tl_math.abs(tmp44)
    tmp46 = tmp40 + tmp45
    tmp47 = tmp23 + tmp46
    tmp50 = tmp48 - tmp49
    tmp51 = tmp50 + tmp3
    tmp52 = tl_math.abs(tmp51)
    tmp55 = tmp53 - tmp54
    tmp56 = tmp55 + tmp3
    tmp57 = tl_math.abs(tmp56)
    tmp58 = tmp52 + tmp57
    tmp61 = tmp59 - tmp60
    tmp62 = tmp61 + tmp3
    tmp63 = tl_math.abs(tmp62)
    tmp64 = tmp58 + tmp63
    tmp67 = tmp65 - tmp66
    tmp68 = tmp67 + tmp3
    tmp69 = tl_math.abs(tmp68)
    tmp70 = tmp64 + tmp69
    tmp71 = tmp47 + tmp70
    tmp74 = tmp72 - tmp73
    tmp75 = tmp74 + tmp3
    tmp76 = tl_math.abs(tmp75)
    tmp79 = tmp77 - tmp78
    tmp80 = tmp79 + tmp3
    tmp81 = tl_math.abs(tmp80)
    tmp82 = tmp76 + tmp81
    tmp85 = tmp83 - tmp84
    tmp86 = tmp85 + tmp3
    tmp87 = tl_math.abs(tmp86)
    tmp88 = tmp82 + tmp87
    tmp91 = tmp89 - tmp90
    tmp92 = tmp91 + tmp3
    tmp93 = tl_math.abs(tmp92)
    tmp94 = tmp88 + tmp93
    tmp95 = tmp71 + tmp94
    tl.store(out_ptr0 + x0, tmp95, xmask)


@triton.jit
def triton_poi_fused_abs_add_sub_sum_1(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (16 + x0), xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask)
    tmp6 = tl.load(in_ptr0 + (80 + x0), xmask)
    tmp7 = tl.load(in_ptr0 + (64 + x0), xmask)
    tmp12 = tl.load(in_ptr0 + (144 + x0), xmask)
    tmp13 = tl.load(in_ptr0 + (128 + x0), xmask)
    tmp18 = tl.load(in_ptr0 + (208 + x0), xmask)
    tmp19 = tl.load(in_ptr0 + (192 + x0), xmask)
    tmp24 = tl.load(in_ptr0 + (32 + x0), xmask)
    tmp28 = tl.load(in_ptr0 + (96 + x0), xmask)
    tmp33 = tl.load(in_ptr0 + (160 + x0), xmask)
    tmp38 = tl.load(in_ptr0 + (224 + x0), xmask)
    tmp44 = tl.load(in_ptr0 + (48 + x0), xmask)
    tmp48 = tl.load(in_ptr0 + (112 + x0), xmask)
    tmp53 = tl.load(in_ptr0 + (176 + x0), xmask)
    tmp58 = tl.load(in_ptr0 + (240 + x0), xmask)
    tmp2 = tmp0 - tmp1
    tmp3 = 1e-06
    tmp4 = tmp2 + tmp3
    tmp5 = tl_math.abs(tmp4)
    tmp8 = tmp6 - tmp7
    tmp9 = tmp8 + tmp3
    tmp10 = tl_math.abs(tmp9)
    tmp11 = tmp5 + tmp10
    tmp14 = tmp12 - tmp13
    tmp15 = tmp14 + tmp3
    tmp16 = tl_math.abs(tmp15)
    tmp17 = tmp11 + tmp16
    tmp20 = tmp18 - tmp19
    tmp21 = tmp20 + tmp3
    tmp22 = tl_math.abs(tmp21)
    tmp23 = tmp17 + tmp22
    tmp25 = tmp24 - tmp0
    tmp26 = tmp25 + tmp3
    tmp27 = tl_math.abs(tmp26)
    tmp29 = tmp28 - tmp6
    tmp30 = tmp29 + tmp3
    tmp31 = tl_math.abs(tmp30)
    tmp32 = tmp27 + tmp31
    tmp34 = tmp33 - tmp12
    tmp35 = tmp34 + tmp3
    tmp36 = tl_math.abs(tmp35)
    tmp37 = tmp32 + tmp36
    tmp39 = tmp38 - tmp18
    tmp40 = tmp39 + tmp3
    tmp41 = tl_math.abs(tmp40)
    tmp42 = tmp37 + tmp41
    tmp43 = tmp23 + tmp42
    tmp45 = tmp44 - tmp24
    tmp46 = tmp45 + tmp3
    tmp47 = tl_math.abs(tmp46)
    tmp49 = tmp48 - tmp28
    tmp50 = tmp49 + tmp3
    tmp51 = tl_math.abs(tmp50)
    tmp52 = tmp47 + tmp51
    tmp54 = tmp53 - tmp33
    tmp55 = tmp54 + tmp3
    tmp56 = tl_math.abs(tmp55)
    tmp57 = tmp52 + tmp56
    tmp59 = tmp58 - tmp38
    tmp60 = tmp59 + tmp3
    tmp61 = tl_math.abs(tmp60)
    tmp62 = tmp57 + tmp61
    tmp63 = tmp43 + tmp62
    tl.store(out_ptr0 + x0, tmp63, xmask)


@triton.jit
def triton_poi_fused_add_div_sum_2(in_ptr0, in_ptr1, out_ptr0, 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 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + (4 + x0), xmask)
    tmp3 = tl.load(in_ptr0 + (8 + x0), xmask)
    tmp5 = tl.load(in_ptr1 + x0, xmask)
    tmp6 = tl.load(in_ptr1 + (4 + x0), xmask)
    tmp8 = tl.load(in_ptr1 + (8 + x0), xmask)
    tmp10 = tl.load(in_ptr1 + (12 + x0), xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp7 = tmp5 + tmp6
    tmp9 = tmp7 + tmp8
    tmp11 = tmp9 + tmp10
    tmp12 = tmp4 + tmp11
    tmp13 = 0.00390625
    tmp14 = tmp12 * tmp13
    tl.store(out_ptr0 + x0, tmp14, 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)
        buf0 = empty_strided_cuda((3, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_abs_add_sub_sum_0[grid(12)](arg0_1, buf0, 12,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_abs_add_sub_sum_1[grid(16)](arg0_1, buf1, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        del arg0_1
        buf2 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused_add_div_sum_2[grid(4)](buf0, buf1, buf2, 4, XBLOCK
            =4, num_warps=1, num_stages=1)
        del buf0
        del buf1
    return buf2,


class TotalVariationNew(nn.Module):
    """TotalVariation: calculates the total variation of a patch.

    Module providing the functionality necessary to calculate the total vatiation (TV) of an adversarial patch.

    """

    def __init__(self):
        super(TotalVariationNew, self).__init__()

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