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
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    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]
    tl.full([XBLOCK, YBLOCK], True, tl.int1)
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4096
    y1 = yindex // 4096
    tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), None, eviction_policy=
        'evict_last')
    tl.store(out_ptr0 + (y0 + 4096 * x2 + 16777216 * y1), tmp0, None)


@triton.jit
def triton_poi_fused__to_copy_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 384
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.16666666666666666
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp9, xmask)


@triton.jit
def triton_poi_fused_add_clamp_2(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 384
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.16666666666666666
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tl.full([1], 1, tl.int64)
    tmp11 = tmp9 + tmp10
    tmp12 = tl.full([1], 63, tl.int64)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tl.store(out_ptr0 + x0, tmp13, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3(out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 384
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.16666666666666666
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 - tmp10
    tmp12 = triton_helpers.maximum(tmp11, tmp7)
    tmp13 = 1.0
    tmp14 = triton_helpers.minimum(tmp12, tmp13)
    tl.store(out_ptr0 + x0, tmp14, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_add_mul_sub_4(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, xnumel, XBLOCK:
    tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 384 % 384
    x0 = xindex % 384
    x2 = xindex // 147456 % 150
    x3 = xindex // 22118400
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr5 + x1, None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last')
    tmp1 = tl.full([XBLOCK], 64, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tmp6 = tmp5 + tmp1
    tmp7 = tmp5 < 0
    tmp8 = tl.where(tmp7, tmp6, tmp5)
    tmp9 = tl.load(in_ptr2 + (x2 + 150 * tmp8 + 9600 * tmp4 + 614400 * x3),
        None, eviction_policy='evict_last')
    tmp11 = tmp10 + tmp1
    tmp12 = tmp10 < 0
    tmp13 = tl.where(tmp12, tmp11, tmp10)
    tmp14 = tl.load(in_ptr2 + (x2 + 150 * tmp13 + 9600 * tmp4 + 614400 * x3
        ), None, eviction_policy='evict_last')
    tmp15 = tmp14 - tmp9
    tmp17 = tmp15 * tmp16
    tmp18 = tmp9 + tmp17
    tmp20 = tmp19 + tmp1
    tmp21 = tmp19 < 0
    tmp22 = tl.where(tmp21, tmp20, tmp19)
    tmp23 = tl.load(in_ptr2 + (x2 + 150 * tmp8 + 9600 * tmp22 + 614400 * x3
        ), None, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr2 + (x2 + 150 * tmp13 + 9600 * tmp22 + 614400 *
        x3), None, eviction_policy='evict_last')
    tmp25 = tmp24 - tmp23
    tmp26 = tmp25 * tmp16
    tmp27 = tmp23 + tmp26
    tmp28 = tmp27 - tmp18
    tmp30 = tmp28 * tmp29
    tmp31 = tmp18 + tmp30
    tl.store(in_out_ptr0 + x5, tmp31, None)


@triton.jit
def triton_red_fused__log_softmax_5(in_ptr0, out_ptr0, out_ptr1, xnumel,
    rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
    rnumel = 150
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rbase = tl.arange(0, RBLOCK)[None, :]
    x0 = xindex % 147456
    x1 = xindex // 147456
    _tmp2 = tl.full([XBLOCK, RBLOCK], float('-inf'), tl.float32)
    x3 = xindex
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (x0 + 147456 * r2 + 22118400 * x1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
        tmp3 = triton_helpers.maximum(_tmp2, tmp1)
        _tmp2 = tl.where(rmask, tmp3, _tmp2)
    tmp2 = triton_helpers.max2(_tmp2, 1)[:, None]
    tl.store(out_ptr0 + x3, tmp2, None)
    _tmp8 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp4 = tl.load(in_ptr0 + (x0 + 147456 * r2 + 22118400 * x1), rmask,
            eviction_policy='evict_first', other=0.0)
        tmp5 = tmp4 - tmp2
        tmp6 = tl_math.exp(tmp5)
        tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
        tmp9 = _tmp8 + tmp7
        _tmp8 = tl.where(rmask, tmp9, _tmp8)
    tmp8 = tl.sum(_tmp8, 1)[:, None]
    tl.store(out_ptr1 + x3, tmp8, None)


@triton.jit
def triton_poi_fused__log_softmax_6(in_out_ptr0, in_ptr0, in_ptr1, 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 % 147456
    x2 = xindex // 22118400
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + (x0 + 147456 * x2), None, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_ptr1 + (x0 + 147456 * x2), None, eviction_policy=
        'evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tl_math.log(tmp3)
    tmp5 = tmp2 - tmp4
    tl.store(in_out_ptr0 + x3, tmp5, None)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (150, 4096, 1, 1), (4096, 1, 1, 1))
    assert_size_stride(primals_2, (4, 4096, 64, 64), (16777216, 4096, 64, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4096, 64, 64), (16777216, 1, 262144, 
            4096), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_0[grid(16384, 4096)](primals_2, buf0, 16384, 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, 150, 64, 64), (614400, 1, 9600, 150))
        buf2 = empty_strided_cuda((384, 1), (1, 1), torch.int64)
        triton_poi_fused__to_copy_1[grid(384)](buf2, 384, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((384, 1), (1, 1), torch.int64)
        triton_poi_fused_add_clamp_2[grid(384)](buf3, 384, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf4 = empty_strided_cuda((384,), (1,), torch.int64)
        triton_poi_fused__to_copy_1[grid(384)](buf4, 384, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf5 = empty_strided_cuda((384,), (1,), torch.int64)
        triton_poi_fused_add_clamp_2[grid(384)](buf5, 384, XBLOCK=256,
            num_warps=4, num_stages=1)
        buf6 = empty_strided_cuda((384,), (1,), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3[grid(384)](buf6,
            384, XBLOCK=256, num_warps=4, num_stages=1)
        buf8 = empty_strided_cuda((384, 1), (1, 1), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3[grid(384)](buf8,
            384, XBLOCK=256, num_warps=4, num_stages=1)
        buf7 = empty_strided_cuda((4, 150, 384, 384), (22118400, 147456, 
            384, 1), torch.float32)
        buf9 = buf7
        del buf7
        triton_poi_fused__unsafe_index_add_mul_sub_4[grid(88473600)](buf9,
            buf2, buf4, buf1, buf5, buf6, buf3, buf8, 88473600, XBLOCK=512,
            num_warps=8, num_stages=1)
        del buf1
        buf10 = empty_strided_cuda((4, 1, 384, 384), (147456, 589824, 384, 
            1), torch.float32)
        buf11 = empty_strided_cuda((4, 1, 384, 384), (147456, 589824, 384, 
            1), torch.float32)
        triton_red_fused__log_softmax_5[grid(589824)](buf9, buf10, buf11, 
            589824, 150, XBLOCK=64, RBLOCK=64, num_warps=16, num_stages=1)
        buf12 = buf9
        del buf9
        triton_poi_fused__log_softmax_6[grid(88473600)](buf12, buf10, buf11,
            88473600, XBLOCK=1024, num_warps=4, num_stages=1)
        del buf10
        del buf11
    return buf12, primals_1, buf0, buf2, buf3, buf4, buf5, buf6, buf8, buf12


class C1BilinearNew(nn.Module):

    def __init__(self, num_class=150, fc_dim=4096, segSize=384, use_softmax
        =False):
        super(C1BilinearNew, self).__init__()
        self.segSize = segSize
        self.use_softmax = use_softmax
        self.conv_last = nn.Conv2d(fc_dim, num_class, 1, 1, 0, bias=False)

    def forward(self, input_0):
        primals_1 = self.conv_last.weight
        primals_2 = input_0
        output = call([primals_1, primals_2])
        return output[0]


Measured latency_ms: 3.74863