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.init as init
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 % 32
    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_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 620928
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 9702 % 16
    x0 = xindex % 9702
    x4 = xindex // 9702
    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 + 9728 * x4), tmp4, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (32, 1, 3, 3, 3), (27, 27, 9, 3, 1))
    assert_size_stride(primals_2, (32,), (1,))
    assert_size_stride(primals_3, (4, 1, 64, 64, 64), (262144, 262144, 4096,
        64, 1))
    assert_size_stride(primals_4, (16, 32, 3, 3, 3), (864, 27, 9, 3, 1))
    assert_size_stride(primals_5, (16,), (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, 32, 64, 64, 64), (8388608, 262144, 
            4096, 64, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_0[grid(33554432)](buf1, primals_2,
            33554432, XBLOCK=1024, num_warps=4, num_stages=1)
        del primals_2
        buf2 = torch.ops.aten.max_pool3d_with_indices.default(buf1, [3, 3, 
            3], [3, 3, 3], [1, 0, 0])
        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, 16, 22, 21, 21), (155232, 9702, 441, 
            21, 1))
        buf6 = empty_strided_cuda((4, 16, 22, 21, 21), (155648, 9728, 441, 
            21, 1), torch.float32)
        triton_poi_fused_convolution_relu_1[grid(620928)](buf5, primals_5,
            buf6, 620928, XBLOCK=512, num_warps=8, num_stages=1)
        del buf5
        del primals_5
        buf7 = torch.ops.aten.max_pool3d_with_indices.default(buf6, [3, 3, 
            3], [3, 3, 3], [1, 0, 0])
        buf8 = buf7[0]
        buf9 = buf7[1]
        del buf7
    return reinterpret_tensor(buf8, (4, 6272), (6272, 1), 0
        ), primals_1, primals_3, primals_4, buf1, buf3, buf4, buf6, buf9


class DGMNConv3DLayerNew(nn.Module):

    def __init__(self, args):
        self.args = args
        super(DGMNConv3DLayerNew, self).__init__()
        self.conv1 = nn.Conv3d(in_channels=1, out_channels=32, kernel_size=
            (3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1))
        self.pool1 = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=(3, 3, 3),
            padding=(1, 0, 0))
        self.conv2 = nn.Conv3d(in_channels=32, out_channels=16, kernel_size
            =(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1))
        self.pool2 = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=(3, 3, 3),
            padding=(1, 0, 0))
        self.flatten = nn.Flatten()
        self.init_weight()

    def init_weight(self):
        init.xavier_uniform_(self.conv1.weight)
        init.constant_(self.conv1.bias, 0.0)
        init.xavier_uniform_(self.conv2.weight)
        init.constant_(self.conv2.bias, 0.0)

    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_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.077172