import torch
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__log_softmax__softmax_0(in_ptr0, out_ptr0, out_ptr1,
    out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x4 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    x3 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x4, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp10 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp13 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tmp12 = triton_helpers.maximum(tmp10, tmp11)
    tmp14 = triton_helpers.maximum(tmp12, tmp13)
    tmp16 = triton_helpers.maximum(tmp14, tmp15)
    tmp17 = tmp0 - tmp16
    tmp18 = tl_math.exp(tmp17)
    tl.store(out_ptr0 + x4, tmp9, xmask)
    tl.store(out_ptr1 + x4, tmp8, xmask)
    tl.store(out_ptr2 + x4, tmp18, xmask)
    tl.store(out_ptr3 + x4, tmp17, xmask)


@triton.jit
def triton_per_fused__log_softmax__softmax_div_mul_sub_sum_1(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    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)
    r3 = rindex
    r0 = rindex % 4
    r2 = rindex // 16
    r4 = rindex // 4
    tmp0 = tl.load(in_ptr0 + r3, None)
    tmp1 = tl.load(in_ptr0 + (r0 + 16 * r2), None, eviction_policy='evict_last'
        )
    tmp2 = tl.load(in_ptr0 + (4 + r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (8 + r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (12 + r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp9 = tl.load(in_ptr1 + r3, None)
    tmp10 = tl.load(in_ptr1 + (r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr1 + (4 + r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr1 + (8 + r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp18 = tl.load(in_ptr1 + (12 + r0 + 16 * r2), None, eviction_policy=
        'evict_last')
    tmp27 = tl.load(in_ptr2 + r3, None)
    tmp28 = tl.load(in_ptr2 + 4 * r4, None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr2 + (1 + 4 * r4), None, eviction_policy='evict_last')
    tmp31 = tl.load(in_ptr2 + (2 + 4 * r4), None, eviction_policy='evict_last')
    tmp33 = tl.load(in_ptr2 + (3 + 4 * r4), None, eviction_policy='evict_last')
    tmp36 = tl.load(in_ptr3 + r3, None)
    tmp37 = tl.load(in_ptr3 + 4 * r4, None, eviction_policy='evict_last')
    tmp39 = tl.load(in_ptr3 + (1 + 4 * r4), None, eviction_policy='evict_last')
    tmp42 = tl.load(in_ptr3 + (2 + 4 * r4), None, eviction_policy='evict_last')
    tmp45 = tl.load(in_ptr3 + (3 + 4 * r4), None, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tmp11 = tl_math.exp(tmp10)
    tmp13 = tl_math.exp(tmp12)
    tmp14 = tmp11 + tmp13
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp14 + tmp16
    tmp19 = tl_math.exp(tmp18)
    tmp20 = tmp17 + tmp19
    tmp21 = tl_math.log(tmp20)
    tmp22 = tmp9 - tmp21
    tmp23 = tmp8 * tmp22
    tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
    tmp26 = tl.sum(tmp24, 1)[:, None]
    tmp30 = tmp28 + tmp29
    tmp32 = tmp30 + tmp31
    tmp34 = tmp32 + tmp33
    tmp35 = tmp27 / tmp34
    tmp38 = tl_math.exp(tmp37)
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp38 + tmp40
    tmp43 = tl_math.exp(tmp42)
    tmp44 = tmp41 + tmp43
    tmp46 = tl_math.exp(tmp45)
    tmp47 = tmp44 + tmp46
    tmp48 = tl_math.log(tmp47)
    tmp49 = tmp36 - tmp48
    tmp50 = tmp35 * tmp49
    tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK])
    tmp53 = tl.sum(tmp51, 1)[:, None]
    tmp54 = -1.0
    tmp55 = tmp26 * tmp54
    tmp56 = tmp55 - tmp53
    tmp57 = 0.0625
    tmp58 = tmp56 * tmp57
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp58, None)


def call(args):
    arg0_1, = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__log_softmax__softmax_0[grid(64)](arg0_1, buf0,
            buf1, buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del arg0_1
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf8 = buf3
        del buf3
        triton_per_fused__log_softmax__softmax_div_mul_sub_sum_1[grid(1)](buf8,
            buf0, buf1, buf4, buf5, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del buf0
        del buf1
        del buf4
        del buf5
    return buf8,


class EntropyNew(nn.Module):

    def __init__(self):
        super(EntropyNew, self).__init__()

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


Measured latency_ms: 0.033374