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
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_per_fused__to_copy_div_eq_gather_max_mul_neg_sum_0(in_out_ptr0,
    in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.
    constexpr):
    RBLOCK: tl.constexpr = 16
    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)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr1 + r0, None)
    tmp39 = tl.load(in_ptr2 + r0, None)
    tmp2 = tmp0 > tmp1
    tmp3 = tmp0 == tmp1
    tmp4 = tl.full([1, 1], 0, tl.int64)
    tmp5 = tl.full([1, 1], 1, tl.int64)
    tmp6 = tmp4 < tmp5
    tmp7 = tmp3 & tmp6
    tmp8 = tmp2 | tmp7
    tmp9 = tl.where(tmp8, tmp0, tmp1)
    tmp10 = tl.where(tmp8, tmp4, tmp5)
    tmp12 = tmp9 > tmp11
    tmp13 = tmp9 == tmp11
    tmp14 = tl.full([1, 1], 2, tl.int64)
    tmp15 = tmp10 < tmp14
    tmp16 = tmp13 & tmp15
    tmp17 = tmp12 | tmp16
    tmp18 = tl.where(tmp17, tmp9, tmp11)
    tmp19 = tl.where(tmp17, tmp10, tmp14)
    tmp21 = tmp18 > tmp20
    tmp22 = tmp18 == tmp20
    tmp23 = tl.full([1, 1], 3, tl.int64)
    tmp24 = tmp19 < tmp23
    tmp25 = tmp22 & tmp24
    tmp26 = tmp21 | tmp25
    tl.where(tmp26, tmp18, tmp20)
    tmp28 = tl.where(tmp26, tmp19, tmp23)
    tmp30 = tmp28 == tmp29
    tmp31 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp32 = tmp29 + tmp31
    tmp33 = tmp29 < 0
    tmp34 = tl.where(tmp33, tmp32, tmp29)
    tl.device_assert((0 <= tmp34) & (tmp34 < 4),
        'index out of bounds: 0 <= tmp34 < 4')
    tmp36 = tl.load(in_ptr0 + (tmp34 + 4 * r0), None, eviction_policy=
        'evict_last')
    tmp37 = -tmp36
    tmp38 = tmp37.to(tl.float32)
    tmp40 = tmp38 * tmp39
    tmp41 = tl.broadcast_to(tmp40, [XBLOCK, RBLOCK])
    tmp43 = tl.sum(tmp41, 1)[:, None]
    tmp44 = tl.broadcast_to(tmp39, [XBLOCK, RBLOCK])
    tmp46 = tl.sum(tmp44, 1)[:, None]
    tmp47 = tmp30.to(tl.float32)
    tmp48 = tmp47 * tmp39
    tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK])
    tmp51 = tl.sum(tmp49, 1)[:, None]
    tmp52 = tmp51 / tmp46
    tmp53 = tmp43 / tmp46
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp52, None)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp53, None)


def call(args):
    arg0_1, arg1_1, arg2_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(arg1_1, (4, 4), (4, 1))
    assert_size_stride(arg2_1, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf3 = empty_strided_cuda((), (), torch.float32)
        buf6 = buf3
        del buf3
        buf5 = buf0
        del buf0
        get_raw_stream(0)
        triton_per_fused__to_copy_div_eq_gather_max_mul_neg_sum_0[grid(1)](buf6
            , buf5, arg0_1, arg1_1, arg2_1, 1, 16, XBLOCK=1, num_warps=2,
            num_stages=1)
        del arg0_1
        del arg1_1
        del arg2_1
    return buf5, buf6


def to_contiguous(tensor):
    if tensor.is_contiguous():
        return tensor
    else:
        return tensor.contiguous()


class LSTMClassCriterionNew(nn.Module):

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

    def forward(self, input_0, input_1, input_2):
        arg0_1 = input_0
        arg1_1 = input_1
        arg2_1 = input_2
        output = call([arg0_1, arg1_1, arg2_1])
        return output[0], output[1]


Measured latency_ms: 0.015777