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


@triton.jit
def triton_poi_fused_convolution_0(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
    tl.store(in_out_ptr0 + x3, tmp2, None)


@triton.jit
def triton_poi_fused__softmax_convolution_1(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex % 4096
    x1 = xindex // 4096
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16384 * x1), None)
    tmp1 = tl.load(in_ptr1 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp4 = tl.load(in_ptr0 + (4096 + x0 + 16384 * x1), None)
    tmp5 = tl.load(in_ptr1 + 1)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp9 = tl.load(in_ptr0 + (8192 + x0 + 16384 * x1), None)
    tmp10 = tl.load(in_ptr1 + 2)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp14 = tl.load(in_ptr0 + (12288 + x0 + 16384 * x1), None)
    tmp15 = tl.load(in_ptr1 + 3)
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tmp7 = tmp4 + tmp6
    tmp8 = triton_helpers.maximum(tmp3, tmp7)
    tmp12 = tmp9 + tmp11
    tmp13 = triton_helpers.maximum(tmp8, tmp12)
    tmp17 = tmp14 + tmp16
    tmp18 = triton_helpers.maximum(tmp13, tmp17)
    tmp19 = tmp3 - tmp18
    tmp20 = tl_math.exp(tmp19)
    tmp21 = tmp7 - tmp18
    tmp22 = tl_math.exp(tmp21)
    tmp23 = tmp20 + tmp22
    tmp24 = tmp12 - tmp18
    tmp25 = tl_math.exp(tmp24)
    tmp26 = tmp23 + tmp25
    tmp27 = tmp17 - tmp18
    tmp28 = tl_math.exp(tmp27)
    tmp29 = tmp26 + tmp28
    tl.store(out_ptr0 + x2, tmp18, None)
    tl.store(out_ptr1 + x2, tmp29, None)


@triton.jit
def triton_poi_fused__softmax_convolution_2(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, 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
    x0 = xindex % 4096
    x2 = xindex // 16384
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr2 + (x0 + 4096 * x2), None, eviction_policy=
        'evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 - tmp3
    tmp5 = tl_math.exp(tmp4)
    tmp7 = tmp5 / tmp6
    tl.store(in_out_ptr0 + x3, tmp7, None)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9) = args
    args.clear()
    assert_size_stride(primals_1, (4, 21, 1, 1), (21, 1, 1, 1))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 21, 64, 64), (86016, 4096, 64, 1))
    assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_9, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf1 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_convolution_0[grid(65536)](buf1, primals_2, 65536,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_2
        buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf3 = buf2
        del buf2
        triton_poi_fused_convolution_0[grid(65536)](buf3, primals_5, 65536,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_5
        buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf5 = buf4
        del buf4
        triton_poi_fused_convolution_0[grid(65536)](buf5, primals_7, 65536,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_7
        buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf6, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf7 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1),
            torch.float32)
        buf8 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1),
            torch.float32)
        triton_poi_fused__softmax_convolution_1[grid(16384)](buf6,
            primals_9, buf7, buf8, 16384, XBLOCK=256, num_warps=4, num_stages=1
            )
        buf9 = buf6
        del buf6
        triton_poi_fused__softmax_convolution_2[grid(65536)](buf9,
            primals_9, buf7, buf8, 65536, XBLOCK=256, num_warps=4, num_stages=1
            )
        del buf7
        del buf8
        del primals_9
    return (buf9, primals_1, primals_3, primals_4, primals_6, primals_8,
        buf1, buf3, buf5, buf9)


class ClassifierEndNew(nn.Module):

    def __init__(self, num_classes: 'int'):
        super(ClassifierEndNew, self).__init__()
        self.num_classes = num_classes
        self.fc_net1 = nn.Conv2d(21, self.num_classes, kernel_size=1, stride=1)
        self.fc_net2 = nn.Conv2d(self.num_classes, self.num_classes,
            kernel_size=1, stride=1)
        self.fc_net3 = nn.Conv2d(self.num_classes, self.num_classes,
            kernel_size=1, stride=1)
        self.fc_net4 = nn.Conv2d(self.num_classes, self.num_classes,
            kernel_size=1, stride=1)
        assert self.num_classes > 0, 'The number of classes must be a positive integer.'
        if self.num_classes > 1:
            self.final = nn.Softmax()
        else:
            self.final = nn.Sigmoid()

    def forward(self, input_0):
        primals_1 = self.fc_net1.weight
        primals_2 = self.fc_net1.bias
        primals_4 = self.fc_net2.weight
        primals_5 = self.fc_net2.bias
        primals_6 = self.fc_net3.weight
        primals_7 = self.fc_net3.bias
        primals_8 = self.fc_net4.weight
        primals_9 = self.fc_net4.bias
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9])
        return output[0]


Measured latency_ms: 0.037724