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
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


@triton.jit
def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 238144
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 3721 % 16
    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_convolution_relu_1(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 53824
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 3364 % 4
    x0 = xindex % 3364
    x4 = xindex // 3364
    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)
    tl.store(out_ptr0 + (x0 + 3392 * x4), tmp4, xmask)


@triton.jit
def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 13456
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 29
    x1 = xindex // 29 % 29
    x4 = xindex // 841
    x3 = xindex // 3364
    x5 = xindex % 3364
    tmp0 = tl.load(in_ptr0 + (2 * x0 + 116 * x1 + 3392 * x4), xmask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 116 * x1 + 3392 * x4), xmask,
        eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (58 + 2 * x0 + 116 * x1 + 3392 * x4), xmask,
        eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (59 + 2 * x0 + 116 * x1 + 3392 * x4), 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 + 3392 * x3), tmp6, xmask)
    tl.store(out_ptr1 + (x5 + 3456 * x3), tmp16, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 10816
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 169 % 16
    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_convolution_tanh_4(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 300
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 25 % 3
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = libdevice.tanh(tmp2)
    tl.store(in_out_ptr0 + x3, tmp3, 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, 3, 64, 64), (12288, 4096, 64, 1))
    assert_size_stride(primals_2, (16, 3, 4, 4), (48, 16, 4, 1))
    assert_size_stride(primals_3, (16,), (1,))
    assert_size_stride(primals_4, (4, 16, 4, 4), (256, 16, 4, 1))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (16, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_7, (16,), (1,))
    assert_size_stride(primals_8, (3, 16, 4, 4), (256, 16, 4, 1))
    assert_size_stride(primals_9, (3,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 16, 61, 61), (59536, 3721, 61, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_0[grid(238144)](buf1, primals_3, 
            238144, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_3
        buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 4, 58, 58), (13456, 3364, 58, 1))
        buf3 = empty_strided_cuda((4, 4, 58, 58), (13568, 3392, 58, 1),
            torch.float32)
        triton_poi_fused_convolution_relu_1[grid(53824)](buf2, primals_5,
            buf3, 53824, XBLOCK=256, num_warps=4, num_stages=1)
        del buf2
        del primals_5
        buf4 = empty_strided_cuda((4, 4, 29, 29), (3392, 841, 29, 1), torch
            .float32)
        buf5 = empty_strided_cuda((4, 4, 29, 29), (3456, 841, 29, 1), torch
            .int8)
        triton_poi_fused_max_pool2d_with_indices_2[grid(13456)](buf3, buf4,
            buf5, 13456, XBLOCK=128, num_warps=4, num_stages=1)
        buf6 = extern_kernels.convolution(buf4, primals_6, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 16, 13, 13), (2704, 169, 13, 1))
        buf7 = buf6
        del buf6
        triton_poi_fused_convolution_relu_3[grid(10816)](buf7, primals_7, 
            10816, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_7
        buf8 = extern_kernels.convolution(buf7, primals_8, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf8, (4, 3, 5, 5), (75, 25, 5, 1))
        buf9 = buf8
        del buf8
        triton_poi_fused_convolution_tanh_4[grid(300)](buf9, primals_9, 300,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_9
    return (buf9, primals_1, primals_2, primals_4, primals_6, primals_8,
        buf1, buf3, buf4, buf5, buf7, buf9)


class ActorNew(nn.Module):

    def __init__(self, kernel_size):
        super(ActorNew, self).__init__()
        self.conv1 = nn.Conv2d(3, 16, kernel_size=kernel_size)
        self.conv2 = nn.Conv2d(16, 4, kernel_size=kernel_size)
        self.pool1 = nn.MaxPool2d(2, 2)
        self.conv1_ = nn.Conv2d(4, 16, kernel_size=kernel_size, stride=2)
        self.conv2_ = nn.Conv2d(16, 3, kernel_size=kernel_size, stride=2)

    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.conv1_.weight
        primals_7 = self.conv1_.bias
        primals_8 = self.conv2_.weight
        primals_9 = self.conv2_.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]


Measured latency_ms: 0.119775