import torch
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
from torch._inductor.runtime.triton_helpers import libdevice
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_div_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp10 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp1, tmp3)
    tmp5 = tmp4 * tmp4
    tmp7 = triton_helpers.maximum(tmp1, tmp6)
    tmp8 = tmp7 * tmp7
    tmp9 = tmp5 + tmp8
    tmp11 = triton_helpers.maximum(tmp1, tmp10)
    tmp12 = tmp11 * tmp11
    tmp13 = tmp9 + tmp12
    tmp15 = triton_helpers.maximum(tmp1, tmp14)
    tmp16 = tmp15 * tmp15
    tmp17 = tmp13 + tmp16
    tmp18 = libdevice.sqrt(tmp17)
    tmp19 = 1e-12
    tmp20 = triton_helpers.maximum(tmp18, tmp19)
    tmp21 = tmp2 / tmp20
    tl.store(out_ptr0 + x3, tmp21, xmask)


@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 256
    xnumel = 25
    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
    x4 = xindex // 5
    y1 = yindex // 4 % 4
    x3 = xindex % 5
    y0 = yindex % 4
    y6 = yindex
    x7 = xindex
    tmp12 = tl.load(in_ptr0 + y6, ymask, eviction_policy='evict_last')
    tmp0 = -2 + x4 + y1
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1, 1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = -2 + x3 + y0
    tmp6 = tmp5 >= tmp1
    tmp7 = tmp5 < tmp3
    tmp8 = tmp2 & tmp4
    tmp9 = tmp8 & tmp6
    tmp10 = tmp9 & tmp7
    tmp11 = tl.load(in_ptr0 + (-10 + x3 + y6 + 4 * x4 + 16 * ((x3 + 5 * x4) //
        25)), tmp10 & xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp13 = tmp11 * tmp12
    tl.store(out_ptr0 + (x7 + 25 * y6), tmp13, xmask & ymask)


@triton.jit
def triton_poi_fused_relu_2(in_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tl.store(out_ptr1 + x0, tmp2, xmask)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_div_relu_0[grid(256)](arg0_1, buf0, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 4, 4, 5, 5), (1600, 400, 100, 25, 
            5, 1), torch.float32)
        triton_poi_fused_clone_1[grid(256, 25)](buf0, buf1, 256, 25, XBLOCK
            =32, YBLOCK=32, num_warps=4, num_stages=1)
        triton_poi_fused_relu_2[grid(256)](arg0_1, arg0_1, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        del arg0_1
        del buf0
    return buf1,


class SelfCorrelationComputationNew(nn.Module):

    def __init__(self, kernel_size=(5, 5), padding=2):
        super(SelfCorrelationComputationNew, self).__init__()
        self.kernel_size = kernel_size
        self.unfold = nn.Unfold(kernel_size=kernel_size, padding=padding)
        self.relu = nn.ReLU(inplace=True)

    def forward(self, input_0):
        arg0_1 = input_0
        output = call([arg0_1])
        return output[0]


Measured latency_ms: 0.037274