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._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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 768
    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 % 192
    y1 = yindex // 192
    tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 192 * x2 + 786432 * y1), tmp0, ymask)


@triton.jit
def triton_poi_fused_clone_1(in_ptr0, 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 % 192
    x1 = xindex // 192 % 64
    x2 = xindex // 12288 % 64
    x3 = xindex // 786432
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 192 * x2 + 12288 * x1 + 786432 * x3), None)
    tl.store(out_ptr0 + x4, tmp0, None)


@triton.jit
def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    xnumel = 64
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 12288
    y1 = yindex // 12288
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 12288 * x2 + 786432 * y1), xmask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 64 * y3), tmp0, xmask)


@triton.jit
def triton_per_fused__softmax_3(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
    tl.constexpr):
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), None)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = triton_helpers.max2(tmp1, 1)[:, None]
    tmp4 = tmp0 - tmp3
    tmp5 = tl_math.exp(tmp4)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
    tmp8 = tl.sum(tmp6, 1)[:, None]
    tmp9 = tmp5 / tmp8
    tl.store(out_ptr2 + (r1 + 64 * x0), tmp9, None)


def call(args):
    primals_1, primals_2, primals_3 = args
    args.clear()
    assert_size_stride(primals_1, (192, 192, 1, 1), (192, 1, 1, 1))
    assert_size_stride(primals_2, (4, 192, 64, 64), (786432, 4096, 64, 1))
    assert_size_stride(primals_3, (192, 192, 1, 1), (192, 1, 1, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 192, 64, 64), (786432, 1, 12288, 192),
            torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(768, 4096)](primals_2, buf0, 768, 4096,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_2
        buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 192, 64, 64), (786432, 1, 12288, 192))
        buf2 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 192, 64, 64), (786432, 1, 12288, 192))
        buf3 = empty_strided_cuda((4, 64, 64, 192), (786432, 12288, 192, 1),
            torch.float32)
        triton_poi_fused_clone_1[grid(3145728)](buf1, buf3, 3145728, XBLOCK
            =512, num_warps=8, num_stages=1)
        buf4 = reinterpret_tensor(buf1, (4, 64, 192, 64), (786432, 12288, 
            64, 1), 0)
        del buf1
        triton_poi_fused_clone_2[grid(49152, 64)](buf2, buf4, 49152, 64,
            XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf2
        buf5 = empty_strided_cuda((256, 64, 64), (4096, 64, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf3, (256, 64, 192), (12288,
            192, 1), 0), reinterpret_tensor(buf4, (256, 192, 64), (12288, 
            64, 1), 0), out=buf5)
        buf8 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
            torch.float32)
        triton_per_fused__softmax_3[grid(16384)](buf5, buf8, 16384, 64,
            XBLOCK=8, num_warps=4, num_stages=1)
        del buf5
    return buf8, primals_1, buf0, primals_3, buf8, reinterpret_tensor(buf3,
        (256, 192, 64), (12288, 1, 192), 0), reinterpret_tensor(buf4, (256,
        64, 192), (12288, 1, 64), 0)


class cnn1x1(nn.Module):

    def __init__(self, dim1=3, dim2=3, bias=True):
        super(cnn1x1, self).__init__()
        self.cnn = nn.Conv2d(dim1, dim2, kernel_size=1, bias=bias)

    def forward(self, x):
        x = self.cnn(x)
        return x


class compute_g_spaNew(nn.Module):

    def __init__(self, dim1=64 * 3, dim2=64 * 3, bias=False):
        super(compute_g_spaNew, self).__init__()
        self.dim1 = dim1
        self.dim2 = dim2
        self.g1 = cnn1x1(self.dim1, self.dim2, bias=bias)
        self.g2 = cnn1x1(self.dim1, self.dim2, bias=bias)
        self.softmax = nn.Softmax(dim=-1)

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


Measured latency_ms: 0.032003