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
import torch.nn as nn
import torch.utils.data
import torch.onnx.operators
import torch.optim
import torch.optim.lr_scheduler
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_poi_fused_stack_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 8
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.load(in_ptr2 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp9 = tl.load(in_ptr3 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp10 = tmp8 + tmp9
    tmp11 = tmp7 - tmp10
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tl.full([1], 2, tl.int64)
    tmp17 = tl.load(in_ptr4 + x1, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp18 = tl.load(in_ptr1 + x1, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp19 = tmp17 + tmp18
    tmp20 = tl.load(in_ptr5 + x1, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp21 = tl.load(in_ptr3 + x1, tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp22 = tmp20 + tmp21
    tmp23 = tmp19 + tmp22
    tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
    tmp25 = tl.where(tmp14, tmp23, tmp24)
    tmp26 = tl.where(tmp4, tmp13, tmp25)
    tl.store(out_ptr0 + x2, tmp26, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_5, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1,
            4, 4, 4), (0, 64, 16, 4), 0), primals_2, stride=(1, 1), padding
            =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 
            0), groups=1, bias=None)
        assert_size_stride(buf0, (1, 4, 1, 1), (4, 1, 1, 1))
        buf1 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1,
            4, 4, 4), (0, 64, 16, 4), 1), primals_4, stride=(1, 1), padding
            =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 
            0), groups=1, bias=None)
        assert_size_stride(buf1, (1, 4, 1, 1), (4, 1, 1, 1))
        buf2 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1,
            4, 4, 4), (0, 64, 16, 4), 1), primals_2, stride=(1, 1), padding
            =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 
            0), groups=1, bias=None)
        assert_size_stride(buf2, (1, 4, 1, 1), (4, 1, 1, 1))
        buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1,
            4, 4, 4), (0, 64, 16, 4), 0), primals_4, stride=(1, 1), padding
            =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 
            0), groups=1, bias=None)
        assert_size_stride(buf3, (1, 4, 1, 1), (4, 1, 1, 1))
        buf4 = empty_strided_cuda((4, 1, 1, 2), (2, 2, 2, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_stack_0[grid(8)](buf0, primals_3, buf1, primals_5,
            buf2, buf3, buf4, 8, XBLOCK=8, num_warps=1, num_stages=1)
        del buf0
        del buf1
        del buf2
        del buf3
        del primals_3
        del primals_5
    return buf4, primals_2, primals_4, reinterpret_tensor(primals_1, (1, 4,
        4, 4), (256, 64, 16, 4), 0), reinterpret_tensor(primals_1, (1, 4, 4,
        4), (256, 64, 16, 4), 1)


class ComplexConv2dNew(nn.Module):

    def __init__(self, in_channel, out_channel, kernel_size, stride=1,
        padding=0, dilation=1, groups=1, bias=True, **kwargs):
        super().__init__()
        self.conv_re = nn.Conv2d(in_channel, out_channel, kernel_size,
            stride=stride, padding=padding, dilation=dilation, groups=
            groups, bias=bias, **kwargs)
        self.conv_im = nn.Conv2d(in_channel, out_channel, kernel_size,
            stride=stride, padding=padding, dilation=dilation, groups=
            groups, bias=bias, **kwargs)

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


Measured latency_ms: 0.014124