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.triton_helpers import math as tl_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


@triton.jit
def triton_poi_fused_abs_add_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, None)
    tmp2 = tl.load(in_ptr1 + x0, None)
    tmp1 = tl_math.abs(tmp0)
    tmp3 = tl_math.abs(tmp2)
    tmp4 = tmp1 + tmp3
    tl.store(out_ptr0 + x0, tmp4, None)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (31, 31, 3, 3), (279, 9, 3, 1))
    assert_size_stride(primals_2, (4, 31, 64, 64), (126976, 4096, 64, 1))
    assert_size_stride(primals_3, (31, 31, 3, 3), (279, 9, 3, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 31, 64, 64), (126976, 4096, 64, 1))
        buf1 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 31, 64, 64), (126976, 4096, 64, 1))
        buf2 = empty_strided_cuda((4, 31, 64, 64), (126976, 4096, 64, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_abs_add_0[grid(507904)](buf0, buf1, buf2, 507904,
            XBLOCK=512, num_warps=8, num_stages=1)
    return buf2, primals_1, primals_2, primals_3, buf0, buf1


class SobelConvNew(nn.Module):

    def __init__(self, in_channel=31, batch_num=16):
        super(SobelConvNew, self).__init__()
        self.bz = batch_num
        self.in_channel = in_channel
        self.convx = nn.Conv2d(in_channels=31, out_channels=31, kernel_size
            =3, stride=1, bias=False, padding=1)
        self.convy = nn.Conv2d(in_channels=31, out_channels=31, kernel_size
            =3, stride=1, bias=False, padding=1)

    def init_weight(self):
        temp_x = torch.tensor([[-1, 0, -1], [2, 0, 2], [-1, 0, -1]])
        temp_y = torch.tensor([[-1, 2, -1], [0, 0, 0], [-1, 2, -1]])
        param_x = torch.zeros_like(self.convx.weight)
        param_y = torch.zeros_like(self.convy.weight)
        for index in range(self.in_channel):
            param_x[index, index, :, :] = temp_x
            param_y[index, index, :, :] = temp_y
        self.convx.weight = nn.Parameter(param_x)
        self.convy.weight = nn.Parameter(param_y)

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


Measured latency_ms: 0.04571