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
from torch import 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_mul_repeat_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)
    x3 = xindex
    x0 = xindex % 4096
    x2 = xindex // 16384
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tl.store(out_ptr0 + x3, tmp2, None)


@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 4096 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_convolution_sigmoid_2(in_out_ptr0, in_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_out_ptr0 + x0, None)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tmp4 = tl.sigmoid(tmp3)
    tl.store(in_out_ptr0 + x0, tmp4, None)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14) = args
    args.clear()
    assert_size_stride(primals_1, (4, 1, 64, 64), (4096, 4096, 64, 1))
    assert_size_stride(primals_2, (4, 4, 64, 64), (16384, 4096, 64, 1))
    assert_size_stride(primals_3, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_4, (4,), (1,))
    assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_10, (4,), (1,))
    assert_size_stride(primals_11, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_14, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 64, 64), (16384, 4096, 64, 1),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_mul_repeat_0[grid(65536)](primals_2, primals_1,
            buf0, 65536, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_1
        del primals_2
        buf1 = extern_kernels.convolution(buf0, 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, 4, 64, 64), (16384, 4096, 64, 1))
        buf2 = buf1
        del buf1
        triton_poi_fused_convolution_relu_1[grid(65536)](buf2, primals_4, 
            65536, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_4
        buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1),
            padding=(2, 2), dilation=(2, 2), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf4 = buf3
        del buf3
        triton_poi_fused_convolution_relu_1[grid(65536)](buf4, primals_6, 
            65536, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_6
        buf5 = extern_kernels.convolution(buf4, primals_7, stride=(1, 1),
            padding=(4, 4), dilation=(4, 4), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_relu_1[grid(65536)](buf6, primals_8, 
            65536, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_8
        buf7 = extern_kernels.convolution(buf6, primals_9, stride=(1, 1),
            padding=(8, 8), dilation=(8, 8), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf8 = buf7
        del buf7
        triton_poi_fused_convolution_relu_1[grid(65536)](buf8, primals_10, 
            65536, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_10
        buf9 = extern_kernels.convolution(buf8, primals_11, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf9, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf10 = buf9
        del buf9
        triton_poi_fused_convolution_relu_1[grid(65536)](buf10, primals_12,
            65536, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_12
        buf11 = extern_kernels.convolution(buf10, primals_13, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf11, (4, 1, 64, 64), (4096, 4096, 64, 1))
        buf12 = buf11
        del buf11
        triton_poi_fused_convolution_sigmoid_2[grid(16384)](buf12,
            primals_14, 16384, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_14
    return (buf12, primals_3, primals_5, primals_7, primals_9, primals_11,
        primals_13, buf0, buf2, buf4, buf6, buf8, buf10, buf12)


class RelateModuleNew(nn.Module):
    """
    A neural module that takes as input a feature map and an attention and produces an attention
    as output.

    Extended Summary
    ----------------
    A :class:`RelateModule` takes input features and an attention and produces an attention. It
    multiplicatively combines the attention and the features to attend to a relevant region, then
    uses a series of dilated convolutional filters to indicate a spatial relationship to the input
    attended region.

    Parameters
    ----------
    dim: int
        The number of channels of each convolutional filter.
    """

    def __init__(self, dim: 'int'):
        super().__init__()
        self.conv1 = nn.Conv2d(dim, dim, kernel_size=3, padding=1, dilation=1)
        self.conv2 = nn.Conv2d(dim, dim, kernel_size=3, padding=2, dilation=2)
        self.conv3 = nn.Conv2d(dim, dim, kernel_size=3, padding=4, dilation=4)
        self.conv4 = nn.Conv2d(dim, dim, kernel_size=3, padding=8, dilation=8)
        self.conv5 = nn.Conv2d(dim, dim, kernel_size=3, padding=1, dilation=1)
        self.conv6 = nn.Conv2d(dim, 1, kernel_size=1, padding=0)
        torch.nn.init.kaiming_normal_(self.conv1.weight)
        torch.nn.init.kaiming_normal_(self.conv2.weight)
        torch.nn.init.kaiming_normal_(self.conv3.weight)
        torch.nn.init.kaiming_normal_(self.conv4.weight)
        torch.nn.init.kaiming_normal_(self.conv5.weight)
        torch.nn.init.kaiming_normal_(self.conv6.weight)
        self.dim = dim

    def forward(self, input_0, input_1):
        primals_3 = self.conv1.weight
        primals_4 = self.conv1.bias
        primals_5 = self.conv2.weight
        primals_6 = self.conv2.bias
        primals_7 = self.conv3.weight
        primals_8 = self.conv3.bias
        primals_9 = self.conv4.weight
        primals_10 = self.conv4.bias
        primals_11 = self.conv5.weight
        primals_12 = self.conv5.bias
        primals_13 = self.conv6.weight
        primals_14 = self.conv6.bias
        primals_2 = input_0
        primals_1 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14])
        return output[0]


Measured latency_ms: 0.077174