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
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_cat_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 2, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 32 * x2), tmp4 & xmask, 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 + (x0 + 16 * x1 + 32 * x2), tmp4 & xmask, 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], 4, tl.int64)
    tmp17 = tl.load(in_ptr4 + (x0 + 16 * (-2 + x1) + 32 * x2), tmp14 &
        xmask, other=0.0)
    tmp18 = tl.load(in_ptr3 + (-2 + x1), tmp14 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp19 = tmp17 + tmp18
    tmp20 = tl.load(in_ptr5 + (x0 + 16 * (-2 + x1) + 32 * x2), tmp14 &
        xmask, other=0.0)
    tmp21 = tl.load(in_ptr1 + (-2 + 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 + x3, 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, (2, 2, 1, 1), (2, 1, 1, 1))
    assert_size_stride(primals_3, (2,), (1,))
    assert_size_stride(primals_4, (2, 2, 1, 1), (2, 1, 1, 1))
    assert_size_stride(primals_5, (2,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
            2, 4, 4), (64, 16, 4, 1), 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, (4, 2, 4, 4), (32, 16, 4, 1))
        buf1 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
            2, 4, 4), (64, 16, 4, 1), 32), 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, (4, 2, 4, 4), (32, 16, 4, 1))
        buf2 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
            2, 4, 4), (64, 16, 4, 1), 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(buf2, (4, 2, 4, 4), (32, 16, 4, 1))
        buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
            2, 4, 4), (64, 16, 4, 1), 32), primals_2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 2, 4, 4), (32, 16, 4, 1))
        buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(256)](buf0, primals_3, buf1, primals_5,
            buf2, buf3, buf4, 256, XBLOCK=256, num_warps=4, 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, (4, 2,
        4, 4), (64, 16, 4, 1), 0), reinterpret_tensor(primals_1, (4, 2, 4, 
        4), (64, 16, 4, 1), 32)


class ComplexConv2dNew(nn.Module):

    def __init__(self, in_channels, out_channels, kernel_size=(1, 1),
        stride=(1, 1), padding=(0, 0), dilation=1, groups=1, causal=True,
        complex_axis=1):
        """
            in_channels: real+imag
            out_channels: real+imag
            kernel_size : input [B,C,D,T] kernel size in [D,T]
            padding : input [B,C,D,T] padding in [D,T]
            causal: if causal, will padding time dimension's left side,
                    otherwise both

        """
        super(ComplexConv2dNew, self).__init__()
        self.in_channels = in_channels // 2
        self.out_channels = out_channels // 2
        self.kernel_size = kernel_size
        self.stride = stride
        self.padding = padding
        self.causal = causal
        self.groups = groups
        self.dilation = dilation
        self.complex_axis = complex_axis
        self.real_conv = nn.Conv2d(self.in_channels, self.out_channels,
            kernel_size, self.stride, padding=[self.padding[0], 0],
            dilation=self.dilation, groups=self.groups)
        self.imag_conv = nn.Conv2d(self.in_channels, self.out_channels,
            kernel_size, self.stride, padding=[self.padding[0], 0],
            dilation=self.dilation, groups=self.groups)
        nn.init.normal_(self.real_conv.weight.data, std=0.05)
        nn.init.normal_(self.imag_conv.weight.data, std=0.05)
        nn.init.constant_(self.real_conv.bias, 0.0)
        nn.init.constant_(self.imag_conv.bias, 0.0)

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


Measured latency_ms: 0.0229