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
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_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 80
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 5
    x1 = xindex // 5
    x2 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 4, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp2 & xmask, other=0.0)
    tl.store(out_ptr0 + x2, tmp3, xmask)


@triton.jit
def triton_poi_fused_mul_sigmoid_tanh_1(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 8
    x4 = xindex % 8
    x1 = xindex // 4 % 2
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x4 + 16 * x2), xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (8 + x4 + 16 * x2), xmask)
    tmp5 = tl.load(in_ptr1 + (2 + x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = libdevice.tanh(tmp2)
    tmp6 = tmp4 + tmp5
    tmp7 = tl.sigmoid(tmp6)
    tmp8 = tmp3 * tmp7
    tl.store(out_ptr0 + x3, tmp3, xmask)
    tl.store(out_ptr1 + x3, tmp7, xmask)
    tl.store(out_ptr2 + x3, tmp8, xmask)


@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 4 % 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_add_convolution_mul_sqrt_3(in_out_ptr0, in_ptr0,
    in_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 4 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x3, xmask)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = 0.7071067690849304
    tmp6 = tmp4 * tmp5
    tl.store(in_out_ptr0 + x3, tmp6, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 2, 1), (2, 1, 1))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (4, 2, 1), (2, 1, 1))
    assert_size_stride(primals_7, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_constant_pad_nd_0[grid(80)](primals_1, buf0, 80,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1,),
            padding=(1,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf1, (4, 4, 4), (16, 4, 1))
        buf2 = empty_strided_cuda((4, 2, 4), (8, 4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 2, 4), (8, 4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 2, 4), (8, 4, 1), torch.float32)
        triton_poi_fused_mul_sigmoid_tanh_1[grid(32)](buf1, primals_3, buf2,
            buf3, buf4, 32, XBLOCK=32, num_warps=1, num_stages=1)
        del buf1
        del primals_3
        buf5 = extern_kernels.convolution(buf4, primals_4, stride=(1,),
            padding=(0,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf5, (4, 4, 4), (16, 4, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_2[grid(64)](buf6, primals_5, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_5
        buf7 = extern_kernels.convolution(buf4, primals_6, stride=(1,),
            padding=(0,), dilation=(1,), transposed=False, output_padding=(
            0,), groups=1, bias=None)
        assert_size_stride(buf7, (4, 4, 4), (16, 4, 1))
        buf8 = buf7
        del buf7
        triton_poi_fused_add_convolution_mul_sqrt_3[grid(64)](buf8,
            primals_7, primals_1, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del primals_1
        del primals_7
    return buf8, buf6, primals_2, primals_4, primals_6, buf0, buf2, buf3, buf4


class WaveNetLayerNew(torch.nn.Module):
    """a single gated residual wavenet layer"""

    def __init__(self, channels: 'int', kernel_size: 'int', dilation: 'int'):
        super().__init__()
        self._conv = torch.nn.Conv1d(in_channels=channels, out_channels=
            channels, kernel_size=kernel_size, padding='same', dilation=
            dilation)
        self._conv_skip = torch.nn.Conv1d(in_channels=channels // 2,
            out_channels=channels, kernel_size=1)
        self._conv_out = torch.nn.Conv1d(in_channels=channels // 2,
            out_channels=channels, kernel_size=1)

    def forward(self, input_0):
        primals_1 = self._conv.weight
        primals_3 = self._conv.bias
        primals_4 = self._conv_skip.weight
        primals_5 = self._conv_skip.bias
        primals_6 = self._conv_out.weight
        primals_7 = self._conv_out.bias
        primals_2 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7])
        return output[0], output[1]


Measured latency_ms: 0.086501