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
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_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 16 % 256
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 16 % 128
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 16 % 512
    x0 = xindex % 16
    x2 = xindex // 8192
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 256, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 4096 * x2), tmp4, other=0.0)
    tmp6 = tl.load(in_ptr1 + x1, tmp4, eviction_policy='evict_last', other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.full([1], 0, tl.int32)
    tmp9 = triton_helpers.maximum(tmp8, tmp7)
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp4, tmp9, tmp10)
    tmp12 = tmp0 >= tmp3
    tmp13 = tl.full([1], 384, tl.int64)
    tmp14 = tmp0 < tmp13
    tmp15 = tmp12 & tmp14
    tmp16 = tl.load(in_ptr2 + (x0 + 16 * (-256 + x1) + 2048 * x2), tmp15,
        other=0.0)
    tmp17 = tl.load(in_ptr3 + (-256 + x1), tmp15, eviction_policy=
        'evict_last', other=0.0)
    tmp18 = tmp16 + tmp17
    tmp19 = triton_helpers.maximum(tmp8, tmp18)
    tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
    tmp21 = tl.where(tmp15, tmp19, tmp20)
    tmp22 = tmp0 >= tmp13
    tl.full([1], 512, tl.int64)
    tmp25 = tl.load(in_ptr4 + (x0 + 16 * (-384 + x1) + 2048 * x2), tmp22,
        other=0.0)
    tmp26 = tl.load(in_ptr5 + (-384 + x1), tmp22, eviction_policy=
        'evict_last', other=0.0)
    tmp27 = tmp25 + tmp26
    tmp28 = triton_helpers.maximum(tmp8, tmp27)
    tmp29 = tl.full(tmp28.shape, 0.0, tmp28.dtype)
    tmp30 = tl.where(tmp22, tmp28, tmp29)
    tmp31 = tl.where(tmp15, tmp21, tmp30)
    tmp32 = tl.where(tmp4, tmp11, tmp31)
    tl.store(out_ptr0 + x3, tmp32, None)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_3(in_ptr0, in_ptr1,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 16 % 128
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + x3, tmp6, None)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_4(in_ptr0, in_ptr1,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 16 % 256
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + x3, tmp6, None)


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) = args
    args.clear()
    assert_size_stride(primals_1, (256, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_2, (256,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (256, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_5, (256,), (1,))
    assert_size_stride(primals_6, (128, 256, 3, 3), (2304, 9, 3, 1))
    assert_size_stride(primals_7, (128,), (1,))
    assert_size_stride(primals_8, (128, 256, 3, 3), (2304, 9, 3, 1))
    assert_size_stride(primals_9, (128,), (1,))
    assert_size_stride(primals_10, (128, 128, 3, 3), (1152, 9, 3, 1))
    assert_size_stride(primals_11, (128,), (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, 256, 4, 4), (4096, 16, 4, 1))
        buf1 = extern_kernels.convolution(primals_3, primals_4, stride=(1, 
            1), padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 256, 4, 4), (4096, 16, 4, 1))
        buf2 = buf1
        del buf1
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_0[grid(16384)](buf2, primals_5, 
            16384, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_5
        buf3 = extern_kernels.convolution(buf2, primals_6, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 128, 4, 4), (2048, 16, 4, 1))
        buf4 = extern_kernels.convolution(buf2, primals_8, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 128, 4, 4), (2048, 16, 4, 1))
        buf5 = buf4
        del buf4
        triton_poi_fused_convolution_relu_1[grid(8192)](buf5, primals_9, 
            8192, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_9
        buf6 = extern_kernels.convolution(buf5, primals_10, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 128, 4, 4), (2048, 16, 4, 1))
        buf7 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.
            float32)
        triton_poi_fused_cat_2[grid(32768)](buf0, primals_2, buf3,
            primals_7, buf6, primals_11, buf7, 32768, XBLOCK=256, num_warps
            =4, num_stages=1)
        buf8 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_3[grid(8192)](buf6
            , primals_11, buf8, 8192, XBLOCK=256, num_warps=4, num_stages=1)
        del buf6
        del primals_11
        buf9 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_3[grid(8192)](buf3
            , primals_7, buf9, 8192, XBLOCK=256, num_warps=4, num_stages=1)
        del buf3
        del primals_7
        buf10 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.bool
            )
        triton_poi_fused_convolution_relu_threshold_backward_4[grid(16384)](
            buf0, primals_2, buf10, 16384, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf0
        del primals_2
    return (buf7, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, buf2, buf5, buf8, buf9, buf10)


class FEMNew(nn.Module):

    def __init__(self, channel_size):
        super(FEMNew, self).__init__()
        self.cs = channel_size
        self.cpm1 = nn.Conv2d(self.cs, 256, kernel_size=3, dilation=1,
            stride=1, padding=1)
        self.cpm2 = nn.Conv2d(self.cs, 256, kernel_size=3, dilation=2,
            stride=1, padding=2)
        self.cpm3 = nn.Conv2d(256, 128, kernel_size=3, dilation=1, stride=1,
            padding=1)
        self.cpm4 = nn.Conv2d(256, 128, kernel_size=3, dilation=2, stride=1,
            padding=2)
        self.cpm5 = nn.Conv2d(128, 128, kernel_size=3, dilation=1, stride=1,
            padding=1)

    def forward(self, input_0):
        primals_1 = self.cpm1.weight
        primals_2 = self.cpm1.bias
        primals_4 = self.cpm2.weight
        primals_5 = self.cpm2.bias
        primals_6 = self.cpm3.weight
        primals_7 = self.cpm3.bias
        primals_8 = self.cpm4.weight
        primals_9 = self.cpm4.bias
        primals_10 = self.cpm5.weight
        primals_11 = self.cpm5.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])
        return output[0]


Measured latency_ms: 0.014022