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.triton_helpers import libdevice
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_div_index_put_lift_fresh_mul_reciprocal_sum_0(in_ptr0,
    in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    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), xmask, other=0.0)
    tmp13 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0)
    tmp1 = 0.001
    tmp2 = tmp0 * tmp1
    tmp3 = 0.0
    tmp4 = tmp2 == tmp3
    tmp5 = -1.0
    tmp6 = tl.where(tmp4, tmp5, tmp2)
    tmp7 = tl.full([1, 1], 1, tl.int32)
    tmp8 = tmp7 / tmp6
    tmp9 = 1.0
    tmp10 = tmp8 * tmp9
    tmp11 = tmp10 == tmp5
    tmp12 = tl.where(tmp11, tmp3, tmp10)
    tmp14 = tmp13 * tmp1
    tmp15 = tmp14 == tmp3
    tmp16 = tl.where(tmp15, tmp5, tmp14)
    tmp17 = tmp7 / tmp16
    tmp18 = tmp17 * tmp9
    tmp19 = tmp18 == tmp5
    tmp20 = tl.where(tmp19, tmp3, tmp18)
    tmp21 = tmp12 > tmp3
    tmp22 = tmp21.to(tl.float32)
    tmp23 = tmp12 * tmp22
    tmp24 = tmp20 * tmp22
    tmp25 = tmp23 - tmp24
    tmp26 = tmp25 * tmp25
    tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK])
    tmp29 = tl.where(xmask, tmp27, 0)
    tmp30 = tl.sum(tmp29, 1)[:, None]
    tmp31 = tl.broadcast_to(tmp22, [XBLOCK, RBLOCK])
    tmp33 = tl.where(xmask, tmp31, 0)
    tmp34 = tl.sum(tmp33, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp30, xmask)
    tl.store(out_ptr1 + x0, tmp34, xmask)


@triton.jit
def triton_per_fused_div_mean_sqrt_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    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 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp2 = tmp0 / tmp1
    tmp3 = libdevice.sqrt(tmp2)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
    tmp6 = tl.sum(tmp4, 1)[:, None]
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, None)


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


class iRMSENew(nn.Module):

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

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


Measured latency_ms: 0.01503