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
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 256
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tl.store(out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 1040
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 260
    x1 = xindex // 260
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 256, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (256 * x1 + x0), tmp4 & xmask, eviction_policy
        ='evict_last', other=0.0).to(tl.int1)
    tmp6 = tl.load(in_ptr1 + (256 * x1 + x0), tmp4 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp8 = tmp6 + tmp7
    tmp9 = 0.01
    tmp10 = tmp8 * tmp9
    tmp11 = tl.where(tmp5, tmp8, tmp10)
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tl.full([1], 260, tl.int64)
    tmp17 = tl.load(in_ptr3 + (4 * x1 + (-256 + x0)), tmp14 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp18 = tl.where(tmp4, tmp13, tmp17)
    tl.store(out_ptr0 + x2, tmp18, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 256
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 128
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.01
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10) = args
    args.clear()
    assert_size_stride(primals_1, (256, 4), (4, 1))
    assert_size_stride(primals_2, (256,), (1,))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, 4), (4, 1))
    assert_size_stride(primals_5, (256, 260), (260, 1))
    assert_size_stride(primals_6, (256,), (1,))
    assert_size_stride(primals_7, (128, 256), (256, 1))
    assert_size_stride(primals_8, (128,), (1,))
    assert_size_stride(primals_9, (1, 128), (128, 1))
    assert_size_stride(primals_10, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 256), (256, 1), torch.float32)
        extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 256),
            (1, 4), 0), out=buf0)
        del primals_1
        buf1 = empty_strided_cuda((4, 256), (256, 1), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_leaky_relu_0[grid(1024)](buf0, primals_2, buf1, 
            1024, XBLOCK=256, num_warps=4, num_stages=1)
        buf2 = empty_strided_cuda((4, 260), (260, 1), torch.float32)
        triton_poi_fused_cat_1[grid(1040)](buf1, buf0, primals_2, primals_4,
            buf2, 1040, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_2
        del primals_4
        buf3 = buf0
        del buf0
        extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (260, 256), (
            1, 260), 0), out=buf3)
        buf4 = empty_strided_cuda((4, 256), (256, 1), torch.bool)
        buf5 = empty_strided_cuda((4, 256), (256, 1), torch.float32)
        triton_poi_fused_leaky_relu_2[grid(1024)](buf3, primals_6, buf4,
            buf5, 1024, XBLOCK=256, num_warps=4, num_stages=1)
        del buf3
        del primals_6
        buf6 = empty_strided_cuda((4, 128), (128, 1), torch.float32)
        extern_kernels.mm(buf5, reinterpret_tensor(primals_7, (256, 128), (
            1, 256), 0), out=buf6)
        buf7 = empty_strided_cuda((4, 128), (128, 1), torch.bool)
        buf8 = empty_strided_cuda((4, 128), (128, 1), torch.float32)
        triton_poi_fused_leaky_relu_3[grid(512)](buf6, primals_8, buf7,
            buf8, 512, XBLOCK=128, num_warps=4, num_stages=1)
        del buf6
        del primals_8
        buf10 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.addmm(primals_10, buf8, reinterpret_tensor(primals_9,
            (128, 1), (1, 128), 0), alpha=1, beta=1, out=buf10)
        del primals_10
    return (buf10, primals_3, buf1, buf2, buf4, buf5, buf7, buf8, primals_9,
        primals_7, primals_5)


def hidden_init(layer):
    fan_in = layer.weight.data.size()[0]
    lim = 1.0 / np.sqrt(fan_in)
    return -lim, lim


class CriticNew(nn.Module):
    """Critic (Value) Model."""

    def __init__(self, state_size, action_size, seed, fcs1_units=256,
        fc2_units=256, fc3_units=128):
        """Initialize parameters and build model.
        Params
        ======
            state_size (int): Dimension of each state
            action_size (int): Dimension of each action
            seed (int): Random seed
            fcs1_units (int): Number of nodes in the first hidden layer
            fc2_units (int): Number of nodes in the second hidden layer
        """
        super(CriticNew, self).__init__()
        self.seed = torch.manual_seed(seed)
        self.fcs1 = nn.Linear(state_size, fcs1_units)
        self.fc2 = nn.Linear(fcs1_units + action_size, fc2_units)
        self.fc3 = nn.Linear(fc2_units, fc3_units)
        self.fc4 = nn.Linear(fc3_units, 1)
        self.reset_parameters()

    def reset_parameters(self):
        self.fcs1.weight.data.uniform_(*hidden_init(self.fcs1))
        self.fc2.weight.data.uniform_(*hidden_init(self.fc2))
        self.fc3.weight.data.uniform_(*hidden_init(self.fc3))
        self.fc4.weight.data.uniform_(-0.003, 0.003)

    def forward(self, input_0, input_1):
        primals_1 = self.fcs1.weight
        primals_2 = self.fcs1.bias
        primals_5 = self.fc2.weight
        primals_6 = self.fc2.bias
        primals_7 = self.fc3.weight
        primals_8 = self.fc3.bias
        primals_9 = self.fc4.weight
        primals_10 = self.fc4.bias
        primals_3 = input_0
        primals_4 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
        return output[0]


Measured latency_ms: 0.091