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.utils
import torch.utils.data
import torch.optim
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 9
    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 % 2
    y1 = yindex // 2
    tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
        )
    tl.store(out_ptr0 + (y0 + 2 * x2 + 18 * y1), tmp0, xmask)


@triton.jit
def triton_poi_fused_constant_pad_nd_1(in_ptr0, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 8
    xnumel = 36
    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
    x3 = xindex // 6
    x2 = xindex % 6
    y4 = yindex
    x5 = xindex
    y0 = yindex % 2
    y1 = yindex // 2
    tmp0 = -2 + x3
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = x2
    tmp4 = tl.full([1, 1], 4, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp2 & tmp5
    tmp7 = tl.load(in_ptr0 + (-8 + x2 + 4 * x3 + 16 * y4), tmp6 & xmask &
        ymask, eviction_policy='evict_last', other=0.0)
    tl.store(out_ptr0 + (y0 + 2 * x5 + 72 * y1), tmp7, xmask & ymask)


@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_2(in_ptr0, in_ptr1,
    out_ptr0, out_ptr1, 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
    y0 = yindex % 512
    y1 = yindex // 512
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 512 * x2 + 8192 * 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 + 16 * y3), tmp4, xmask)
    tl.store(out_ptr1 + (y0 + 512 * x2 + 8192 * y1), tmp6, xmask)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (4, 2, 4, 4), (32, 16, 4, 1))
    assert_size_stride(primals_2, (512, 2, 3, 3), (18, 9, 3, 1))
    assert_size_stride(primals_3, (512,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((512, 2, 3, 3), (18, 1, 6, 2), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(1024, 9)](primals_2, buf0, 1024, 9, XBLOCK=
            16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_2
        buf1 = empty_strided_cuda((4, 2, 6, 6), (72, 1, 12, 2), torch.float32)
        triton_poi_fused_constant_pad_nd_1[grid(8, 36)](primals_1, buf1, 8,
            36, XBLOCK=32, YBLOCK=8, num_warps=4, num_stages=1)
        del primals_1
        buf2 = extern_kernels.convolution(buf1, buf0, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 512, 4, 4), (8192, 1, 2048, 512))
        buf3 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.
            float32)
        buf4 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512),
            torch.bool)
        triton_poi_fused_convolution_relu_threshold_backward_2[grid(2048, 16)](
            buf2, primals_3, buf3, buf4, 2048, 16, XBLOCK=16, YBLOCK=64,
            num_warps=4, num_stages=1)
        del buf2
        del primals_3
    return buf3, buf0, buf1, buf4


class BatchDHCNNew(nn.Module):
    """docstring for BatchDHCN"""

    def __init__(self, embed_size=512, output_size=512, num_channel=2,
        conv_size=3, batch_norm=True):
        super(BatchDHCNNew, self).__init__()
        self.batch_norm = batch_norm
        self.embed_size = embed_size
        self.output_size = output_size
        self.num_channel = num_channel
        self.padding = nn.ZeroPad2d((0, conv_size - 1, conv_size - 1, 0))
        self.conv_1 = nn.Conv2d(self.num_channel, self.output_size, (
            conv_size, conv_size))
        self.dropout = nn.Dropout(p=0.5)

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


Measured latency_ms: 0.059355