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 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_replication_pad2d_rsub_0(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 1200
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 3
    x1 = xindex // 3 % 10
    x2 = xindex // 30 % 10
    x3 = xindex // 300
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (4 * (3 * (3 <= 0 * (0 >= -3 + x2) + (-3 + x2) *
        (-3 + x2 > 0)) + (0 * (0 >= -3 + x2) + (-3 + x2) * (-3 + x2 > 0)) *
        (0 * (0 >= -3 + x2) + (-3 + x2) * (-3 + x2 > 0) < 3)) + 16 * x0 + 
        48 * x3 + (3 * (3 <= 0 * (0 >= -3 + x1) + (-3 + x1) * (-3 + x1 > 0)
        ) + (0 * (0 >= -3 + x1) + (-3 + x1) * (-3 + x1 > 0)) * (0 * (0 >= -
        3 + x1) + (-3 + x1) * (-3 + x1 > 0) < 3))), xmask, eviction_policy=
        'evict_last')
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tl.store(out_ptr0 + x4, tmp2, xmask)


@triton.jit
def triton_poi_fused_clamp_mul_rsub_1(in_ptr0, out_ptr0, ynumel, xnumel,
    YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 12
    xnumel = 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]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 3
    y1 = yindex // 3
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 3 * x2 + 48 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = 0.0
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp3 = 1.0
    tmp4 = triton_helpers.minimum(tmp2, tmp3)
    tmp5 = 2.0
    tmp6 = tmp4 * tmp5
    tmp7 = tmp3 - tmp6
    tl.store(out_ptr0 + (x2 + 16 * y3), tmp7, xmask & ymask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 3, 4, 4), (48, 16, 4, 1))
    assert_size_stride(arg1_1, (3, 1, 7, 7), (49, 49, 7, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 3, 10, 10), (300, 1, 30, 3), torch.
            float32)
        get_raw_stream(0)
        triton_poi_fused_replication_pad2d_rsub_0[grid(1200)](arg0_1, buf0,
            1200, XBLOCK=256, num_warps=4, num_stages=1)
        del arg0_1
        buf1 = extern_kernels.convolution(buf0, arg1_1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=3, bias=None)
        assert_size_stride(buf1, (4, 3, 4, 4), (48, 1, 12, 3))
        del arg1_1
        del buf0
        buf2 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32)
        triton_poi_fused_clamp_mul_rsub_1[grid(12, 16)](buf1, buf2, 12, 16,
            XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
        del buf1
    return buf2,


class MyDilateBlurNew(nn.Module):

    def __init__(self, kernel_size=7, channels=3, sigma=0.8):
        super(MyDilateBlurNew, self).__init__()
        self.kernel_size = kernel_size
        self.channels = channels
        x_cord = torch.arange(self.kernel_size + 0.0)
        x_grid = x_cord.repeat(self.kernel_size).view(self.kernel_size,
            self.kernel_size)
        y_grid = x_grid.t()
        self.xy_grid = torch.stack([x_grid, y_grid], dim=-1)
        self.mean = (self.kernel_size - 1) // 2
        self.diff = -torch.sum((self.xy_grid - self.mean) ** 2.0, dim=-1)
        self.gaussian_filter = nn.Conv2d(in_channels=self.channels,
            out_channels=self.channels, kernel_size=self.kernel_size,
            groups=self.channels, bias=False)
        self.gaussian_filter.weight.requires_grad = False
        variance = sigma ** 2.0
        gaussian_kernel = 1.0 / (2.0 * math.pi * variance) * torch.exp(self
            .diff / (2 * variance))
        gaussian_kernel = 2 * gaussian_kernel / torch.sum(gaussian_kernel)
        gaussian_kernel = gaussian_kernel.view(1, 1, self.kernel_size, self
            .kernel_size)
        gaussian_kernel = gaussian_kernel.repeat(self.channels, 1, 1, 1)
        self.gaussian_filter.weight.data = gaussian_kernel

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


Measured latency_ms: 0.035437