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


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0,
    in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 80
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 5 % 4
    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)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x3, tmp4, xmask)
    tl.store(out_ptr0 + x3, tmp6, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 
            1), padding=(0, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 1, 5), (20, 5, 5, 1))
        buf1 = buf0
        del buf0
        buf2 = empty_strided_cuda((4, 4, 1, 5), (20, 5, 5, 1), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_convolution_relu_threshold_backward_0[grid(80)](buf1,
            primals_3, buf2, 80, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_3
    return buf1, reinterpret_tensor(primals_4, (4, 1, 4, 4), (64, 16, 4, 1), 32
        ), primals_1, primals_2, buf2


def cal_width_dim_2d(input_dim, kernel_size, stride, padding=1):
    return math.floor((input_dim + 2 * padding - kernel_size) / stride + 1)


class Conv2dLayerNew(nn.Module):

    def __init__(self, input_size, in_channel, out_channel, kernel_size,
        stride, dropout=0.1, batch_norm=False, residual=False,
        act_func_type='relu'):
        super(Conv2dLayerNew, self).__init__()
        self.input_size = input_size
        self.in_channel = in_channel
        self.out_channel = out_channel
        self.batch_norm = batch_norm
        self.kernel_size = kernel_size
        self.stride = stride
        self.padding = 0, kernel_size // 2 if isinstance(self.kernel_size, int
            ) else kernel_size[1] // 2
        self.residual = residual
        self.act_func_type = act_func_type
        self.conv_layer = nn.Conv2d(in_channels=in_channel, out_channels=
            out_channel, kernel_size=self.kernel_size, stride=self.stride,
            padding=self.padding)
        self.output_size = cal_width_dim_2d(input_size, self.kernel_size if
            isinstance(self.kernel_size, int) else self.kernel_size[1], 
            self.stride if isinstance(self.stride, int) else self.stride[1],
            padding=self.padding if isinstance(self.padding, int) else self
            .padding[1])
        if self.batch_norm:
            self.norm = nn.BatchNorm2d(out_channel)
        self.dropout = nn.Dropout(dropout)

    def return_output_mask(self, mask, t):
        stride = self.stride if isinstance(self.stride, int) else self.stride[0
            ]
        kernel_size = self.kernel_size if isinstance(self.kernel_size, int
            ) else self.kernel_size[0]
        mask = mask[:, math.floor(kernel_size / 2)::stride][:, :t]
        return mask

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


Measured latency_ms: 0.023934