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
import torch.nn.parallel
import torch.optim
from torch.nn.init import *
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_convolution_relu_0(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)
    x3 = xindex
    x1 = xindex // 262144 % 64
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, 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 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_1(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)
    x3 = xindex
    x1 = xindex // 65536 % 128
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, 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 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_2(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)
    x3 = xindex
    x1 = xindex // 8192 % 256
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, 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 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_3(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)
    x3 = xindex
    x1 = xindex // 1024 % 512
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, 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 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_relu_4(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)
    x3 = xindex
    x1 = xindex // 128 % 512
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, 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 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_relu_5(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 % 4096
    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)


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, primals_20, primals_21, primals_22, primals_23
        ) = args
    args.clear()
    assert_size_stride(primals_1, (64, 3, 3, 3, 3), (81, 27, 9, 3, 1))
    assert_size_stride(primals_2, (64,), (1,))
    assert_size_stride(primals_3, (4, 3, 64, 64, 64), (786432, 262144, 4096,
        64, 1))
    assert_size_stride(primals_4, (128, 64, 3, 3, 3), (1728, 27, 9, 3, 1))
    assert_size_stride(primals_5, (128,), (1,))
    assert_size_stride(primals_6, (256, 128, 3, 3, 3), (3456, 27, 9, 3, 1))
    assert_size_stride(primals_7, (256,), (1,))
    assert_size_stride(primals_8, (256, 256, 3, 3, 3), (6912, 27, 9, 3, 1))
    assert_size_stride(primals_9, (256,), (1,))
    assert_size_stride(primals_10, (512, 256, 3, 3, 3), (6912, 27, 9, 3, 1))
    assert_size_stride(primals_11, (512,), (1,))
    assert_size_stride(primals_12, (512, 512, 3, 3, 3), (13824, 27, 9, 3, 1))
    assert_size_stride(primals_13, (512,), (1,))
    assert_size_stride(primals_14, (512, 512, 3, 3, 3), (13824, 27, 9, 3, 1))
    assert_size_stride(primals_15, (512,), (1,))
    assert_size_stride(primals_16, (512, 512, 3, 3, 3), (13824, 27, 9, 3, 1))
    assert_size_stride(primals_17, (512,), (1,))
    assert_size_stride(primals_18, (4096, 8192), (8192, 1))
    assert_size_stride(primals_19, (4096,), (1,))
    assert_size_stride(primals_20, (4096, 4096), (4096, 1))
    assert_size_stride(primals_21, (4096,), (1,))
    assert_size_stride(primals_22, (4, 4096), (4096, 1))
    assert_size_stride(primals_23, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1, 1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 64, 64, 64, 64), (16777216, 262144, 
            4096, 64, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_0[grid(67108864)](buf1, primals_2,
            67108864, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_2
        buf2 = torch.ops.aten.max_pool3d_with_indices.default(buf1, [1, 2, 
            2], [1, 2, 2])
        buf3 = buf2[0]
        buf4 = buf2[1]
        del buf2
        buf5 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1, 1),
            padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 128, 64, 32, 32), (8388608, 65536, 
            1024, 32, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_relu_1[grid(33554432)](buf6, primals_5,
            33554432, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_5
        buf7 = torch.ops.aten.max_pool3d_with_indices.default(buf6, [2, 2, 
            2], [2, 2, 2])
        buf8 = buf7[0]
        buf9 = buf7[1]
        del buf7
        buf10 = extern_kernels.convolution(buf8, primals_6, stride=(1, 1, 1
            ), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 256, 32, 16, 16), (2097152, 8192, 256,
            16, 1))
        buf11 = buf10
        del buf10
        triton_poi_fused_convolution_relu_2[grid(8388608)](buf11, primals_7,
            8388608, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_7
        buf12 = extern_kernels.convolution(buf11, primals_8, stride=(1, 1, 
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 256, 32, 16, 16), (2097152, 8192, 256,
            16, 1))
        buf13 = buf12
        del buf12
        triton_poi_fused_convolution_relu_2[grid(8388608)](buf13, primals_9,
            8388608, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_9
        buf14 = torch.ops.aten.max_pool3d_with_indices.default(buf13, [2, 2,
            2], [2, 2, 2])
        buf15 = buf14[0]
        buf16 = buf14[1]
        del buf14
        buf17 = extern_kernels.convolution(buf15, primals_10, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf17, (4, 512, 16, 8, 8), (524288, 1024, 64, 8, 1))
        buf18 = buf17
        del buf17
        triton_poi_fused_convolution_relu_3[grid(2097152)](buf18,
            primals_11, 2097152, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_11
        buf19 = extern_kernels.convolution(buf18, primals_12, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf19, (4, 512, 16, 8, 8), (524288, 1024, 64, 8, 1))
        buf20 = buf19
        del buf19
        triton_poi_fused_convolution_relu_3[grid(2097152)](buf20,
            primals_13, 2097152, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_13
        buf21 = torch.ops.aten.max_pool3d_with_indices.default(buf20, [2, 2,
            2], [2, 2, 2])
        buf22 = buf21[0]
        buf23 = buf21[1]
        del buf21
        buf24 = extern_kernels.convolution(buf22, primals_14, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf24, (4, 512, 8, 4, 4), (65536, 128, 16, 4, 1))
        buf25 = buf24
        del buf24
        triton_poi_fused_convolution_relu_4[grid(262144)](buf25, primals_15,
            262144, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_15
        buf26 = extern_kernels.convolution(buf25, primals_16, stride=(1, 1,
            1), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
            output_padding=(0, 0, 0), groups=1, bias=None)
        assert_size_stride(buf26, (4, 512, 8, 4, 4), (65536, 128, 16, 4, 1))
        buf27 = buf26
        del buf26
        triton_poi_fused_convolution_relu_4[grid(262144)](buf27, primals_17,
            262144, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_17
        buf28 = torch.ops.aten.max_pool3d_with_indices.default(buf27, [2, 2,
            2], [2, 2, 2], [0, 1, 1])
        buf29 = buf28[0]
        buf30 = buf28[1]
        del buf28
        buf31 = empty_strided_cuda((9, 4096), (4096, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf29, (9, 8192), (8192, 1), 0
            ), reinterpret_tensor(primals_18, (8192, 4096), (1, 8192), 0),
            out=buf31)
        buf32 = buf31
        del buf31
        triton_poi_fused_relu_5[grid(36864)](buf32, primals_19, 36864,
            XBLOCK=512, num_warps=4, num_stages=1)
        del primals_19
        buf33 = empty_strided_cuda((9, 4096), (4096, 1), torch.float32)
        extern_kernels.mm(buf32, reinterpret_tensor(primals_20, (4096, 4096
            ), (1, 4096), 0), out=buf33)
        buf34 = buf33
        del buf33
        triton_poi_fused_relu_5[grid(36864)](buf34, primals_21, 36864,
            XBLOCK=512, num_warps=4, num_stages=1)
        del primals_21
        buf35 = empty_strided_cuda((9, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_23, buf34, reinterpret_tensor(
            primals_22, (4096, 4), (1, 4096), 0), alpha=1, beta=1, out=buf35)
        del primals_23
    return (buf35, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, primals_12, primals_14, primals_16, buf1, buf3, buf4,
        buf6, buf8, buf9, buf11, buf13, buf15, buf16, buf18, buf20, buf22,
        buf23, buf25, buf27, buf30, reinterpret_tensor(buf29, (9, 8192), (
        8192, 1), 0), buf32, buf34, primals_22, primals_20, primals_18)


class C3DNew(nn.Module):
    """
    The C3D network.
    """

    def __init__(self, num_classes, pretrained=False, path=None):
        super(C3DNew, self).__init__()
        self.conv1 = nn.Conv3d(3, 64, kernel_size=(3, 3, 3), padding=(1, 1, 1))
        self.pool1 = nn.MaxPool3d(kernel_size=(1, 2, 2), stride=(1, 2, 2))
        self.conv2 = nn.Conv3d(64, 128, kernel_size=(3, 3, 3), padding=(1, 
            1, 1))
        self.pool2 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))
        self.conv3a = nn.Conv3d(128, 256, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.conv3b = nn.Conv3d(256, 256, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.pool3 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))
        self.conv4a = nn.Conv3d(256, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.conv4b = nn.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.pool4 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))
        self.conv5a = nn.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.conv5b = nn.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1,
            1, 1))
        self.pool5 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2),
            padding=(0, 1, 1))
        self.fc6 = nn.Linear(8192, 4096)
        self.fc7 = nn.Linear(4096, 4096)
        self.fc8 = nn.Linear(4096, num_classes)
        self.dropout = nn.Dropout(p=0.5)
        self.relu = nn.ReLU()
        self.__init_weight()
        self.path = path
        if pretrained:
            self.__load_pretrained_weights()

    def __load_pretrained_weights(self):
        """Initialiaze network."""
        corresp_name = {'features.0.weight': 'conv1.weight',
            'features.0.bias': 'conv1.bias', 'features.3.weight':
            'conv2.weight', 'features.3.bias': 'conv2.bias',
            'features.6.weight': 'conv3a.weight', 'features.6.bias':
            'conv3a.bias', 'features.8.weight': 'conv3b.weight',
            'features.8.bias': 'conv3b.bias', 'features.11.weight':
            'conv4a.weight', 'features.11.bias': 'conv4a.bias',
            'features.13.weight': 'conv4b.weight', 'features.13.bias':
            'conv4b.bias', 'features.16.weight': 'conv5a.weight',
            'features.16.bias': 'conv5a.bias', 'features.18.weight':
            'conv5b.weight', 'features.18.bias': 'conv5b.bias',
            'classifier.0.weight': 'fc6.weight', 'classifier.0.bias':
            'fc6.bias', 'classifier.3.weight': 'fc7.weight',
            'classifier.3.bias': 'fc7.bias'}
        p_dict = torch.load(self.path)
        s_dict = self.state_dict()
        for name in p_dict:
            if name not in corresp_name:
                continue
            s_dict[corresp_name[name]] = p_dict[name]
        self.load_state_dict(s_dict)

    def __init_weight(self):
        for m in self.modules():
            if isinstance(m, nn.Conv3d):
                torch.nn.init.kaiming_normal_(m.weight)
            elif isinstance(m, nn.BatchNorm3d):
                m.weight.data.fill_(1)
                m.bias.data.zero_()

    def forward(self, input_0):
        primals_1 = self.conv1.weight
        primals_2 = self.conv1.bias
        primals_4 = self.conv2.weight
        primals_5 = self.conv2.bias
        primals_6 = self.conv3a.weight
        primals_7 = self.conv3a.bias
        primals_8 = self.conv3b.weight
        primals_9 = self.conv3b.bias
        primals_10 = self.conv4a.weight
        primals_11 = self.conv4a.bias
        primals_12 = self.conv4b.weight
        primals_13 = self.conv4b.bias
        primals_14 = self.conv5a.weight
        primals_15 = self.conv5a.bias
        primals_16 = self.conv5b.weight
        primals_17 = self.conv5b.bias
        primals_18 = self.fc6.weight
        primals_19 = self.fc6.bias
        primals_20 = self.fc7.weight
        primals_21 = self.fc7.bias
        primals_22 = self.fc8.weight
        primals_23 = self.fc8.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, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19,
            primals_20, primals_21, primals_22, primals_23])
        return output[0]


Measured latency_ms: 0.02174