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_native_group_norm_relu_0(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 64
    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)
    r3 = rindex
    x0 = xindex
    r2 = rindex // 16
    tmp0 = tl.load(in_out_ptr0 + (r3 + 64 * x0), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + r2, None, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr2 + r2, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp3, 0)
    tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp8 = tl.where(xmask, tmp6, 0)
    tmp9 = tl.sum(tmp8, 1)[:, None]
    tmp10 = tl.full([XBLOCK, 1], 64, tl.int32)
    tmp11 = tmp10.to(tl.float32)
    tmp12 = tmp9 / tmp11
    tmp13 = tmp3 - tmp12
    tmp14 = tmp13 * tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.where(xmask, tmp15, 0)
    tmp18 = tl.sum(tmp17, 1)[:, None]
    tmp19 = tmp2 - tmp12
    tmp20 = 64.0
    tmp21 = tmp18 / tmp20
    tmp22 = 1e-05
    tmp23 = tmp21 + tmp22
    tmp24 = libdevice.rsqrt(tmp23)
    tmp25 = tmp19 * tmp24
    tmp27 = tmp25 * tmp26
    tmp29 = tmp27 + tmp28
    tmp30 = tl.full([1, 1], 0, tl.int32)
    tmp31 = triton_helpers.maximum(tmp30, tmp29)
    tl.store(in_out_ptr0 + (r3 + 64 * x0), tmp2, xmask)
    tl.store(out_ptr2 + (r3 + 64 * x0), tmp31, xmask)
    tl.store(out_ptr3 + x0, tmp24, xmask)
    tl.store(out_ptr0 + x0, tmp12, xmask)


@triton.jit
def triton_per_fused_convolution_native_group_norm_relu_1(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    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)
    r3 = rindex
    x0 = xindex
    r2 = rindex // 4
    tmp0 = tl.load(in_out_ptr0 + (r3 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + r2, None, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr2 + r2, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp3, 0)
    tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp8 = tl.where(xmask, tmp6, 0)
    tmp9 = tl.sum(tmp8, 1)[:, None]
    tmp10 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp11 = tmp10.to(tl.float32)
    tmp12 = tmp9 / tmp11
    tmp13 = tmp3 - tmp12
    tmp14 = tmp13 * tmp13
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
    tmp17 = tl.where(xmask, tmp15, 0)
    tmp18 = tl.sum(tmp17, 1)[:, None]
    tmp19 = tmp2 - tmp12
    tmp20 = 16.0
    tmp21 = tmp18 / tmp20
    tmp22 = 1e-05
    tmp23 = tmp21 + tmp22
    tmp24 = libdevice.rsqrt(tmp23)
    tmp25 = tmp19 * tmp24
    tmp27 = tmp25 * tmp26
    tmp29 = tmp27 + tmp28
    tmp30 = tl.full([1, 1], 0, tl.int32)
    tmp31 = triton_helpers.maximum(tmp30, tmp29)
    tl.store(in_out_ptr0 + (r3 + 16 * x0), tmp2, xmask)
    tl.store(out_ptr2 + (r3 + 16 * x0), tmp31, xmask)
    tl.store(out_ptr3 + x0, tmp24, xmask)
    tl.store(out_ptr0 + x0, tmp12, xmask)


@triton.jit
def triton_per_fused_add_convolution_native_group_norm_relu_threshold_backward_2(
    in_out_ptr0, in_out_ptr1, in_out_ptr2, in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, in_ptr4, in_ptr5, out_ptr0, out_ptr2, out_ptr4, out_ptr5,
    out_ptr6, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    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)
    r3 = rindex
    x0 = xindex
    r2 = rindex // 4
    tmp0 = tl.load(in_out_ptr0 + (r3 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.load(in_ptr0 + r2, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_out_ptr1 + (r3 + 16 * x0), xmask, other=0.0)
    tmp4 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
    tmp43 = tl.load(in_ptr2 + r2, None, eviction_policy='evict_last')
    tmp45 = tl.load(in_ptr3 + r2, None, eviction_policy='evict_last')
    tmp52 = tl.load(in_ptr4 + r2, None, eviction_policy='evict_last')
    tmp54 = tl.load(in_ptr5 + r2, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp6, 0)
    tmp9 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp11 = tl.where(xmask, tmp9, 0)
    tmp12 = tl.sum(tmp11, 1)[:, None]
    tmp13 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp14 = tmp13.to(tl.float32)
    tmp15 = tmp12 / tmp14
    tmp16 = tmp6 - tmp15
    tmp17 = tmp16 * tmp16
    tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK])
    tmp20 = tl.where(xmask, tmp18, 0)
    tmp21 = tl.sum(tmp20, 1)[:, None]
    tmp22 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tl.where(xmask, tmp22, 0)
    tmp25 = tl.broadcast_to(tmp22, [XBLOCK, RBLOCK])
    tmp27 = tl.where(xmask, tmp25, 0)
    tmp28 = tl.sum(tmp27, 1)[:, None]
    tmp29 = tmp28 / tmp14
    tmp30 = tmp22 - tmp29
    tmp31 = tmp30 * tmp30
    tmp32 = tl.broadcast_to(tmp31, [XBLOCK, RBLOCK])
    tmp34 = tl.where(xmask, tmp32, 0)
    tmp35 = tl.sum(tmp34, 1)[:, None]
    tmp36 = tmp5 - tmp15
    tmp37 = 16.0
    tmp38 = tmp21 / tmp37
    tmp39 = 1e-05
    tmp40 = tmp38 + tmp39
    tmp41 = libdevice.rsqrt(tmp40)
    tmp42 = tmp36 * tmp41
    tmp44 = tmp42 * tmp43
    tmp46 = tmp44 + tmp45
    tmp47 = tmp2 - tmp29
    tmp48 = tmp35 / tmp37
    tmp49 = tmp48 + tmp39
    tmp50 = libdevice.rsqrt(tmp49)
    tmp51 = tmp47 * tmp50
    tmp53 = tmp51 * tmp52
    tmp55 = tmp53 + tmp54
    tmp56 = tmp46 + tmp55
    tmp57 = tl.full([1, 1], 0, tl.int32)
    tmp58 = triton_helpers.maximum(tmp57, tmp56)
    tmp59 = 0.0
    tmp60 = tmp58 <= tmp59
    tl.store(in_out_ptr0 + (r3 + 16 * x0), tmp2, xmask)
    tl.store(in_out_ptr1 + (r3 + 16 * x0), tmp5, xmask)
    tl.store(in_out_ptr2 + (r3 + 16 * x0), tmp58, xmask)
    tl.store(out_ptr4 + (r3 + 16 * x0), tmp60, xmask)
    tl.store(out_ptr5 + x0, tmp41, xmask)
    tl.store(out_ptr6 + x0, tmp50, xmask)
    tl.store(out_ptr0 + x0, tmp15, xmask)
    tl.store(out_ptr2 + x0, tmp29, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16, primals_17) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 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,), (1,))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_11, (4,), (1,))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_15, (4,), (1,))
    assert_size_stride(primals_16, (4,), (1,))
    assert_size_stride(primals_17, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(0, 0), 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, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        get_raw_stream(0)
        triton_per_fused_convolution_native_group_norm_relu_0[grid(4)](buf1,
            primals_2, primals_4, primals_5, buf2, buf6, buf5, 4, 64,
            XBLOCK=1, num_warps=2, num_stages=1)
        del primals_2
        del primals_5
        buf7 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 4, 2, 2), (16, 4, 2, 1))
        buf8 = buf7
        del buf7
        buf9 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        buf13 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf12 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        triton_per_fused_convolution_native_group_norm_relu_1[grid(4)](buf8,
            primals_7, primals_8, primals_9, buf9, buf13, buf12, 4, 16,
            XBLOCK=1, num_warps=2, num_stages=1)
        del primals_7
        del primals_9
        buf14 = extern_kernels.convolution(buf13, primals_10, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf14, (4, 4, 2, 2), (16, 4, 2, 1))
        buf20 = extern_kernels.convolution(primals_3, primals_14, stride=(1,
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf20, (4, 4, 2, 2), (16, 4, 2, 1))
        buf21 = buf20
        del buf20
        buf15 = buf14
        del buf14
        buf16 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        buf22 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        buf26 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf27 = buf26
        del buf26
        buf28 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool)
        buf19 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        buf25 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
        triton_per_fused_add_convolution_native_group_norm_relu_threshold_backward_2[
            grid(4)](buf21, buf15, buf27, primals_15, primals_11,
            primals_12, primals_13, primals_16, primals_17, buf16, buf22,
            buf28, buf19, buf25, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
        del primals_11
        del primals_13
        del primals_15
        del primals_17
    return (buf27, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, primals_12, primals_14, primals_16, buf1,
        reinterpret_tensor(buf2, (4, 1), (1, 1), 0), reinterpret_tensor(
        buf5, (4, 1), (1, 1), 0), buf6, buf8, reinterpret_tensor(buf9, (4, 
        1), (1, 1), 0), reinterpret_tensor(buf12, (4, 1), (1, 1), 0), buf13,
        buf15, reinterpret_tensor(buf16, (4, 1), (1, 1), 0),
        reinterpret_tensor(buf19, (4, 1), (1, 1), 0), buf21,
        reinterpret_tensor(buf22, (4, 1), (1, 1), 0), reinterpret_tensor(
        buf25, (4, 1), (1, 1), 0), buf28)


class unet_bottleneckNew(nn.Module):

    def __init__(self, in_ch, out_ch, ker=3):
        super(unet_bottleneckNew, self).__init__()
        self.relu = nn.ReLU(inplace=True)
        self.conv1 = nn.Conv2d(in_ch, out_ch, 1)
        self.bn1 = nn.GroupNorm(out_ch // 4, out_ch)
        self.conv2 = nn.Conv2d(out_ch, out_ch, 3)
        self.bn2 = nn.GroupNorm(out_ch // 4, out_ch)
        self.conv3 = nn.Conv2d(out_ch, out_ch, 1)
        self.bn3 = nn.GroupNorm(out_ch // 4, out_ch)
        self.s_conv = nn.Conv2d(in_ch, out_ch, 3)
        self.s_bn = nn.GroupNorm(out_ch // 4, out_ch)

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = self.conv1.bias
        primals_4 = self.bn1.weight
        primals_5 = self.bn1.bias
        primals_6 = self.conv2.weight
        primals_7 = self.conv2.bias
        primals_8 = self.bn2.weight
        primals_9 = self.bn2.bias
        primals_10 = self.conv3.weight
        primals_11 = self.conv3.bias
        primals_12 = self.bn3.weight
        primals_13 = self.bn3.bias
        primals_14 = self.s_conv.weight
        primals_15 = self.s_conv.bias
        primals_16 = self.s_bn.weight
        primals_17 = self.s_bn.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17])
        return output[0]


Measured latency_ms: 0.014787