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 math as tl_math
import numpy as np
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_mul_sin_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, None)
    tmp1 = 30.0
    tmp2 = tmp0 * tmp1
    tmp3 = tl_math.sin(tmp2)
    tl.store(out_ptr0 + x0, tmp3, None)


@triton.jit
def triton_poi_fused_mul_sin_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, None)
    tmp1 = 30.0
    tmp2 = tmp0 * tmp1
    tmp3 = tl_math.sin(tmp2)
    tl.store(out_ptr0 + x0, tmp3, None)


@triton.jit
def triton_poi_fused_mul_sin_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, None)
    tmp1 = 30.0
    tmp2 = tmp0 * tmp1
    tmp3 = tl_math.sin(tmp2)
    tl.store(out_ptr0 + x0, tmp3, None)


@triton.jit
def triton_poi_fused_mul_sin_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = 30.0
    tmp2 = tmp0 * tmp1
    tmp3 = tl_math.sin(tmp2)
    tl.store(out_ptr0 + x0, tmp3, 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, primals_14, primals_15, primals_16, primals_17) = args
    args.clear()
    assert_size_stride(primals_1, (128, 4), (4, 1))
    assert_size_stride(primals_2, (128,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_4, (64, 128), (128, 1))
    assert_size_stride(primals_5, (64,), (1,))
    assert_size_stride(primals_6, (32, 64), (64, 1))
    assert_size_stride(primals_7, (32,), (1,))
    assert_size_stride(primals_8, (4, 32), (32, 1))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (32, 4), (4, 1))
    assert_size_stride(primals_11, (32,), (1,))
    assert_size_stride(primals_12, (64, 32), (32, 1))
    assert_size_stride(primals_13, (64,), (1,))
    assert_size_stride(primals_14, (128, 64), (64, 1))
    assert_size_stride(primals_15, (128,), (1,))
    assert_size_stride(primals_16, (4, 128), (128, 1))
    assert_size_stride(primals_17, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
        extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 
            4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 128), (1, 4),
            0), alpha=1, beta=1, out=buf0)
        del primals_1
        del primals_2
        buf1 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mul_sin_0[grid(8192)](buf0, buf1, 8192, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf2 = empty_strided_cuda((64, 64), (64, 1), torch.float32)
        extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128),
            (128, 1), 0), reinterpret_tensor(primals_4, (128, 64), (1, 128),
            0), alpha=1, beta=1, out=buf2)
        del primals_5
        buf3 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.
            float32)
        triton_poi_fused_mul_sin_1[grid(4096)](buf2, buf3, 4096, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf4 = empty_strided_cuda((64, 32), (32, 1), torch.float32)
        extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 64),
            (64, 1), 0), reinterpret_tensor(primals_6, (64, 32), (1, 64), 0
            ), alpha=1, beta=1, out=buf4)
        del primals_7
        buf5 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.
            float32)
        triton_poi_fused_mul_sin_2[grid(2048)](buf4, buf5, 2048, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_9, reinterpret_tensor(buf5, (64, 32),
            (32, 1), 0), reinterpret_tensor(primals_8, (32, 4), (1, 32), 0),
            alpha=1, beta=1, out=buf6)
        del primals_9
        buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_mul_sin_3[grid(256)](buf6, buf7, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf8 = empty_strided_cuda((64, 32), (32, 1), torch.float32)
        extern_kernels.addmm(primals_11, reinterpret_tensor(buf7, (64, 4),
            (4, 1), 0), reinterpret_tensor(primals_10, (4, 32), (1, 4), 0),
            alpha=1, beta=1, out=buf8)
        del primals_11
        buf9 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.
            float32)
        triton_poi_fused_mul_sin_2[grid(2048)](buf8, buf9, 2048, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf10 = empty_strided_cuda((64, 64), (64, 1), torch.float32)
        extern_kernels.addmm(primals_13, reinterpret_tensor(buf9, (64, 32),
            (32, 1), 0), reinterpret_tensor(primals_12, (32, 64), (1, 32), 
            0), alpha=1, beta=1, out=buf10)
        del primals_13
        buf11 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch
            .float32)
        triton_poi_fused_mul_sin_1[grid(4096)](buf10, buf11, 4096, XBLOCK=
            256, num_warps=4, num_stages=1)
        buf12 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
        extern_kernels.addmm(primals_15, reinterpret_tensor(buf11, (64, 64),
            (64, 1), 0), reinterpret_tensor(primals_14, (64, 128), (1, 64),
            0), alpha=1, beta=1, out=buf12)
        del primals_15
        buf13 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
            torch.float32)
        triton_poi_fused_mul_sin_0[grid(8192)](buf12, buf13, 8192, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf14 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_17, reinterpret_tensor(buf13, (64, 128
            ), (128, 1), 0), reinterpret_tensor(primals_16, (128, 4), (1, 
            128), 0), alpha=1, beta=1, out=buf14)
        del primals_17
    return (reinterpret_tensor(buf14, (4, 4, 4, 4), (64, 16, 4, 1), 0),
        buf7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf0,
        reinterpret_tensor(buf1, (64, 128), (128, 1), 0), buf2,
        reinterpret_tensor(buf3, (64, 64), (64, 1), 0), buf4,
        reinterpret_tensor(buf5, (64, 32), (32, 1), 0), buf6,
        reinterpret_tensor(buf7, (64, 4), (4, 1), 0), buf8,
        reinterpret_tensor(buf9, (64, 32), (32, 1), 0), buf10,
        reinterpret_tensor(buf11, (64, 64), (64, 1), 0), buf12,
        reinterpret_tensor(buf13, (64, 128), (128, 1), 0), primals_16,
        primals_14, primals_12, primals_10, primals_8, primals_6, primals_4)


class SirenLayer(nn.Module):

    def __init__(self, in_f, out_f, w0=30, is_first=False, is_last=False):
        super().__init__()
        self.in_f = in_f
        self.w0 = w0
        self.linear = nn.Linear(in_f, out_f)
        self.is_first = is_first
        self.is_last = is_last
        self.init_weights()

    def init_weights(self):
        b = 1 / self.in_f if self.is_first else np.sqrt(6 / self.in_f
            ) / self.w0
        with torch.no_grad():
            self.linear.weight.uniform_(-b, b)

    def forward(self, x):
        x = self.linear(x)
        return x if self.is_last else torch.sin(self.w0 * x)


class RefineDoublePendulumModelNew(torch.nn.Module):

    def __init__(self, in_channels):
        super(RefineDoublePendulumModelNew, self).__init__()
        self.layer1 = SirenLayer(in_channels, 128, is_first=True)
        self.layer2 = SirenLayer(128, 64)
        self.layer3 = SirenLayer(64, 32)
        self.layer4 = SirenLayer(32, 4)
        self.layer5 = SirenLayer(4, 32)
        self.layer6 = SirenLayer(32, 64)
        self.layer7 = SirenLayer(64, 128)
        self.layer8 = SirenLayer(128, in_channels, is_last=True)

    def forward(self, input_0):
        primals_1 = self.layer1.linear.weight
        primals_2 = self.layer1.linear.bias
        primals_4 = self.layer2.linear.weight
        primals_5 = self.layer2.linear.bias
        primals_6 = self.layer3.linear.weight
        primals_7 = self.layer3.linear.bias
        primals_8 = self.layer4.linear.weight
        primals_9 = self.layer4.linear.bias
        primals_10 = self.layer5.linear.weight
        primals_11 = self.layer5.linear.bias
        primals_12 = self.layer6.linear.weight
        primals_13 = self.layer6.linear.bias
        primals_14 = self.layer7.linear.weight
        primals_15 = self.layer7.linear.bias
        primals_16 = self.layer8.linear.weight
        primals_17 = self.layer8.linear.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, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17])
        return output[0], output[1]


Measured latency_ms: 0.023726