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 import triton_helpers
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_div_sub_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 = 127.0
    tmp2 = tmp0 - tmp1
    tmp3 = 0.00392156862745098
    tmp4 = tmp2 * tmp3
    tl.store(out_ptr0 + x0, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 246016
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 961 % 64
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 57600
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 15
    x1 = xindex // 15 % 15
    x2 = xindex // 225
    x5 = xindex
    x4 = xindex // 14400
    x6 = xindex % 14400
    tmp0 = tl.load(in_ptr0 + (2 * x0 + 62 * x1 + 961 * x2), xmask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 62 * x1 + 961 * x2), xmask,
        eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (31 + 2 * x0 + 62 * x1 + 961 * x2), xmask,
        eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (32 + 2 * x0 + 62 * x1 + 961 * x2), xmask,
        eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tmp7 = tmp1 > tmp0
    tmp8 = tl.full([1], 1, tl.int8)
    tmp9 = tl.full([1], 0, tl.int8)
    tmp10 = tl.where(tmp7, tmp8, tmp9)
    tmp11 = tmp3 > tmp2
    tmp12 = tl.full([1], 2, tl.int8)
    tmp13 = tl.where(tmp11, tmp12, tmp10)
    tmp14 = tmp5 > tmp4
    tmp15 = tl.full([1], 3, tl.int8)
    tmp16 = tl.where(tmp14, tmp15, tmp13)
    tl.store(out_ptr0 + x5, tmp6, xmask)
    tl.store(out_ptr1 + (x6 + 14464 * x4), tmp16, xmask)


@triton.jit
def triton_poi_fused_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 9216
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 36 % 64
    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_cat_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 3080
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 770
    x1 = xindex // 770
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 768, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (768 * x1 + x0 % 768), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + x0 // 16 % 48, tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.full([1], 0, tl.int32)
    tmp9 = triton_helpers.maximum(tmp8, tmp7)
    tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
    tmp11 = tl.where(tmp4, tmp9, tmp10)
    tmp12 = tmp0 >= tmp3
    tl.full([1], 770, tl.int64)
    tmp15 = tl.load(in_ptr2 + (128 * (-768 + x0) + 65536 * x1), tmp12 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp16 = tl.where(tmp4, tmp11, tmp15)
    tl.store(out_ptr0 + x2, tmp16, xmask)


@triton.jit
def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 24
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.full([1], 0, tl.int32)
    tmp9 = triton_helpers.maximum(tmp8, tmp7)
    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_ptr2 + (128 * (-4 + x0) + 65536 * x1), tmp12 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp16 = tl.where(tmp4, tmp11, tmp15)
    tl.store(out_ptr0 + x2, tmp16, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_6(in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + x2, tmp6, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_7(in_ptr0, in_ptr1,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 3072
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 48
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + x3, tmp6, 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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 128, 128), (65536, 16384, 128, 1))
    assert_size_stride(primals_2, (64, 4, 8, 8), (256, 64, 8, 1))
    assert_size_stride(primals_3, (64,), (1,))
    assert_size_stride(primals_4, (64, 64, 4, 4), (1024, 16, 4, 1))
    assert_size_stride(primals_5, (64,), (1,))
    assert_size_stride(primals_6, (48, 64, 3, 3), (576, 9, 3, 1))
    assert_size_stride(primals_7, (48,), (1,))
    assert_size_stride(primals_8, (4, 770), (770, 1))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (4, 6), (6, 1))
    assert_size_stride(primals_11, (4,), (1,))
    assert_size_stride(primals_12, (4, 6), (6, 1))
    assert_size_stride(primals_13, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 128, 128), (65536, 16384, 128, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_div_sub_0[grid(262144)](primals_1, buf0, 262144,
            XBLOCK=512, num_warps=8, num_stages=1)
        buf1 = extern_kernels.convolution(buf0, primals_2, stride=(4, 4),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 64, 31, 31), (61504, 961, 31, 1))
        buf2 = buf1
        del buf1
        triton_poi_fused_convolution_relu_1[grid(246016)](buf2, primals_3, 
            246016, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_3
        buf3 = empty_strided_cuda((4, 64, 15, 15), (14400, 225, 15, 1),
            torch.float32)
        buf4 = empty_strided_cuda((4, 64, 15, 15), (14464, 225, 15, 1),
            torch.int8)
        triton_poi_fused_max_pool2d_with_indices_2[grid(57600)](buf2, buf3,
            buf4, 57600, XBLOCK=256, num_warps=4, num_stages=1)
        buf5 = extern_kernels.convolution(buf3, primals_4, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 64, 6, 6), (2304, 36, 6, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_3[grid(9216)](buf6, primals_5, 9216,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_5
        buf7 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 48, 4, 4), (768, 16, 4, 1))
        buf8 = empty_strided_cuda((4, 770), (770, 1), torch.float32)
        triton_poi_fused_cat_4[grid(3080)](buf7, primals_7, primals_1, buf8,
            3080, XBLOCK=128, num_warps=4, num_stages=1)
        buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf8, reinterpret_tensor(primals_8, (770, 4), (1,
            770), 0), out=buf9)
        buf10 = empty_strided_cuda((4, 6), (6, 1), torch.float32)
        triton_poi_fused_cat_5[grid(24)](buf9, primals_9, primals_1, buf10,
            24, XBLOCK=32, num_warps=1, num_stages=1)
        buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf10, reinterpret_tensor(primals_10, (6, 4), (1,
            6), 0), out=buf11)
        buf12 = empty_strided_cuda((4, 6), (6, 1), torch.float32)
        triton_poi_fused_cat_5[grid(24)](buf11, primals_11, primals_1,
            buf12, 24, XBLOCK=32, num_warps=1, num_stages=1)
        del primals_1
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_13, buf12, reinterpret_tensor(
            primals_12, (6, 4), (1, 6), 0), alpha=1, beta=1, out=buf13)
        del primals_13
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_6[grid(16)](buf11,
            primals_11, buf14, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf11
        del primals_11
        buf15 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_6[grid(16)](buf9,
            primals_9, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf9
        del primals_9
        buf16 = empty_strided_cuda((4, 48, 4, 4), (768, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_7[grid(3072)](buf7
            , primals_7, buf16, 3072, XBLOCK=256, num_warps=4, num_stages=1)
        del buf7
        del primals_7
    return (buf13, primals_2, primals_4, primals_6, buf0, buf2, buf3, buf4,
        buf6, buf8, buf10, buf12, primals_12, buf14, primals_10, buf15,
        primals_8, buf16)


class NetworkDQNNew(nn.Module):

    def __init__(self, fs, input_dim, fc1, fc2, n_actions):
        super(NetworkDQNNew, self).__init__()
        self.conv1 = nn.Conv2d(fs, 64, 8, 4)
        self.pool1 = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(64, 64, 4, 2)
        self.conv3 = nn.Conv2d(64, 48, 3, 1)
        self.lin1 = nn.Linear(256 * 3 + 2, fc1)
        self.lin2 = nn.Linear(fc1 + 2, fc2)
        self.actl = nn.Linear(fc2 + 2, n_actions)

    def forward(self, input_0):
        primals_2 = self.conv1.weight
        primals_3 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_6 = self.conv3.weight
        primals_7 = self.conv3.bias
        primals_8 = self.lin1.weight
        primals_9 = self.lin1.bias
        primals_10 = self.lin2.weight
        primals_11 = self.lin2.bias
        primals_12 = self.actl.weight
        primals_13 = self.actl.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])
        return output[0]


Measured latency_ms: 0.214561