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
from torch.nn import functional as F
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 96
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 3
    y1 = yindex // 3
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy
        ='evict_last')
    tl.store(out_ptr0 + (y0 + 3 * x2 + 48 * y1), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 12
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    x2 = xindex
    y3 = yindex
    y0 = yindex % 3
    y1 = yindex // 3
    tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask)


@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 32
    y1 = yindex // 32
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 32 * x2 + 512 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 64
    y1 = yindex // 64
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 64 * x2 + 1024 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 128
    y1 = yindex // 128
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 128 * x2 + 2048 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_5(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 123008
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 32
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, 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 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 50176
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 64
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, 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 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_7(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 % 128
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, 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 + x2, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_8(in_ptr0, in_ptr1,
    out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.
    constexpr):
    xnumel = 4
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 256
    y1 = yindex // 256
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 256 * x2 + 1024 * y1), xmask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1, 1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp4, xmask)
    tl.store(out_ptr1 + (y0 + 256 * x2 + 1024 * y1), 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) = args
    args.clear()
    assert_size_stride(primals_1, (32, 3, 4, 4), (48, 16, 4, 1))
    assert_size_stride(primals_2, (32,), (1,))
    assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
    assert_size_stride(primals_4, (64, 32, 4, 4), (512, 16, 4, 1))
    assert_size_stride(primals_5, (64,), (1,))
    assert_size_stride(primals_6, (128, 64, 4, 4), (1024, 16, 4, 1))
    assert_size_stride(primals_7, (128,), (1,))
    assert_size_stride(primals_8, (256, 128, 4, 4), (2048, 16, 4, 1))
    assert_size_stride(primals_9, (256,), (1,))
    assert_size_stride(primals_10, (4, 1024), (1024, 1))
    assert_size_stride(primals_11, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((32, 3, 4, 4), (48, 1, 12, 3), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(96, 16)](primals_1, buf0, 96, 16, XBLOCK=16,
            YBLOCK=64, num_warps=4, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch
            .float32)
        triton_poi_fused_1[grid(12, 4096)](primals_3, buf1, 12, 4096,
            XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
        del primals_3
        buf2 = empty_strided_cuda((64, 32, 4, 4), (512, 1, 128, 32), torch.
            float32)
        triton_poi_fused_2[grid(2048, 16)](primals_4, buf2, 2048, 16,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_4
        buf3 = empty_strided_cuda((128, 64, 4, 4), (1024, 1, 256, 64),
            torch.float32)
        triton_poi_fused_3[grid(8192, 16)](primals_6, buf3, 8192, 16,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_6
        buf4 = empty_strided_cuda((256, 128, 4, 4), (2048, 1, 512, 128),
            torch.float32)
        triton_poi_fused_4[grid(32768, 16)](primals_8, buf4, 32768, 16,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_8
        buf5 = extern_kernels.convolution(buf1, buf0, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 32, 31, 31), (30752, 1, 992, 32))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_relu_5[grid(123008)](buf6, primals_2, 
            123008, XBLOCK=512, num_warps=8, num_stages=1)
        del primals_2
        buf7 = extern_kernels.convolution(buf6, buf2, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 64, 14, 14), (12544, 1, 896, 64))
        buf8 = buf7
        del buf7
        triton_poi_fused_convolution_relu_6[grid(50176)](buf8, primals_5, 
            50176, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_5
        buf9 = extern_kernels.convolution(buf8, buf3, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 128, 6, 6), (4608, 1, 768, 128))
        buf10 = buf9
        del buf9
        triton_poi_fused_convolution_relu_7[grid(18432)](buf10, primals_7, 
            18432, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_7
        buf11 = extern_kernels.convolution(buf10, buf4, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf11, (4, 256, 2, 2), (1024, 1, 512, 256))
        buf12 = empty_strided_cuda((4, 256, 2, 2), (1024, 4, 2, 1), torch.
            float32)
        buf14 = empty_strided_cuda((4, 256, 2, 2), (1024, 1, 512, 256),
            torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_8[grid(1024, 4)](
            buf11, primals_9, buf12, buf14, 1024, 4, XBLOCK=4, YBLOCK=64,
            num_warps=4, num_stages=1)
        del buf11
        del primals_9
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_11, reinterpret_tensor(buf12, (4, 1024
            ), (1024, 1), 0), reinterpret_tensor(primals_10, (1024, 4), (1,
            1024), 0), alpha=1, beta=1, out=buf13)
        del primals_11
    return (buf13, buf0, buf1, buf2, buf3, buf4, buf6, buf8, buf10,
        reinterpret_tensor(buf12, (4, 1024), (1024, 1), 0), primals_10, buf14)


class ConvEncoderNew(nn.Module):

    def __init__(self, embedding_size, act_fn='relu'):
        super().__init__()
        self.act_fn = getattr(F, act_fn)
        self.embedding_size = embedding_size
        self.conv_1 = nn.Conv2d(3, 32, 4, stride=2)
        self.conv_2 = nn.Conv2d(32, 64, 4, stride=2)
        self.conv_3 = nn.Conv2d(64, 128, 4, stride=2)
        self.conv_4 = nn.Conv2d(128, 256, 4, stride=2)
        if embedding_size == 1024:
            self.fc_1 = nn.Identity()
        else:
            self.fc_1 = nn.Linear(1024, embedding_size)

    def forward(self, input_0):
        primals_1 = self.conv_1.weight
        primals_2 = self.conv_1.bias
        primals_4 = self.conv_2.weight
        primals_5 = self.conv_2.bias
        primals_6 = self.conv_3.weight
        primals_7 = self.conv_3.bias
        primals_8 = self.conv_4.weight
        primals_9 = self.conv_4.bias
        primals_10 = self.fc_1.weight
        primals_11 = self.fc_1.bias
        primals_3 = 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])
        return output[0]


Measured latency_ms: 0.064354