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, math as tl_math
from torch import 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, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 6
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 2, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 1, tl.int64)
    tmp6 = tmp0 < tmp5
    tmp7 = 0.0
    tmp8 = 1.0
    tmp9 = tl.where(tmp6, tmp7, tmp8)
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp4, tmp9, tmp10)
    tmp12 = tmp0 >= tmp3
    tl.full([1], 6, tl.int64)
    tmp15 = tl.load(in_ptr0 + (-2 + x0), tmp12 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp16 = tl.where(tmp4, tmp11, tmp15)
    tl.store(out_ptr0 + x0, tmp16, xmask)


@triton.jit
def triton_poi_fused_softplus_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.load(in_ptr0 + 0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = 1.0
    tmp3 = tmp1 * tmp2
    tmp4 = 20.0
    tmp5 = tmp3 > tmp4
    tmp6 = tl_math.exp(tmp3)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tmp7 * tmp2
    tmp9 = tl.where(tmp5, tmp1, tmp8)
    tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp9, None)


@triton.jit
def triton_poi_fused_softplus_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 1024
    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 = 1.0
    tmp2 = tmp0 * tmp1
    tmp3 = 20.0
    tmp4 = tmp2 > tmp3
    tmp5 = tl_math.exp(tmp2)
    tmp6 = libdevice.log1p(tmp5)
    tmp7 = tmp6 * tmp1
    tmp8 = tl.where(tmp4, tmp0, tmp7)
    tl.store(out_ptr0 + x0, tmp8, xmask)


@triton.jit
def triton_poi_fused_add_sigmoid_softplus_3(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 1024
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = 1.0
    tmp3 = tmp1 * tmp2
    tmp4 = 20.0
    tmp5 = tmp3 > tmp4
    tmp6 = tl_math.exp(tmp3)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tmp7 * tmp2
    tmp9 = tl.where(tmp5, tmp1, tmp8)
    tmp10 = tmp0 + tmp9
    tmp11 = tl.sigmoid(tmp10)
    tl.store(in_out_ptr0 + x2, tmp11, None)


@triton.jit
def triton_poi_fused_sub_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    tmp0 = tl.load(in_ptr0 + 1)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
    tmp2 = tl.load(in_ptr1 + 1)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp4 = tl.load(in_ptr2 + 0)
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK])
    tmp16 = tl.load(in_ptr0 + 0)
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK])
    tmp18 = tl.load(in_ptr1 + 0)
    tmp19 = tl.broadcast_to(tmp18, [XBLOCK])
    tmp6 = 1.0
    tmp7 = tmp5 * tmp6
    tmp8 = 20.0
    tmp9 = tmp7 > tmp8
    tmp10 = tl_math.exp(tmp7)
    tmp11 = libdevice.log1p(tmp10)
    tmp12 = tmp11 * tmp6
    tmp13 = tl.where(tmp9, tmp5, tmp12)
    tmp14 = tmp3 + tmp13
    tmp15 = tmp1 + tmp14
    tmp20 = tmp19 + tmp13
    tmp21 = tmp17 + tmp20
    tmp22 = tmp15 - tmp21
    tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp22, None)


@triton.jit
def triton_poi_fused_add_div_mul_neg_softplus_sub_5(in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr1, out_ptr2, out_ptr3,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (2 + x0), xmask)
    tmp1 = tl.load(in_ptr1 + (2 + x0), xmask)
    tmp2 = tl.load(in_ptr2 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp14 = tl.load(in_ptr0 + 0)
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK])
    tmp16 = tl.load(in_ptr1 + 0)
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK])
    tmp21 = tl.load(in_ptr3 + 0)
    tmp22 = tl.broadcast_to(tmp21, [XBLOCK])
    tmp25 = tl.load(in_ptr4 + 0)
    tmp26 = tl.broadcast_to(tmp25, [XBLOCK])
    tmp27 = tl.load(in_ptr5 + 0)
    tmp28 = tl.broadcast_to(tmp27, [XBLOCK])
    tmp4 = 1.0
    tmp5 = tmp3 * tmp4
    tmp6 = 20.0
    tmp7 = tmp5 > tmp6
    tmp8 = tl_math.exp(tmp5)
    tmp9 = libdevice.log1p(tmp8)
    tmp10 = tmp9 * tmp4
    tmp11 = tl.where(tmp7, tmp3, tmp10)
    tmp12 = tmp1 + tmp11
    tmp13 = tmp0 + tmp12
    tmp18 = tmp17 + tmp11
    tmp19 = tmp15 + tmp18
    tmp20 = tmp13 - tmp19
    tmp23 = tmp20 / tmp22
    tmp24 = tmp23 / tmp22
    tmp29 = tmp28 * tmp4
    tmp30 = tmp29 > tmp6
    tmp31 = tl_math.exp(tmp29)
    tmp32 = libdevice.log1p(tmp31)
    tmp33 = tmp32 * tmp4
    tmp34 = tl.where(tmp30, tmp28, tmp33)
    tmp35 = tmp34 * tmp23
    tmp36 = tmp26 + tmp35
    tmp37 = -tmp36
    tl.store(out_ptr1 + x0, tmp23, xmask)
    tl.store(out_ptr2 + x0, tmp24, xmask)
    tl.store(out_ptr3 + x0, tmp37, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9) = args
    args.clear()
    assert_size_stride(primals_1, (4,), (1,))
    assert_size_stride(primals_2, (1, 1), (1, 1))
    assert_size_stride(primals_3, (1,), (1,))
    assert_size_stride(primals_4, (1, 1024), (1024, 1))
    assert_size_stride(primals_5, (1024,), (1,))
    assert_size_stride(primals_6, (1024, 1), (1, 1))
    assert_size_stride(primals_7, (1,), (1,))
    assert_size_stride(primals_8, (), ())
    assert_size_stride(primals_9, (), ())
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((6,), (1,), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(6)](primals_1, buf0, 6, XBLOCK=8,
            num_warps=1, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((1, 1), (1, 1), torch.float32)
        triton_poi_fused_softplus_1[grid(1)](primals_2, buf1, 1, XBLOCK=1,
            num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((1,), (1,), torch.float32)
        triton_poi_fused_softplus_1[grid(1)](primals_3, buf2, 1, XBLOCK=1,
            num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((6, 1), (1, 1), torch.float32)
        extern_kernels.addmm(buf2, reinterpret_tensor(buf0, (6, 1), (1, 0),
            0), buf1, alpha=1, beta=1, out=buf4)
        del buf1
        buf5 = empty_strided_cuda((1, 1024), (1024, 1), torch.float32)
        triton_poi_fused_softplus_2[grid(1024)](primals_4, buf5, 1024,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf6 = empty_strided_cuda((6, 1024), (1024, 1), torch.float32)
        extern_kernels.mm(buf4, buf5, out=buf6)
        buf7 = buf6
        del buf6
        triton_poi_fused_add_sigmoid_softplus_3[grid(6144)](buf7, primals_5,
            6144, XBLOCK=128, num_warps=4, num_stages=1)
        buf8 = empty_strided_cuda((1024, 1), (1, 1), torch.float32)
        triton_poi_fused_softplus_2[grid(1024)](primals_6, buf8, 1024,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf9 = empty_strided_cuda((6, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf7, buf8, out=buf9)
        buf11 = reinterpret_tensor(buf2, (), (), 0)
        del buf2
        triton_poi_fused_sub_4[grid(1)](buf4, buf9, primals_7, buf11, 1,
            XBLOCK=1, num_warps=1, num_stages=1)
        buf12 = empty_strided_cuda((4,), (1,), torch.float32)
        buf14 = empty_strided_cuda((4,), (1,), torch.float32)
        buf13 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused_add_div_mul_neg_softplus_sub_5[grid(4)](buf4, buf9,
            primals_7, buf11, primals_8, primals_9, buf12, buf14, buf13, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        del buf9
        del primals_8
    return (buf13, buf12, primals_2, primals_3, primals_4, primals_5,
        primals_6, primals_7, primals_9, reinterpret_tensor(buf0, (6, 1), (
        1, 1), 0), buf7, buf11, buf12, buf14, reinterpret_tensor(buf8, (1, 
        1024), (1, 1), 0), reinterpret_tensor(buf4, (1, 6), (1, 1), 0),
        reinterpret_tensor(buf5, (1024, 1), (1, 1024), 0))


class PositiveLinear(nn.Module):

    def __init__(self, in_features: 'int', out_features: 'int') ->None:
        super().__init__()
        self.weight = nn.Parameter(torch.randn(in_features, out_features))
        self.bias = nn.Parameter(torch.zeros(out_features))
        self.softplus = nn.Softplus()

    def forward(self, input: 'torch.Tensor'):
        return input @ self.softplus(self.weight) + self.softplus(self.bias)


class SNRNetworkNew(nn.Module):

    def __init__(self) ->None:
        super().__init__()
        self.l1 = PositiveLinear(1, 1)
        self.l2 = PositiveLinear(1, 1024)
        self.l3 = PositiveLinear(1024, 1)
        self.gamma_min = nn.Parameter(torch.tensor(-10.0))
        self.gamma_max = nn.Parameter(torch.tensor(20.0))
        self.softplus = nn.Softplus()

    def forward(self, input_0):
        primals_8 = self.gamma_min
        primals_9 = self.gamma_max
        primals_2 = self.l1.weight
        primals_3 = self.l1.bias
        primals_4 = self.l2.weight
        primals_5 = self.l2.bias
        primals_6 = self.l3.weight
        primals_7 = self.l3.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9])
        return output[0], output[1]


Measured latency_ms: 0.023365