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 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_native_layer_norm_0(in_ptr0, 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')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tmp9 = tmp0 - tmp8
    tmp10 = tmp9 * tmp9
    tmp11 = tmp1 - tmp8
    tmp12 = tmp11 * tmp11
    tmp13 = tmp10 + tmp12
    tmp14 = tmp3 - tmp8
    tmp15 = tmp14 * tmp14
    tmp16 = tmp13 + tmp15
    tmp17 = tmp5 - tmp8
    tmp18 = tmp17 * tmp17
    tmp19 = tmp16 + tmp18
    tmp20 = tmp19 / tmp7
    tmp21 = 1e-05
    tmp22 = tmp20 + tmp21
    tmp23 = libdevice.rsqrt(tmp22)
    tl.store(out_ptr0 + x0, tmp8, xmask)
    tl.store(out_ptr1 + x0, tmp23, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_native_layer_norm_1(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 * tmp3
    tmp6 = tmp4 * tmp5
    tmp8 = tmp6 + tmp7
    tmp9 = 0.0
    tmp10 = tmp8 > tmp9
    tmp11 = 0.17
    tmp12 = tmp8 * tmp11
    tmp13 = tl.where(tmp10, tmp8, tmp12)
    tl.store(in_out_ptr0 + x2, tmp13, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_native_layer_norm_2(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 * tmp3
    tmp6 = tmp4 * tmp5
    tmp8 = tmp6 + tmp7
    tmp9 = 0.0
    tmp10 = tmp8 > tmp9
    tmp11 = 0.495
    tmp12 = tmp8 * tmp11
    tmp13 = tl.where(tmp10, tmp8, tmp12)
    tl.store(in_out_ptr0 + x2, tmp13, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_native_layer_norm_3(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 * tmp3
    tmp6 = tmp4 * tmp5
    tmp8 = tmp6 + tmp7
    tmp9 = 0.0
    tmp10 = tmp8 > tmp9
    tmp11 = 0.825
    tmp12 = tmp8 * tmp11
    tmp13 = tl.where(tmp10, tmp8, tmp12)
    tl.store(in_out_ptr0 + x2, tmp13, xmask)


@triton.jit
def triton_poi_fused_native_layer_norm_4(in_ptr0, out_ptr0, 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 + 2 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 2.0
    tmp4 = tmp2 / tmp3
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused_native_layer_norm_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 2
    x0 = xindex % 2
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp3 - tmp1
    tmp5 = tmp4 * tmp4
    tmp7 = tmp6 - tmp1
    tmp8 = tmp7 * tmp7
    tmp9 = tmp5 + tmp8
    tmp10 = 2.0
    tmp11 = tmp9 / tmp10
    tmp12 = 1e-05
    tmp13 = tmp11 + tmp12
    tmp14 = libdevice.rsqrt(tmp13)
    tmp15 = tmp2 * tmp14
    tmp17 = tmp15 * tmp16
    tmp19 = tmp17 + tmp18
    tl.store(out_ptr0 + x2, tmp19, xmask)


@triton.jit
def triton_poi_fused_sigmoid_6(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
    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
    tmp3 = tl.sigmoid(tmp2)
    tl.store(in_out_ptr0 + x2, 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,
        primals_18, primals_19) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (4, 4), (4, 1))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (4, 4), (4, 1))
    assert_size_stride(primals_11, (4,), (1,))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (2, 4), (4, 1))
    assert_size_stride(primals_15, (2,), (1,))
    assert_size_stride(primals_16, (2,), (1,))
    assert_size_stride(primals_17, (2,), (1,))
    assert_size_stride(primals_18, (4, 2), (2, 1))
    assert_size_stride(primals_19, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (64, 
            4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf0)
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_native_layer_norm_0[grid(64)](buf0, buf1, buf2, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf4 = buf3
        del buf3
        triton_poi_fused_leaky_relu_native_layer_norm_1[grid(256)](buf4,
            buf0, buf1, buf2, primals_4, primals_5, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_7, reinterpret_tensor(buf4, (64, 4), (
            4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0),
            alpha=1, beta=1, out=buf5)
        del primals_7
        buf6 = buf2
        del buf2
        buf7 = buf1
        del buf1
        triton_poi_fused_native_layer_norm_0[grid(64)](buf5, buf6, buf7, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf9 = buf8
        del buf8
        triton_poi_fused_leaky_relu_native_layer_norm_2[grid(256)](buf9,
            buf5, buf6, buf7, primals_8, primals_9, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf10 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_11, reinterpret_tensor(buf9, (64, 4),
            (4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0),
            alpha=1, beta=1, out=buf10)
        del primals_11
        buf11 = buf7
        del buf7
        buf12 = buf6
        del buf6
        triton_poi_fused_native_layer_norm_0[grid(64)](buf10, buf11, buf12,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf14 = buf13
        del buf13
        triton_poi_fused_leaky_relu_native_layer_norm_3[grid(256)](buf14,
            buf10, buf11, buf12, primals_12, primals_13, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf11
        buf15 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
        extern_kernels.addmm(primals_15, reinterpret_tensor(buf14, (64, 4),
            (4, 1), 0), reinterpret_tensor(primals_14, (4, 2), (1, 4), 0),
            alpha=1, beta=1, out=buf15)
        del primals_15
        buf16 = buf12
        del buf12
        triton_poi_fused_native_layer_norm_4[grid(64)](buf15, buf16, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf17 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
        triton_poi_fused_native_layer_norm_5[grid(128)](buf15, buf16,
            primals_16, primals_17, buf17, 128, XBLOCK=128, num_warps=4,
            num_stages=1)
        del buf16
        del primals_17
        buf18 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf17, (64, 2), (2, 1), 0),
            reinterpret_tensor(primals_18, (2, 4), (1, 2), 0), out=buf18)
        buf19 = reinterpret_tensor(buf18, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf18
        triton_poi_fused_sigmoid_6[grid(256)](buf19, primals_19, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_19
    return (buf19, primals_4, primals_5, primals_8, primals_9, primals_12,
        primals_13, primals_16, reinterpret_tensor(primals_1, (64, 4), (4, 
        1), 0), buf0, reinterpret_tensor(buf4, (64, 4), (4, 1), 0), buf5,
        reinterpret_tensor(buf9, (64, 4), (4, 1), 0), buf10,
        reinterpret_tensor(buf14, (64, 4), (4, 1), 0), buf15,
        reinterpret_tensor(buf17, (64, 2), (2, 1), 0), buf19, primals_18,
        primals_14, primals_10, primals_6)


class ActorNew(nn.Module):

    def __init__(self, hidden_size, action, num_inputs, num_output,
        spp_num_outputs=[1, 2, 4], data_width=8):
        super(ActorNew, self).__init__()
        self.action = action
        self.num_inputs = num_inputs
        self.num_outputs = num_output
        self.spp_data_width = data_width
        self.spp_num_outputs = spp_num_outputs
        self.fc_num_inputs = sum([(i * i) for i in self.spp_num_outputs])
        """
        #设计残差模块用于Cb-x的向量输入
        self.Cbx_res_block1 = nn.Sequential(
            nn.Conv2d(1, 128, kernel_size=1, padding=0),
            nn.BatchNorm2d(128),
            nn.RReLU(0.66, 0.99),
            nn.Conv2d(128, 128, kernel_size=3, padding=1),
            nn.BatchNorm2d(128),
            nn.RReLU(0.33, 0.66),
            nn.Conv2d(128, 1, kernel_size=3, padding=1),
            nn.BatchNorm2d(1)
        )

        self.Cbx_res_block2 = nn.Sequential(
            nn.Conv2d(1, 128, kernel_size=1, padding=0),
            nn.BatchNorm2d(128),
            nn.RReLU(0.66, 0.99),
            nn.Conv2d(128, 128, kernel_size=3, padding=1),
            nn.BatchNorm2d(128),
            nn.RReLU(0.33, 0.66),
            nn.Conv2d(128, 1, kernel_size=3, padding=1),
            nn.BatchNorm2d(1)
        )
        """
        self.afc1 = nn.Linear(self.num_inputs, hidden_size)
        self.ln1 = nn.LayerNorm(hidden_size)
        self.relu1 = nn.RReLU(0.01, 0.33)
        self.afc2 = nn.Linear(hidden_size, hidden_size)
        self.ln2 = nn.LayerNorm(hidden_size)
        self.relu2 = nn.RReLU(0.33, 0.66)
        self.afc3 = nn.Linear(hidden_size, hidden_size)
        self.ln3 = nn.LayerNorm(hidden_size)
        self.relu3 = nn.RReLU(0.66, 0.99)
        self.afc4 = nn.Linear(hidden_size, hidden_size // 2)
        self.ln4 = nn.LayerNorm(hidden_size // 2)
        self.drop = nn.Dropout()
        self.mu = nn.Linear(hidden_size // 2, self.num_outputs)
        self.mu.weight.data.mul_(0.1)
        self.mu.bias.data.mul_(0.1)

    def forward(self, input_0):
        primals_2 = self.afc1.weight
        primals_3 = self.afc1.bias
        primals_4 = self.ln1.weight
        primals_5 = self.ln1.bias
        primals_6 = self.afc2.weight
        primals_7 = self.afc2.bias
        primals_8 = self.ln2.weight
        primals_9 = self.ln2.bias
        primals_10 = self.afc3.weight
        primals_11 = self.afc3.bias
        primals_12 = self.ln3.weight
        primals_13 = self.ln3.bias
        primals_14 = self.afc4.weight
        primals_15 = self.afc4.bias
        primals_16 = self.ln4.weight
        primals_17 = self.ln4.bias
        primals_18 = self.mu.weight
        primals_19 = self.mu.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,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19])
        return output[0]


Measured latency_ms: 0.179802