# 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_6/inductor_cache/5l/c5lgdvchkbmivjnvcs2kuewrdqraps4bwq34ys346n3lh32qesvr.py
# Topologically Sorted Source Nodes: [out, mean, std, sub, out_1, relu1], Original ATen: [aten.convolution, aten.mean, aten.std, aten.sub, aten.div, aten.relu]
# Source node to ATen node mapping:
#   mean => mean
#   out => convolution
#   out_1 => div
#   relu1 => relu
#   std => sqrt, var
#   sub => sub
# Graph fragment:
#   %convolution : [num_users=3] = call_function[target=torch.ops.aten.convolution.default](args = (%primals_3, %primals_1, %primals_2, [1, 1], [1, 1], [1, 1], False, [0, 0], 1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%view, [2]), kwargs = {})
#   %var : [num_users=1] = call_function[target=torch.ops.aten.var.correction](args = (%view, [2]), kwargs = {correction: 1.0})
#   %sqrt : [num_users=2] = call_function[target=torch.ops.aten.sqrt.default](args = (%var,), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%convolution, %view_1), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sub, %view_2), kwargs = {})
#   %relu : [num_users=2] = call_function[target=torch.ops.aten.relu.default](args = (%div,), kwargs = {})
triton_per_fused_convolution_div_mean_relu_std_sub_0 = async_compile.triton('triton_per_fused_convolution_div_mean_relu_std_sub_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.persistent_reduction(
    size_hints=[16, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32', 6: '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, 3, 4, 5, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_convolution_div_mean_relu_std_sub_0', 'mutated_arg_names': ['in_out_ptr0', 'in_out_ptr1', 'in_out_ptr2'], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 4, '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}
)
@triton.jit
def triton_per_fused_convolution_div_mean_relu_std_sub_0(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + (r2 + (16*x3)), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + (x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp3 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tmp21 = 16.0
    tmp22 = tmp6 / tmp21
    tmp23 = 15.0
    tmp24 = tmp20 / tmp23
    tmp25 = libdevice.sqrt(tmp24)
    tmp26 = tmp2 - tmp22
    tmp27 = tmp26 / tmp25
    tmp28 = tl.full([1, 1], 0, tl.int32)
    tmp29 = triton_helpers.maximum(tmp28, tmp27)
    tl.store(in_out_ptr0 + (r2 + (16*x3)), tmp2, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + (x3), tmp22, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr2 + (x3), tmp25, xmask)
    tl.store(out_ptr0 + (r2 + (16*x3)), tmp29, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/7d/c7dol2m4pzrwhlm3ie26bkh5wyzfwzx2tgk5pk3xbho7pf72e76y.py
# Topologically Sorted Source Nodes: [out_2, mean_2, std_2, sub_1, out_3, out_4, out_5], Original ATen: [aten.convolution, aten.mean, aten.std, aten.sub, aten.div, aten.add, aten.relu, aten.threshold_backward]
# Source node to ATen node mapping:
#   mean_2 => mean_1
#   out_2 => convolution_1
#   out_3 => div_1
#   out_4 => add
#   out_5 => relu_1
#   std_2 => sqrt_1, var_1
#   sub_1 => sub_1
# Graph fragment:
#   %convolution_1 : [num_users=3] = call_function[target=torch.ops.aten.convolution.default](args = (%relu, %primals_4, %primals_5, [1, 1], [1, 1], [1, 1], False, [0, 0], 1), kwargs = {})
#   %mean_1 : [num_users=1] = call_function[target=torch.ops.aten.mean.dim](args = (%view_3, [2]), kwargs = {})
#   %var_1 : [num_users=1] = call_function[target=torch.ops.aten.var.correction](args = (%view_3, [2]), kwargs = {correction: 1.0})
#   %sqrt_1 : [num_users=2] = call_function[target=torch.ops.aten.sqrt.default](args = (%var_1,), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%convolution_1, %view_4), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%sub_1, %view_5), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div_1, %primals_3), kwargs = {})
#   %relu_1 : [num_users=2] = call_function[target=torch.ops.aten.relu.default](args = (%add,), kwargs = {})
#   %le : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%relu_1, 0), kwargs = {})
triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_1 = async_compile.triton('triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_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.persistent_reduction(
    size_hints=[16, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*i1', 7: 'i32', 8: '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, 3, 4, 5, 6, 7, 8), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_1', 'mutated_arg_names': ['in_out_ptr0', 'in_out_ptr1', 'in_out_ptr2'], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 4, '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}
)
@triton.jit
def triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_1(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + (r2 + (16*x3)), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + (x0), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr1 + (r2 + (16*x3)), xmask, other=0.0)
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp3 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tmp21 = 16.0
    tmp22 = tmp6 / tmp21
    tmp23 = 15.0
    tmp24 = tmp20 / tmp23
    tmp25 = libdevice.sqrt(tmp24)
    tmp26 = tmp2 - tmp22
    tmp27 = tmp26 / tmp25
    tmp29 = tmp27 + tmp28
    tmp30 = tl.full([1, 1], 0, tl.int32)
    tmp31 = triton_helpers.maximum(tmp30, tmp29)
    tmp32 = 0.0
    tmp33 = tmp31 <= tmp32
    tl.store(in_out_ptr0 + (r2 + (16*x3)), tmp2, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + (x3), tmp22, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr2 + (x3), tmp25, xmask)
    tl.store(out_ptr0 + (r2 + (16*x3)), tmp31, xmask)
    tl.store(out_ptr1 + (r2 + (16*x3)), tmp33, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (4, ), (1, ))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_5, (4, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        # Topologically Sorted Source Nodes: [out], Original ATen: [aten.convolution]
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
        buf1 = buf0; del buf0  # reuse
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = buf2; del buf2  # reuse
        buf7 = buf5; del buf5  # reuse
        buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [out, mean, std, sub, out_1, relu1], Original ATen: [aten.convolution, aten.mean, aten.std, aten.sub, aten.div, aten.relu]
        stream0 = get_raw_stream(0)
        triton_per_fused_convolution_div_mean_relu_std_sub_0.run(buf1, buf3, buf7, primals_2, buf8, 16, 16, grid=grid(16), stream=stream0)
        del primals_2
        # Topologically Sorted Source Nodes: [out_2], Original ATen: [aten.convolution]
        buf9 = extern_kernels.convolution(buf8, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 4, 4, 4), (64, 16, 4, 1))
        buf10 = buf9; del buf9  # reuse
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf12 = buf11; del buf11  # reuse
        buf16 = buf14; del buf14  # reuse
        buf17 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        # Topologically Sorted Source Nodes: [out_2, mean_2, std_2, sub_1, out_3, out_4, out_5], Original ATen: [aten.convolution, aten.mean, aten.std, aten.sub, aten.div, aten.add, aten.relu, aten.threshold_backward]
        triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_1.run(buf10, buf12, buf16, primals_5, primals_3, buf17, buf18, 16, 16, grid=grid(16), stream=stream0)
        del primals_5
    return (buf8, buf17, primals_1, primals_3, primals_4, buf1, reinterpret_tensor(buf3, (4, 4, 1, 1), (4, 1, 1, 1), 0), buf7, buf8, buf10, reinterpret_tensor(buf12, (4, 4, 1, 1), (4, 1, 1, 1), 0), buf16, buf18, )


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((4, 4, 3, 3), (36, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, 4, 3, 3), (36, 9, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5])
    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 RemoveChannelMeanStd(torch.nn.Module):

    def forward(self, x):
        x2 = x.view(x.size(0), x.size(1), -1)
        mean = x2.mean(dim=2).view(x.size(0), x.size(1), 1, 1)
        std = x2.std(dim=2).view(x.size(0), x.size(1), 1, 1)
        return (x - mean) / std


class Block(nn.Module):

    def __init__(self, in_planes, planes, stride=1, groups=False):
        super(Block, self).__init__()
        self.bn1 = RemoveChannelMeanStd()
        if not groups:
            self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride
                =stride, padding=1, bias=True)
            self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1,
                padding=1, bias=True)
        else:
            self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride
                =stride, padding=1, bias=True, groups=min(in_planes, planes))
            self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1,
                padding=1, bias=True, groups=planes)
        self.bn2 = RemoveChannelMeanStd()
        if stride != 1 or in_planes != planes:
            self.shortcut = nn.Sequential(nn.Conv2d(in_planes, planes,
                kernel_size=1, stride=stride, bias=True),
                RemoveChannelMeanStd())

    def forward(self, x):
        out = self.conv1(x)
        out = self.bn1(out)
        relu1 = F.relu(out)
        out = self.conv2(relu1)
        out = self.bn2(out)
        shortcut = self.shortcut(x) if hasattr(self, 'shortcut') else x
        out += shortcut
        out = F.relu(out)
        return relu1, out


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


def get_init_inputs():
    return [[], {'in_planes': 4, 'planes': 4}]

import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
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_per_fused_convolution_div_mean_relu_std_sub_0(in_out_ptr0,
    in_out_ptr1, in_out_ptr2, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl
    .constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp3 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tmp21 = 16.0
    tmp22 = tmp6 / tmp21
    tmp23 = 15.0
    tmp24 = tmp20 / tmp23
    tmp25 = libdevice.sqrt(tmp24)
    tmp26 = tmp2 - tmp22
    tmp27 = tmp26 / tmp25
    tmp28 = tl.full([1, 1], 0, tl.int32)
    tmp29 = triton_helpers.maximum(tmp28, tmp27)
    tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + x3, tmp22, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr2 + x3, tmp25, xmask)
    tl.store(out_ptr0 + (r2 + 16 * x3), tmp29, xmask)


@triton.jit
def triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_1(
    in_out_ptr0, in_out_ptr1, in_out_ptr2, in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr1 + (r2 + 16 * x3), xmask, other=0.0)
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tmp8 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp10 = tl.where(xmask, tmp8, 0)
    tmp11 = tl.sum(tmp10, 1)[:, None]
    tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp13 = tmp12.to(tl.float32)
    tmp14 = tmp11 / tmp13
    tmp15 = tmp3 - tmp14
    tmp16 = tmp15 * tmp15
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.sum(tmp19, 1)[:, None]
    tmp21 = 16.0
    tmp22 = tmp6 / tmp21
    tmp23 = 15.0
    tmp24 = tmp20 / tmp23
    tmp25 = libdevice.sqrt(tmp24)
    tmp26 = tmp2 - tmp22
    tmp27 = tmp26 / tmp25
    tmp29 = tmp27 + tmp28
    tmp30 = tl.full([1, 1], 0, tl.int32)
    tmp31 = triton_helpers.maximum(tmp30, tmp29)
    tmp32 = 0.0
    tmp33 = tmp31 <= tmp32
    tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + x3, tmp22, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr2 + x3, tmp25, xmask)
    tl.store(out_ptr0 + (r2 + 16 * x3), tmp31, xmask)
    tl.store(out_ptr1 + (r2 + 16 * x3), tmp33, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_5, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
        buf1 = buf0
        del buf0
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = buf2
        del buf2
        buf7 = buf5
        del buf5
        buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_convolution_div_mean_relu_std_sub_0[grid(16)](buf1,
            buf3, buf7, primals_2, buf8, 16, 16, XBLOCK=8, num_warps=2,
            num_stages=1)
        del primals_2
        buf9 = extern_kernels.convolution(buf8, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 4, 4, 4), (64, 16, 4, 1))
        buf10 = buf9
        del buf9
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf12 = buf11
        del buf11
        buf16 = buf14
        del buf14
        buf17 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_per_fused_add_convolution_div_mean_relu_std_sub_threshold_backward_1[
            grid(16)](buf10, buf12, buf16, primals_5, primals_3, buf17,
            buf18, 16, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del primals_5
    return (buf8, buf17, primals_1, primals_3, primals_4, buf1,
        reinterpret_tensor(buf3, (4, 4, 1, 1), (4, 1, 1, 1), 0), buf7, buf8,
        buf10, reinterpret_tensor(buf12, (4, 4, 1, 1), (4, 1, 1, 1), 0),
        buf16, buf18)


class RemoveChannelMeanStd(torch.nn.Module):

    def forward(self, x):
        x2 = x.view(x.size(0), x.size(1), -1)
        mean = x2.mean(dim=2).view(x.size(0), x.size(1), 1, 1)
        std = x2.std(dim=2).view(x.size(0), x.size(1), 1, 1)
        return (x - mean) / std


class BlockNew(nn.Module):

    def __init__(self, in_planes, planes, stride=1, groups=False):
        super(BlockNew, self).__init__()
        self.bn1 = RemoveChannelMeanStd()
        if not groups:
            self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride
                =stride, padding=1, bias=True)
            self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1,
                padding=1, bias=True)
        else:
            self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride
                =stride, padding=1, bias=True, groups=min(in_planes, planes))
            self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1,
                padding=1, bias=True, groups=planes)
        self.bn2 = RemoveChannelMeanStd()
        if stride != 1 or in_planes != planes:
            self.shortcut = nn.Sequential(nn.Conv2d(in_planes, planes,
                kernel_size=1, stride=stride, bias=True),
                RemoveChannelMeanStd())

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0], output[1]
