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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 384
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 96
    tmp0 = tl.load(in_out_ptr0 + x2, 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 + x2, tmp4, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 1, 3, 3), (36, 9, 9, 3, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1,
            4, 4, 4, 4), (256, 64, 16, 4, 1), 0), 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, (1, 4, 6, 4, 4), (384, 96, 16, 4, 1))
        buf1 = reinterpret_tensor(buf0, (4, 6, 4, 4), (96, 16, 4, 1), 0)
        del buf0
        get_raw_stream(0)
        triton_poi_fused_relu_0[grid(384)](buf1, primals_2, 384, XBLOCK=128,
            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
    return buf3, primals_1, reinterpret_tensor(primals_3, (1, 4, 4, 4, 4),
        (256, 64, 16, 4, 1), 0), buf1, buf4


def define_norm(n_channel, norm_type, n_group=None, dim_mode=2):
    if norm_type == 'bn':
        if dim_mode == 2:
            return nn.BatchNorm2d(n_channel)
        elif dim_mode == 3:
            return nn.BatchNorm3d(n_channel)
    elif norm_type == 'gn':
        if n_group is None:
            n_group = 2
        return nn.GroupNorm(n_group, n_channel)
    elif norm_type == 'in':
        return nn.GroupNorm(n_channel, n_channel)
    elif norm_type == 'ln':
        return nn.GroupNorm(1, n_channel)
    elif norm_type is None:
        return
    else:
        return ValueError('Normalization type - ' + norm_type +
            ' is not defined yet')


class Conv3D_BlockNew(nn.Module):
    """ 
  use conv3D than multiple Conv2D blocks (for a sake of reducing computational burden)
  INPUT dimension: BxCxTxHxW
  """

    def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
        padding=1, norm_type=None):
        super(Conv3D_BlockNew, self).__init__()
        self.norm_type = norm_type
        self.conv = nn.Conv3d(in_channels, out_channels, kernel_size=(1,
            kernel_size, kernel_size), stride=(1, stride, stride), padding=
            (1, padding, padding))
        self.relu = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool3d(kernel_size=(1, 2, 2), stride=(1, 2, 2))
        self.norm_layer = define_norm(out_channels, norm_type, dim_mode=3)

    def forward(self, input_0):
        primals_1 = self.conv.weight
        primals_2 = self.conv.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3])
        return output[0]


Measured latency_ms: 0.04296