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.triton_helpers import libdevice
import numpy as np
import torch.nn as nn
from torch.autograd import Variable
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_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused__prelu_kernel_div_pow_sub_sum_1(in_ptr0, in_ptr1,
    out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + 0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp5 = tmp4 * tmp0
    tmp6 = tl.where(tmp2, tmp0, tmp5)
    tmp8 = tmp7 > tmp1
    tmp9 = tmp4 * tmp7
    tmp10 = tl.where(tmp8, tmp7, tmp9)
    tmp11 = tmp6 + tmp10
    tmp13 = tmp12 > tmp1
    tmp14 = tmp4 * tmp12
    tmp15 = tl.where(tmp13, tmp12, tmp14)
    tmp16 = tmp11 + tmp15
    tmp18 = tmp17 > tmp1
    tmp19 = tmp4 * tmp17
    tmp20 = tl.where(tmp18, tmp17, tmp19)
    tmp21 = tmp16 + tmp20
    tmp22 = 0.25
    tmp23 = tmp21 * tmp22
    tmp24 = tmp6 - tmp23
    tmp25 = tmp24 * tmp24
    tmp26 = tmp10 - tmp23
    tmp27 = tmp26 * tmp26
    tmp28 = tmp25 + tmp27
    tmp29 = tmp15 - tmp23
    tmp30 = tmp29 * tmp29
    tmp31 = tmp28 + tmp30
    tmp32 = tmp20 - tmp23
    tmp33 = tmp32 * tmp32
    tmp34 = tmp31 + tmp33
    tmp35 = tmp34 * tmp22
    tl.store(out_ptr0 + x0, tmp23, xmask)
    tl.store(out_ptr1 + x0, tmp35, xmask)


@triton.jit
def triton_poi_fused__prelu_kernel_add_div_mul_sub_2(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
    x4 = xindex
    x5 = xindex // 4
    x2 = xindex // 16 % 4
    tmp0 = tl.load(in_ptr0 + x4, xmask)
    tmp3 = tl.load(in_ptr1 + 0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp7 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + x5, xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr4 + x2, xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr5 + x2, xmask, eviction_policy='evict_last')
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp5 = tmp4 * tmp0
    tmp6 = tl.where(tmp2, tmp0, tmp5)
    tmp8 = tmp6 - tmp7
    tmp10 = 1e-08
    tmp11 = tmp9 + tmp10
    tmp12 = libdevice.sqrt(tmp11)
    tmp13 = tmp8 / tmp12
    tmp15 = tmp13 * tmp14
    tmp17 = tmp15 + tmp16
    tl.store(out_ptr0 + x4, tmp17, xmask)


@triton.jit
def triton_poi_fused__prelu_kernel_add_convolution_div_mul_pow_sqrt_sub_sum_3(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + 0)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp18 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp7 = tmp6 * tmp2
    tmp8 = tl.where(tmp4, tmp2, tmp7)
    tmp9 = 1.0
    tmp10 = tmp8 * tmp9
    tmp11 = tmp8 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = tmp12 * tmp9
    tmp14 = 1e-08
    tmp15 = tmp13 + tmp14
    tmp16 = libdevice.sqrt(tmp15)
    tmp17 = tmp11 / tmp16
    tmp19 = tmp17 * tmp18
    tmp21 = tmp19 + tmp20
    tl.store(in_out_ptr0 + x2, tmp2, xmask)
    tl.store(out_ptr0 + x2, tmp21, xmask)


@triton.jit
def triton_poi_fused_convolution_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x2, tmp2, 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) = 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, (1,), (1,))
    assert_size_stride(primals_5, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_6, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_7, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (1,), (1,))
    assert_size_stride(primals_10, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_11, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_12, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_13, (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
        get_raw_stream(0)
        triton_poi_fused_convolution_0[grid(256)](buf1, primals_2, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_2
        buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        triton_poi_fused__prelu_kernel_div_pow_sub_sum_1[grid(64)](buf1,
            primals_4, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__prelu_kernel_add_div_mul_sub_2[grid(256)](buf1,
            primals_4, buf2, buf3, primals_5, primals_6, buf4, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        del buf2
        del buf3
        del primals_6
        buf5 = extern_kernels.convolution(buf4, primals_7, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 4, 1, 1), (4, 1, 1, 1))
        buf6 = buf5
        del buf5
        buf7 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
        triton_poi_fused__prelu_kernel_add_convolution_div_mul_pow_sqrt_sub_sum_3[
            grid(16)](buf6, primals_8, primals_9, primals_10, primals_11,
            buf7, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_11
        del primals_8
        buf8 = extern_kernels.convolution(buf7, primals_12, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 4, 1, 1), (4, 1, 1, 1))
        buf9 = buf8
        del buf8
        triton_poi_fused_convolution_4[grid(16)](buf9, primals_13, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        del primals_13
    return (buf9, primals_1, primals_3, primals_4, primals_5, primals_7,
        primals_9, primals_10, primals_12, buf1, buf4, buf6, buf7)


class tLN(nn.Module):

    def __init__(self, dimension, eps=1e-08, trainable=True):
        super(tLN, self).__init__()
        self.eps = eps
        if trainable:
            self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1))
            self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1))
        else:
            self.gain = Variable(torch.ones(1, dimension, 1, 1),
                requires_grad=False)
            self.bias = Variable(torch.zeros(1, dimension, 1, 1),
                requires_grad=False)

    def forward(self, inp):
        inp.size(0)
        mean = torch.sum(inp, 3, keepdim=True) / inp.shape[3]
        std = torch.sqrt(torch.sum((inp - mean) ** 2, 3, keepdim=True) /
            inp.shape[3] + self.eps)
        x = (inp - mean.expand_as(inp)) / std.expand_as(inp)
        return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as(
            x).type(x.type())


class CausalConv2d(torch.nn.Conv2d):

    def __init__(self, in_channels, out_channels, kernel_size, stride=(1, 1
        ), dilation=(1, 1), groups=1, bias=True):
        _pad = int(np.log2((kernel_size[1] - 1) / 2))
        padding_2 = int(2 ** (np.log2(dilation[1]) + _pad))
        self.__padding = (kernel_size[0] - 1) * dilation[0], padding_2
        super(CausalConv2d, self).__init__(in_channels, out_channels,
            kernel_size=kernel_size, stride=stride, padding=self.__padding,
            dilation=dilation, groups=groups, bias=bias)

    def forward(self, input):
        result = super(CausalConv2d, self).forward(input)
        if self.__padding[0] != 0:
            return result[:, :, :-self.__padding[0]]
        return result


class DepthConv2dNew(nn.Module):

    def __init__(self, input_channel, hidden_channel, kernel, dilation=(1, 
        1), stride=(1, 1), padding=(0, 0), causal=False):
        super(DepthConv2dNew, self).__init__()
        self.padding = padding
        self.linear = nn.Conv2d(input_channel, hidden_channel, (1, 1))
        if causal:
            self.conv1d = CausalConv2d(hidden_channel, hidden_channel,
                kernel, stride=stride, dilation=dilation)
        else:
            self.conv1d = nn.Conv2d(hidden_channel, hidden_channel, kernel,
                stride=stride, padding=self.padding, dilation=dilation)
        self.BN = nn.Conv2d(hidden_channel, input_channel, (1, 1))
        self.nonlinearity1 = nn.PReLU()
        self.nonlinearity2 = nn.PReLU()
        self.reg1 = tLN(hidden_channel)
        self.reg2 = tLN(hidden_channel)

    def forward(self, input_0):
        primals_1 = self.linear.weight
        primals_2 = self.linear.bias
        primals_3 = self.conv1d.weight
        primals_8 = self.conv1d.bias
        primals_12 = self.BN.weight
        primals_13 = self.BN.bias
        primals_4 = self.nonlinearity1.weight
        primals_9 = self.nonlinearity2.weight
        primals_5 = self.reg1.gain
        primals_6 = self.reg1.bias
        primals_10 = self.reg2.gain
        primals_11 = self.reg2.bias
        primals_7 = 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])
        return output[0]


Measured latency_ms: 0.052622