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
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


@triton.jit
def triton_poi_fused_constant_pad_nd_0(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
    x0 = xindex % 5
    x1 = xindex // 5
    x2 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 4, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp2 & xmask, other=0.0)
    tl.store(out_ptr0 + x2, tmp3, xmask)


@triton.jit
def triton_poi_fused_constant_pad_nd_1(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
    x1 = xindex // 4 % 5
    x2 = xindex // 20
    x3 = xindex % 20
    x4 = xindex
    tmp0 = x1
    tmp1 = tl.full([1], 4, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.load(in_ptr0 + (x3 + 16 * x2), tmp2 & xmask, other=0.0)
    tl.store(out_ptr0 + x4, tmp3, xmask)


@triton.jit
def triton_poi_fused_fill_lift_fresh_2(in_out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x2 = xindex
    tmp3 = tl.load(in_out_ptr0 + x2, xmask)
    tmp0 = x0
    tmp1 = tl.full([1], 3, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = 0.0
    tmp5 = tl.where(tmp2, tmp4, tmp3)
    tl.store(in_out_ptr0 + x2, tmp5, xmask)


@triton.jit
def triton_poi_fused_fill_lift_fresh_3(in_out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x3 = xindex
    tmp3 = tl.load(in_out_ptr0 + x3, xmask)
    tmp0 = x1
    tmp1 = tl.full([1], 3, tl.int32)
    tmp2 = tmp0 == tmp1
    tmp4 = 0.0
    tmp5 = tl.where(tmp2, tmp4, tmp3)
    tl.store(in_out_ptr0 + x3, tmp5, xmask)


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


class Forward_GradNew(nn.Module):

    def __init__(self):
        super(Forward_GradNew, self).__init__()
        self.x_ker_init = torch.tensor([[[[-1, 1]]]], dtype=torch.float,
            requires_grad=True)
        self.y_ker_init = torch.tensor([[[[-1], [1]]]], dtype=torch.float,
            requires_grad=True)
        self.forward_conv_x = nn.Conv2d(1, 1, (1, 2), bias=False)
        self.forward_conv_x.weight.data = self.x_ker_init
        self.forward_conv_y = nn.Conv2d(1, 1, (2, 1), bias=False)
        self.forward_conv_y.weight.data = self.y_ker_init

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


Measured latency_ms: 0.042474