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 numpy as np
import torch.nn as nn
import torch.utils.data
from torch.nn.parameter import Parameter
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_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    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]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 4 * x2 + 16384 * y1), tmp0, ymask)


@triton.jit
def triton_poi_fused_convolution_1(in_ptr0, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 3600
    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
    x2 = xindex
    y0 = yindex % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 14400 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 3600 * y3), tmp0, xmask & ymask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(arg1_1, (4, 4, 64, 64), (16384, 4096, 64, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 64, 64), (16384, 1, 256, 4), torch
            .float32)
        get_raw_stream(0)
        triton_poi_fused_convolution_0[grid(16, 4096)](arg1_1, buf0, 16, 
            4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
        del arg1_1
        buf1 = extern_kernels.convolution(buf0, arg0_1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf1, (4, 4, 60, 60), (14400, 1, 240, 4))
        del arg0_1
        del buf0
        buf2 = empty_strided_cuda((4, 4, 60, 60), (14400, 3600, 60, 1),
            torch.float32)
        triton_poi_fused_convolution_1[grid(16, 3600)](buf1, buf2, 16, 3600,
            XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
        del buf1
    return buf2,


class GaussianConv2dNew(nn.Module):

    def __init__(self, in_channels, out_channels, ksize=5):
        """Applies 2-D Gaussian Blur.

    Args:
      in_channels: An integer indicates input channel dimension.
      out_channels: An integer indicates output channel dimension.
      ksize: An integer indicates Gaussian kernel size.
    """
        super(GaussianConv2dNew, self).__init__()
        weight = (np.arange(ksize, dtype=np.float32) - ksize // 2) ** 2
        weight = np.sqrt(weight[None, :] + weight[:, None])
        weight = np.reshape(weight, (1, 1, ksize, ksize)) / weight.sum()
        self.weight = Parameter(torch.Tensor(weight).expand(out_channels, -
            1, -1, -1))
        self._in_channels = in_channels
        self._out_channels = out_channels

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


Measured latency_ms: 0.036278